qnetworkreplyfileimpl.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/network/access/qnetworkreplyfileimpl.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
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 "qnetworkreplyfileimpl_p.h"-
35-
36#include "QtCore/qdatetime.h"-
37#include <QtCore/QCoreApplication>-
38#include <QtCore/QFileInfo>-
39-
40QT_BEGIN_NAMESPACE-
41-
42QNetworkReplyFileImplPrivate::QNetworkReplyFileImplPrivate()-
43 : QNetworkReplyPrivate(), realFileSize(0)-
44{-
45}
executed 30 times by 2 tests: end of block
Executed by:
  • tst_QNetworkReply
  • tst_QXmlStream
30
46-
47QNetworkReplyFileImpl::~QNetworkReplyFileImpl()-
48{-
49}-
50-
51QNetworkReplyFileImpl::QNetworkReplyFileImpl(QObject *parent, const QNetworkRequest &req, const QNetworkAccessManager::Operation op)-
52 : QNetworkReply(*new QNetworkReplyFileImplPrivate(), parent)-
53{-
54 setRequest(req);-
55 setUrl(req.url());-
56 setOperation(op);-
57 setFinished(true);-
58 QNetworkReply::open(QIODevice::ReadOnly);-
59-
60 QNetworkReplyFileImplPrivate *d = (QNetworkReplyFileImplPrivate*) d_func();-
61-
62 QUrl url = req.url();-
63 if (url.host() == QLatin1String("localhost"))
url.host() == ...g("localhost")Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 29 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_QXmlStream
1-29
64 url.setHost(QString());
executed 1 time by 1 test: url.setHost(QString());
Executed by:
  • tst_QNetworkReply
1
65-
66#if !defined(Q_OS_WIN)-
67 // do not allow UNC paths on Unix-
68 if (!url.host().isEmpty()) {
!url.host().isEmpty()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 29 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_QXmlStream
1-29
69 // we handle only local files-
70 QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Request for opening non-local file %1").arg(url.toString());-
71 setError(QNetworkReply::ProtocolInvalidOperationError, msg);-
72 QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,-
73 Q_ARG(QNetworkReply::NetworkError, QNetworkReply::ProtocolInvalidOperationError));-
74 QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection);-
75 return;
executed 1 time by 1 test: return;
Executed by:
  • tst_QNetworkReply
1
76 }-
77#endif-
78 if (url.path().isEmpty())
url.path().isEmpty()Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 28 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_QXmlStream
1-28
79 url.setPath(QLatin1String("/"));
executed 1 time by 1 test: url.setPath(QLatin1String("/"));
Executed by:
  • tst_QNetworkReply
1
80 setUrl(url);-
81-
82-
83 QString fileName = url.toLocalFile();-
84 if (fileName.isEmpty()) {
fileName.isEmpty()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 27 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_QXmlStream
2-27
85 if (url.scheme() == QLatin1String("qrc")) {
url.scheme() =...1String("qrc")Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEnever evaluated
0-2
86 fileName = QLatin1Char(':') + url.path();-
87 } else {
executed 2 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
2
88#if defined(Q_OS_ANDROID)-
89 if (url.scheme() == QLatin1String("assets"))-
90 fileName = QLatin1String("assets:") + url.path();-
91 else-
92#endif-
93 fileName = url.toString(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery);-
94 }
never executed: end of block
0
95 }-
96-
97 QFileInfo fi(fileName);-
98 if (fi.isDir()) {
fi.isDir()Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 26 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_QXmlStream
3-26
99 QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Cannot open %1: Path is a directory").arg(url.toString());-
100 setError(QNetworkReply::ContentOperationNotPermittedError, msg);-
101 QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,-
102 Q_ARG(QNetworkReply::NetworkError, QNetworkReply::ContentOperationNotPermittedError));-
103 QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection);-
104 return;
executed 3 times by 1 test: return;
Executed by:
  • tst_QNetworkReply
3
105 }-
106-
107 d->realFile.setFileName(fileName);-
108 bool opened = d->realFile.open(QIODevice::ReadOnly | QIODevice::Unbuffered);-
109-
110 // could we open the file?-
111 if (!opened) {
!openedDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 23 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_QXmlStream
3-23
112 QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Error opening %1: %2")-
113 .arg(d->realFile.fileName(), d->realFile.errorString());-
114-
115 if (d->realFile.exists()) {
d->realFile.exists()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QNetworkReply
1-2
116 setError(QNetworkReply::ContentAccessDenied, msg);-
117 QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,-
118 Q_ARG(QNetworkReply::NetworkError, QNetworkReply::ContentAccessDenied));-
119 } else {
executed 2 times by 1 test: end of block
Executed by:
  • tst_QNetworkReply
2
120 setError(QNetworkReply::ContentNotFoundError, msg);-
121 QMetaObject::invokeMethod(this, "error", Qt::QueuedConnection,-
122 Q_ARG(QNetworkReply::NetworkError, QNetworkReply::ContentNotFoundError));-
123 }
executed 1 time by 1 test: end of block
Executed by:
  • tst_QNetworkReply
1
124 QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection);-
125 return;
executed 3 times by 1 test: return;
Executed by:
  • tst_QNetworkReply
3
126 }-
127-
128 setHeader(QNetworkRequest::LastModifiedHeader, fi.lastModified());-
129 d->realFileSize = fi.size();-
130 setHeader(QNetworkRequest::ContentLengthHeader, d->realFileSize);-
131-
132 QMetaObject::invokeMethod(this, "metaDataChanged", Qt::QueuedConnection);-
133 QMetaObject::invokeMethod(this, "downloadProgress", Qt::QueuedConnection,-
134 Q_ARG(qint64, d->realFileSize), Q_ARG(qint64, d->realFileSize));-
135 QMetaObject::invokeMethod(this, "readyRead", Qt::QueuedConnection);-
136 QMetaObject::invokeMethod(this, "finished", Qt::QueuedConnection);-
137}
executed 23 times by 2 tests: end of block
Executed by:
  • tst_QNetworkReply
  • tst_QXmlStream
23
138-
139void QNetworkReplyFileImpl::close()-
140{-
141 Q_D(QNetworkReplyFileImpl);-
142 QNetworkReply::close();-
143 d->realFile.close();-
144}
never executed: end of block
0
145-
146void QNetworkReplyFileImpl::abort()-
147{-
148 Q_D(QNetworkReplyFileImpl);-
149 QNetworkReply::close();-
150 d->realFile.close();-
151}
executed 1 time by 1 test: end of block
Executed by:
  • tst_QNetworkReply
1
152-
153qint64 QNetworkReplyFileImpl::bytesAvailable() const-
154{-
155 Q_D(const QNetworkReplyFileImpl);-
156 if (!d->realFile.isOpen())
!d->realFile.isOpen()Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 184 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_QXmlStream
2-184
157 return QNetworkReply::bytesAvailable();
executed 2 times by 1 test: return QNetworkReply::bytesAvailable();
Executed by:
  • tst_QNetworkReply
2
158 return QNetworkReply::bytesAvailable() + d->realFile.bytesAvailable();
executed 184 times by 2 tests: return QNetworkReply::bytesAvailable() + d->realFile.bytesAvailable();
Executed by:
  • tst_QNetworkReply
  • tst_QXmlStream
184
159}-
160-
161bool QNetworkReplyFileImpl::isSequential () const-
162{-
163 return true;
executed 183 times by 2 tests: return true;
Executed by:
  • tst_QNetworkReply
  • tst_QXmlStream
183
164}-
165-
166qint64 QNetworkReplyFileImpl::size() const-
167{-
168 Q_D(const QNetworkReplyFileImpl);-
169 return d->realFileSize;
never executed: return d->realFileSize;
0
170}-
171-
172/*!-
173 \internal-
174*/-
175qint64 QNetworkReplyFileImpl::readData(char *data, qint64 maxlen)-
176{-
177 Q_D(QNetworkReplyFileImpl);-
178 if (!d->realFile.isOpen())
!d->realFile.isOpen()Description
TRUEevaluated 17 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 166 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_QXmlStream
17-166
179 return -1;
executed 17 times by 1 test: return -1;
Executed by:
  • tst_QNetworkReply
17
180 qint64 ret = d->realFile.read(data, maxlen);-
181 if (bytesAvailable() == 0 && d->realFile.isOpen())
bytesAvailable() == 0Description
TRUEevaluated 15 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 151 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_QXmlStream
d->realFile.isOpen()Description
TRUEevaluated 15 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEnever evaluated
0-151
182 d->realFile.close();
executed 15 times by 1 test: d->realFile.close();
Executed by:
  • tst_QNetworkReply
15
183 if (ret == 0 && bytesAvailable() == 0)
ret == 0Description
TRUEevaluated 3 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_QXmlStream
FALSEevaluated 163 times by 2 tests
Evaluated by:
  • tst_QNetworkReply
  • tst_QXmlStream
bytesAvailable() == 0Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • tst_QNetworkReply
FALSEevaluated 1 time by 1 test
Evaluated by:
  • tst_QXmlStream
1-163
184 return -1;
executed 2 times by 1 test: return -1;
Executed by:
  • tst_QNetworkReply
2
185 else {-
186 setAttribute(QNetworkRequest::HttpStatusCodeAttribute, 200);-
187 setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, QLatin1String("OK"));-
188 return ret;
executed 164 times by 2 tests: return ret;
Executed by:
  • tst_QNetworkReply
  • tst_QXmlStream
164
189 }-
190}-
191-
192-
193QT_END_NAMESPACE-
194-
195#include "moc_qnetworkreplyfileimpl_p.cpp"-
196-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9