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