Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/access/qnetworkreplyimpl.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||||||||
2 | ** | - | ||||||||||||||||||
3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
5 | ** | - | ||||||||||||||||||
6 | ** This file is part of the QtNetwork module of the Qt Toolkit. | - | ||||||||||||||||||
7 | ** | - | ||||||||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
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 The Qt Company. For licensing terms | - | ||||||||||||||||||
14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
15 | ** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free | - | ||||||||||||||||||
20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
25 | ** | - | ||||||||||||||||||
26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
29 | ** | - | ||||||||||||||||||
30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
31 | ** | - | ||||||||||||||||||
32 | ****************************************************************************/ | - | ||||||||||||||||||
33 | - | |||||||||||||||||||
34 | #include "qnetworkreplyimpl_p.h" | - | ||||||||||||||||||
35 | #include "qnetworkaccessbackend_p.h" | - | ||||||||||||||||||
36 | #include "qnetworkcookie.h" | - | ||||||||||||||||||
37 | #include "qnetworkcookiejar.h" | - | ||||||||||||||||||
38 | #include "qabstractnetworkcache.h" | - | ||||||||||||||||||
39 | #include "QtCore/qcoreapplication.h" | - | ||||||||||||||||||
40 | #include "QtCore/qdatetime.h" | - | ||||||||||||||||||
41 | #include "QtNetwork/qsslconfiguration.h" | - | ||||||||||||||||||
42 | #include "QtNetwork/qnetworksession.h" | - | ||||||||||||||||||
43 | #include "qnetworkaccessmanager_p.h" | - | ||||||||||||||||||
44 | - | |||||||||||||||||||
45 | #include <QtCore/QCoreApplication> | - | ||||||||||||||||||
46 | - | |||||||||||||||||||
47 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
48 | - | |||||||||||||||||||
49 | inline QNetworkReplyImplPrivate::QNetworkReplyImplPrivate() | - | ||||||||||||||||||
50 | : backend(0), outgoingData(0), | - | ||||||||||||||||||
51 | copyDevice(0), | - | ||||||||||||||||||
52 | cacheEnabled(false), cacheSaveDevice(0), | - | ||||||||||||||||||
53 | notificationHandlingPaused(false), | - | ||||||||||||||||||
54 | bytesDownloaded(0), lastBytesDownloaded(-1), bytesUploaded(-1), preMigrationDownloaded(-1), | - | ||||||||||||||||||
55 | httpStatusCode(0), | - | ||||||||||||||||||
56 | state(Idle) | - | ||||||||||||||||||
57 | , downloadBufferReadPosition(0) | - | ||||||||||||||||||
58 | , downloadBufferCurrentSize(0) | - | ||||||||||||||||||
59 | , downloadBufferMaximumSize(0) | - | ||||||||||||||||||
60 | , downloadBuffer(0) | - | ||||||||||||||||||
61 | { | - | ||||||||||||||||||
62 | if (request.attribute(QNetworkRequest::EmitAllUploadProgressSignalsAttribute).toBool() == true)
| 0-122 | ||||||||||||||||||
63 | emitAllUploadProgressSignals = true; never executed: emitAllUploadProgressSignals = true; | 0 | ||||||||||||||||||
64 | } executed 122 times by 3 tests: end of block Executed by:
| 122 | ||||||||||||||||||
65 | - | |||||||||||||||||||
66 | void QNetworkReplyImplPrivate::_q_startOperation() | - | ||||||||||||||||||
67 | { | - | ||||||||||||||||||
68 | // ensure this function is only being called once | - | ||||||||||||||||||
69 | if (state == Working || state == Finished) {
| 0-124 | ||||||||||||||||||
70 | qDebug("QNetworkReplyImpl::_q_startOperation was called more than once"); | - | ||||||||||||||||||
71 | return; never executed: return; | 0 | ||||||||||||||||||
72 | } | - | ||||||||||||||||||
73 | state = Working; | - | ||||||||||||||||||
74 | - | |||||||||||||||||||
75 | // note: if that method is called directly, it cannot happen that the backend is 0, | - | ||||||||||||||||||
76 | // because we just checked via a qobject_cast that we got a http backend (see | - | ||||||||||||||||||
77 | // QNetworkReplyImplPrivate::setup()) | - | ||||||||||||||||||
78 | if (!backend) {
| 4-120 | ||||||||||||||||||
79 | error(QNetworkReplyImpl::ProtocolUnknownError, | - | ||||||||||||||||||
80 | QCoreApplication::translate("QNetworkReply", "Protocol \"%1\" is unknown").arg(url.scheme())); // not really true!; | - | ||||||||||||||||||
81 | finished(); | - | ||||||||||||||||||
82 | return; executed 4 times by 1 test: return; Executed by:
| 4 | ||||||||||||||||||
83 | } | - | ||||||||||||||||||
84 | - | |||||||||||||||||||
85 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
86 | Q_Q(QNetworkReplyImpl); | - | ||||||||||||||||||
87 | // Do not start background requests if they are not allowed by session policy | - | ||||||||||||||||||
88 | QSharedPointer<QNetworkSession> session(manager->d_func()->getNetworkSession()); | - | ||||||||||||||||||
89 | QVariant isBackground = backend->request().attribute(QNetworkRequest::BackgroundRequestAttribute, QVariant::fromValue(false)); | - | ||||||||||||||||||
90 | if (isBackground.toBool() && session && session->usagePolicies().testFlag(QNetworkSession::NoBackgroundTrafficPolicy)) {
| 0-115 | ||||||||||||||||||
91 | error(QNetworkReply::BackgroundRequestNotAllowedError, | - | ||||||||||||||||||
92 | QCoreApplication::translate("QNetworkReply", "Background request not allowed.")); | - | ||||||||||||||||||
93 | finished(); | - | ||||||||||||||||||
94 | return; executed 1 time by 1 test: return; Executed by:
| 1 | ||||||||||||||||||
95 | } | - | ||||||||||||||||||
96 | #endif | - | ||||||||||||||||||
97 | - | |||||||||||||||||||
98 | if (!backend->start()) {
| 3-116 | ||||||||||||||||||
99 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
100 | // backend failed to start because the session state is not Connected. | - | ||||||||||||||||||
101 | // QNetworkAccessManager will call _q_startOperation again for us when the session | - | ||||||||||||||||||
102 | // state changes. | - | ||||||||||||||||||
103 | state = WaitingForSession; | - | ||||||||||||||||||
104 | - | |||||||||||||||||||
105 | if (session) {
| 0-3 | ||||||||||||||||||
106 | QObject::connect(session.data(), SIGNAL(error(QNetworkSession::SessionError)), | - | ||||||||||||||||||
107 | q, SLOT(_q_networkSessionFailed())); | - | ||||||||||||||||||
108 | - | |||||||||||||||||||
109 | if (!session->isOpen()) {
| 0-3 | ||||||||||||||||||
110 | session->setSessionProperty(QStringLiteral("ConnectInBackground"), isBackground); executed 3 times by 1 test: return qstring_literal_temp; Executed by:
| 3 | ||||||||||||||||||
111 | session->open(); | - | ||||||||||||||||||
112 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||
113 | } else { executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||
114 | qWarning("Backend is waiting for QNetworkSession to connect, but there is none!"); | - | ||||||||||||||||||
115 | state = Working; | - | ||||||||||||||||||
116 | error(QNetworkReplyImpl::NetworkSessionFailedError, | - | ||||||||||||||||||
117 | QCoreApplication::translate("QNetworkReply", "Network session error.")); | - | ||||||||||||||||||
118 | finished(); | - | ||||||||||||||||||
119 | } never executed: end of block | 0 | ||||||||||||||||||
120 | #else | - | ||||||||||||||||||
121 | qWarning("Backend start failed"); | - | ||||||||||||||||||
122 | state = Working; | - | ||||||||||||||||||
123 | error(QNetworkReplyImpl::UnknownNetworkError, | - | ||||||||||||||||||
124 | QCoreApplication::translate("QNetworkReply", "backend start error.")); | - | ||||||||||||||||||
125 | finished(); | - | ||||||||||||||||||
126 | #endif | - | ||||||||||||||||||
127 | return; executed 3 times by 1 test: return; Executed by:
| 3 | ||||||||||||||||||
128 | } else { | - | ||||||||||||||||||
129 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
130 | if (session) {
| 0-116 | ||||||||||||||||||
131 | QObject::connect(session.data(), SIGNAL(stateChanged(QNetworkSession::State)), | - | ||||||||||||||||||
132 | q, SLOT(_q_networkSessionStateChanged(QNetworkSession::State)), Qt::QueuedConnection); | - | ||||||||||||||||||
133 | } executed 116 times by 2 tests: end of block Executed by:
| 116 | ||||||||||||||||||
134 | #endif | - | ||||||||||||||||||
135 | } executed 116 times by 2 tests: end of block Executed by:
| 116 | ||||||||||||||||||
136 | - | |||||||||||||||||||
137 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
138 | if (session) {
| 0-116 | ||||||||||||||||||
139 | //get notification of policy changes. | - | ||||||||||||||||||
140 | QObject::connect(session.data(), SIGNAL(usagePoliciesChanged(QNetworkSession::UsagePolicies)), | - | ||||||||||||||||||
141 | q, SLOT(_q_networkSessionUsagePoliciesChanged(QNetworkSession::UsagePolicies))); | - | ||||||||||||||||||
142 | } executed 116 times by 2 tests: end of block Executed by:
| 116 | ||||||||||||||||||
143 | #endif | - | ||||||||||||||||||
144 | - | |||||||||||||||||||
145 | // Prepare timer for progress notifications | - | ||||||||||||||||||
146 | downloadProgressSignalChoke.start(); | - | ||||||||||||||||||
147 | uploadProgressSignalChoke.invalidate(); | - | ||||||||||||||||||
148 | - | |||||||||||||||||||
149 | if (backend && backend->isSynchronous()) {
| 0-116 | ||||||||||||||||||
150 | state = Finished; | - | ||||||||||||||||||
151 | q_func()->setFinished(true); | - | ||||||||||||||||||
152 | } else { never executed: end of block | 0 | ||||||||||||||||||
153 | if (state != Finished) {
| 17-99 | ||||||||||||||||||
154 | if (operation == QNetworkAccessManager::GetOperation)
| 40-59 | ||||||||||||||||||
155 | pendingNotifications.append(NotifyDownstreamReadyWrite); executed 40 times by 1 test: pendingNotifications.append(NotifyDownstreamReadyWrite); Executed by:
| 40 | ||||||||||||||||||
156 | - | |||||||||||||||||||
157 | handleNotifications(); | - | ||||||||||||||||||
158 | } executed 99 times by 1 test: end of block Executed by:
| 99 | ||||||||||||||||||
159 | } executed 116 times by 2 tests: end of block Executed by:
| 116 | ||||||||||||||||||
160 | } | - | ||||||||||||||||||
161 | - | |||||||||||||||||||
162 | void QNetworkReplyImplPrivate::_q_copyReadyRead() | - | ||||||||||||||||||
163 | { | - | ||||||||||||||||||
164 | Q_Q(QNetworkReplyImpl); | - | ||||||||||||||||||
165 | if (state != Working)
| 0-9 | ||||||||||||||||||
166 | return; never executed: return; | 0 | ||||||||||||||||||
167 | if (!copyDevice || !q->isOpen())
| 0-9 | ||||||||||||||||||
168 | return; never executed: return; | 0 | ||||||||||||||||||
169 | - | |||||||||||||||||||
170 | // FIXME Optimize to use download buffer if it is a QBuffer. | - | ||||||||||||||||||
171 | // Needs to be done where sendCacheContents() (?) of HTTP is emitting | - | ||||||||||||||||||
172 | // metaDataChanged ? | - | ||||||||||||||||||
173 | - | |||||||||||||||||||
174 | forever { | - | ||||||||||||||||||
175 | qint64 bytesToRead = nextDownstreamBlockSize(); | - | ||||||||||||||||||
176 | if (bytesToRead == 0)
| 0-9 | ||||||||||||||||||
177 | // we'll be called again, eventually | - | ||||||||||||||||||
178 | break; never executed: break; | 0 | ||||||||||||||||||
179 | - | |||||||||||||||||||
180 | bytesToRead = qBound<qint64>(1, bytesToRead, copyDevice->bytesAvailable()); | - | ||||||||||||||||||
181 | QByteArray byteData; | - | ||||||||||||||||||
182 | byteData.resize(bytesToRead); | - | ||||||||||||||||||
183 | qint64 bytesActuallyRead = copyDevice->read(byteData.data(), byteData.size()); | - | ||||||||||||||||||
184 | if (bytesActuallyRead == -1) {
| 0-9 | ||||||||||||||||||
185 | byteData.clear(); | - | ||||||||||||||||||
186 | backendNotify(NotifyCopyFinished); | - | ||||||||||||||||||
187 | break; never executed: break; | 0 | ||||||||||||||||||
188 | } | - | ||||||||||||||||||
189 | - | |||||||||||||||||||
190 | byteData.resize(bytesActuallyRead); | - | ||||||||||||||||||
191 | readBuffer.append(byteData); | - | ||||||||||||||||||
192 | - | |||||||||||||||||||
193 | if (!copyDevice->isSequential() && copyDevice->atEnd()) {
| 0-9 | ||||||||||||||||||
194 | backendNotify(NotifyCopyFinished); | - | ||||||||||||||||||
195 | bytesDownloaded += bytesActuallyRead; | - | ||||||||||||||||||
196 | break; executed 9 times by 2 tests: break; Executed by:
| 9 | ||||||||||||||||||
197 | } | - | ||||||||||||||||||
198 | - | |||||||||||||||||||
199 | bytesDownloaded += bytesActuallyRead; | - | ||||||||||||||||||
200 | } never executed: end of block | 0 | ||||||||||||||||||
201 | - | |||||||||||||||||||
202 | if (bytesDownloaded == lastBytesDownloaded) {
| 0-9 | ||||||||||||||||||
203 | // we didn't read anything | - | ||||||||||||||||||
204 | return; never executed: return; | 0 | ||||||||||||||||||
205 | } | - | ||||||||||||||||||
206 | - | |||||||||||||||||||
207 | lastBytesDownloaded = bytesDownloaded; | - | ||||||||||||||||||
208 | QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); | - | ||||||||||||||||||
209 | if (preMigrationDownloaded != Q_INT64_C(-1))
| 0-9 | ||||||||||||||||||
210 | totalSize = totalSize.toLongLong() + preMigrationDownloaded; never executed: totalSize = totalSize.toLongLong() + preMigrationDownloaded; | 0 | ||||||||||||||||||
211 | pauseNotificationHandling(); | - | ||||||||||||||||||
212 | // emit readyRead before downloadProgress incase this will cause events to be | - | ||||||||||||||||||
213 | // processed and we get into a recursive call (as in QProgressDialog). | - | ||||||||||||||||||
214 | emit q->readyRead(); | - | ||||||||||||||||||
215 | if (downloadProgressSignalChoke.elapsed() >= progressSignalInterval) {
| 0-9 | ||||||||||||||||||
216 | downloadProgressSignalChoke.restart(); | - | ||||||||||||||||||
217 | emit q->downloadProgress(bytesDownloaded, | - | ||||||||||||||||||
218 | totalSize.isNull() ? Q_INT64_C(-1) : totalSize.toLongLong()); | - | ||||||||||||||||||
219 | } never executed: end of block | 0 | ||||||||||||||||||
220 | resumeNotificationHandling(); | - | ||||||||||||||||||
221 | } executed 9 times by 2 tests: end of block Executed by:
| 9 | ||||||||||||||||||
222 | - | |||||||||||||||||||
223 | void QNetworkReplyImplPrivate::_q_copyReadChannelFinished() | - | ||||||||||||||||||
224 | { | - | ||||||||||||||||||
225 | _q_copyReadyRead(); | - | ||||||||||||||||||
226 | } never executed: end of block | 0 | ||||||||||||||||||
227 | - | |||||||||||||||||||
228 | void QNetworkReplyImplPrivate::_q_bufferOutgoingDataFinished() | - | ||||||||||||||||||
229 | { | - | ||||||||||||||||||
230 | Q_Q(QNetworkReplyImpl); | - | ||||||||||||||||||
231 | - | |||||||||||||||||||
232 | // make sure this is only called once, ever. | - | ||||||||||||||||||
233 | //_q_bufferOutgoingData may call it or the readChannelFinished emission | - | ||||||||||||||||||
234 | if (state != Buffering)
| 0 | ||||||||||||||||||
235 | return; never executed: return; | 0 | ||||||||||||||||||
236 | - | |||||||||||||||||||
237 | // disconnect signals | - | ||||||||||||||||||
238 | QObject::disconnect(outgoingData, SIGNAL(readyRead()), q, SLOT(_q_bufferOutgoingData())); | - | ||||||||||||||||||
239 | QObject::disconnect(outgoingData, SIGNAL(readChannelFinished()), q, SLOT(_q_bufferOutgoingDataFinished())); | - | ||||||||||||||||||
240 | - | |||||||||||||||||||
241 | // finally, start the request | - | ||||||||||||||||||
242 | QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); | - | ||||||||||||||||||
243 | } never executed: end of block | 0 | ||||||||||||||||||
244 | - | |||||||||||||||||||
245 | void QNetworkReplyImplPrivate::_q_bufferOutgoingData() | - | ||||||||||||||||||
246 | { | - | ||||||||||||||||||
247 | Q_Q(QNetworkReplyImpl); | - | ||||||||||||||||||
248 | - | |||||||||||||||||||
249 | if (!outgoingDataBuffer) {
| 0 | ||||||||||||||||||
250 | // first call, create our buffer | - | ||||||||||||||||||
251 | outgoingDataBuffer = QSharedPointer<QRingBuffer>::create(); | - | ||||||||||||||||||
252 | - | |||||||||||||||||||
253 | QObject::connect(outgoingData, SIGNAL(readyRead()), q, SLOT(_q_bufferOutgoingData())); | - | ||||||||||||||||||
254 | QObject::connect(outgoingData, SIGNAL(readChannelFinished()), q, SLOT(_q_bufferOutgoingDataFinished())); | - | ||||||||||||||||||
255 | } never executed: end of block | 0 | ||||||||||||||||||
256 | - | |||||||||||||||||||
257 | qint64 bytesBuffered = 0; | - | ||||||||||||||||||
258 | qint64 bytesToBuffer = 0; | - | ||||||||||||||||||
259 | - | |||||||||||||||||||
260 | // read data into our buffer | - | ||||||||||||||||||
261 | forever { | - | ||||||||||||||||||
262 | bytesToBuffer = outgoingData->bytesAvailable(); | - | ||||||||||||||||||
263 | // unknown? just try 2 kB, this also ensures we always try to read the EOF | - | ||||||||||||||||||
264 | if (bytesToBuffer <= 0)
| 0 | ||||||||||||||||||
265 | bytesToBuffer = 2*1024; never executed: bytesToBuffer = 2*1024; | 0 | ||||||||||||||||||
266 | - | |||||||||||||||||||
267 | char *dst = outgoingDataBuffer->reserve(bytesToBuffer); | - | ||||||||||||||||||
268 | bytesBuffered = outgoingData->read(dst, bytesToBuffer); | - | ||||||||||||||||||
269 | - | |||||||||||||||||||
270 | if (bytesBuffered == -1) {
| 0 | ||||||||||||||||||
271 | // EOF has been reached. | - | ||||||||||||||||||
272 | outgoingDataBuffer->chop(bytesToBuffer); | - | ||||||||||||||||||
273 | - | |||||||||||||||||||
274 | _q_bufferOutgoingDataFinished(); | - | ||||||||||||||||||
275 | break; never executed: break; | 0 | ||||||||||||||||||
276 | } else if (bytesBuffered == 0) {
| 0 | ||||||||||||||||||
277 | // nothing read right now, just wait until we get called again | - | ||||||||||||||||||
278 | outgoingDataBuffer->chop(bytesToBuffer); | - | ||||||||||||||||||
279 | - | |||||||||||||||||||
280 | break; never executed: break; | 0 | ||||||||||||||||||
281 | } else { | - | ||||||||||||||||||
282 | // don't break, try to read() again | - | ||||||||||||||||||
283 | outgoingDataBuffer->chop(bytesToBuffer - bytesBuffered); | - | ||||||||||||||||||
284 | } never executed: end of block | 0 | ||||||||||||||||||
285 | } | - | ||||||||||||||||||
286 | } never executed: end of block | 0 | ||||||||||||||||||
287 | - | |||||||||||||||||||
288 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
289 | void QNetworkReplyImplPrivate::_q_networkSessionConnected() | - | ||||||||||||||||||
290 | { | - | ||||||||||||||||||
291 | Q_Q(QNetworkReplyImpl); | - | ||||||||||||||||||
292 | - | |||||||||||||||||||
293 | if (manager.isNull())
| 0-3 | ||||||||||||||||||
294 | return; never executed: return; | 0 | ||||||||||||||||||
295 | - | |||||||||||||||||||
296 | QSharedPointer<QNetworkSession> session = manager->d_func()->getNetworkSession(); | - | ||||||||||||||||||
297 | if (!session)
| 0-3 | ||||||||||||||||||
298 | return; never executed: return; | 0 | ||||||||||||||||||
299 | - | |||||||||||||||||||
300 | if (session->state() != QNetworkSession::Connected)
| 0-3 | ||||||||||||||||||
301 | return; never executed: return; | 0 | ||||||||||||||||||
302 | - | |||||||||||||||||||
303 | switch (state) { | - | ||||||||||||||||||
304 | case QNetworkReplyPrivate::Buffering: never executed: case QNetworkReplyPrivate::Buffering: | 0 | ||||||||||||||||||
305 | case QNetworkReplyPrivate::Working: never executed: case QNetworkReplyPrivate::Working: | 0 | ||||||||||||||||||
306 | case QNetworkReplyPrivate::Reconnecting: never executed: case QNetworkReplyPrivate::Reconnecting: | 0 | ||||||||||||||||||
307 | // Migrate existing downloads to new network connection. | - | ||||||||||||||||||
308 | migrateBackend(); | - | ||||||||||||||||||
309 | break; never executed: break; | 0 | ||||||||||||||||||
310 | case QNetworkReplyPrivate::WaitingForSession: executed 3 times by 1 test: case QNetworkReplyPrivate::WaitingForSession: Executed by:
| 3 | ||||||||||||||||||
311 | // Start waiting requests. | - | ||||||||||||||||||
312 | QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); | - | ||||||||||||||||||
313 | break; executed 3 times by 1 test: break; Executed by:
| 3 | ||||||||||||||||||
314 | default: never executed: default: | 0 | ||||||||||||||||||
315 | ; | - | ||||||||||||||||||
316 | } never executed: end of block | 0 | ||||||||||||||||||
317 | } | - | ||||||||||||||||||
318 | - | |||||||||||||||||||
319 | void QNetworkReplyImplPrivate::_q_networkSessionStateChanged(QNetworkSession::State sessionState) | - | ||||||||||||||||||
320 | { | - | ||||||||||||||||||
321 | if (sessionState == QNetworkSession::Disconnected
| 0 | ||||||||||||||||||
322 | && state != Idle && state != Reconnecting) {
| 0 | ||||||||||||||||||
323 | error(QNetworkReplyImpl::NetworkSessionFailedError, | - | ||||||||||||||||||
324 | QCoreApplication::translate("QNetworkReply", "Network session error.")); | - | ||||||||||||||||||
325 | finished(); | - | ||||||||||||||||||
326 | } never executed: end of block | 0 | ||||||||||||||||||
327 | } never executed: end of block | 0 | ||||||||||||||||||
328 | - | |||||||||||||||||||
329 | void QNetworkReplyImplPrivate::_q_networkSessionFailed() | - | ||||||||||||||||||
330 | { | - | ||||||||||||||||||
331 | // Abort waiting and working replies. | - | ||||||||||||||||||
332 | if (state == WaitingForSession || state == Working) {
| 0 | ||||||||||||||||||
333 | state = Working; | - | ||||||||||||||||||
334 | QSharedPointer<QNetworkSession> session(manager->d_func()->getNetworkSession()); | - | ||||||||||||||||||
335 | QString errorStr; | - | ||||||||||||||||||
336 | if (session)
| 0 | ||||||||||||||||||
337 | errorStr = session->errorString(); never executed: errorStr = session->errorString(); | 0 | ||||||||||||||||||
338 | else | - | ||||||||||||||||||
339 | errorStr = QCoreApplication::translate("QNetworkReply", "Network session error."); never executed: errorStr = QCoreApplication::translate("QNetworkReply", "Network session error."); | 0 | ||||||||||||||||||
340 | error(QNetworkReplyImpl::NetworkSessionFailedError, errorStr); | - | ||||||||||||||||||
341 | finished(); | - | ||||||||||||||||||
342 | } never executed: end of block | 0 | ||||||||||||||||||
343 | } never executed: end of block | 0 | ||||||||||||||||||
344 | - | |||||||||||||||||||
345 | void QNetworkReplyImplPrivate::_q_networkSessionUsagePoliciesChanged(QNetworkSession::UsagePolicies newPolicies) | - | ||||||||||||||||||
346 | { | - | ||||||||||||||||||
347 | if (backend->request().attribute(QNetworkRequest::BackgroundRequestAttribute).toBool()) {
| 2-3 | ||||||||||||||||||
348 | if (newPolicies & QNetworkSession::NoBackgroundTrafficPolicy) {
| 1 | ||||||||||||||||||
349 | // Abort waiting and working replies. | - | ||||||||||||||||||
350 | if (state == WaitingForSession || state == Working) {
| 0-1 | ||||||||||||||||||
351 | state = Working; | - | ||||||||||||||||||
352 | error(QNetworkReply::BackgroundRequestNotAllowedError, | - | ||||||||||||||||||
353 | QCoreApplication::translate("QNetworkReply", "Background request not allowed.")); | - | ||||||||||||||||||
354 | finished(); | - | ||||||||||||||||||
355 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
356 | // ### if backend->canResume(), then we could resume automatically, however no backend supports resuming | - | ||||||||||||||||||
357 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
358 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
359 | } executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||||||||
360 | #endif | - | ||||||||||||||||||
361 | - | |||||||||||||||||||
362 | void QNetworkReplyImplPrivate::setup(QNetworkAccessManager::Operation op, const QNetworkRequest &req, | - | ||||||||||||||||||
363 | QIODevice *data) | - | ||||||||||||||||||
364 | { | - | ||||||||||||||||||
365 | Q_Q(QNetworkReplyImpl); | - | ||||||||||||||||||
366 | - | |||||||||||||||||||
367 | outgoingData = data; | - | ||||||||||||||||||
368 | request = req; | - | ||||||||||||||||||
369 | url = request.url(); | - | ||||||||||||||||||
370 | operation = op; | - | ||||||||||||||||||
371 | - | |||||||||||||||||||
372 | q->QIODevice::open(QIODevice::ReadOnly); | - | ||||||||||||||||||
373 | // Internal code that does a HTTP reply for the synchronous Ajax | - | ||||||||||||||||||
374 | // in Qt WebKit. | - | ||||||||||||||||||
375 | QVariant synchronousHttpAttribute = req.attribute( | - | ||||||||||||||||||
376 | static_cast<QNetworkRequest::Attribute>(QNetworkRequest::SynchronousRequestAttribute)); | - | ||||||||||||||||||
377 | // The synchronous HTTP is a corner case, we will put all upload data in one big QByteArray in the outgoingDataBuffer. | - | ||||||||||||||||||
378 | // Yes, this is not the most efficient thing to do, but on the other hand synchronous XHR needs to die anyway. | - | ||||||||||||||||||
379 | if (synchronousHttpAttribute.toBool() && outgoingData) {
| 0-122 | ||||||||||||||||||
380 | outgoingDataBuffer = QSharedPointer<QRingBuffer>::create(); | - | ||||||||||||||||||
381 | qint64 previousDataSize = 0; | - | ||||||||||||||||||
382 | do { | - | ||||||||||||||||||
383 | previousDataSize = outgoingDataBuffer->size(); | - | ||||||||||||||||||
384 | outgoingDataBuffer->append(outgoingData->readAll()); | - | ||||||||||||||||||
385 | } while (outgoingDataBuffer->size() != previousDataSize); never executed: end of block
| 0 | ||||||||||||||||||
386 | } never executed: end of block | 0 | ||||||||||||||||||
387 | - | |||||||||||||||||||
388 | if (backend)
| 4-118 | ||||||||||||||||||
389 | backend->setSynchronous(synchronousHttpAttribute.toBool()); executed 118 times by 3 tests: backend->setSynchronous(synchronousHttpAttribute.toBool()); Executed by:
| 118 | ||||||||||||||||||
390 | - | |||||||||||||||||||
391 | - | |||||||||||||||||||
392 | if (outgoingData && backend && !backend->isSynchronous()) {
| 0-63 | ||||||||||||||||||
393 | // there is data to be uploaded, e.g. HTTP POST. | - | ||||||||||||||||||
394 | - | |||||||||||||||||||
395 | if (!backend->needsResetableUploadData() || !outgoingData->isSequential()) {
| 0-59 | ||||||||||||||||||
396 | // backend does not need upload buffering or | - | ||||||||||||||||||
397 | // fixed size non-sequential | - | ||||||||||||||||||
398 | // just start the operation | - | ||||||||||||||||||
399 | QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); | - | ||||||||||||||||||
400 | } else { executed 59 times by 1 test: end of block Executed by:
| 59 | ||||||||||||||||||
401 | bool bufferingDisallowed = | - | ||||||||||||||||||
402 | req.attribute(QNetworkRequest::DoNotBufferUploadDataAttribute, | - | ||||||||||||||||||
403 | false).toBool(); | - | ||||||||||||||||||
404 | - | |||||||||||||||||||
405 | if (bufferingDisallowed) {
| 0 | ||||||||||||||||||
406 | // if a valid content-length header for the request was supplied, we can disable buffering | - | ||||||||||||||||||
407 | // if not, we will buffer anyway | - | ||||||||||||||||||
408 | if (req.header(QNetworkRequest::ContentLengthHeader).isValid()) {
| 0 | ||||||||||||||||||
409 | QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); | - | ||||||||||||||||||
410 | } else { never executed: end of block | 0 | ||||||||||||||||||
411 | state = Buffering; | - | ||||||||||||||||||
412 | QMetaObject::invokeMethod(q, "_q_bufferOutgoingData", Qt::QueuedConnection); | - | ||||||||||||||||||
413 | } never executed: end of block | 0 | ||||||||||||||||||
414 | } else { | - | ||||||||||||||||||
415 | // _q_startOperation will be called when the buffering has finished. | - | ||||||||||||||||||
416 | state = Buffering; | - | ||||||||||||||||||
417 | QMetaObject::invokeMethod(q, "_q_bufferOutgoingData", Qt::QueuedConnection); | - | ||||||||||||||||||
418 | } never executed: end of block | 0 | ||||||||||||||||||
419 | } | - | ||||||||||||||||||
420 | } else { | - | ||||||||||||||||||
421 | // for HTTP, we want to send out the request as fast as possible to the network, without | - | ||||||||||||||||||
422 | // invoking methods in a QueuedConnection | - | ||||||||||||||||||
423 | if (backend && backend->isSynchronous())
| 0-59 | ||||||||||||||||||
424 | _q_startOperation(); never executed: _q_startOperation(); | 0 | ||||||||||||||||||
425 | else | - | ||||||||||||||||||
426 | QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); executed 63 times by 3 tests: QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); Executed by:
| 63 | ||||||||||||||||||
427 | } | - | ||||||||||||||||||
428 | } | - | ||||||||||||||||||
429 | - | |||||||||||||||||||
430 | void QNetworkReplyImplPrivate::backendNotify(InternalNotifications notification) | - | ||||||||||||||||||
431 | { | - | ||||||||||||||||||
432 | Q_Q(QNetworkReplyImpl); | - | ||||||||||||||||||
433 | if (!pendingNotifications.contains(notification))
| 403-601 | ||||||||||||||||||
434 | pendingNotifications.enqueue(notification); executed 601 times by 2 tests: pendingNotifications.enqueue(notification); Executed by:
| 601 | ||||||||||||||||||
435 | - | |||||||||||||||||||
436 | if (pendingNotifications.size() == 1)
| 0-1004 | ||||||||||||||||||
437 | QCoreApplication::postEvent(q, new QEvent(QEvent::NetworkReplyUpdated)); executed 1004 times by 2 tests: QCoreApplication::postEvent(q, new QEvent(QEvent::NetworkReplyUpdated)); Executed by:
| 1004 | ||||||||||||||||||
438 | } executed 1004 times by 2 tests: end of block Executed by:
| 1004 | ||||||||||||||||||
439 | - | |||||||||||||||||||
440 | void QNetworkReplyImplPrivate::handleNotifications() | - | ||||||||||||||||||
441 | { | - | ||||||||||||||||||
442 | if (notificationHandlingPaused)
| 0-1133 | ||||||||||||||||||
443 | return; never executed: return; | 0 | ||||||||||||||||||
444 | - | |||||||||||||||||||
445 | NotificationQueue current = pendingNotifications; | - | ||||||||||||||||||
446 | pendingNotifications.clear(); | - | ||||||||||||||||||
447 | - | |||||||||||||||||||
448 | if (state != Working)
| 164-969 | ||||||||||||||||||
449 | return; executed 164 times by 2 tests: return; Executed by:
| 164 | ||||||||||||||||||
450 | - | |||||||||||||||||||
451 | while (state == Working && !current.isEmpty()) {
| 4-1569 | ||||||||||||||||||
452 | InternalNotifications notification = current.dequeue(); | - | ||||||||||||||||||
453 | switch (notification) { | - | ||||||||||||||||||
454 | case NotifyDownstreamReadyWrite: executed 604 times by 1 test: case NotifyDownstreamReadyWrite: Executed by:
| 604 | ||||||||||||||||||
455 | if (copyDevice)
| 0-604 | ||||||||||||||||||
456 | _q_copyReadyRead(); never executed: _q_copyReadyRead(); | 0 | ||||||||||||||||||
457 | else | - | ||||||||||||||||||
458 | backend->downstreamReadyWrite(); executed 604 times by 1 test: backend->downstreamReadyWrite(); Executed by:
| 604 | ||||||||||||||||||
459 | break; executed 604 times by 1 test: break; Executed by:
| 604 | ||||||||||||||||||
460 | - | |||||||||||||||||||
461 | case NotifyCloseDownstreamChannel: never executed: case NotifyCloseDownstreamChannel: | 0 | ||||||||||||||||||
462 | backend->closeDownstreamChannel(); | - | ||||||||||||||||||
463 | break; never executed: break; | 0 | ||||||||||||||||||
464 | - | |||||||||||||||||||
465 | case NotifyCopyFinished: { never executed: case NotifyCopyFinished: | 0 | ||||||||||||||||||
466 | QIODevice *dev = copyDevice; | - | ||||||||||||||||||
467 | copyDevice = 0; | - | ||||||||||||||||||
468 | backend->copyFinished(dev); | - | ||||||||||||||||||
469 | break; never executed: break; | 0 | ||||||||||||||||||
470 | } | - | ||||||||||||||||||
471 | } | - | ||||||||||||||||||
472 | } executed 604 times by 1 test: end of block Executed by:
| 604 | ||||||||||||||||||
473 | } executed 969 times by 1 test: end of block Executed by:
| 969 | ||||||||||||||||||
474 | - | |||||||||||||||||||
475 | // Do not handle the notifications while we are emitting downloadProgress | - | ||||||||||||||||||
476 | // or readyRead | - | ||||||||||||||||||
477 | void QNetworkReplyImplPrivate::pauseNotificationHandling() | - | ||||||||||||||||||
478 | { | - | ||||||||||||||||||
479 | notificationHandlingPaused = true; | - | ||||||||||||||||||
480 | } executed 1620 times by 3 tests: end of block Executed by:
| 1620 | ||||||||||||||||||
481 | - | |||||||||||||||||||
482 | // Resume notification handling | - | ||||||||||||||||||
483 | void QNetworkReplyImplPrivate::resumeNotificationHandling() | - | ||||||||||||||||||
484 | { | - | ||||||||||||||||||
485 | Q_Q(QNetworkReplyImpl); | - | ||||||||||||||||||
486 | notificationHandlingPaused = false; | - | ||||||||||||||||||
487 | if (pendingNotifications.size() >= 1)
| 208-1412 | ||||||||||||||||||
488 | QCoreApplication::postEvent(q, new QEvent(QEvent::NetworkReplyUpdated)); executed 208 times by 2 tests: QCoreApplication::postEvent(q, new QEvent(QEvent::NetworkReplyUpdated)); Executed by:
| 208 | ||||||||||||||||||
489 | } executed 1620 times by 3 tests: end of block Executed by:
| 1620 | ||||||||||||||||||
490 | - | |||||||||||||||||||
491 | QAbstractNetworkCache *QNetworkReplyImplPrivate::networkCache() const | - | ||||||||||||||||||
492 | { | - | ||||||||||||||||||
493 | if (!backend)
| 0-30 | ||||||||||||||||||
494 | return 0; never executed: return 0; | 0 | ||||||||||||||||||
495 | return backend->networkCache(); executed 30 times by 1 test: return backend->networkCache(); Executed by:
| 30 | ||||||||||||||||||
496 | } | - | ||||||||||||||||||
497 | - | |||||||||||||||||||
498 | void QNetworkReplyImplPrivate::createCache() | - | ||||||||||||||||||
499 | { | - | ||||||||||||||||||
500 | // check if we can save and if we're allowed to | - | ||||||||||||||||||
501 | if (!networkCache()
| 0-30 | ||||||||||||||||||
502 | || !request.attribute(QNetworkRequest::CacheSaveControlAttribute, true).toBool())
| 0 | ||||||||||||||||||
503 | return; executed 30 times by 1 test: return; Executed by:
| 30 | ||||||||||||||||||
504 | cacheEnabled = true; | - | ||||||||||||||||||
505 | } never executed: end of block | 0 | ||||||||||||||||||
506 | - | |||||||||||||||||||
507 | bool QNetworkReplyImplPrivate::isCachingEnabled() const | - | ||||||||||||||||||
508 | { | - | ||||||||||||||||||
509 | return (cacheEnabled && networkCache() != 0); executed 122 times by 3 tests: return (cacheEnabled && networkCache() != 0); Executed by:
| 0-122 | ||||||||||||||||||
510 | } | - | ||||||||||||||||||
511 | - | |||||||||||||||||||
512 | void QNetworkReplyImplPrivate::setCachingEnabled(bool enable) | - | ||||||||||||||||||
513 | { | - | ||||||||||||||||||
514 | if (!enable && !cacheEnabled)
| 0-30 | ||||||||||||||||||
515 | return; // nothing to do executed 13 times by 2 tests: return; Executed by:
| 13 | ||||||||||||||||||
516 | if (enable && cacheEnabled)
| 0-30 | ||||||||||||||||||
517 | return; // nothing to do either! never executed: return; | 0 | ||||||||||||||||||
518 | - | |||||||||||||||||||
519 | if (enable) {
| 0-30 | ||||||||||||||||||
520 | if (bytesDownloaded) {
| 0-30 | ||||||||||||||||||
521 | // refuse to enable in this case | - | ||||||||||||||||||
522 | qCritical("QNetworkReplyImpl: backend error: caching was enabled after some bytes had been written"); | - | ||||||||||||||||||
523 | return; never executed: return; | 0 | ||||||||||||||||||
524 | } | - | ||||||||||||||||||
525 | - | |||||||||||||||||||
526 | createCache(); | - | ||||||||||||||||||
527 | } else { executed 30 times by 1 test: end of block Executed by:
| 30 | ||||||||||||||||||
528 | // someone told us to turn on, then back off? | - | ||||||||||||||||||
529 | // ok... but you should make up your mind | - | ||||||||||||||||||
530 | qDebug("QNetworkReplyImpl: setCachingEnabled(true) called after setCachingEnabled(false) -- " | - | ||||||||||||||||||
531 | "backend %s probably needs to be fixed", | - | ||||||||||||||||||
532 | backend->metaObject()->className()); | - | ||||||||||||||||||
533 | networkCache()->remove(url); | - | ||||||||||||||||||
534 | cacheSaveDevice = 0; | - | ||||||||||||||||||
535 | cacheEnabled = false; | - | ||||||||||||||||||
536 | } never executed: end of block | 0 | ||||||||||||||||||
537 | } | - | ||||||||||||||||||
538 | - | |||||||||||||||||||
539 | void QNetworkReplyImplPrivate::completeCacheSave() | - | ||||||||||||||||||
540 | { | - | ||||||||||||||||||
541 | if (cacheEnabled && errorCode != QNetworkReplyImpl::NoError) {
| 0-119 | ||||||||||||||||||
542 | networkCache()->remove(url); | - | ||||||||||||||||||
543 | } else if (cacheEnabled && cacheSaveDevice) { never executed: end of block
| 0-119 | ||||||||||||||||||
544 | networkCache()->insert(cacheSaveDevice); | - | ||||||||||||||||||
545 | } never executed: end of block | 0 | ||||||||||||||||||
546 | cacheSaveDevice = 0; | - | ||||||||||||||||||
547 | cacheEnabled = false; | - | ||||||||||||||||||
548 | } executed 119 times by 3 tests: end of block Executed by:
| 119 | ||||||||||||||||||
549 | - | |||||||||||||||||||
550 | void QNetworkReplyImplPrivate::emitUploadProgress(qint64 bytesSent, qint64 bytesTotal) | - | ||||||||||||||||||
551 | { | - | ||||||||||||||||||
552 | Q_Q(QNetworkReplyImpl); | - | ||||||||||||||||||
553 | bytesUploaded = bytesSent; | - | ||||||||||||||||||
554 | - | |||||||||||||||||||
555 | if (!emitAllUploadProgressSignals) {
| 0-1053 | ||||||||||||||||||
556 | //choke signal emissions, except the first and last signals which are unconditional | - | ||||||||||||||||||
557 | if (uploadProgressSignalChoke.isValid()) {
| 53-1000 | ||||||||||||||||||
558 | if (bytesSent != bytesTotal && uploadProgressSignalChoke.elapsed() < progressSignalInterval) {
| 0-590 | ||||||||||||||||||
559 | return; executed 410 times by 1 test: return; Executed by:
| 410 | ||||||||||||||||||
560 | } | - | ||||||||||||||||||
561 | uploadProgressSignalChoke.restart(); | - | ||||||||||||||||||
562 | } else { executed 590 times by 1 test: end of block Executed by:
| 590 | ||||||||||||||||||
563 | uploadProgressSignalChoke.start(); | - | ||||||||||||||||||
564 | } executed 53 times by 1 test: end of block Executed by:
| 53 | ||||||||||||||||||
565 | } | - | ||||||||||||||||||
566 | - | |||||||||||||||||||
567 | pauseNotificationHandling(); | - | ||||||||||||||||||
568 | emit q->uploadProgress(bytesSent, bytesTotal); | - | ||||||||||||||||||
569 | resumeNotificationHandling(); | - | ||||||||||||||||||
570 | } executed 643 times by 1 test: end of block Executed by:
| 643 | ||||||||||||||||||
571 | - | |||||||||||||||||||
572 | - | |||||||||||||||||||
573 | qint64 QNetworkReplyImplPrivate::nextDownstreamBlockSize() const | - | ||||||||||||||||||
574 | { | - | ||||||||||||||||||
575 | enum { DesiredBufferSize = 32 * 1024 }; | - | ||||||||||||||||||
576 | if (readBufferMaxSize == 0)
| 5-644 | ||||||||||||||||||
577 | return DesiredBufferSize; executed 644 times by 2 tests: return DesiredBufferSize; Executed by:
| 644 | ||||||||||||||||||
578 | - | |||||||||||||||||||
579 | return qMax<qint64>(0, readBufferMaxSize - readBuffer.byteAmount()); executed 5 times by 1 test: return qMax<qint64>(0, readBufferMaxSize - readBuffer.byteAmount()); Executed by:
| 5 | ||||||||||||||||||
580 | } | - | ||||||||||||||||||
581 | - | |||||||||||||||||||
582 | void QNetworkReplyImplPrivate::initCacheSaveDevice() | - | ||||||||||||||||||
583 | { | - | ||||||||||||||||||
584 | Q_Q(QNetworkReplyImpl); | - | ||||||||||||||||||
585 | - | |||||||||||||||||||
586 | // The disk cache does not support partial content, so don't even try to | - | ||||||||||||||||||
587 | // save any such content into the cache. | - | ||||||||||||||||||
588 | if (q->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 206) {
| 0 | ||||||||||||||||||
589 | cacheEnabled = false; | - | ||||||||||||||||||
590 | return; never executed: return; | 0 | ||||||||||||||||||
591 | } | - | ||||||||||||||||||
592 | - | |||||||||||||||||||
593 | // save the meta data | - | ||||||||||||||||||
594 | QNetworkCacheMetaData metaData; | - | ||||||||||||||||||
595 | metaData.setUrl(url); | - | ||||||||||||||||||
596 | metaData = backend->fetchCacheMetaData(metaData); | - | ||||||||||||||||||
597 | - | |||||||||||||||||||
598 | // save the redirect request also in the cache | - | ||||||||||||||||||
599 | QVariant redirectionTarget = q->attribute(QNetworkRequest::RedirectionTargetAttribute); | - | ||||||||||||||||||
600 | if (redirectionTarget.isValid()) {
| 0 | ||||||||||||||||||
601 | QNetworkCacheMetaData::AttributesMap attributes = metaData.attributes(); | - | ||||||||||||||||||
602 | attributes.insert(QNetworkRequest::RedirectionTargetAttribute, redirectionTarget); | - | ||||||||||||||||||
603 | metaData.setAttributes(attributes); | - | ||||||||||||||||||
604 | } never executed: end of block | 0 | ||||||||||||||||||
605 | - | |||||||||||||||||||
606 | cacheSaveDevice = networkCache()->prepare(metaData); | - | ||||||||||||||||||
607 | - | |||||||||||||||||||
608 | if (!cacheSaveDevice || (cacheSaveDevice && !cacheSaveDevice->isOpen())) {
| 0 | ||||||||||||||||||
609 | if (cacheSaveDevice && !cacheSaveDevice->isOpen())
| 0 | ||||||||||||||||||
610 | qCritical("QNetworkReplyImpl: network cache returned a device that is not open -- " never executed: QMessageLogger(__FILE__, 610, __PRETTY_FUNCTION__).critical("QNetworkReplyImpl: network cache returned a device that is not open -- " "class %s probably needs to be fixed", networkCache()->metaObject()->className()); | 0 | ||||||||||||||||||
611 | "class %s probably needs to be fixed", never executed: QMessageLogger(__FILE__, 610, __PRETTY_FUNCTION__).critical("QNetworkReplyImpl: network cache returned a device that is not open -- " "class %s probably needs to be fixed", networkCache()->metaObject()->className()); | 0 | ||||||||||||||||||
612 | networkCache()->metaObject()->className()); never executed: QMessageLogger(__FILE__, 610, __PRETTY_FUNCTION__).critical("QNetworkReplyImpl: network cache returned a device that is not open -- " "class %s probably needs to be fixed", networkCache()->metaObject()->className()); | 0 | ||||||||||||||||||
613 | - | |||||||||||||||||||
614 | networkCache()->remove(url); | - | ||||||||||||||||||
615 | cacheSaveDevice = 0; | - | ||||||||||||||||||
616 | cacheEnabled = false; | - | ||||||||||||||||||
617 | } never executed: end of block | 0 | ||||||||||||||||||
618 | } never executed: end of block | 0 | ||||||||||||||||||
619 | - | |||||||||||||||||||
620 | // we received downstream data and send this to the cache | - | ||||||||||||||||||
621 | // and to our readBuffer (which in turn gets read by the user of QNetworkReply) | - | ||||||||||||||||||
622 | void QNetworkReplyImplPrivate::appendDownstreamData(QByteDataBuffer &data) | - | ||||||||||||||||||
623 | { | - | ||||||||||||||||||
624 | Q_Q(QNetworkReplyImpl); | - | ||||||||||||||||||
625 | if (!q->isOpen())
| 0-602 | ||||||||||||||||||
626 | return; never executed: return; | 0 | ||||||||||||||||||
627 | - | |||||||||||||||||||
628 | if (cacheEnabled && !cacheSaveDevice) {
| 0-602 | ||||||||||||||||||
629 | initCacheSaveDevice(); | - | ||||||||||||||||||
630 | } never executed: end of block | 0 | ||||||||||||||||||
631 | - | |||||||||||||||||||
632 | qint64 bytesWritten = 0; | - | ||||||||||||||||||
633 | for (int i = 0; i < data.bufferCount(); i++) {
| 602 | ||||||||||||||||||
634 | QByteArray const &item = data[i]; | - | ||||||||||||||||||
635 | - | |||||||||||||||||||
636 | if (cacheSaveDevice)
| 0-602 | ||||||||||||||||||
637 | cacheSaveDevice->write(item.constData(), item.size()); never executed: cacheSaveDevice->write(item.constData(), item.size()); | 0 | ||||||||||||||||||
638 | readBuffer.append(item); | - | ||||||||||||||||||
639 | - | |||||||||||||||||||
640 | bytesWritten += item.size(); | - | ||||||||||||||||||
641 | } executed 602 times by 1 test: end of block Executed by:
| 602 | ||||||||||||||||||
642 | data.clear(); | - | ||||||||||||||||||
643 | - | |||||||||||||||||||
644 | bytesDownloaded += bytesWritten; | - | ||||||||||||||||||
645 | lastBytesDownloaded = bytesDownloaded; | - | ||||||||||||||||||
646 | - | |||||||||||||||||||
647 | appendDownstreamDataSignalEmissions(); | - | ||||||||||||||||||
648 | } executed 602 times by 1 test: end of block Executed by:
| 602 | ||||||||||||||||||
649 | - | |||||||||||||||||||
650 | void QNetworkReplyImplPrivate::appendDownstreamDataSignalEmissions() | - | ||||||||||||||||||
651 | { | - | ||||||||||||||||||
652 | Q_Q(QNetworkReplyImpl); | - | ||||||||||||||||||
653 | - | |||||||||||||||||||
654 | QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); | - | ||||||||||||||||||
655 | if (preMigrationDownloaded != Q_INT64_C(-1))
| 0-602 | ||||||||||||||||||
656 | totalSize = totalSize.toLongLong() + preMigrationDownloaded; never executed: totalSize = totalSize.toLongLong() + preMigrationDownloaded; | 0 | ||||||||||||||||||
657 | pauseNotificationHandling(); | - | ||||||||||||||||||
658 | // important: At the point of this readyRead(), the data parameter list must be empty, | - | ||||||||||||||||||
659 | // else implicit sharing will trigger memcpy when the user is reading data! | - | ||||||||||||||||||
660 | emit q->readyRead(); | - | ||||||||||||||||||
661 | // emit readyRead before downloadProgress incase this will cause events to be | - | ||||||||||||||||||
662 | // processed and we get into a recursive call (as in QProgressDialog). | - | ||||||||||||||||||
663 | if (downloadProgressSignalChoke.elapsed() >= progressSignalInterval) {
| 5-597 | ||||||||||||||||||
664 | downloadProgressSignalChoke.restart(); | - | ||||||||||||||||||
665 | emit q->downloadProgress(bytesDownloaded, | - | ||||||||||||||||||
666 | totalSize.isNull() ? Q_INT64_C(-1) : totalSize.toLongLong()); | - | ||||||||||||||||||
667 | } executed 5 times by 1 test: end of block Executed by:
| 5 | ||||||||||||||||||
668 | - | |||||||||||||||||||
669 | resumeNotificationHandling(); | - | ||||||||||||||||||
670 | // do we still have room in the buffer? | - | ||||||||||||||||||
671 | if (nextDownstreamBlockSize() > 0)
| 5-597 | ||||||||||||||||||
672 | backendNotify(QNetworkReplyImplPrivate::NotifyDownstreamReadyWrite); executed 597 times by 1 test: backendNotify(QNetworkReplyImplPrivate::NotifyDownstreamReadyWrite); Executed by:
| 597 | ||||||||||||||||||
673 | } executed 602 times by 1 test: end of block Executed by:
| 602 | ||||||||||||||||||
674 | - | |||||||||||||||||||
675 | // this is used when it was fetched from the cache, right? | - | ||||||||||||||||||
676 | void QNetworkReplyImplPrivate::appendDownstreamData(QIODevice *data) | - | ||||||||||||||||||
677 | { | - | ||||||||||||||||||
678 | Q_Q(QNetworkReplyImpl); | - | ||||||||||||||||||
679 | if (!q->isOpen())
| 0-9 | ||||||||||||||||||
680 | return; never executed: return; | 0 | ||||||||||||||||||
681 | - | |||||||||||||||||||
682 | // read until EOF from data | - | ||||||||||||||||||
683 | if (copyDevice) {
| 0-9 | ||||||||||||||||||
684 | qCritical("QNetworkReplyImpl: copy from QIODevice already in progress -- " | - | ||||||||||||||||||
685 | "backend probly needs to be fixed"); | - | ||||||||||||||||||
686 | return; never executed: return; | 0 | ||||||||||||||||||
687 | } | - | ||||||||||||||||||
688 | - | |||||||||||||||||||
689 | copyDevice = data; | - | ||||||||||||||||||
690 | q->connect(copyDevice, SIGNAL(readyRead()), SLOT(_q_copyReadyRead())); | - | ||||||||||||||||||
691 | q->connect(copyDevice, SIGNAL(readChannelFinished()), SLOT(_q_copyReadChannelFinished())); | - | ||||||||||||||||||
692 | - | |||||||||||||||||||
693 | // start the copy: | - | ||||||||||||||||||
694 | _q_copyReadyRead(); | - | ||||||||||||||||||
695 | } executed 9 times by 2 tests: end of block Executed by:
| 9 | ||||||||||||||||||
696 | - | |||||||||||||||||||
697 | void QNetworkReplyImplPrivate::appendDownstreamData(const QByteArray &data) | - | ||||||||||||||||||
698 | { | - | ||||||||||||||||||
699 | Q_UNUSED(data) | - | ||||||||||||||||||
700 | // TODO implement | - | ||||||||||||||||||
701 | - | |||||||||||||||||||
702 | // TODO call | - | ||||||||||||||||||
703 | - | |||||||||||||||||||
704 | qFatal("QNetworkReplyImplPrivate::appendDownstreamData not implemented"); | - | ||||||||||||||||||
705 | } never executed: end of block | 0 | ||||||||||||||||||
706 | - | |||||||||||||||||||
707 | static void downloadBufferDeleter(char *ptr) | - | ||||||||||||||||||
708 | { | - | ||||||||||||||||||
709 | delete[] ptr; | - | ||||||||||||||||||
710 | } never executed: end of block | 0 | ||||||||||||||||||
711 | - | |||||||||||||||||||
712 | char* QNetworkReplyImplPrivate::getDownloadBuffer(qint64 size) | - | ||||||||||||||||||
713 | { | - | ||||||||||||||||||
714 | Q_Q(QNetworkReplyImpl); | - | ||||||||||||||||||
715 | - | |||||||||||||||||||
716 | if (!downloadBuffer) {
| 0 | ||||||||||||||||||
717 | // We are requested to create it | - | ||||||||||||||||||
718 | // Check attribute() if allocating a buffer of that size can be allowed | - | ||||||||||||||||||
719 | QVariant bufferAllocationPolicy = request.attribute(QNetworkRequest::MaximumDownloadBufferSizeAttribute); | - | ||||||||||||||||||
720 | if (bufferAllocationPolicy.isValid() && bufferAllocationPolicy.toLongLong() >= size) {
| 0 | ||||||||||||||||||
721 | downloadBufferCurrentSize = 0; | - | ||||||||||||||||||
722 | downloadBufferMaximumSize = size; | - | ||||||||||||||||||
723 | downloadBuffer = new char[downloadBufferMaximumSize]; // throws if allocation fails | - | ||||||||||||||||||
724 | downloadBufferPointer = QSharedPointer<char>(downloadBuffer, downloadBufferDeleter); | - | ||||||||||||||||||
725 | - | |||||||||||||||||||
726 | q->setAttribute(QNetworkRequest::DownloadBufferAttribute, QVariant::fromValue<QSharedPointer<char> > (downloadBufferPointer)); | - | ||||||||||||||||||
727 | } never executed: end of block | 0 | ||||||||||||||||||
728 | } never executed: end of block | 0 | ||||||||||||||||||
729 | - | |||||||||||||||||||
730 | return downloadBuffer; never executed: return downloadBuffer; | 0 | ||||||||||||||||||
731 | } | - | ||||||||||||||||||
732 | - | |||||||||||||||||||
733 | void QNetworkReplyImplPrivate::setDownloadBuffer(QSharedPointer<char> sp, qint64 size) | - | ||||||||||||||||||
734 | { | - | ||||||||||||||||||
735 | Q_Q(QNetworkReplyImpl); | - | ||||||||||||||||||
736 | - | |||||||||||||||||||
737 | downloadBufferPointer = sp; | - | ||||||||||||||||||
738 | downloadBuffer = downloadBufferPointer.data(); | - | ||||||||||||||||||
739 | downloadBufferCurrentSize = 0; | - | ||||||||||||||||||
740 | downloadBufferMaximumSize = size; | - | ||||||||||||||||||
741 | q->setAttribute(QNetworkRequest::DownloadBufferAttribute, QVariant::fromValue<QSharedPointer<char> > (downloadBufferPointer)); | - | ||||||||||||||||||
742 | } never executed: end of block | 0 | ||||||||||||||||||
743 | - | |||||||||||||||||||
744 | - | |||||||||||||||||||
745 | void QNetworkReplyImplPrivate::appendDownstreamDataDownloadBuffer(qint64 bytesReceived, qint64 bytesTotal) | - | ||||||||||||||||||
746 | { | - | ||||||||||||||||||
747 | Q_Q(QNetworkReplyImpl); | - | ||||||||||||||||||
748 | if (!q->isOpen())
| 0 | ||||||||||||||||||
749 | return; never executed: return; | 0 | ||||||||||||||||||
750 | - | |||||||||||||||||||
751 | if (cacheEnabled && !cacheSaveDevice)
| 0 | ||||||||||||||||||
752 | initCacheSaveDevice(); never executed: initCacheSaveDevice(); | 0 | ||||||||||||||||||
753 | - | |||||||||||||||||||
754 | if (cacheSaveDevice && bytesReceived == bytesTotal) {
| 0 | ||||||||||||||||||
755 | // if (lastBytesDownloaded == -1) | - | ||||||||||||||||||
756 | // lastBytesDownloaded = 0; | - | ||||||||||||||||||
757 | // cacheSaveDevice->write(downloadBuffer + lastBytesDownloaded, bytesReceived - lastBytesDownloaded); | - | ||||||||||||||||||
758 | - | |||||||||||||||||||
759 | // Write everything in one go if we use a download buffer. might be more performant. | - | ||||||||||||||||||
760 | cacheSaveDevice->write(downloadBuffer, bytesTotal); | - | ||||||||||||||||||
761 | } never executed: end of block | 0 | ||||||||||||||||||
762 | - | |||||||||||||||||||
763 | bytesDownloaded = bytesReceived; | - | ||||||||||||||||||
764 | lastBytesDownloaded = bytesReceived; | - | ||||||||||||||||||
765 | - | |||||||||||||||||||
766 | downloadBufferCurrentSize = bytesReceived; | - | ||||||||||||||||||
767 | - | |||||||||||||||||||
768 | // Only emit readyRead when actual data is there | - | ||||||||||||||||||
769 | // emit readyRead before downloadProgress incase this will cause events to be | - | ||||||||||||||||||
770 | // processed and we get into a recursive call (as in QProgressDialog). | - | ||||||||||||||||||
771 | if (bytesDownloaded > 0)
| 0 | ||||||||||||||||||
772 | emit q->readyRead(); never executed: q->readyRead(); | 0 | ||||||||||||||||||
773 | if (downloadProgressSignalChoke.elapsed() >= progressSignalInterval) {
| 0 | ||||||||||||||||||
774 | downloadProgressSignalChoke.restart(); | - | ||||||||||||||||||
775 | emit q->downloadProgress(bytesDownloaded, bytesTotal); | - | ||||||||||||||||||
776 | } never executed: end of block | 0 | ||||||||||||||||||
777 | } never executed: end of block | 0 | ||||||||||||||||||
778 | - | |||||||||||||||||||
779 | void QNetworkReplyImplPrivate::finished() | - | ||||||||||||||||||
780 | { | - | ||||||||||||||||||
781 | Q_Q(QNetworkReplyImpl); | - | ||||||||||||||||||
782 | - | |||||||||||||||||||
783 | if (state == Finished || state == Aborted || state == WaitingForSession)
| 0-122 | ||||||||||||||||||
784 | return; never executed: return; | 0 | ||||||||||||||||||
785 | - | |||||||||||||||||||
786 | pauseNotificationHandling(); | - | ||||||||||||||||||
787 | QVariant totalSize = cookedHeaders.value(QNetworkRequest::ContentLengthHeader); | - | ||||||||||||||||||
788 | if (preMigrationDownloaded != Q_INT64_C(-1))
| 0-122 | ||||||||||||||||||
789 | totalSize = totalSize.toLongLong() + preMigrationDownloaded; never executed: totalSize = totalSize.toLongLong() + preMigrationDownloaded; | 0 | ||||||||||||||||||
790 | - | |||||||||||||||||||
791 | if (!manager.isNull()) {
| 0-122 | ||||||||||||||||||
792 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
793 | QSharedPointer<QNetworkSession> session (manager->d_func()->getNetworkSession()); | - | ||||||||||||||||||
794 | if (session && session->state() == QNetworkSession::Roaming &&
| 0-121 | ||||||||||||||||||
795 | state == Working && errorCode != QNetworkReply::OperationCanceledError) {
| 0 | ||||||||||||||||||
796 | // only content with a known size will fail with a temporary network failure error | - | ||||||||||||||||||
797 | if (!totalSize.isNull()) {
| 0 | ||||||||||||||||||
798 | if (bytesDownloaded != totalSize) {
| 0 | ||||||||||||||||||
799 | if (migrateBackend()) {
| 0 | ||||||||||||||||||
800 | // either we are migrating or the request is finished/aborted | - | ||||||||||||||||||
801 | if (state == Reconnecting || state == WaitingForSession) {
| 0 | ||||||||||||||||||
802 | resumeNotificationHandling(); | - | ||||||||||||||||||
803 | return; // exit early if we are migrating. never executed: return; | 0 | ||||||||||||||||||
804 | } | - | ||||||||||||||||||
805 | } else { never executed: end of block | 0 | ||||||||||||||||||
806 | error(QNetworkReply::TemporaryNetworkFailureError, | - | ||||||||||||||||||
807 | QNetworkReply::tr("Temporary network failure.")); | - | ||||||||||||||||||
808 | } never executed: end of block | 0 | ||||||||||||||||||
809 | } | - | ||||||||||||||||||
810 | } never executed: end of block | 0 | ||||||||||||||||||
811 | } never executed: end of block | 0 | ||||||||||||||||||
812 | #endif | - | ||||||||||||||||||
813 | } executed 122 times by 3 tests: end of block Executed by:
| 122 | ||||||||||||||||||
814 | resumeNotificationHandling(); | - | ||||||||||||||||||
815 | - | |||||||||||||||||||
816 | state = Finished; | - | ||||||||||||||||||
817 | q->setFinished(true); | - | ||||||||||||||||||
818 | - | |||||||||||||||||||
819 | pendingNotifications.clear(); | - | ||||||||||||||||||
820 | - | |||||||||||||||||||
821 | pauseNotificationHandling(); | - | ||||||||||||||||||
822 | if (totalSize.isNull() || totalSize == -1) {
| 0-88 | ||||||||||||||||||
823 | emit q->downloadProgress(bytesDownloaded, bytesDownloaded); | - | ||||||||||||||||||
824 | } else { executed 88 times by 3 tests: end of block Executed by:
| 88 | ||||||||||||||||||
825 | emit q->downloadProgress(bytesDownloaded, totalSize.toLongLong()); | - | ||||||||||||||||||
826 | } executed 34 times by 1 test: end of block Executed by:
| 34 | ||||||||||||||||||
827 | - | |||||||||||||||||||
828 | if (bytesUploaded == -1 && (outgoingData || outgoingDataBuffer))
| 0-69 | ||||||||||||||||||
829 | emit q->uploadProgress(0, 0); executed 6 times by 1 test: q->uploadProgress(0, 0); Executed by:
| 6 | ||||||||||||||||||
830 | resumeNotificationHandling(); | - | ||||||||||||||||||
831 | - | |||||||||||||||||||
832 | // if we don't know the total size of or we received everything save the cache | - | ||||||||||||||||||
833 | if (totalSize.isNull() || totalSize == -1 || bytesDownloaded == totalSize)
| 0-88 | ||||||||||||||||||
834 | completeCacheSave(); executed 119 times by 3 tests: completeCacheSave(); Executed by:
| 119 | ||||||||||||||||||
835 | - | |||||||||||||||||||
836 | // note: might not be a good idea, since users could decide to delete us | - | ||||||||||||||||||
837 | // which would delete the backend too... | - | ||||||||||||||||||
838 | // maybe we should protect the backend | - | ||||||||||||||||||
839 | pauseNotificationHandling(); | - | ||||||||||||||||||
840 | emit q->readChannelFinished(); | - | ||||||||||||||||||
841 | emit q->finished(); | - | ||||||||||||||||||
842 | resumeNotificationHandling(); | - | ||||||||||||||||||
843 | } executed 122 times by 3 tests: end of block Executed by:
| 122 | ||||||||||||||||||
844 | - | |||||||||||||||||||
845 | void QNetworkReplyImplPrivate::error(QNetworkReplyImpl::NetworkError code, const QString &errorMessage) | - | ||||||||||||||||||
846 | { | - | ||||||||||||||||||
847 | Q_Q(QNetworkReplyImpl); | - | ||||||||||||||||||
848 | // Can't set and emit multiple errors. | - | ||||||||||||||||||
849 | if (errorCode != QNetworkReply::NoError) {
| 0-25 | ||||||||||||||||||
850 | qWarning( "QNetworkReplyImplPrivate::error: Internal problem, this method must only be called once."); | - | ||||||||||||||||||
851 | return; never executed: return; | 0 | ||||||||||||||||||
852 | } | - | ||||||||||||||||||
853 | - | |||||||||||||||||||
854 | errorCode = code; | - | ||||||||||||||||||
855 | q->setErrorString(errorMessage); | - | ||||||||||||||||||
856 | - | |||||||||||||||||||
857 | // note: might not be a good idea, since users could decide to delete us | - | ||||||||||||||||||
858 | // which would delete the backend too... | - | ||||||||||||||||||
859 | // maybe we should protect the backend | - | ||||||||||||||||||
860 | emit q->error(code); | - | ||||||||||||||||||
861 | } executed 25 times by 3 tests: end of block Executed by:
| 25 | ||||||||||||||||||
862 | - | |||||||||||||||||||
863 | void QNetworkReplyImplPrivate::metaDataChanged() | - | ||||||||||||||||||
864 | { | - | ||||||||||||||||||
865 | Q_Q(QNetworkReplyImpl); | - | ||||||||||||||||||
866 | // 1. do we have cookies? | - | ||||||||||||||||||
867 | // 2. are we allowed to set them? | - | ||||||||||||||||||
868 | if (cookedHeaders.contains(QNetworkRequest::SetCookieHeader) && !manager.isNull()
| 0-54 | ||||||||||||||||||
869 | && (static_cast<QNetworkRequest::LoadControl>
| 0 | ||||||||||||||||||
870 | (request.attribute(QNetworkRequest::CookieSaveControlAttribute,
| 0 | ||||||||||||||||||
871 | QNetworkRequest::Automatic).toInt()) == QNetworkRequest::Automatic)) {
| 0 | ||||||||||||||||||
872 | QList<QNetworkCookie> cookies = | - | ||||||||||||||||||
873 | qvariant_cast<QList<QNetworkCookie> >(cookedHeaders.value(QNetworkRequest::SetCookieHeader)); | - | ||||||||||||||||||
874 | QNetworkCookieJar *jar = manager->cookieJar(); | - | ||||||||||||||||||
875 | if (jar)
| 0 | ||||||||||||||||||
876 | jar->setCookiesFromUrl(cookies, url); never executed: jar->setCookiesFromUrl(cookies, url); | 0 | ||||||||||||||||||
877 | } never executed: end of block | 0 | ||||||||||||||||||
878 | emit q->metaDataChanged(); | - | ||||||||||||||||||
879 | } executed 54 times by 2 tests: end of block Executed by:
| 54 | ||||||||||||||||||
880 | - | |||||||||||||||||||
881 | void QNetworkReplyImplPrivate::redirectionRequested(const QUrl &target) | - | ||||||||||||||||||
882 | { | - | ||||||||||||||||||
883 | attributes.insert(QNetworkRequest::RedirectionTargetAttribute, target); | - | ||||||||||||||||||
884 | } never executed: end of block | 0 | ||||||||||||||||||
885 | - | |||||||||||||||||||
886 | void QNetworkReplyImplPrivate::encrypted() | - | ||||||||||||||||||
887 | { | - | ||||||||||||||||||
888 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
889 | Q_Q(QNetworkReplyImpl); | - | ||||||||||||||||||
890 | emit q->encrypted(); | - | ||||||||||||||||||
891 | #endif | - | ||||||||||||||||||
892 | } never executed: end of block | 0 | ||||||||||||||||||
893 | - | |||||||||||||||||||
894 | void QNetworkReplyImplPrivate::sslErrors(const QList<QSslError> &errors) | - | ||||||||||||||||||
895 | { | - | ||||||||||||||||||
896 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
897 | Q_Q(QNetworkReplyImpl); | - | ||||||||||||||||||
898 | emit q->sslErrors(errors); | - | ||||||||||||||||||
899 | #else | - | ||||||||||||||||||
900 | Q_UNUSED(errors); | - | ||||||||||||||||||
901 | #endif | - | ||||||||||||||||||
902 | } never executed: end of block | 0 | ||||||||||||||||||
903 | - | |||||||||||||||||||
904 | QNetworkReplyImpl::QNetworkReplyImpl(QObject *parent) | - | ||||||||||||||||||
905 | : QNetworkReply(*new QNetworkReplyImplPrivate, parent) | - | ||||||||||||||||||
906 | { | - | ||||||||||||||||||
907 | } executed 122 times by 3 tests: end of block Executed by:
| 122 | ||||||||||||||||||
908 | - | |||||||||||||||||||
909 | QNetworkReplyImpl::~QNetworkReplyImpl() | - | ||||||||||||||||||
910 | { | - | ||||||||||||||||||
911 | Q_D(QNetworkReplyImpl); | - | ||||||||||||||||||
912 | - | |||||||||||||||||||
913 | // This code removes the data from the cache if it was prematurely aborted. | - | ||||||||||||||||||
914 | // See QNetworkReplyImplPrivate::completeCacheSave(), we disable caching there after the cache | - | ||||||||||||||||||
915 | // save had been properly finished. So if it is still enabled it means we got deleted/aborted. | - | ||||||||||||||||||
916 | if (d->isCachingEnabled())
| 0-122 | ||||||||||||||||||
917 | d->networkCache()->remove(url()); never executed: d->networkCache()->remove(url()); | 0 | ||||||||||||||||||
918 | } executed 122 times by 3 tests: end of block Executed by:
| 122 | ||||||||||||||||||
919 | - | |||||||||||||||||||
920 | void QNetworkReplyImpl::abort() | - | ||||||||||||||||||
921 | { | - | ||||||||||||||||||
922 | Q_D(QNetworkReplyImpl); | - | ||||||||||||||||||
923 | if (d->state == QNetworkReplyPrivate::Finished || d->state == QNetworkReplyPrivate::Aborted)
| 0 | ||||||||||||||||||
924 | return; never executed: return; | 0 | ||||||||||||||||||
925 | - | |||||||||||||||||||
926 | // stop both upload and download | - | ||||||||||||||||||
927 | if (d->outgoingData)
| 0 | ||||||||||||||||||
928 | disconnect(d->outgoingData, 0, this, 0); never executed: disconnect(d->outgoingData, 0, this, 0); | 0 | ||||||||||||||||||
929 | if (d->copyDevice)
| 0 | ||||||||||||||||||
930 | disconnect(d->copyDevice, 0, this, 0); never executed: disconnect(d->copyDevice, 0, this, 0); | 0 | ||||||||||||||||||
931 | - | |||||||||||||||||||
932 | QNetworkReply::close(); | - | ||||||||||||||||||
933 | - | |||||||||||||||||||
934 | // call finished which will emit signals | - | ||||||||||||||||||
935 | d->error(OperationCanceledError, tr("Operation canceled")); | - | ||||||||||||||||||
936 | if (d->state == QNetworkReplyPrivate::WaitingForSession)
| 0 | ||||||||||||||||||
937 | d->state = QNetworkReplyPrivate::Working; never executed: d->state = QNetworkReplyPrivate::Working; | 0 | ||||||||||||||||||
938 | d->finished(); | - | ||||||||||||||||||
939 | d->state = QNetworkReplyPrivate::Aborted; | - | ||||||||||||||||||
940 | - | |||||||||||||||||||
941 | // finished may access the backend | - | ||||||||||||||||||
942 | if (d->backend) {
| 0 | ||||||||||||||||||
943 | d->backend->deleteLater(); | - | ||||||||||||||||||
944 | d->backend = 0; | - | ||||||||||||||||||
945 | } never executed: end of block | 0 | ||||||||||||||||||
946 | } never executed: end of block | 0 | ||||||||||||||||||
947 | - | |||||||||||||||||||
948 | void QNetworkReplyImpl::close() | - | ||||||||||||||||||
949 | { | - | ||||||||||||||||||
950 | Q_D(QNetworkReplyImpl); | - | ||||||||||||||||||
951 | if (d->state == QNetworkReplyPrivate::Aborted ||
| 0-15 | ||||||||||||||||||
952 | d->state == QNetworkReplyPrivate::Finished)
| 2-13 | ||||||||||||||||||
953 | return; executed 13 times by 1 test: return; Executed by:
| 13 | ||||||||||||||||||
954 | - | |||||||||||||||||||
955 | // stop the download | - | ||||||||||||||||||
956 | if (d->backend)
| 0-2 | ||||||||||||||||||
957 | d->backend->closeDownstreamChannel(); executed 2 times by 2 tests: d->backend->closeDownstreamChannel(); Executed by:
| 2 | ||||||||||||||||||
958 | if (d->copyDevice)
| 0-2 | ||||||||||||||||||
959 | disconnect(d->copyDevice, 0, this, 0); never executed: disconnect(d->copyDevice, 0, this, 0); | 0 | ||||||||||||||||||
960 | - | |||||||||||||||||||
961 | QNetworkReply::close(); | - | ||||||||||||||||||
962 | - | |||||||||||||||||||
963 | // call finished which will emit signals | - | ||||||||||||||||||
964 | d->error(OperationCanceledError, tr("Operation canceled")); | - | ||||||||||||||||||
965 | d->finished(); | - | ||||||||||||||||||
966 | } executed 2 times by 2 tests: end of block Executed by:
| 2 | ||||||||||||||||||
967 | - | |||||||||||||||||||
968 | bool QNetworkReplyImpl::canReadLine () const | - | ||||||||||||||||||
969 | { | - | ||||||||||||||||||
970 | Q_D(const QNetworkReplyImpl); | - | ||||||||||||||||||
971 | return QNetworkReply::canReadLine() || d->readBuffer.canReadLine(); never executed: return QNetworkReply::canReadLine() || d->readBuffer.canReadLine();
| 0 | ||||||||||||||||||
972 | } | - | ||||||||||||||||||
973 | - | |||||||||||||||||||
974 | - | |||||||||||||||||||
975 | /*! | - | ||||||||||||||||||
976 | Returns the number of bytes available for reading with | - | ||||||||||||||||||
977 | QIODevice::read(). The number of bytes available may grow until | - | ||||||||||||||||||
978 | the finished() signal is emitted. | - | ||||||||||||||||||
979 | */ | - | ||||||||||||||||||
980 | qint64 QNetworkReplyImpl::bytesAvailable() const | - | ||||||||||||||||||
981 | { | - | ||||||||||||||||||
982 | // Special case for the "zero copy" download buffer | - | ||||||||||||||||||
983 | Q_D(const QNetworkReplyImpl); | - | ||||||||||||||||||
984 | if (d->downloadBuffer) {
| 0-340 | ||||||||||||||||||
985 | qint64 maxAvail = d->downloadBufferCurrentSize - d->downloadBufferReadPosition; | - | ||||||||||||||||||
986 | return QNetworkReply::bytesAvailable() + maxAvail; never executed: return QNetworkReply::bytesAvailable() + maxAvail; | 0 | ||||||||||||||||||
987 | } | - | ||||||||||||||||||
988 | - | |||||||||||||||||||
989 | return QNetworkReply::bytesAvailable() + d_func()->readBuffer.byteAmount(); executed 340 times by 1 test: return QNetworkReply::bytesAvailable() + d_func()->readBuffer.byteAmount(); Executed by:
| 340 | ||||||||||||||||||
990 | } | - | ||||||||||||||||||
991 | - | |||||||||||||||||||
992 | void QNetworkReplyImpl::setReadBufferSize(qint64 size) | - | ||||||||||||||||||
993 | { | - | ||||||||||||||||||
994 | Q_D(QNetworkReplyImpl); | - | ||||||||||||||||||
995 | if (size > d->readBufferMaxSize &&
| 2 | ||||||||||||||||||
996 | size > d->readBuffer.byteAmount())
| 0-2 | ||||||||||||||||||
997 | d->backendNotify(QNetworkReplyImplPrivate::NotifyDownstreamReadyWrite); executed 2 times by 1 test: d->backendNotify(QNetworkReplyImplPrivate::NotifyDownstreamReadyWrite); Executed by:
| 2 | ||||||||||||||||||
998 | - | |||||||||||||||||||
999 | QNetworkReply::setReadBufferSize(size); | - | ||||||||||||||||||
1000 | - | |||||||||||||||||||
1001 | if (d->backend)
| 0-4 | ||||||||||||||||||
1002 | d->backend->setDownstreamLimited(d->readBufferMaxSize > 0); executed 4 times by 1 test: d->backend->setDownstreamLimited(d->readBufferMaxSize > 0); Executed by:
| 4 | ||||||||||||||||||
1003 | } executed 4 times by 1 test: end of block Executed by:
| 4 | ||||||||||||||||||
1004 | - | |||||||||||||||||||
1005 | #ifndef QT_NO_SSL | - | ||||||||||||||||||
1006 | void QNetworkReplyImpl::sslConfigurationImplementation(QSslConfiguration &configuration) const | - | ||||||||||||||||||
1007 | { | - | ||||||||||||||||||
1008 | Q_D(const QNetworkReplyImpl); | - | ||||||||||||||||||
1009 | if (d->backend)
| 0 | ||||||||||||||||||
1010 | d->backend->fetchSslConfiguration(configuration); never executed: d->backend->fetchSslConfiguration(configuration); | 0 | ||||||||||||||||||
1011 | } never executed: end of block | 0 | ||||||||||||||||||
1012 | - | |||||||||||||||||||
1013 | void QNetworkReplyImpl::setSslConfigurationImplementation(const QSslConfiguration &config) | - | ||||||||||||||||||
1014 | { | - | ||||||||||||||||||
1015 | Q_D(QNetworkReplyImpl); | - | ||||||||||||||||||
1016 | if (d->backend && !config.isNull())
| 0-104 | ||||||||||||||||||
1017 | d->backend->setSslConfiguration(config); executed 104 times by 1 test: d->backend->setSslConfiguration(config); Executed by:
| 104 | ||||||||||||||||||
1018 | } executed 108 times by 1 test: end of block Executed by:
| 108 | ||||||||||||||||||
1019 | - | |||||||||||||||||||
1020 | void QNetworkReplyImpl::ignoreSslErrors() | - | ||||||||||||||||||
1021 | { | - | ||||||||||||||||||
1022 | Q_D(QNetworkReplyImpl); | - | ||||||||||||||||||
1023 | if (d->backend)
| 0 | ||||||||||||||||||
1024 | d->backend->ignoreSslErrors(); never executed: d->backend->ignoreSslErrors(); | 0 | ||||||||||||||||||
1025 | } never executed: end of block | 0 | ||||||||||||||||||
1026 | - | |||||||||||||||||||
1027 | void QNetworkReplyImpl::ignoreSslErrorsImplementation(const QList<QSslError> &errors) | - | ||||||||||||||||||
1028 | { | - | ||||||||||||||||||
1029 | Q_D(QNetworkReplyImpl); | - | ||||||||||||||||||
1030 | if (d->backend)
| 0 | ||||||||||||||||||
1031 | d->backend->ignoreSslErrors(errors); never executed: d->backend->ignoreSslErrors(errors); | 0 | ||||||||||||||||||
1032 | } never executed: end of block | 0 | ||||||||||||||||||
1033 | #endif // QT_NO_SSL | - | ||||||||||||||||||
1034 | - | |||||||||||||||||||
1035 | /*! | - | ||||||||||||||||||
1036 | \internal | - | ||||||||||||||||||
1037 | */ | - | ||||||||||||||||||
1038 | qint64 QNetworkReplyImpl::readData(char *data, qint64 maxlen) | - | ||||||||||||||||||
1039 | { | - | ||||||||||||||||||
1040 | Q_D(QNetworkReplyImpl); | - | ||||||||||||||||||
1041 | - | |||||||||||||||||||
1042 | // Special case code if we have the "zero copy" download buffer | - | ||||||||||||||||||
1043 | if (d->downloadBuffer) {
| 0-482 | ||||||||||||||||||
1044 | qint64 maxAvail = qMin<qint64>(d->downloadBufferCurrentSize - d->downloadBufferReadPosition, maxlen); | - | ||||||||||||||||||
1045 | if (maxAvail == 0)
| 0 | ||||||||||||||||||
1046 | return d->state == QNetworkReplyPrivate::Finished ? -1 : 0; never executed: return d->state == QNetworkReplyPrivate::Finished ? -1 : 0;
| 0 | ||||||||||||||||||
1047 | // FIXME what about "Aborted" state? | - | ||||||||||||||||||
1048 | memcpy(data, d->downloadBuffer + d->downloadBufferReadPosition, maxAvail); | - | ||||||||||||||||||
1049 | d->downloadBufferReadPosition += maxAvail; | - | ||||||||||||||||||
1050 | return maxAvail; never executed: return maxAvail; | 0 | ||||||||||||||||||
1051 | } | - | ||||||||||||||||||
1052 | - | |||||||||||||||||||
1053 | - | |||||||||||||||||||
1054 | if (d->readBuffer.isEmpty())
| 86-396 | ||||||||||||||||||
1055 | return d->state == QNetworkReplyPrivate::Finished ? -1 : 0; executed 86 times by 2 tests: return d->state == QNetworkReplyPrivate::Finished ? -1 : 0; Executed by:
| 0-86 | ||||||||||||||||||
1056 | // FIXME what about "Aborted" state? | - | ||||||||||||||||||
1057 | - | |||||||||||||||||||
1058 | d->backendNotify(QNetworkReplyImplPrivate::NotifyDownstreamReadyWrite); | - | ||||||||||||||||||
1059 | if (maxlen == 1) {
| 0-396 | ||||||||||||||||||
1060 | // optimization for getChar() | - | ||||||||||||||||||
1061 | *data = d->readBuffer.getChar(); | - | ||||||||||||||||||
1062 | return 1; never executed: return 1; | 0 | ||||||||||||||||||
1063 | } | - | ||||||||||||||||||
1064 | - | |||||||||||||||||||
1065 | maxlen = qMin<qint64>(maxlen, d->readBuffer.byteAmount()); | - | ||||||||||||||||||
1066 | return d->readBuffer.read(data, maxlen); executed 396 times by 2 tests: return d->readBuffer.read(data, maxlen); Executed by:
| 396 | ||||||||||||||||||
1067 | } | - | ||||||||||||||||||
1068 | - | |||||||||||||||||||
1069 | /*! | - | ||||||||||||||||||
1070 | \internal Reimplemented for internal purposes | - | ||||||||||||||||||
1071 | */ | - | ||||||||||||||||||
1072 | bool QNetworkReplyImpl::event(QEvent *e) | - | ||||||||||||||||||
1073 | { | - | ||||||||||||||||||
1074 | if (e->type() == QEvent::NetworkReplyUpdated) {
| 273-1034 | ||||||||||||||||||
1075 | d_func()->handleNotifications(); | - | ||||||||||||||||||
1076 | return true; executed 1034 times by 2 tests: return true; Executed by:
| 1034 | ||||||||||||||||||
1077 | } | - | ||||||||||||||||||
1078 | - | |||||||||||||||||||
1079 | return QObject::event(e); executed 273 times by 3 tests: return QObject::event(e); Executed by:
| 273 | ||||||||||||||||||
1080 | } | - | ||||||||||||||||||
1081 | - | |||||||||||||||||||
1082 | /* | - | ||||||||||||||||||
1083 | Migrates the backend of the QNetworkReply to a new network connection if required. Returns | - | ||||||||||||||||||
1084 | true if the reply is migrated or it is not required; otherwise returns \c false. | - | ||||||||||||||||||
1085 | */ | - | ||||||||||||||||||
1086 | bool QNetworkReplyImplPrivate::migrateBackend() | - | ||||||||||||||||||
1087 | { | - | ||||||||||||||||||
1088 | Q_Q(QNetworkReplyImpl); | - | ||||||||||||||||||
1089 | - | |||||||||||||||||||
1090 | // Network reply is already finished or aborted, don't need to migrate. | - | ||||||||||||||||||
1091 | if (state == Finished || state == Aborted)
| 0 | ||||||||||||||||||
1092 | return true; never executed: return true; | 0 | ||||||||||||||||||
1093 | - | |||||||||||||||||||
1094 | // Request has outgoing data, not migrating. | - | ||||||||||||||||||
1095 | if (outgoingData)
| 0 | ||||||||||||||||||
1096 | return false; never executed: return false; | 0 | ||||||||||||||||||
1097 | - | |||||||||||||||||||
1098 | // Request is serviced from the cache, don't need to migrate. | - | ||||||||||||||||||
1099 | if (copyDevice)
| 0 | ||||||||||||||||||
1100 | return true; never executed: return true; | 0 | ||||||||||||||||||
1101 | - | |||||||||||||||||||
1102 | // Backend does not support resuming download. | - | ||||||||||||||||||
1103 | if (backend && !backend->canResume())
| 0 | ||||||||||||||||||
1104 | return false; never executed: return false; | 0 | ||||||||||||||||||
1105 | - | |||||||||||||||||||
1106 | state = QNetworkReplyPrivate::Reconnecting; | - | ||||||||||||||||||
1107 | - | |||||||||||||||||||
1108 | cookedHeaders.clear(); | - | ||||||||||||||||||
1109 | rawHeaders.clear(); | - | ||||||||||||||||||
1110 | - | |||||||||||||||||||
1111 | preMigrationDownloaded = bytesDownloaded; | - | ||||||||||||||||||
1112 | - | |||||||||||||||||||
1113 | delete backend; | - | ||||||||||||||||||
1114 | backend = manager->d_func()->findBackend(operation, request); | - | ||||||||||||||||||
1115 | - | |||||||||||||||||||
1116 | if (backend) {
| 0 | ||||||||||||||||||
1117 | backend->setParent(q); | - | ||||||||||||||||||
1118 | backend->reply = this; | - | ||||||||||||||||||
1119 | backend->setResumeOffset(bytesDownloaded); | - | ||||||||||||||||||
1120 | } never executed: end of block | 0 | ||||||||||||||||||
1121 | - | |||||||||||||||||||
1122 | QMetaObject::invokeMethod(q, "_q_startOperation", Qt::QueuedConnection); | - | ||||||||||||||||||
1123 | - | |||||||||||||||||||
1124 | return true; never executed: return true; | 0 | ||||||||||||||||||
1125 | } | - | ||||||||||||||||||
1126 | - | |||||||||||||||||||
1127 | #ifndef QT_NO_BEARERMANAGEMENT | - | ||||||||||||||||||
1128 | QDisabledNetworkReply::QDisabledNetworkReply(QObject *parent, | - | ||||||||||||||||||
1129 | const QNetworkRequest &req, | - | ||||||||||||||||||
1130 | QNetworkAccessManager::Operation op) | - | ||||||||||||||||||
1131 | : QNetworkReply(parent) | - | ||||||||||||||||||
1132 | { | - | ||||||||||||||||||
1133 | setRequest(req); | - | ||||||||||||||||||
1134 | setUrl(req.url()); | - | ||||||||||||||||||
1135 | setOperation(op); | - | ||||||||||||||||||
1136 | - | |||||||||||||||||||
1137 | qRegisterMetaType<QNetworkReply::NetworkError>(); | - | ||||||||||||||||||
1138 | - | |||||||||||||||||||
1139 | QString msg = QCoreApplication::translate("QNetworkAccessManager", | - | ||||||||||||||||||
1140 | "Network access is disabled."); | - | ||||||||||||||||||
1141 | setError(UnknownNetworkError, msg); | - | ||||||||||||||||||
1142 | - | |||||||||||||||||||
1143 | QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection, | - | ||||||||||||||||||
1144 | Q_ARG(QNetworkReply::NetworkError, UnknownNetworkError)); | - | ||||||||||||||||||
1145 | QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection); | - | ||||||||||||||||||
1146 | } never executed: end of block | 0 | ||||||||||||||||||
1147 | - | |||||||||||||||||||
1148 | QDisabledNetworkReply::~QDisabledNetworkReply() | - | ||||||||||||||||||
1149 | { | - | ||||||||||||||||||
1150 | } | - | ||||||||||||||||||
1151 | #endif | - | ||||||||||||||||||
1152 | - | |||||||||||||||||||
1153 | QT_END_NAMESPACE | - | ||||||||||||||||||
1154 | - | |||||||||||||||||||
1155 | #include "moc_qnetworkreplyimpl_p.cpp" | - | ||||||||||||||||||
1156 | - | |||||||||||||||||||
Source code | Switch to Preprocessed file |