access/qnetworkaccesscachebackend.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//#define QNETWORKACCESSCACHEBACKEND_DEBUG -
43 -
44#include "qnetworkaccesscachebackend_p.h" -
45#include "qabstractnetworkcache.h" -
46#include "qfileinfo.h" -
47#include "qurlinfo_p.h" -
48#include "qdir.h" -
49#include "qcoreapplication.h" -
50 -
51QT_BEGIN_NAMESPACE -
52 -
53QNetworkAccessCacheBackend::QNetworkAccessCacheBackend() -
54 : QNetworkAccessBackend() -
55 , device(0) -
56{ -
57}
executed: }
Execution Count:13
13
58 -
59QNetworkAccessCacheBackend::~QNetworkAccessCacheBackend() -
60{ -
61} -
62 -
63void QNetworkAccessCacheBackend::open() -
64{ -
65 if (operation() != QNetworkAccessManager::GetOperation || !sendCacheContents()) {
partially evaluated: operation() != QNetworkAccessManager::GetOperation
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13
evaluated: !sendCacheContents()
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:9
0-13
66 QString msg = QCoreApplication::translate("QNetworkAccessCacheBackend", "Error opening %1")
executed (the execution status of this line is deduced): QString msg = QCoreApplication::translate("QNetworkAccessCacheBackend", "Error opening %1")
-
67 .arg(this->url().toString());
executed (the execution status of this line is deduced): .arg(this->url().toString());
-
68 error(QNetworkReply::ContentNotFoundError, msg);
executed (the execution status of this line is deduced): error(QNetworkReply::ContentNotFoundError, msg);
-
69 } else {
executed: }
Execution Count:4
4
70 setAttribute(QNetworkRequest::SourceIsFromCacheAttribute, true);
executed (the execution status of this line is deduced): setAttribute(QNetworkRequest::SourceIsFromCacheAttribute, true);
-
71 }
executed: }
Execution Count:9
9
72 finished();
executed (the execution status of this line is deduced): finished();
-
73}
executed: }
Execution Count:13
13
74 -
75bool QNetworkAccessCacheBackend::sendCacheContents() -
76{ -
77 setCachingEnabled(false);
executed (the execution status of this line is deduced): setCachingEnabled(false);
-
78 QAbstractNetworkCache *nc = networkCache();
executed (the execution status of this line is deduced): QAbstractNetworkCache *nc = networkCache();
-
79 if (!nc)
partially evaluated: !nc
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:13
0-13
80 return false;
never executed: return false;
0
81 -
82 QNetworkCacheMetaData item = nc->metaData(url());
executed (the execution status of this line is deduced): QNetworkCacheMetaData item = nc->metaData(url());
-
83 if (!item.isValid())
evaluated: !item.isValid()
TRUEFALSE
yes
Evaluation Count:1
yes
Evaluation Count:12
1-12
84 return false;
executed: return false;
Execution Count:1
1
85 -
86 QNetworkCacheMetaData::AttributesMap attributes = item.attributes();
executed (the execution status of this line is deduced): QNetworkCacheMetaData::AttributesMap attributes = item.attributes();
-
87 setAttribute(QNetworkRequest::HttpStatusCodeAttribute, attributes.value(QNetworkRequest::HttpStatusCodeAttribute));
executed (the execution status of this line is deduced): setAttribute(QNetworkRequest::HttpStatusCodeAttribute, attributes.value(QNetworkRequest::HttpStatusCodeAttribute));
-
88 setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, attributes.value(QNetworkRequest::HttpReasonPhraseAttribute));
executed (the execution status of this line is deduced): setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, attributes.value(QNetworkRequest::HttpReasonPhraseAttribute));
-
89 -
90 // set the raw headers -
91 QNetworkCacheMetaData::RawHeaderList rawHeaders = item.rawHeaders();
executed (the execution status of this line is deduced): QNetworkCacheMetaData::RawHeaderList rawHeaders = item.rawHeaders();
-
92 QNetworkCacheMetaData::RawHeaderList::ConstIterator it = rawHeaders.constBegin(),
executed (the execution status of this line is deduced): QNetworkCacheMetaData::RawHeaderList::ConstIterator it = rawHeaders.constBegin(),
-
93 end = rawHeaders.constEnd();
executed (the execution status of this line is deduced): end = rawHeaders.constEnd();
-
94 for ( ; it != end; ++it) {
evaluated: it != end
TRUEFALSE
yes
Evaluation Count:39
yes
Evaluation Count:9
9-39
95 if (it->first.toLower() == "cache-control" &&
evaluated: it->first.toLower() == "cache-control"
TRUEFALSE
yes
Evaluation Count:5
yes
Evaluation Count:34
5-34
96 it->second.toLower().contains("must-revalidate")) {
evaluated: it->second.toLower().contains("must-revalidate")
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:2
2-3
97 return false;
executed: return false;
Execution Count:3
3
98 } -
99 setRawHeader(it->first, it->second);
executed (the execution status of this line is deduced): setRawHeader(it->first, it->second);
-
100 }
executed: }
Execution Count:36
36
101 -
102 // handle a possible redirect -
103 QVariant redirectionTarget = attributes.value(QNetworkRequest::RedirectionTargetAttribute);
executed (the execution status of this line is deduced): QVariant redirectionTarget = attributes.value(QNetworkRequest::RedirectionTargetAttribute);
-
104 if (redirectionTarget.isValid()) {
partially evaluated: redirectionTarget.isValid()
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:9
0-9
105 setAttribute(QNetworkRequest::RedirectionTargetAttribute, redirectionTarget);
never executed (the execution status of this line is deduced): setAttribute(QNetworkRequest::RedirectionTargetAttribute, redirectionTarget);
-
106 redirectionRequested(redirectionTarget.toUrl());
never executed (the execution status of this line is deduced): redirectionRequested(redirectionTarget.toUrl());
-
107 }
never executed: }
0
108 -
109 // signal we're open -
110 metaDataChanged();
executed (the execution status of this line is deduced): metaDataChanged();
-
111 -
112 if (operation() == QNetworkAccessManager::GetOperation) {
partially evaluated: operation() == QNetworkAccessManager::GetOperation
TRUEFALSE
yes
Evaluation Count:9
no
Evaluation Count:0
0-9
113 QIODevice *contents = nc->data(url());
executed (the execution status of this line is deduced): QIODevice *contents = nc->data(url());
-
114 if (!contents)
partially evaluated: !contents
TRUEFALSE
no
Evaluation Count:0
yes
Evaluation Count:9
0-9
115 return false;
never executed: return false;
0
116 contents->setParent(this);
executed (the execution status of this line is deduced): contents->setParent(this);
-
117 writeDownstreamData(contents);
executed (the execution status of this line is deduced): writeDownstreamData(contents);
-
118 }
executed: }
Execution Count:9
9
119 -
120#if defined(QNETWORKACCESSCACHEBACKEND_DEBUG) -
121 qDebug() << "Successfully sent cache:" << url(); -
122#endif -
123 return true;
executed: return true;
Execution Count:9
9
124} -
125 -
126void QNetworkAccessCacheBackend::closeDownstreamChannel() -
127{ -
128 if (operation() == QNetworkAccessManager::GetOperation) {
never evaluated: operation() == QNetworkAccessManager::GetOperation
0
129 device->close();
never executed (the execution status of this line is deduced): device->close();
-
130 delete device;
never executed (the execution status of this line is deduced): delete device;
-
131 device = 0;
never executed (the execution status of this line is deduced): device = 0;
-
132 }
never executed: }
0
133}
never executed: }
0
134 -
135void QNetworkAccessCacheBackend::closeUpstreamChannel() -
136{ -
137 Q_ASSERT_X(false, Q_FUNC_INFO, "This function show not have been called!");
never executed (the execution status of this line is deduced): qt_noop();
-
138}
never executed: }
0
139 -
140void QNetworkAccessCacheBackend::upstreamReadyRead() -
141{ -
142 Q_ASSERT_X(false, Q_FUNC_INFO, "This function show not have been called!");
never executed (the execution status of this line is deduced): qt_noop();
-
143}
never executed: }
0
144 -
145void QNetworkAccessCacheBackend::downstreamReadyWrite() -
146{ -
147 Q_ASSERT_X(false, Q_FUNC_INFO, "This function show not have been called!");
never executed (the execution status of this line is deduced): qt_noop();
-
148}
never executed: }
0
149 -
150QT_END_NAMESPACE -
151 -
152 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial