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:
3
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 |
#include "qnetworkreplyimpl_p.h" |
|
43 |
#include "qnetworkaccessbackend_p.h" |
|
44 |
#include "qnetworkcookie.h" |
|
45 |
#include "qabstractnetworkcache.h" |
|
46 |
#include "QtCore/qcoreapplication.h" |
|
47 |
#include "QtCore/qdatetime.h" |
|
48 |
#include "QtNetwork/qsslconfiguration.h" |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
49 |
#include "QtNetwork/qnetworksession.h" |
0 | 50 |
#include "qnetworkaccesshttpbackend_p.h" |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
51 |
#include "qnetworkaccessmanager_p.h" |
0 | 52 |
|
53 |
#include <QtCore/QCoreApplication> |
|
54 |
||
55 |
QT_BEGIN_NAMESPACE |
|
56 |
||
57 |
inline QNetworkReplyImplPrivate::QNetworkReplyImplPrivate() |
|
58 |
: backend(0), outgoingData(0), outgoingDataBuffer(0), |
|
59 |
copyDevice(0), |
|
60 |
cacheEnabled(false), cacheSaveDevice(0), |
|
61 |
notificationHandlingPaused(false), |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
62 |
bytesDownloaded(0), lastBytesDownloaded(-1), bytesUploaded(-1), preMigrationDownloaded(-1), |
0 | 63 |
httpStatusCode(0), |
64 |
state(Idle) |
|
65 |
{ |
|
66 |
} |
|
67 |
||
68 |
void QNetworkReplyImplPrivate::_q_startOperation() |
|
69 |
{ |
|
70 |
// ensure this function is only being called once |
|
71 |
if (state == Working) { |
|
72 |
qDebug("QNetworkReplyImpl::_q_startOperation was called more than once"); |
|
73 |
return; |
|
74 |
} |
|
75 |
state = Working; |
|
76 |
||
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
77 |
// note: if that method is called directly, it cannot happen that the backend is 0, |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
78 |
// because we just checked via a qobject_cast that we got a http backend (see |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
79 |
// QNetworkReplyImplPrivate::setup()) |
0 | 80 |
if (!backend) { |
81 |
error(QNetworkReplyImpl::ProtocolUnknownError, |
|
82 |
QCoreApplication::translate("QNetworkReply", "Protocol \"%1\" is unknown").arg(url.scheme())); // not really true!; |
|
83 |
finished(); |
|
84 |
return; |
|
85 |
} |
|
86 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
87 |
#ifndef QT_NO_BEARERMANAGEMENT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
88 |
if (!backend->start()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
89 |
// backend failed to start because the session state is not Connected. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
90 |
// QNetworkAccessManager will call reply->backend->start() again for us when the session |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
91 |
// state changes. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
92 |
state = WaitingForSession; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
93 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
94 |
QNetworkSession *session = manager->d_func()->networkSession; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
95 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
96 |
if (session) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
97 |
Q_Q(QNetworkReplyImpl); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
98 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
99 |
QObject::connect(session, SIGNAL(error(QNetworkSession::SessionError)), |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
100 |
q, SLOT(_q_networkSessionFailed())); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
101 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
102 |
if (!session->isOpen()) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
103 |
session->open(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
104 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
105 |
qWarning("Backend is waiting for QNetworkSession to connect, but there is none!"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
106 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
107 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
108 |
return; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
109 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
110 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
111 |
|
0 | 112 |
if (state != Finished) { |
113 |
if (operation == QNetworkAccessManager::GetOperation) |
|
114 |
pendingNotifications.append(NotifyDownstreamReadyWrite); |
|
115 |
||
116 |
handleNotifications(); |
|
117 |
} |
|
118 |
} |
|
119 |
||
120 |
void QNetworkReplyImplPrivate::_q_copyReadyRead() |
|
121 |
{ |
|
122 |
Q_Q(QNetworkReplyImpl); |
|
123 |
if (state != Working) |
|
124 |
return; |
|
125 |
if (!copyDevice || !q->isOpen()) |
|
126 |
return; |
|
127 |
||
128 |
forever { |
|
129 |
qint64 bytesToRead = nextDownstreamBlockSize(); |
|
130 |
if (bytesToRead == 0) |
|
131 |
// we'll be called again, eventually |
|
132 |
break; |
|
133 |
||
134 |
bytesToRead = qBound<qint64>(1, bytesToRead, copyDevice->bytesAvailable()); |
|
135 |
QByteArray byteData; |
|
136 |
byteData.resize(bytesToRead); |
|
137 |
qint64 bytesActuallyRead = copyDevice->read(byteData.data(), byteData.size()); |
|
138 |
if (bytesActuallyRead == -1) { |
|
139 |
byteData.clear(); |
|
140 |
backendNotify(NotifyCopyFinished); |
|
141 |
break; |
|
142 |
} |
|
143 |
||
144 |
byteData.resize(bytesActuallyRead); |
|
145 |
readBuffer.append(byteData); |
|
146 |
||
147 |
if (!copyDevice->isSequential() && copyDevice->atEnd()) { |
|
148 |
backendNotify(NotifyCopyFinished); |
|
149 |
bytesDownloaded += bytesActuallyRead; |
|
150 |
break; |
|
151 |
} |
|
152 |
||
153 |
bytesDownloaded += bytesActuallyRead; |
|
154 |
} |
|
155 |
||
156 |
if (bytesDownloaded == lastBytesDownloaded) { |
|
157 |
// we didn't read anything |
|
158 |
return; |
|
159 |
} |
|
160 |
||
161 |
lastBytesDownloaded = bytesDownloaded; |
|
162 |
QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
163 |
if (preMigrationDownloaded != Q_INT64_C(-1)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
164 |
totalSize = totalSize.toLongLong() + preMigrationDownloaded; |
0 | 165 |
pauseNotificationHandling(); |
166 |
emit q->downloadProgress(bytesDownloaded, |
|
167 |
totalSize.isNull() ? Q_INT64_C(-1) : totalSize.toLongLong()); |
|
168 |
emit q->readyRead(); |
|
169 |
resumeNotificationHandling(); |
|
170 |
} |
|
171 |
||
172 |
void QNetworkReplyImplPrivate::_q_copyReadChannelFinished() |
|
173 |
{ |
|
174 |
_q_copyReadyRead(); |
|
175 |
} |
|
176 |
||
177 |
void QNetworkReplyImplPrivate::_q_bufferOutgoingDataFinished() |
|
178 |
{ |
|
179 |
Q_Q(QNetworkReplyImpl); |
|
180 |
||
181 |
// make sure this is only called once, ever. |
|
182 |
//_q_bufferOutgoingData may call it or the readChannelFinished emission |
|
183 |
if (state != Buffering) |
|
184 |
return; |
|
185 |
||
186 |
// disconnect signals |
|
187 |
QObject::disconnect(outgoingData, SIGNAL(readyRead()), q, SLOT(_q_bufferOutgoingData())); |
|
188 |
QObject::disconnect(outgoingData, SIGNAL(readChannelFinished()), q, SLOT(_q_bufferOutgoingDataFinished())); |
|
189 |
||
190 |
// finally, start the request |
|
191 |
QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); |
|
192 |
} |
|
193 |
||
194 |
void QNetworkReplyImplPrivate::_q_bufferOutgoingData() |
|
195 |
{ |
|
196 |
Q_Q(QNetworkReplyImpl); |
|
197 |
||
198 |
if (!outgoingDataBuffer) { |
|
199 |
// first call, create our buffer |
|
200 |
outgoingDataBuffer = new QRingBuffer(); |
|
201 |
||
202 |
QObject::connect(outgoingData, SIGNAL(readyRead()), q, SLOT(_q_bufferOutgoingData())); |
|
203 |
QObject::connect(outgoingData, SIGNAL(readChannelFinished()), q, SLOT(_q_bufferOutgoingDataFinished())); |
|
204 |
} |
|
205 |
||
206 |
qint64 bytesBuffered = 0; |
|
207 |
qint64 bytesToBuffer = 0; |
|
208 |
||
209 |
// read data into our buffer |
|
210 |
forever { |
|
211 |
bytesToBuffer = outgoingData->bytesAvailable(); |
|
212 |
// unknown? just try 2 kB, this also ensures we always try to read the EOF |
|
213 |
if (bytesToBuffer <= 0) |
|
214 |
bytesToBuffer = 2*1024; |
|
215 |
||
216 |
char *dst = outgoingDataBuffer->reserve(bytesToBuffer); |
|
217 |
bytesBuffered = outgoingData->read(dst, bytesToBuffer); |
|
218 |
||
219 |
if (bytesBuffered == -1) { |
|
220 |
// EOF has been reached. |
|
221 |
outgoingDataBuffer->chop(bytesToBuffer); |
|
222 |
||
223 |
_q_bufferOutgoingDataFinished(); |
|
224 |
break; |
|
225 |
} else if (bytesBuffered == 0) { |
|
226 |
// nothing read right now, just wait until we get called again |
|
227 |
outgoingDataBuffer->chop(bytesToBuffer); |
|
228 |
||
229 |
break; |
|
230 |
} else { |
|
231 |
// don't break, try to read() again |
|
232 |
outgoingDataBuffer->chop(bytesToBuffer - bytesBuffered); |
|
233 |
} |
|
234 |
} |
|
235 |
} |
|
236 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
237 |
#ifndef QT_NO_BEARERMANAGEMENT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
238 |
void QNetworkReplyImplPrivate::_q_networkSessionConnected() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
239 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
240 |
Q_Q(QNetworkReplyImpl); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
241 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
242 |
if (manager.isNull()) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
243 |
return; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
244 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
245 |
QNetworkSession *session = manager->d_func()->networkSession; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
246 |
if (!session) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
247 |
return; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
248 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
249 |
if (session->state() != QNetworkSession::Connected) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
250 |
return; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
251 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
252 |
switch (state) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
253 |
case QNetworkReplyImplPrivate::Buffering: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
254 |
case QNetworkReplyImplPrivate::Working: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
255 |
case QNetworkReplyImplPrivate::Reconnecting: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
256 |
// Migrate existing downloads to new network connection. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
257 |
migrateBackend(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
258 |
break; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
259 |
case QNetworkReplyImplPrivate::WaitingForSession: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
260 |
// Start waiting requests. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
261 |
QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
262 |
break; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
263 |
default: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
264 |
; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
265 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
266 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
267 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
268 |
void QNetworkReplyImplPrivate::_q_networkSessionFailed() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
269 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
270 |
// Abort waiting replies. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
271 |
if (state == WaitingForSession) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
272 |
state = Working; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
273 |
error(QNetworkReplyImpl::UnknownNetworkError, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
274 |
QCoreApplication::translate("QNetworkReply", "Network session error.")); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
275 |
finished(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
276 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
277 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
278 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
279 |
|
0 | 280 |
void QNetworkReplyImplPrivate::setup(QNetworkAccessManager::Operation op, const QNetworkRequest &req, |
281 |
QIODevice *data) |
|
282 |
{ |
|
283 |
Q_Q(QNetworkReplyImpl); |
|
284 |
||
285 |
outgoingData = data; |
|
286 |
request = req; |
|
287 |
url = request.url(); |
|
288 |
operation = op; |
|
289 |
||
290 |
if (outgoingData && backend) { |
|
291 |
// there is data to be uploaded, e.g. HTTP POST. |
|
292 |
||
293 |
if (!backend->needsResetableUploadData() || !outgoingData->isSequential()) { |
|
294 |
// backend does not need upload buffering or |
|
295 |
// fixed size non-sequential |
|
296 |
// just start the operation |
|
297 |
QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); |
|
298 |
} else { |
|
299 |
bool bufferingDisallowed = |
|
300 |
req.attribute(QNetworkRequest::DoNotBufferUploadDataAttribute, |
|
301 |
false).toBool(); |
|
302 |
||
303 |
if (bufferingDisallowed) { |
|
304 |
// if a valid content-length header for the request was supplied, we can disable buffering |
|
305 |
// if not, we will buffer anyway |
|
306 |
if (req.header(QNetworkRequest::ContentLengthHeader).isValid()) { |
|
307 |
QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); |
|
308 |
} else { |
|
309 |
state = Buffering; |
|
310 |
QMetaObject::invokeMethod(q, "_q_bufferOutgoingData", Qt::QueuedConnection); |
|
311 |
} |
|
312 |
} else { |
|
313 |
// _q_startOperation will be called when the buffering has finished. |
|
314 |
state = Buffering; |
|
315 |
QMetaObject::invokeMethod(q, "_q_bufferOutgoingData", Qt::QueuedConnection); |
|
316 |
} |
|
317 |
} |
|
318 |
} else { |
|
319 |
// No outgoing data (e.g. HTTP GET request) |
|
320 |
// or no backend |
|
321 |
// if no backend, _q_startOperation will handle the error of this |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
322 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
323 |
// for HTTP, we want to send out the request as fast as possible to the network, without |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
324 |
// invoking methods in a QueuedConnection |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
325 |
#ifndef QT_NO_HTTP |
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
326 |
if (qobject_cast<QNetworkAccessHttpBackend *>(backend)) { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
327 |
_q_startOperation(); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
328 |
} else { |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
329 |
QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
330 |
} |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
331 |
#else |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
332 |
QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
333 |
#endif // QT_NO_HTTP |
0 | 334 |
} |
335 |
||
336 |
q->QIODevice::open(QIODevice::ReadOnly); |
|
337 |
} |
|
338 |
||
339 |
void QNetworkReplyImplPrivate::backendNotify(InternalNotifications notification) |
|
340 |
{ |
|
341 |
Q_Q(QNetworkReplyImpl); |
|
342 |
if (!pendingNotifications.contains(notification)) |
|
343 |
pendingNotifications.enqueue(notification); |
|
344 |
||
345 |
if (pendingNotifications.size() == 1) |
|
346 |
QCoreApplication::postEvent(q, new QEvent(QEvent::NetworkReplyUpdated)); |
|
347 |
} |
|
348 |
||
349 |
void QNetworkReplyImplPrivate::handleNotifications() |
|
350 |
{ |
|
351 |
if (notificationHandlingPaused) |
|
352 |
return; |
|
353 |
||
354 |
NotificationQueue current = pendingNotifications; |
|
355 |
pendingNotifications.clear(); |
|
356 |
||
357 |
if (state != Working) |
|
358 |
return; |
|
359 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
360 |
while (state == Working && !current.isEmpty()) { |
0 | 361 |
InternalNotifications notification = current.dequeue(); |
362 |
switch (notification) { |
|
363 |
case NotifyDownstreamReadyWrite: |
|
364 |
if (copyDevice) |
|
365 |
_q_copyReadyRead(); |
|
366 |
else |
|
367 |
backend->downstreamReadyWrite(); |
|
368 |
break; |
|
369 |
||
370 |
case NotifyCloseDownstreamChannel: |
|
371 |
backend->closeDownstreamChannel(); |
|
372 |
break; |
|
373 |
||
374 |
case NotifyCopyFinished: { |
|
375 |
QIODevice *dev = copyDevice; |
|
376 |
copyDevice = 0; |
|
377 |
backend->copyFinished(dev); |
|
378 |
break; |
|
379 |
} |
|
380 |
} |
|
381 |
} |
|
382 |
} |
|
383 |
||
384 |
// Do not handle the notifications while we are emitting downloadProgress |
|
385 |
// or readyRead |
|
386 |
void QNetworkReplyImplPrivate::pauseNotificationHandling() |
|
387 |
{ |
|
388 |
notificationHandlingPaused = true; |
|
389 |
} |
|
390 |
||
391 |
// Resume notification handling |
|
392 |
void QNetworkReplyImplPrivate::resumeNotificationHandling() |
|
393 |
{ |
|
394 |
Q_Q(QNetworkReplyImpl); |
|
395 |
notificationHandlingPaused = false; |
|
396 |
if (pendingNotifications.size() >= 1) |
|
397 |
QCoreApplication::postEvent(q, new QEvent(QEvent::NetworkReplyUpdated)); |
|
398 |
} |
|
399 |
||
400 |
QAbstractNetworkCache *QNetworkReplyImplPrivate::networkCache() const |
|
401 |
{ |
|
402 |
if (!backend) |
|
403 |
return 0; |
|
404 |
return backend->networkCache(); |
|
405 |
} |
|
406 |
||
407 |
void QNetworkReplyImplPrivate::createCache() |
|
408 |
{ |
|
409 |
// check if we can save and if we're allowed to |
|
410 |
if (!networkCache() |
|
411 |
|| !request.attribute(QNetworkRequest::CacheSaveControlAttribute, true).toBool() |
|
412 |
|| request.attribute(QNetworkRequest::CacheLoadControlAttribute, |
|
413 |
QNetworkRequest::PreferNetwork).toInt() |
|
414 |
== QNetworkRequest::AlwaysNetwork) |
|
415 |
return; |
|
416 |
cacheEnabled = true; |
|
417 |
} |
|
418 |
||
419 |
bool QNetworkReplyImplPrivate::isCachingEnabled() const |
|
420 |
{ |
|
421 |
return (cacheEnabled && networkCache() != 0); |
|
422 |
} |
|
423 |
||
424 |
void QNetworkReplyImplPrivate::setCachingEnabled(bool enable) |
|
425 |
{ |
|
426 |
if (!enable && !cacheEnabled) |
|
427 |
return; // nothing to do |
|
428 |
if (enable && cacheEnabled) |
|
429 |
return; // nothing to do either! |
|
430 |
||
431 |
if (enable) { |
|
432 |
if (bytesDownloaded) { |
|
433 |
// refuse to enable in this case |
|
434 |
qCritical("QNetworkReplyImpl: backend error: caching was enabled after some bytes had been written"); |
|
435 |
return; |
|
436 |
} |
|
437 |
||
438 |
createCache(); |
|
439 |
} else { |
|
440 |
// someone told us to turn on, then back off? |
|
441 |
// ok... but you should make up your mind |
|
442 |
qDebug("QNetworkReplyImpl: setCachingEnabled(true) called after setCachingEnabled(false) -- " |
|
443 |
"backend %s probably needs to be fixed", |
|
444 |
backend->metaObject()->className()); |
|
445 |
networkCache()->remove(url); |
|
446 |
cacheSaveDevice = 0; |
|
447 |
cacheEnabled = false; |
|
448 |
} |
|
449 |
} |
|
450 |
||
451 |
void QNetworkReplyImplPrivate::completeCacheSave() |
|
452 |
{ |
|
453 |
if (cacheEnabled && errorCode != QNetworkReplyImpl::NoError) { |
|
454 |
networkCache()->remove(url); |
|
455 |
} else if (cacheEnabled && cacheSaveDevice) { |
|
456 |
networkCache()->insert(cacheSaveDevice); |
|
457 |
} |
|
458 |
cacheSaveDevice = 0; |
|
459 |
cacheEnabled = false; |
|
460 |
} |
|
461 |
||
462 |
void QNetworkReplyImplPrivate::emitUploadProgress(qint64 bytesSent, qint64 bytesTotal) |
|
463 |
{ |
|
464 |
Q_Q(QNetworkReplyImpl); |
|
465 |
bytesUploaded = bytesSent; |
|
466 |
pauseNotificationHandling(); |
|
467 |
emit q->uploadProgress(bytesSent, bytesTotal); |
|
468 |
resumeNotificationHandling(); |
|
469 |
} |
|
470 |
||
471 |
||
472 |
qint64 QNetworkReplyImplPrivate::nextDownstreamBlockSize() const |
|
473 |
{ |
|
474 |
enum { DesiredBufferSize = 32 * 1024 }; |
|
475 |
if (readBufferMaxSize == 0) |
|
476 |
return DesiredBufferSize; |
|
477 |
||
478 |
return qMax<qint64>(0, readBufferMaxSize - readBuffer.byteAmount()); |
|
479 |
} |
|
480 |
||
23
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
481 |
void QNetworkReplyImplPrivate::initCacheSaveDevice() |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
482 |
{ |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
483 |
Q_Q(QNetworkReplyImpl); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
484 |
|
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
485 |
// save the meta data |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
486 |
QNetworkCacheMetaData metaData; |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
487 |
metaData.setUrl(url); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
488 |
metaData = backend->fetchCacheMetaData(metaData); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
489 |
|
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
490 |
// save the redirect request also in the cache |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
491 |
QVariant redirectionTarget = q->attribute(QNetworkRequest::RedirectionTargetAttribute); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
492 |
if (redirectionTarget.isValid()) { |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
493 |
QNetworkCacheMetaData::AttributesMap attributes = metaData.attributes(); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
494 |
attributes.insert(QNetworkRequest::RedirectionTargetAttribute, redirectionTarget); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
495 |
metaData.setAttributes(attributes); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
496 |
} |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
497 |
|
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
498 |
cacheSaveDevice = networkCache()->prepare(metaData); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
499 |
|
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
500 |
if (!cacheSaveDevice || (cacheSaveDevice && !cacheSaveDevice->isOpen())) { |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
501 |
if (cacheSaveDevice && !cacheSaveDevice->isOpen()) |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
502 |
qCritical("QNetworkReplyImpl: network cache returned a device that is not open -- " |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
503 |
"class %s probably needs to be fixed", |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
504 |
networkCache()->metaObject()->className()); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
505 |
|
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
506 |
networkCache()->remove(url); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
507 |
cacheSaveDevice = 0; |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
508 |
cacheEnabled = false; |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
509 |
} |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
510 |
} |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
511 |
|
0 | 512 |
// we received downstream data and send this to the cache |
513 |
// and to our readBuffer (which in turn gets read by the user of QNetworkReply) |
|
514 |
void QNetworkReplyImplPrivate::appendDownstreamData(QByteDataBuffer &data) |
|
515 |
{ |
|
516 |
Q_Q(QNetworkReplyImpl); |
|
517 |
if (!q->isOpen()) |
|
518 |
return; |
|
519 |
||
520 |
if (cacheEnabled && !cacheSaveDevice) { |
|
23
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
521 |
initCacheSaveDevice(); |
0 | 522 |
} |
523 |
||
524 |
qint64 bytesWritten = 0; |
|
525 |
for (int i = 0; i < data.bufferCount(); i++) { |
|
23
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
526 |
QByteArray const &item = data[i]; |
0 | 527 |
|
528 |
if (cacheSaveDevice) |
|
529 |
cacheSaveDevice->write(item.constData(), item.size()); |
|
530 |
readBuffer.append(item); |
|
531 |
||
532 |
bytesWritten += item.size(); |
|
533 |
} |
|
534 |
data.clear(); |
|
535 |
||
536 |
bytesDownloaded += bytesWritten; |
|
537 |
lastBytesDownloaded = bytesDownloaded; |
|
538 |
||
23
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
539 |
appendDownstreamDataSignalEmissions(); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
540 |
} |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
541 |
|
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
542 |
void QNetworkReplyImplPrivate::appendDownstreamDataSignalEmissions() |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
543 |
{ |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
544 |
Q_Q(QNetworkReplyImpl); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
545 |
|
0 | 546 |
QPointer<QNetworkReplyImpl> qq = q; |
547 |
||
548 |
QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
549 |
if (preMigrationDownloaded != Q_INT64_C(-1)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
550 |
totalSize = totalSize.toLongLong() + preMigrationDownloaded; |
0 | 551 |
pauseNotificationHandling(); |
552 |
emit q->downloadProgress(bytesDownloaded, |
|
553 |
totalSize.isNull() ? Q_INT64_C(-1) : totalSize.toLongLong()); |
|
554 |
// important: At the point of this readyRead(), the data parameter list must be empty, |
|
555 |
// else implicit sharing will trigger memcpy when the user is reading data! |
|
556 |
emit q->readyRead(); |
|
557 |
||
558 |
// hopefully we haven't been deleted here |
|
559 |
if (!qq.isNull()) { |
|
560 |
resumeNotificationHandling(); |
|
561 |
// do we still have room in the buffer? |
|
562 |
if (nextDownstreamBlockSize() > 0) |
|
563 |
backendNotify(QNetworkReplyImplPrivate::NotifyDownstreamReadyWrite); |
|
564 |
} |
|
565 |
} |
|
566 |
||
567 |
// this is used when it was fetched from the cache, right? |
|
568 |
void QNetworkReplyImplPrivate::appendDownstreamData(QIODevice *data) |
|
569 |
{ |
|
570 |
Q_Q(QNetworkReplyImpl); |
|
571 |
if (!q->isOpen()) |
|
572 |
return; |
|
573 |
||
574 |
// read until EOF from data |
|
575 |
if (copyDevice) { |
|
576 |
qCritical("QNetworkReplyImpl: copy from QIODevice already in progress -- " |
|
577 |
"backend probly needs to be fixed"); |
|
578 |
return; |
|
579 |
} |
|
580 |
||
581 |
copyDevice = data; |
|
582 |
q->connect(copyDevice, SIGNAL(readyRead()), SLOT(_q_copyReadyRead())); |
|
583 |
q->connect(copyDevice, SIGNAL(readChannelFinished()), SLOT(_q_copyReadChannelFinished())); |
|
584 |
||
585 |
// start the copy: |
|
586 |
_q_copyReadyRead(); |
|
587 |
} |
|
588 |
||
23
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
589 |
void QNetworkReplyImplPrivate::appendDownstreamData(const QByteArray &data) |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
590 |
{ |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
591 |
// TODO implement |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
592 |
|
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
593 |
// TODO call |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
594 |
|
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
595 |
qFatal("QNetworkReplyImplPrivate::appendDownstreamData not implemented"); |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
596 |
} |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
597 |
|
0 | 598 |
void QNetworkReplyImplPrivate::finished() |
599 |
{ |
|
600 |
Q_Q(QNetworkReplyImpl); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
601 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
602 |
if (state == Finished || state == Aborted || state == WaitingForSession) |
0 | 603 |
return; |
604 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
605 |
pauseNotificationHandling(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
606 |
QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
607 |
if (preMigrationDownloaded != Q_INT64_C(-1)) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
608 |
totalSize = totalSize.toLongLong() + preMigrationDownloaded; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
609 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
610 |
if (!manager.isNull()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
611 |
#ifndef QT_NO_BEARERMANAGEMENT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
612 |
QNetworkSession *session = manager->d_func()->networkSession; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
613 |
if (session && session->state() == QNetworkSession::Roaming && |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
614 |
state == Working && errorCode != QNetworkReply::OperationCanceledError) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
615 |
// only content with a known size will fail with a temporary network failure error |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
616 |
if (!totalSize.isNull()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
617 |
if (bytesDownloaded != totalSize) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
618 |
if (migrateBackend()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
619 |
// either we are migrating or the request is finished/aborted |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
620 |
if (state == Reconnecting || state == WaitingForSession) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
621 |
resumeNotificationHandling(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
622 |
return; // exit early if we are migrating. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
623 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
624 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
625 |
error(QNetworkReply::TemporaryNetworkFailureError, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
626 |
QNetworkReply::tr("Temporary network failure.")); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
627 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
628 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
629 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
630 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
631 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
632 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
633 |
resumeNotificationHandling(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
634 |
|
0 | 635 |
state = Finished; |
636 |
pendingNotifications.clear(); |
|
637 |
||
638 |
pauseNotificationHandling(); |
|
639 |
if (totalSize.isNull() || totalSize == -1) { |
|
640 |
emit q->downloadProgress(bytesDownloaded, bytesDownloaded); |
|
641 |
} |
|
642 |
||
643 |
if (bytesUploaded == -1 && (outgoingData || outgoingDataBuffer)) |
|
644 |
emit q->uploadProgress(0, 0); |
|
645 |
resumeNotificationHandling(); |
|
646 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
647 |
// if we don't know the total size of or we received everything save the cache |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
648 |
if (totalSize.isNull() || totalSize == -1 || bytesDownloaded == totalSize) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
649 |
completeCacheSave(); |
0 | 650 |
|
651 |
// note: might not be a good idea, since users could decide to delete us |
|
652 |
// which would delete the backend too... |
|
653 |
// maybe we should protect the backend |
|
654 |
pauseNotificationHandling(); |
|
655 |
emit q->readChannelFinished(); |
|
656 |
emit q->finished(); |
|
657 |
resumeNotificationHandling(); |
|
658 |
} |
|
659 |
||
660 |
void QNetworkReplyImplPrivate::error(QNetworkReplyImpl::NetworkError code, const QString &errorMessage) |
|
661 |
{ |
|
662 |
Q_Q(QNetworkReplyImpl); |
|
663 |
||
664 |
errorCode = code; |
|
665 |
q->setErrorString(errorMessage); |
|
666 |
||
667 |
// note: might not be a good idea, since users could decide to delete us |
|
668 |
// which would delete the backend too... |
|
669 |
// maybe we should protect the backend |
|
670 |
emit q->error(code); |
|
671 |
} |
|
672 |
||
673 |
void QNetworkReplyImplPrivate::metaDataChanged() |
|
674 |
{ |
|
675 |
Q_Q(QNetworkReplyImpl); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
676 |
// 1. do we have cookies? |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
677 |
// 2. are we allowed to set them? |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
678 |
if (cookedHeaders.contains(QNetworkRequest::SetCookieHeader) && !manager.isNull() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
679 |
&& (static_cast<QNetworkRequest::LoadControl> |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
680 |
(request.attribute(QNetworkRequest::CookieSaveControlAttribute, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
681 |
QNetworkRequest::Automatic).toInt()) == QNetworkRequest::Automatic)) { |
0 | 682 |
QList<QNetworkCookie> cookies = |
683 |
qvariant_cast<QList<QNetworkCookie> >(cookedHeaders.value(QNetworkRequest::SetCookieHeader)); |
|
684 |
QNetworkCookieJar *jar = manager->cookieJar(); |
|
685 |
if (jar) |
|
686 |
jar->setCookiesFromUrl(cookies, url); |
|
687 |
} |
|
688 |
emit q->metaDataChanged(); |
|
689 |
} |
|
690 |
||
691 |
void QNetworkReplyImplPrivate::redirectionRequested(const QUrl &target) |
|
692 |
{ |
|
693 |
attributes.insert(QNetworkRequest::RedirectionTargetAttribute, target); |
|
694 |
} |
|
695 |
||
696 |
void QNetworkReplyImplPrivate::sslErrors(const QList<QSslError> &errors) |
|
697 |
{ |
|
698 |
#ifndef QT_NO_OPENSSL |
|
699 |
Q_Q(QNetworkReplyImpl); |
|
700 |
emit q->sslErrors(errors); |
|
701 |
#else |
|
702 |
Q_UNUSED(errors); |
|
703 |
#endif |
|
704 |
} |
|
705 |
||
706 |
bool QNetworkReplyImplPrivate::isFinished() const |
|
707 |
{ |
|
708 |
return (state == Finished || state == Aborted); |
|
709 |
} |
|
710 |
||
711 |
QNetworkReplyImpl::QNetworkReplyImpl(QObject *parent) |
|
712 |
: QNetworkReply(*new QNetworkReplyImplPrivate, parent) |
|
713 |
{ |
|
714 |
} |
|
715 |
||
716 |
QNetworkReplyImpl::~QNetworkReplyImpl() |
|
717 |
{ |
|
718 |
Q_D(QNetworkReplyImpl); |
|
23
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
719 |
|
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
720 |
// This code removes the data from the cache if it was prematurely aborted. |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
721 |
// See QNetworkReplyImplPrivate::completeCacheSave(), we disable caching there after the cache |
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
722 |
// save had been properly finished. So if it is still enabled it means we got deleted/aborted. |
0 | 723 |
if (d->isCachingEnabled()) |
724 |
d->networkCache()->remove(url()); |
|
23
89e065397ea6
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
725 |
|
0 | 726 |
if (d->outgoingDataBuffer) |
727 |
delete d->outgoingDataBuffer; |
|
728 |
} |
|
729 |
||
730 |
void QNetworkReplyImpl::abort() |
|
731 |
{ |
|
732 |
Q_D(QNetworkReplyImpl); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
733 |
if (d->state == QNetworkReplyImplPrivate::Finished || d->state == QNetworkReplyImplPrivate::Aborted) |
0 | 734 |
return; |
735 |
||
736 |
// stop both upload and download |
|
737 |
if (d->outgoingData) |
|
738 |
disconnect(d->outgoingData, 0, this, 0); |
|
739 |
if (d->copyDevice) |
|
740 |
disconnect(d->copyDevice, 0, this, 0); |
|
741 |
||
742 |
QNetworkReply::close(); |
|
743 |
||
744 |
if (d->state != QNetworkReplyImplPrivate::Finished) { |
|
745 |
// emit signals |
|
746 |
d->error(OperationCanceledError, tr("Operation canceled")); |
|
747 |
d->finished(); |
|
748 |
} |
|
749 |
d->state = QNetworkReplyImplPrivate::Aborted; |
|
750 |
||
751 |
// finished may access the backend |
|
752 |
if (d->backend) { |
|
753 |
d->backend->deleteLater(); |
|
754 |
d->backend = 0; |
|
755 |
} |
|
756 |
} |
|
757 |
||
758 |
void QNetworkReplyImpl::close() |
|
759 |
{ |
|
760 |
Q_D(QNetworkReplyImpl); |
|
761 |
if (d->state == QNetworkReplyImplPrivate::Aborted || |
|
762 |
d->state == QNetworkReplyImplPrivate::Finished) |
|
763 |
return; |
|
764 |
||
765 |
// stop the download |
|
766 |
if (d->backend) |
|
767 |
d->backend->closeDownstreamChannel(); |
|
768 |
if (d->copyDevice) |
|
769 |
disconnect(d->copyDevice, 0, this, 0); |
|
770 |
||
771 |
QNetworkReply::close(); |
|
772 |
||
773 |
// emit signals |
|
774 |
d->error(OperationCanceledError, tr("Operation canceled")); |
|
775 |
d->finished(); |
|
776 |
} |
|
777 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
778 |
bool QNetworkReplyImpl::canReadLine () const |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
779 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
780 |
Q_D(const QNetworkReplyImpl); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
781 |
return QNetworkReply::canReadLine() || d->readBuffer.canReadLine(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
782 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
783 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
784 |
|
0 | 785 |
/*! |
786 |
Returns the number of bytes available for reading with |
|
787 |
QIODevice::read(). The number of bytes available may grow until |
|
788 |
the finished() signal is emitted. |
|
789 |
*/ |
|
790 |
qint64 QNetworkReplyImpl::bytesAvailable() const |
|
791 |
{ |
|
792 |
return QNetworkReply::bytesAvailable() + d_func()->readBuffer.byteAmount(); |
|
793 |
} |
|
794 |
||
795 |
void QNetworkReplyImpl::setReadBufferSize(qint64 size) |
|
796 |
{ |
|
797 |
Q_D(QNetworkReplyImpl); |
|
798 |
if (size > d->readBufferMaxSize && |
|
799 |
size > d->readBuffer.byteAmount()) |
|
800 |
d->backendNotify(QNetworkReplyImplPrivate::NotifyDownstreamReadyWrite); |
|
801 |
||
802 |
QNetworkReply::setReadBufferSize(size); |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
803 |
|
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
804 |
if (d->backend) |
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
805 |
d->backend->setDownstreamLimited(d->readBufferMaxSize > 0); |
0 | 806 |
} |
807 |
||
808 |
#ifndef QT_NO_OPENSSL |
|
809 |
QSslConfiguration QNetworkReplyImpl::sslConfigurationImplementation() const |
|
810 |
{ |
|
811 |
Q_D(const QNetworkReplyImpl); |
|
812 |
QSslConfiguration config; |
|
813 |
if (d->backend) |
|
814 |
d->backend->fetchSslConfiguration(config); |
|
815 |
return config; |
|
816 |
} |
|
817 |
||
818 |
void QNetworkReplyImpl::setSslConfigurationImplementation(const QSslConfiguration &config) |
|
819 |
{ |
|
820 |
Q_D(QNetworkReplyImpl); |
|
821 |
if (d->backend && !config.isNull()) |
|
822 |
d->backend->setSslConfiguration(config); |
|
823 |
} |
|
824 |
||
825 |
void QNetworkReplyImpl::ignoreSslErrors() |
|
826 |
{ |
|
827 |
Q_D(QNetworkReplyImpl); |
|
828 |
if (d->backend) |
|
829 |
d->backend->ignoreSslErrors(); |
|
830 |
} |
|
831 |
||
832 |
void QNetworkReplyImpl::ignoreSslErrorsImplementation(const QList<QSslError> &errors) |
|
833 |
{ |
|
834 |
Q_D(QNetworkReplyImpl); |
|
835 |
if (d->backend) |
|
836 |
d->backend->ignoreSslErrors(errors); |
|
837 |
} |
|
838 |
#endif // QT_NO_OPENSSL |
|
839 |
||
840 |
/*! |
|
841 |
\internal |
|
842 |
*/ |
|
843 |
qint64 QNetworkReplyImpl::readData(char *data, qint64 maxlen) |
|
844 |
{ |
|
845 |
Q_D(QNetworkReplyImpl); |
|
846 |
if (d->readBuffer.isEmpty()) |
|
847 |
return d->state == QNetworkReplyImplPrivate::Finished ? -1 : 0; |
|
848 |
||
849 |
d->backendNotify(QNetworkReplyImplPrivate::NotifyDownstreamReadyWrite); |
|
850 |
if (maxlen == 1) { |
|
851 |
// optimization for getChar() |
|
852 |
*data = d->readBuffer.getChar(); |
|
853 |
return 1; |
|
854 |
} |
|
855 |
||
856 |
maxlen = qMin<qint64>(maxlen, d->readBuffer.byteAmount()); |
|
857 |
return d->readBuffer.read(data, maxlen); |
|
858 |
} |
|
859 |
||
860 |
/*! |
|
861 |
\internal Reimplemented for internal purposes |
|
862 |
*/ |
|
863 |
bool QNetworkReplyImpl::event(QEvent *e) |
|
864 |
{ |
|
865 |
if (e->type() == QEvent::NetworkReplyUpdated) { |
|
866 |
d_func()->handleNotifications(); |
|
867 |
return true; |
|
868 |
} |
|
869 |
||
870 |
return QObject::event(e); |
|
871 |
} |
|
872 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
873 |
/* |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
874 |
Migrates the backend of the QNetworkReply to a new network connection if required. Returns |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
875 |
true if the reply is migrated or it is not required; otherwise returns false. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
876 |
*/ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
877 |
bool QNetworkReplyImplPrivate::migrateBackend() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
878 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
879 |
Q_Q(QNetworkReplyImpl); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
880 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
881 |
// Network reply is already finished or aborted, don't need to migrate. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
882 |
if (state == Finished || state == Aborted) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
883 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
884 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
885 |
// Backend does not support resuming download. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
886 |
if (!backend->canResume()) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
887 |
return false; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
888 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
889 |
// Request has outgoing data, not migrating. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
890 |
if (outgoingData) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
891 |
return false; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
892 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
893 |
// Request is serviced from the cache, don't need to migrate. |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
894 |
if (copyDevice) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
895 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
896 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
897 |
state = QNetworkReplyImplPrivate::Reconnecting; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
898 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
899 |
if (backend) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
900 |
delete backend; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
901 |
backend = 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
902 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
903 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
904 |
cookedHeaders.clear(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
905 |
rawHeaders.clear(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
906 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
907 |
preMigrationDownloaded = bytesDownloaded; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
908 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
909 |
backend = manager->d_func()->findBackend(operation, request); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
910 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
911 |
if (backend) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
912 |
backend->setParent(q); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
913 |
backend->reply = this; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
914 |
backend->setResumeOffset(bytesDownloaded); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
915 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
916 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
917 |
#ifndef QT_NO_HTTP |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
918 |
if (qobject_cast<QNetworkAccessHttpBackend *>(backend)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
919 |
_q_startOperation(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
920 |
} else { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
921 |
QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
922 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
923 |
#else |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
924 |
QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
925 |
#endif // QT_NO_HTTP |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
926 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
927 |
return true; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
928 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
929 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
930 |
#ifndef QT_NO_BEARERMANAGEMENT |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
931 |
QDisabledNetworkReply::QDisabledNetworkReply(QObject *parent, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
932 |
const QNetworkRequest &req, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
933 |
QNetworkAccessManager::Operation op) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
934 |
: QNetworkReply(parent) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
935 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
936 |
setRequest(req); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
937 |
setUrl(req.url()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
938 |
setOperation(op); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
939 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
940 |
qRegisterMetaType<QNetworkReply::NetworkError>("QNetworkReply::NetworkError"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
941 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
942 |
QString msg = QCoreApplication::translate("QNetworkAccessManager", |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
943 |
"Network access is disabled."); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
944 |
setError(UnknownNetworkError, msg); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
945 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
946 |
QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
947 |
Q_ARG(QNetworkReply::NetworkError, UnknownNetworkError)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
948 |
QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
949 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
950 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
951 |
QDisabledNetworkReply::~QDisabledNetworkReply() |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
952 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
953 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
954 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
23
diff
changeset
|
955 |
|
0 | 956 |
QT_END_NAMESPACE |
957 |
||
958 |
#include "moc_qnetworkreplyimpl_p.cpp" |
|
959 |