| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/network/access/qnetworkaccessfilebackend.cpp |
| Switch to Source code | Preprocessed file |
| Line | Source | Count | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | - | |||||||||||||||||||||||||
| 2 | - | |||||||||||||||||||||||||
| 3 | - | |||||||||||||||||||||||||
| 4 | - | |||||||||||||||||||||||||
| 5 | QStringList QNetworkAccessFileBackendFactory::supportedSchemes() const | - | ||||||||||||||||||||||||
| 6 | { | - | ||||||||||||||||||||||||
| 7 | QStringList schemes; | - | ||||||||||||||||||||||||
| 8 | schemes << ([]() -> QString { enum { Size = sizeof(u"" "file")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "file" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return never executed: qstring_literal_temp;return qstring_literal_temp;never executed: }())return qstring_literal_temp; | 0 | ||||||||||||||||||||||||
| 9 | << ([]() -> QString { enum { Size = sizeof(u"" "qrc")/2 - 1 }; static const QStaticStringData<Size> qstring_literal = { { { { -1 } }, Size, 0, 0, sizeof(QStringData) }, u"" "qrc" }; QStringDataPtr holder = { qstring_literal.data_ptr() }; const QString qstring_literal_temp(holder); return never executed: qstring_literal_temp;return qstring_literal_temp;never executed: }());return qstring_literal_temp; | 0 | ||||||||||||||||||||||||
| 10 | - | |||||||||||||||||||||||||
| 11 | - | |||||||||||||||||||||||||
| 12 | - | |||||||||||||||||||||||||
| 13 | return never executed: schemes;return schemes;never executed: return schemes; | 0 | ||||||||||||||||||||||||
| 14 | } | - | ||||||||||||||||||||||||
| 15 | - | |||||||||||||||||||||||||
| 16 | QNetworkAccessBackend * | - | ||||||||||||||||||||||||
| 17 | QNetworkAccessFileBackendFactory::create(QNetworkAccessManager::Operation op, | - | ||||||||||||||||||||||||
| 18 | const QNetworkRequest &request) const | - | ||||||||||||||||||||||||
| 19 | { | - | ||||||||||||||||||||||||
| 20 | - | |||||||||||||||||||||||||
| 21 | switch (op) { | - | ||||||||||||||||||||||||
| 22 | case executed 8 times by 1 test: QNetworkAccessManager::GetOperation:case QNetworkAccessManager::GetOperation:Executed by:
executed 8 times by 1 test: case QNetworkAccessManager::GetOperation:Executed by:
| 8 | ||||||||||||||||||||||||
| 23 | case executed 39 times by 1 test: QNetworkAccessManager::PutOperation:case QNetworkAccessManager::PutOperation:Executed by:
executed 39 times by 1 test: case QNetworkAccessManager::PutOperation:Executed by:
| 39 | ||||||||||||||||||||||||
| 24 | break; executed 47 times by 1 test: break;Executed by:
| 47 | ||||||||||||||||||||||||
| 25 | - | |||||||||||||||||||||||||
| 26 | default never executed: :default:never executed: default: | 0 | ||||||||||||||||||||||||
| 27 | - | |||||||||||||||||||||||||
| 28 | return never executed: 0;return 0;never executed: return 0; | 0 | ||||||||||||||||||||||||
| 29 | } | - | ||||||||||||||||||||||||
| 30 | - | |||||||||||||||||||||||||
| 31 | QUrl url = request.url(); | - | ||||||||||||||||||||||||
| 32 | if (url.scheme().compare(QLatin1String("qrc"), Qt::CaseInsensitive) == 0
| 0-47 | ||||||||||||||||||||||||
| 33 | - | |||||||||||||||||||||||||
| 34 | - | |||||||||||||||||||||||||
| 35 | - | |||||||||||||||||||||||||
| 36 | || url.isLocalFile()
| 8-39 | ||||||||||||||||||||||||
| 37 | return executed 39 times by 1 test: new QNetworkAccessFileBackend;return new QNetworkAccessFileBackend;Executed by:
executed 39 times by 1 test: return new QNetworkAccessFileBackend;Executed by:
| 39 | ||||||||||||||||||||||||
| 38 | } else if (!url.scheme().isEmpty()
| 0-5 | ||||||||||||||||||||||||
| 39 | - | |||||||||||||||||||||||||
| 40 | - | |||||||||||||||||||||||||
| 41 | - | |||||||||||||||||||||||||
| 42 | - | |||||||||||||||||||||||||
| 43 | - | |||||||||||||||||||||||||
| 44 | - | |||||||||||||||||||||||||
| 45 | QFileInfo fi(url.toString(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery)); | - | ||||||||||||||||||||||||
| 46 | if (fi.exists()
| 0-4 | ||||||||||||||||||||||||
| 47 | return executed 4 times by 1 test: new QNetworkAccessFileBackend;return new QNetworkAccessFileBackend;Executed by:
executed 4 times by 1 test: return new QNetworkAccessFileBackend;Executed by:
| 4 | ||||||||||||||||||||||||
| 48 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 49 | - | |||||||||||||||||||||||||
| 50 | return executed 4 times by 1 test: 0;return 0;Executed by:
executed 4 times by 1 test: return 0;Executed by:
| 4 | ||||||||||||||||||||||||
| 51 | } | - | ||||||||||||||||||||||||
| 52 | - | |||||||||||||||||||||||||
| 53 | QNetworkAccessFileBackend::QNetworkAccessFileBackend() | - | ||||||||||||||||||||||||
| 54 | : uploadByteDevice(0), totalBytes(0), hasUploadFinished(false) | - | ||||||||||||||||||||||||
| 55 | { | - | ||||||||||||||||||||||||
| 56 | } executed 43 times by 1 test: end of blockExecuted by:
| 43 | ||||||||||||||||||||||||
| 57 | - | |||||||||||||||||||||||||
| 58 | QNetworkAccessFileBackend::~QNetworkAccessFileBackend() | - | ||||||||||||||||||||||||
| 59 | { | - | ||||||||||||||||||||||||
| 60 | } | - | ||||||||||||||||||||||||
| 61 | - | |||||||||||||||||||||||||
| 62 | void QNetworkAccessFileBackend::open() | - | ||||||||||||||||||||||||
| 63 | { | - | ||||||||||||||||||||||||
| 64 | QUrl url = this->url(); | - | ||||||||||||||||||||||||
| 65 | - | |||||||||||||||||||||||||
| 66 | if (url.host() == QLatin1String("localhost")
| 0-43 | ||||||||||||||||||||||||
| 67 | url.setHost(QString()); never executed: url.setHost(QString()); | 0 | ||||||||||||||||||||||||
| 68 | - | |||||||||||||||||||||||||
| 69 | - | |||||||||||||||||||||||||
| 70 | if (!url.host().isEmpty()
| 0-43 | ||||||||||||||||||||||||
| 71 | - | |||||||||||||||||||||||||
| 72 | error(QNetworkReply::ProtocolInvalidOperationError, | - | ||||||||||||||||||||||||
| 73 | QCoreApplication::translate("QNetworkAccessFileBackend", "Request for opening non-local file %1").arg(url.toString())); | - | ||||||||||||||||||||||||
| 74 | finished(); | - | ||||||||||||||||||||||||
| 75 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 76 | } | - | ||||||||||||||||||||||||
| 77 | - | |||||||||||||||||||||||||
| 78 | if (url.path().isEmpty()
| 0-43 | ||||||||||||||||||||||||
| 79 | url.setPath(QLatin1String("/")); never executed: url.setPath(QLatin1String("/")); | 0 | ||||||||||||||||||||||||
| 80 | setUrl(url); | - | ||||||||||||||||||||||||
| 81 | - | |||||||||||||||||||||||||
| 82 | QString fileName = url.toLocalFile(); | - | ||||||||||||||||||||||||
| 83 | if (fileName.isEmpty()
| 4-39 | ||||||||||||||||||||||||
| 84 | if (url.scheme() == QLatin1String("qrc")
| 0-4 | ||||||||||||||||||||||||
| 85 | fileName = QLatin1Char(':') + url.path(); | - | ||||||||||||||||||||||||
| 86 | } never executed: else {end of block | 0 | ||||||||||||||||||||||||
| 87 | - | |||||||||||||||||||||||||
| 88 | - | |||||||||||||||||||||||||
| 89 | - | |||||||||||||||||||||||||
| 90 | - | |||||||||||||||||||||||||
| 91 | - | |||||||||||||||||||||||||
| 92 | fileName = url.toString(QUrl::RemoveAuthority | QUrl::RemoveFragment | QUrl::RemoveQuery); | - | ||||||||||||||||||||||||
| 93 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 94 | } | - | ||||||||||||||||||||||||
| 95 | file.setFileName(fileName); | - | ||||||||||||||||||||||||
| 96 | - | |||||||||||||||||||||||||
| 97 | if (operation() == QNetworkAccessManager::GetOperation
| 4-39 | ||||||||||||||||||||||||
| 98 | if (!loadFileInfo()
| 0-4 | ||||||||||||||||||||||||
| 99 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 100 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 101 | - | |||||||||||||||||||||||||
| 102 | QIODevice::OpenMode mode; | - | ||||||||||||||||||||||||
| 103 | switch (operation()) { | - | ||||||||||||||||||||||||
| 104 | case executed 4 times by 1 test: QNetworkAccessManager::GetOperation:case QNetworkAccessManager::GetOperation:Executed by:
executed 4 times by 1 test: case QNetworkAccessManager::GetOperation:Executed by:
| 4 | ||||||||||||||||||||||||
| 105 | mode = QIODevice::ReadOnly; | - | ||||||||||||||||||||||||
| 106 | break; executed 4 times by 1 test: break;Executed by:
| 4 | ||||||||||||||||||||||||
| 107 | case executed 39 times by 1 test: QNetworkAccessManager::PutOperation:case QNetworkAccessManager::PutOperation:Executed by:
executed 39 times by 1 test: case QNetworkAccessManager::PutOperation:Executed by:
| 39 | ||||||||||||||||||||||||
| 108 | mode = QIODevice::WriteOnly | QIODevice::Truncate; | - | ||||||||||||||||||||||||
| 109 | uploadByteDevice = createUploadByteDevice(); | - | ||||||||||||||||||||||||
| 110 | QObject::connect(uploadByteDevice, qFlagLocation("2""readyRead()" "\0" __FILE__ ":" "149"), this, qFlagLocation("1""uploadReadyReadSlot()" "\0" __FILE__ ":" "149")); | - | ||||||||||||||||||||||||
| 111 | QMetaObject::invokeMethod(this, "uploadReadyReadSlot", Qt::QueuedConnection); | - | ||||||||||||||||||||||||
| 112 | break; executed 39 times by 1 test: break;Executed by:
| 39 | ||||||||||||||||||||||||
| 113 | default never executed: :default:never executed: default: | 0 | ||||||||||||||||||||||||
| 114 | ((!(false)) ? qt_assert_x("QNetworkAccessFileBackend::open", "Got a request operation I cannot handle!!", | - | ||||||||||||||||||||||||
| 115 | __FILE__ | - | ||||||||||||||||||||||||
| 116 | , | - | ||||||||||||||||||||||||
| 117 | 154 | - | ||||||||||||||||||||||||
| 118 | ) : qt_noop()) | - | ||||||||||||||||||||||||
| 119 | ; | - | ||||||||||||||||||||||||
| 120 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 121 | } | - | ||||||||||||||||||||||||
| 122 | - | |||||||||||||||||||||||||
| 123 | mode |= QIODevice::Unbuffered; | - | ||||||||||||||||||||||||
| 124 | bool opened = file.open(mode); | - | ||||||||||||||||||||||||
| 125 | - | |||||||||||||||||||||||||
| 126 | - | |||||||||||||||||||||||||
| 127 | if (!opened
| 0-43 | ||||||||||||||||||||||||
| 128 | QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Error opening %1: %2") | - | ||||||||||||||||||||||||
| 129 | .arg(this->url().toString(), file.errorString()); | - | ||||||||||||||||||||||||
| 130 | - | |||||||||||||||||||||||||
| 131 | - | |||||||||||||||||||||||||
| 132 | - | |||||||||||||||||||||||||
| 133 | - | |||||||||||||||||||||||||
| 134 | if (file.exists()
| 0 | ||||||||||||||||||||||||
| 135 | error(QNetworkReply::ContentAccessDenied, msg); never executed: error(QNetworkReply::ContentAccessDenied, msg); | 0 | ||||||||||||||||||||||||
| 136 | else | - | ||||||||||||||||||||||||
| 137 | error(QNetworkReply::ContentNotFoundError, msg); never executed: error(QNetworkReply::ContentNotFoundError, msg); | 0 | ||||||||||||||||||||||||
| 138 | finished(); | - | ||||||||||||||||||||||||
| 139 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 140 | } executed 43 times by 1 test: end of blockExecuted by:
| 43 | ||||||||||||||||||||||||
| 141 | - | |||||||||||||||||||||||||
| 142 | void QNetworkAccessFileBackend::uploadReadyReadSlot() | - | ||||||||||||||||||||||||
| 143 | { | - | ||||||||||||||||||||||||
| 144 | if (hasUploadFinished
| 2-124 | ||||||||||||||||||||||||
| 145 | return; executed 2 times by 1 test: return;Executed by:
| 2 | ||||||||||||||||||||||||
| 146 | - | |||||||||||||||||||||||||
| 147 | for(;;) { | - | ||||||||||||||||||||||||
| 148 | qint64 haveRead; | - | ||||||||||||||||||||||||
| 149 | const char *readPointer = uploadByteDevice->readPointer(-1, haveRead); | - | ||||||||||||||||||||||||
| 150 | if (haveRead == -1
| 39-672 | ||||||||||||||||||||||||
| 151 | - | |||||||||||||||||||||||||
| 152 | hasUploadFinished = true; | - | ||||||||||||||||||||||||
| 153 | file.flush(); | - | ||||||||||||||||||||||||
| 154 | file.close(); | - | ||||||||||||||||||||||||
| 155 | finished(); | - | ||||||||||||||||||||||||
| 156 | break; executed 39 times by 1 test: break;Executed by:
| 39 | ||||||||||||||||||||||||
| 157 | } else if (haveRead == 0
| 0-587 | ||||||||||||||||||||||||
| 158 | - | |||||||||||||||||||||||||
| 159 | break; executed 85 times by 1 test: break;Executed by:
| 85 | ||||||||||||||||||||||||
| 160 | } else { | - | ||||||||||||||||||||||||
| 161 | qint64 haveWritten; | - | ||||||||||||||||||||||||
| 162 | haveWritten = file.write(readPointer, haveRead); | - | ||||||||||||||||||||||||
| 163 | - | |||||||||||||||||||||||||
| 164 | if (haveWritten < 0
| 0-587 | ||||||||||||||||||||||||
| 165 | - | |||||||||||||||||||||||||
| 166 | QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Write error writing to %1: %2") | - | ||||||||||||||||||||||||
| 167 | .arg(url().toString(), file.errorString()); | - | ||||||||||||||||||||||||
| 168 | error(QNetworkReply::ProtocolFailure, msg); | - | ||||||||||||||||||||||||
| 169 | - | |||||||||||||||||||||||||
| 170 | finished(); | - | ||||||||||||||||||||||||
| 171 | return; never executed: return; | 0 | ||||||||||||||||||||||||
| 172 | } else { | - | ||||||||||||||||||||||||
| 173 | uploadByteDevice->advanceReadPointer(haveWritten); | - | ||||||||||||||||||||||||
| 174 | } executed 587 times by 1 test: end of blockExecuted by:
| 587 | ||||||||||||||||||||||||
| 175 | - | |||||||||||||||||||||||||
| 176 | - | |||||||||||||||||||||||||
| 177 | file.flush(); | - | ||||||||||||||||||||||||
| 178 | } executed 587 times by 1 test: end of blockExecuted by:
| 587 | ||||||||||||||||||||||||
| 179 | } | - | ||||||||||||||||||||||||
| 180 | } executed 124 times by 1 test: end of blockExecuted by:
| 124 | ||||||||||||||||||||||||
| 181 | - | |||||||||||||||||||||||||
| 182 | void QNetworkAccessFileBackend::closeDownstreamChannel() | - | ||||||||||||||||||||||||
| 183 | { | - | ||||||||||||||||||||||||
| 184 | if (operation() == QNetworkAccessManager::GetOperation
| 0 | ||||||||||||||||||||||||
| 185 | file.close(); | - | ||||||||||||||||||||||||
| 186 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 187 | } never executed: end of block | 0 | ||||||||||||||||||||||||
| 188 | - | |||||||||||||||||||||||||
| 189 | void QNetworkAccessFileBackend::downstreamReadyWrite() | - | ||||||||||||||||||||||||
| 190 | { | - | ||||||||||||||||||||||||
| 191 | ((!(operation() == QNetworkAccessManager::GetOperation)) ? qt_assert_x("QNetworkAccessFileBackend", "We're being told to download data but operation isn't GET!", | - | ||||||||||||||||||||||||
| 192 | __FILE__ | - | ||||||||||||||||||||||||
| 193 | , | - | ||||||||||||||||||||||||
| 194 | 227 | - | ||||||||||||||||||||||||
| 195 | ) : qt_noop()) | - | ||||||||||||||||||||||||
| 196 | ; | - | ||||||||||||||||||||||||
| 197 | - | |||||||||||||||||||||||||
| 198 | readMoreFromFile(); | - | ||||||||||||||||||||||||
| 199 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||||||||||||||||||||
| 200 | - | |||||||||||||||||||||||||
| 201 | bool QNetworkAccessFileBackend::loadFileInfo() | - | ||||||||||||||||||||||||
| 202 | { | - | ||||||||||||||||||||||||
| 203 | QFileInfo fi(file); | - | ||||||||||||||||||||||||
| 204 | setHeader(QNetworkRequest::LastModifiedHeader, fi.lastModified()); | - | ||||||||||||||||||||||||
| 205 | setHeader(QNetworkRequest::ContentLengthHeader, fi.size()); | - | ||||||||||||||||||||||||
| 206 | - | |||||||||||||||||||||||||
| 207 | - | |||||||||||||||||||||||||
| 208 | metaDataChanged(); | - | ||||||||||||||||||||||||
| 209 | - | |||||||||||||||||||||||||
| 210 | if (fi.isDir()
| 0-4 | ||||||||||||||||||||||||
| 211 | error(QNetworkReply::ContentOperationNotPermittedError, | - | ||||||||||||||||||||||||
| 212 | QCoreApplication::translate("QNetworkAccessFileBackend", "Cannot open %1: Path is a directory").arg(url().toString())); | - | ||||||||||||||||||||||||
| 213 | finished(); | - | ||||||||||||||||||||||||
| 214 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 215 | } | - | ||||||||||||||||||||||||
| 216 | - | |||||||||||||||||||||||||
| 217 | return executed 4 times by 1 test: true;return true;Executed by:
executed 4 times by 1 test: return true;Executed by:
| 4 | ||||||||||||||||||||||||
| 218 | } | - | ||||||||||||||||||||||||
| 219 | - | |||||||||||||||||||||||||
| 220 | bool QNetworkAccessFileBackend::readMoreFromFile() | - | ||||||||||||||||||||||||
| 221 | { | - | ||||||||||||||||||||||||
| 222 | qint64 wantToRead; | - | ||||||||||||||||||||||||
| 223 | while ((
| 0-38 | ||||||||||||||||||||||||
| 224 | - | |||||||||||||||||||||||||
| 225 | - | |||||||||||||||||||||||||
| 226 | - | |||||||||||||||||||||||||
| 227 | QByteArray data; | - | ||||||||||||||||||||||||
| 228 | data.reserve(wantToRead); | - | ||||||||||||||||||||||||
| 229 | qint64 actuallyRead = file.read(data.data(), wantToRead); | - | ||||||||||||||||||||||||
| 230 | if (actuallyRead <= 0
| 4-34 | ||||||||||||||||||||||||
| 231 | - | |||||||||||||||||||||||||
| 232 | if (file.error() != QFile::NoError
| 0-4 | ||||||||||||||||||||||||
| 233 | QString msg = QCoreApplication::translate("QNetworkAccessFileBackend", "Read error reading from %1: %2") | - | ||||||||||||||||||||||||
| 234 | .arg(url().toString(), file.errorString()); | - | ||||||||||||||||||||||||
| 235 | error(QNetworkReply::ProtocolFailure, msg); | - | ||||||||||||||||||||||||
| 236 | - | |||||||||||||||||||||||||
| 237 | finished(); | - | ||||||||||||||||||||||||
| 238 | return never executed: false;return false;never executed: return false; | 0 | ||||||||||||||||||||||||
| 239 | } | - | ||||||||||||||||||||||||
| 240 | - | |||||||||||||||||||||||||
| 241 | finished(); | - | ||||||||||||||||||||||||
| 242 | return executed 4 times by 1 test: true;return true;Executed by:
executed 4 times by 1 test: return true;Executed by:
| 4 | ||||||||||||||||||||||||
| 243 | } | - | ||||||||||||||||||||||||
| 244 | - | |||||||||||||||||||||||||
| 245 | data.resize(actuallyRead); | - | ||||||||||||||||||||||||
| 246 | totalBytes += actuallyRead; | - | ||||||||||||||||||||||||
| 247 | - | |||||||||||||||||||||||||
| 248 | QByteDataBuffer list; | - | ||||||||||||||||||||||||
| 249 | list.append(data); | - | ||||||||||||||||||||||||
| 250 | data.clear(); | - | ||||||||||||||||||||||||
| 251 | writeDownstreamData(list); | - | ||||||||||||||||||||||||
| 252 | } executed 34 times by 1 test: end of blockExecuted by:
| 34 | ||||||||||||||||||||||||
| 253 | return never executed: true;return true;never executed: return true; | 0 | ||||||||||||||||||||||||
| 254 | } | - | ||||||||||||||||||||||||
| 255 | - | |||||||||||||||||||||||||
| 256 | - | |||||||||||||||||||||||||
| Switch to Source code | Preprocessed file |