access/qnetworkaccessbackend.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtNetwork module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qnetworkaccessbackend_p.h" -
43#include "qnetworkaccessmanager_p.h" -
44#include "qnetworkconfigmanager.h" -
45#include "qnetworkrequest.h" -
46#include "qnetworkreply.h" -
47#include "qnetworkreply_p.h" -
48#include "QtCore/qhash.h" -
49#include "QtCore/qmutex.h" -
50#include "QtNetwork/private/qnetworksession_p.h" -
51 -
52#include "qnetworkaccesscachebackend_p.h" -
53#include "qabstractnetworkcache.h" -
54#include "qhostinfo.h" -
55 -
56#include "private/qnoncontiguousbytedevice_p.h" -
57 -
58QT_BEGIN_NAMESPACE -
59 -
60class QNetworkAccessBackendFactoryData: public QList<QNetworkAccessBackendFactory *> -
61{ -
62public: -
63 QNetworkAccessBackendFactoryData() : mutex(QMutex::Recursive) -
64 { -
65 valid.ref();
executed (the execution status of this line is deduced): valid.ref();
-
66 }
executed: }
Execution Count:8
8
67 ~QNetworkAccessBackendFactoryData() -
68 { -
69 QMutexLocker locker(&mutex); // why do we need to lock?
executed (the execution status of this line is deduced): QMutexLocker locker(&mutex);
-
70 valid.deref();
executed (the execution status of this line is deduced): valid.deref();
-
71 }
executed: }
Execution Count:8
8
72 -
73 QMutex mutex; -
74 //this is used to avoid (re)constructing factory data from destructors of other global classes -
75 static QBasicAtomicInt valid; -
76}; -
77Q_GLOBAL_STATIC(QNetworkAccessBackendFactoryData, factoryData)
never executed: delete x;
executed: return thisGlobalStatic.pointer.load();
Execution Count:331
partially evaluated: !thisGlobalStatic.pointer.testAndSetOrdered(0, x)
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:8
evaluated: !thisGlobalStatic.pointer.load()
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:323
partially evaluated: !thisGlobalStatic.destroyed
TRUEFALSE
yes
Evaluation Count:8
no
Evaluation Count:0
0-331
78QBasicAtomicInt QNetworkAccessBackendFactoryData::valid = Q_BASIC_ATOMIC_INITIALIZER(0); -
79 -
80QNetworkAccessBackendFactory::QNetworkAccessBackendFactory() -
81{ -
82 QMutexLocker locker(&factoryData()->mutex);
executed (the execution status of this line is deduced): QMutexLocker locker(&factoryData()->mutex);
-
83 factoryData()->append(this);
executed (the execution status of this line is deduced): factoryData()->append(this);
-
84}
executed: }
Execution Count:16
16
85 -
86QNetworkAccessBackendFactory::~QNetworkAccessBackendFactory() -
87{ -
88 if (QNetworkAccessBackendFactoryData::valid.load()) {
partially evaluated: QNetworkAccessBackendFactoryData::valid.load()
TRUEFALSE
yes
Evaluation Count:16
no
Evaluation Count:0
0-16
89 QMutexLocker locker(&factoryData()->mutex);
executed (the execution status of this line is deduced): QMutexLocker locker(&factoryData()->mutex);
-
90 factoryData()->removeAll(this);
executed (the execution status of this line is deduced): factoryData()->removeAll(this);
-
91 }
executed: }
Execution Count:16
16
92}
executed: }
Execution Count:16
16
93 -
94QNetworkAccessBackend *QNetworkAccessManagerPrivate::findBackend(QNetworkAccessManager::Operation op, -
95 const QNetworkRequest &request) -
96{ -
97 if (QNetworkAccessBackendFactoryData::valid.load()) {
partially evaluated: QNetworkAccessBackendFactoryData::valid.load()
TRUEFALSE
yes
Evaluation Count:89
no
Evaluation Count:0
0-89
98 QMutexLocker locker(&factoryData()->mutex);
executed (the execution status of this line is deduced): QMutexLocker locker(&factoryData()->mutex);
-
99 QNetworkAccessBackendFactoryData::ConstIterator it = factoryData()->constBegin(),
executed (the execution status of this line is deduced): QNetworkAccessBackendFactoryData::ConstIterator it = factoryData()->constBegin(),
-
100 end = factoryData()->constEnd();
executed (the execution status of this line is deduced): end = factoryData()->constEnd();
-
101 while (it != end) {
evaluated: it != end
TRUEFALSE
yes
Evaluation Count:136
yes
Evaluation Count:4
4-136
102 QNetworkAccessBackend *backend = (*it)->create(op, request);
executed (the execution status of this line is deduced): QNetworkAccessBackend *backend = (*it)->create(op, request);
-
103 if (backend) {
evaluated: backend
TRUEFALSE
yes
Evaluation Count:85
yes
Evaluation Count:51
51-85
104 backend->manager = this;
executed (the execution status of this line is deduced): backend->manager = this;
-
105 return backend; // found a factory that handled our request
executed: return backend;
Execution Count:85
85
106 } -
107 ++it;
executed (the execution status of this line is deduced): ++it;
-
108 }
executed: }
Execution Count:51
51
109 }
executed: }
Execution Count:4
4
110 return 0;
executed: return 0;
Execution Count:4
4
111} -
112 -
113QNonContiguousByteDevice* QNetworkAccessBackend::createUploadByteDevice() -
114{ -
115 if (reply->outgoingDataBuffer)
partially evaluated: reply->outgoingDataBuffer
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:50
0-50
116 uploadByteDevice = QSharedPointer<QNonContiguousByteDevice>(QNonContiguousByteDeviceFactory::create(reply->outgoingDataBuffer));
never executed: uploadByteDevice = QSharedPointer<QNonContiguousByteDevice>(QNonContiguousByteDeviceFactory::create(reply->outgoingDataBuffer));
0
117 else if (reply->outgoingData) {
partially evaluated: reply->outgoingData
TRUEFALSE
yes
Evaluation Count:50
no
Evaluation Count:0
0-50
118 uploadByteDevice = QSharedPointer<QNonContiguousByteDevice>(QNonContiguousByteDeviceFactory::create(reply->outgoingData));
executed (the execution status of this line is deduced): uploadByteDevice = QSharedPointer<QNonContiguousByteDevice>(QNonContiguousByteDeviceFactory::create(reply->outgoingData));
-
119 } else {
executed: }
Execution Count:50
50
120 return 0;
never executed: return 0;
0
121 } -
122 -
123 bool bufferDisallowed =
executed (the execution status of this line is deduced): bool bufferDisallowed =
-
124 reply->request.attribute(QNetworkRequest::DoNotBufferUploadDataAttribute,
executed (the execution status of this line is deduced): reply->request.attribute(QNetworkRequest::DoNotBufferUploadDataAttribute,
-
125 QVariant(false)) == QVariant(true);
executed (the execution status of this line is deduced): QVariant(false)) == QVariant(true);
-
126 if (bufferDisallowed)
partially evaluated: bufferDisallowed
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:50
0-50
127 uploadByteDevice->disableReset();
never executed: uploadByteDevice->disableReset();
0
128 -
129 // We want signal emissions only for normal asynchronous uploads -
130 if (!isSynchronous())
partially evaluated: !isSynchronous()
TRUEFALSE
yes
Evaluation Count:50
no
Evaluation Count:0
0-50
131 connect(uploadByteDevice.data(), SIGNAL(readProgress(qint64,qint64)), this, SLOT(emitReplyUploadProgress(qint64,qint64)));
executed: connect(uploadByteDevice.data(), "2""readProgress(qint64,qint64)", this, "1""emitReplyUploadProgress(qint64,qint64)");
Execution Count:50
50
132 -
133 return uploadByteDevice.data();
executed: return uploadByteDevice.data();
Execution Count:50
50
134} -
135 -
136// need to have this function since the reply is a private member variable -
137// and the special backends need to access this. -
138void QNetworkAccessBackend::emitReplyUploadProgress(qint64 bytesSent, qint64 bytesTotal) -
139{ -
140 if (reply->isFinished)
partially evaluated: reply->isFinished
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:896
0-896
141 return;
never executed: return;
0
142 reply->emitUploadProgress(bytesSent, bytesTotal);
executed (the execution status of this line is deduced): reply->emitUploadProgress(bytesSent, bytesTotal);
-
143}
executed: }
Execution Count:896
896
144 -
145QNetworkAccessBackend::QNetworkAccessBackend() -
146 : manager(0) -
147 , reply(0) -
148 , synchronous(false) -
149{ -
150}
executed: }
Execution Count:98
98
151 -
152QNetworkAccessBackend::~QNetworkAccessBackend() -
153{ -
154} -
155 -
156void QNetworkAccessBackend::downstreamReadyWrite() -
157{ -
158 // do nothing -
159} -
160 -
161void QNetworkAccessBackend::setDownstreamLimited(bool b) -
162{ -
163 Q_UNUSED(b);
never executed (the execution status of this line is deduced): (void)b;;
-
164 // do nothing -
165}
never executed: }
0
166 -
167void QNetworkAccessBackend::copyFinished(QIODevice *) -
168{ -
169 // do nothing -
170} -
171 -
172void QNetworkAccessBackend::ignoreSslErrors() -
173{ -
174 // do nothing -
175} -
176 -
177void QNetworkAccessBackend::ignoreSslErrors(const QList<QSslError> &errors) -
178{ -
179 Q_UNUSED(errors);
never executed (the execution status of this line is deduced): (void)errors;;
-
180 // do nothing -
181}
never executed: }
0
182 -
183void QNetworkAccessBackend::fetchSslConfiguration(QSslConfiguration &) const -
184{ -
185 // do nothing -
186} -
187 -
188void QNetworkAccessBackend::setSslConfiguration(const QSslConfiguration &) -
189{ -
190 // do nothing -
191} -
192 -
193QNetworkCacheMetaData QNetworkAccessBackend::fetchCacheMetaData(const QNetworkCacheMetaData &) const -
194{ -
195 return QNetworkCacheMetaData();
never executed: return QNetworkCacheMetaData();
0
196} -
197 -
198QNetworkAccessManager::Operation QNetworkAccessBackend::operation() const -
199{ -
200 return reply->operation;
executed: return reply->operation;
Execution Count:256
256
201} -
202 -
203QNetworkRequest QNetworkAccessBackend::request() const -
204{ -
205 return reply->request;
executed: return reply->request;
Execution Count:98
98
206} -
207 -
208#ifndef QT_NO_NETWORKPROXY -
209QList<QNetworkProxy> QNetworkAccessBackend::proxyList() const -
210{ -
211 return reply->proxyList;
executed: return reply->proxyList;
Execution Count:42
42
212} -
213#endif -
214 -
215QAbstractNetworkCache *QNetworkAccessBackend::networkCache() const -
216{ -
217 if (!manager)
partially evaluated: !manager
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:35
0-35
218 return 0;
never executed: return 0;
0
219 return manager->networkCache;
executed: return manager->networkCache;
Execution Count:35
35
220} -
221 -
222void QNetworkAccessBackend::setCachingEnabled(bool enable) -
223{ -
224 reply->setCachingEnabled(enable);
executed (the execution status of this line is deduced): reply->setCachingEnabled(enable);
-
225}
executed: }
Execution Count:35
35
226 -
227bool QNetworkAccessBackend::isCachingEnabled() const -
228{ -
229 return reply->isCachingEnabled();
never executed: return reply->isCachingEnabled();
0
230} -
231 -
232qint64 QNetworkAccessBackend::nextDownstreamBlockSize() const -
233{ -
234 return reply->nextDownstreamBlockSize();
executed: return reply->nextDownstreamBlockSize();
Execution Count:38
38
235} -
236 -
237void QNetworkAccessBackend::writeDownstreamData(QByteDataBuffer &list) -
238{ -
239 reply->appendDownstreamData(list);
executed (the execution status of this line is deduced): reply->appendDownstreamData(list);
-
240}
executed: }
Execution Count:822
822
241 -
242void QNetworkAccessBackend::writeDownstreamData(QIODevice *data) -
243{ -
244 reply->appendDownstreamData(data);
executed (the execution status of this line is deduced): reply->appendDownstreamData(data);
-
245}
executed: }
Execution Count:9
9
246 -
247// not actually appending data, it was already written to the user buffer -
248void QNetworkAccessBackend::writeDownstreamDataDownloadBuffer(qint64 bytesReceived, qint64 bytesTotal) -
249{ -
250 reply->appendDownstreamDataDownloadBuffer(bytesReceived, bytesTotal);
never executed (the execution status of this line is deduced): reply->appendDownstreamDataDownloadBuffer(bytesReceived, bytesTotal);
-
251}
never executed: }
0
252 -
253char* QNetworkAccessBackend::getDownloadBuffer(qint64 size) -
254{ -
255 return reply->getDownloadBuffer(size);
never executed: return reply->getDownloadBuffer(size);
0
256} -
257 -
258QVariant QNetworkAccessBackend::header(QNetworkRequest::KnownHeaders header) const -
259{ -
260 return reply->q_func()->header(header);
never executed: return reply->q_func()->header(header);
0
261} -
262 -
263void QNetworkAccessBackend::setHeader(QNetworkRequest::KnownHeaders header, const QVariant &value) -
264{ -
265 reply->setCookedHeader(header, value);
executed (the execution status of this line is deduced): reply->setCookedHeader(header, value);
-
266}
executed: }
Execution Count:52
52
267 -
268bool QNetworkAccessBackend::hasRawHeader(const QByteArray &headerName) const -
269{ -
270 return reply->q_func()->hasRawHeader(headerName);
never executed: return reply->q_func()->hasRawHeader(headerName);
0
271} -
272 -
273QByteArray QNetworkAccessBackend::rawHeader(const QByteArray &headerName) const -
274{ -
275 return reply->q_func()->rawHeader(headerName);
never executed: return reply->q_func()->rawHeader(headerName);
0
276} -
277 -
278QList<QByteArray> QNetworkAccessBackend::rawHeaderList() const -
279{ -
280 return reply->q_func()->rawHeaderList();
never executed: return reply->q_func()->rawHeaderList();
0
281} -
282 -
283void QNetworkAccessBackend::setRawHeader(const QByteArray &headerName, const QByteArray &headerValue) -
284{ -
285 reply->setRawHeader(headerName, headerValue);
executed (the execution status of this line is deduced): reply->setRawHeader(headerName, headerValue);
-
286}
executed: }
Execution Count:36
36
287 -
288QVariant QNetworkAccessBackend::attribute(QNetworkRequest::Attribute code) const -
289{ -
290 return reply->q_func()->attribute(code);
never executed: return reply->q_func()->attribute(code);
0
291} -
292 -
293void QNetworkAccessBackend::setAttribute(QNetworkRequest::Attribute code, const QVariant &value) -
294{ -
295 if (value.isValid())
evaluated: value.isValid()
TRUEFALSE
yes
Evaluation Count:25
yes
Evaluation Count:8
8-25
296 reply->attributes.insert(code, value);
executed: reply->attributes.insert(code, value);
Execution Count:25
25
297 else -
298 reply->attributes.remove(code);
executed: reply->attributes.remove(code);
Execution Count:8
8
299} -
300QUrl QNetworkAccessBackend::url() const -
301{ -
302 return reply->url;
executed: return reply->url;
Execution Count:333
333
303} -
304 -
305void QNetworkAccessBackend::setUrl(const QUrl &url) -
306{ -
307 reply->url = url;
executed (the execution status of this line is deduced): reply->url = url;
-
308}
executed: }
Execution Count:46
46
309 -
310void QNetworkAccessBackend::finished() -
311{ -
312 reply->finished();
executed (the execution status of this line is deduced): reply->finished();
-
313}
executed: }
Execution Count:97
97
314 -
315void QNetworkAccessBackend::error(QNetworkReply::NetworkError code, const QString &errorString) -
316{ -
317 reply->error(code, errorString);
executed (the execution status of this line is deduced): reply->error(code, errorString);
-
318}
executed: }
Execution Count:14
14
319 -
320#ifndef QT_NO_NETWORKPROXY -
321void QNetworkAccessBackend::proxyAuthenticationRequired(const QNetworkProxy &proxy, -
322 QAuthenticator *authenticator) -
323{ -
324 manager->proxyAuthenticationRequired(proxy, synchronous, authenticator, &reply->lastProxyAuthentication);
never executed (the execution status of this line is deduced): manager->proxyAuthenticationRequired(proxy, synchronous, authenticator, &reply->lastProxyAuthentication);
-
325}
never executed: }
0
326#endif -
327 -
328void QNetworkAccessBackend::authenticationRequired(QAuthenticator *authenticator) -
329{ -
330 manager->authenticationRequired(authenticator, reply->q_func(), synchronous, reply->url, &reply->urlForLastAuthentication);
executed (the execution status of this line is deduced): manager->authenticationRequired(authenticator, reply->q_func(), synchronous, reply->url, &reply->urlForLastAuthentication);
-
331}
executed: }
Execution Count:1
1
332 -
333void QNetworkAccessBackend::metaDataChanged() -
334{ -
335 reply->metaDataChanged();
executed (the execution status of this line is deduced): reply->metaDataChanged();
-
336}
executed: }
Execution Count:46
46
337 -
338void QNetworkAccessBackend::redirectionRequested(const QUrl &target) -
339{ -
340 reply->redirectionRequested(target);
never executed (the execution status of this line is deduced): reply->redirectionRequested(target);
-
341}
never executed: }
0
342 -
343void QNetworkAccessBackend::sslErrors(const QList<QSslError> &errors) -
344{ -
345#ifndef QT_NO_SSL -
346 reply->sslErrors(errors);
never executed (the execution status of this line is deduced): reply->sslErrors(errors);
-
347#else -
348 Q_UNUSED(errors); -
349#endif -
350}
never executed: }
0
351 -
352/*! -
353 Starts the backend. Returns true if the backend is started. Returns false if the backend -
354 could not be started due to an unopened or roaming session. The caller should recall this -
355 function once the session has been opened or the roaming process has finished. -
356*/ -
357bool QNetworkAccessBackend::start() -
358{ -
359#ifndef QT_NO_BEARERMANAGEMENT -
360 // For bearer, check if session start is required -
361 QSharedPointer<QNetworkSession> networkSession(manager->getNetworkSession());
executed (the execution status of this line is deduced): QSharedPointer<QNetworkSession> networkSession(manager->getNetworkSession());
-
362 if (networkSession) {
partially evaluated: networkSession
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:98
0-98
363 // session required -
364 if (networkSession->isOpen() &&
never evaluated: networkSession->isOpen()
0
365 networkSession->state() == QNetworkSession::Connected) {
never evaluated: networkSession->state() == QNetworkSession::Connected
0
366 // Session is already open and ready to use. -
367 // copy network session down to the backend -
368 setProperty("_q_networksession", QVariant::fromValue(networkSession));
never executed (the execution status of this line is deduced): setProperty("_q_networksession", QVariant::fromValue(networkSession));
-
369 } else {
never executed: }
0
370 // Session not ready, but can skip for loopback connections -
371 -
372 // This is not ideal. -
373 const QString host = reply->url.host();
never executed (the execution status of this line is deduced): const QString host = reply->url.host();
-
374 -
375 if (host == QLatin1String("localhost") ||
never evaluated: host == QLatin1String("localhost")
0
376 QHostAddress(host).isLoopback()) {
never evaluated: QHostAddress(host).isLoopback()
0
377 // Don't need an open session for localhost access. -
378 } else {
never executed: }
0
379 // need to wait for session to be opened -
380 return false;
never executed: return false;
0
381 } -
382 } -
383 } -
384#endif -
385 -
386#ifndef QT_NO_NETWORKPROXY -
387#ifndef QT_NO_BEARERMANAGEMENT -
388 // Get the proxy settings from the network session (in the case of service networks, -
389 // the proxy settings change depending which AP was activated) -
390 QNetworkSession *session = networkSession.data();
executed (the execution status of this line is deduced): QNetworkSession *session = networkSession.data();
-
391 QNetworkConfiguration config;
executed (the execution status of this line is deduced): QNetworkConfiguration config;
-
392 if (session) {
partially evaluated: session
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:98
0-98
393 QNetworkConfigurationManager configManager;
never executed (the execution status of this line is deduced): QNetworkConfigurationManager configManager;
-
394 // The active configuration tells us what IAP is in use -
395 QVariant v = session->sessionProperty(QLatin1String("ActiveConfiguration"));
never executed (the execution status of this line is deduced): QVariant v = session->sessionProperty(QLatin1String("ActiveConfiguration"));
-
396 if (v.isValid())
never evaluated: v.isValid()
0
397 config = configManager.configurationFromIdentifier(qvariant_cast<QString>(v));
never executed: config = configManager.configurationFromIdentifier(qvariant_cast<QString>(v));
0
398 // Fallback to using the configuration if no active configuration -
399 if (!config.isValid())
never evaluated: !config.isValid()
0
400 config = session->configuration();
never executed: config = session->configuration();
0
401 // or unspecified configuration if that is no good either -
402 if (!config.isValid())
never evaluated: !config.isValid()
0
403 config = QNetworkConfiguration();
never executed: config = QNetworkConfiguration();
0
404 }
never executed: }
0
405 reply->proxyList = manager->queryProxy(QNetworkProxyQuery(config, url()));
executed (the execution status of this line is deduced): reply->proxyList = manager->queryProxy(QNetworkProxyQuery(config, url()));
-
406#else // QT_NO_BEARERMANAGEMENT -
407 // Without bearer management, the proxy depends only on the url -
408 reply->proxyList = manager->queryProxy(QNetworkProxyQuery(url())); -
409#endif -
410#endif -
411 -
412 // now start the request -
413 open();
executed (the execution status of this line is deduced): open();
-
414 return true;
executed: return true;
Execution Count:98
98
415} -
416 -
417QT_END_NAMESPACE -
418 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial