| Line | Source Code | Coverage |
|---|
| 1 | | - |
| 2 | | - |
| 3 | | - |
| 4 | | - |
| 5 | | - |
| 6 | enum { | - |
| 7 | DefaultFtpPort = 21 | - |
| 8 | }; | - |
| 9 | | - |
| 10 | static QByteArray makeCacheKey(const QUrl &url) | - |
| 11 | { | - |
| 12 | QUrl copy = url; | - |
| 13 | copy.setPort(url.port(DefaultFtpPort)); | - |
| 14 | return "ftp-connection:" + | 76 |
| 15 | copy.toEncoded(QUrl::RemovePassword | QUrl::RemovePath | QUrl::RemoveQuery | | 76 |
| 16 | QUrl::RemoveFragment); executed: return "ftp-connection:" + copy.toEncoded(QUrl::RemovePassword | QUrl::RemovePath | QUrl::RemoveQuery | QUrl::RemoveFragment);Execution Count:76 | 76 |
| 17 | } | - |
| 18 | | - |
| 19 | QNetworkAccessBackend * | - |
| 20 | QNetworkAccessFtpBackendFactory::create(QNetworkAccessManager::Operation op, | - |
| 21 | const QNetworkRequest &request) const | - |
| 22 | { | - |
| 23 | | - |
| 24 | switch (op) { | - |
| 25 | case QNetworkAccessManager::GetOperation: | - |
| 26 | case QNetworkAccessManager::PutOperation: | - |
| 27 | break; executed: break;Execution Count:89 | 89 |
| 28 | | - |
| 29 | default: | - |
| 30 | | - |
| 31 | return 0; never executed: return 0; | 0 |
| 32 | } | - |
| 33 | | - |
| 34 | QUrl url = request.url(); | - |
| 35 | if (url.scheme().compare(QLatin1String("ftp"), Qt::CaseInsensitive) == 0) evaluated: url.scheme().compare(QLatin1String("ftp"), Qt::CaseInsensitive) == 0| yes Evaluation Count:42 | yes Evaluation Count:47 |
| 42-47 |
| 36 | return new QNetworkAccessFtpBackend; executed: return new QNetworkAccessFtpBackend;Execution Count:42 | 42 |
| 37 | return 0; executed: return 0;Execution Count:47 | 47 |
| 38 | } | - |
| 39 | | - |
| 40 | class QNetworkAccessCachedFtpConnection: public QFtp, public QNetworkAccessCache::CacheableObject | - |
| 41 | { | - |
| 42 | | - |
| 43 | public: | - |
| 44 | QNetworkAccessCachedFtpConnection() | - |
| 45 | { | - |
| 46 | setExpires(true); | - |
| 47 | setShareable(false); | - |
| 48 | } executed: }Execution Count:37 | 37 |
| 49 | | - |
| 50 | void dispose() | - |
| 51 | { | - |
| 52 | connect(this, "2""done(bool)", this, "1""deleteLater()"); | - |
| 53 | close(); | - |
| 54 | } executed: }Execution Count:37 | 37 |
| 55 | }; | - |
| 56 | | - |
| 57 | QNetworkAccessFtpBackend::QNetworkAccessFtpBackend() | - |
| 58 | : ftp(0), uploadDevice(0), totalBytes(0), helpId(-1), sizeId(-1), mdtmId(-1), | - |
| 59 | supportsSize(false), supportsMdtm(false), state(Idle) | - |
| 60 | { | - |
| 61 | } executed: }Execution Count:42 | 42 |
| 62 | | - |
| 63 | QNetworkAccessFtpBackend::~QNetworkAccessFtpBackend() | - |
| 64 | { | - |
| 65 | | - |
| 66 | if (ftp && state != Disconnecting) evaluated: ftp| yes Evaluation Count:1 | yes Evaluation Count:41 |
partially evaluated: state != Disconnecting| no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-41 |
| 67 | ftp->abort(); never executed: ftp->abort(); | 0 |
| 68 | disconnectFromFtp(); | - |
| 69 | } executed: }Execution Count:42 | 42 |
| 70 | | - |
| 71 | void QNetworkAccessFtpBackend::open() | - |
| 72 | { | - |
| 73 | | - |
| 74 | QNetworkProxy proxy; | - |
| 75 | for (QForeachContainer<__typeof__(proxyList())> _container_(proxyList()); !_container_.brk && _container_.i != _container_.e; __extension__ ({ ++_container_.brk; ++_container_.i; })) for (const QNetworkProxy &p = *_container_.i;; __extension__ ({--_container_.brk; break;})) { | - |
| 76 | | - |
| 77 | | - |
| 78 | if (p.type() == QNetworkProxy::FtpCachingProxy evaluated: p.type() == QNetworkProxy::FtpCachingProxy| yes Evaluation Count:2 | yes Evaluation Count:42 |
| 2-42 |
| 79 | || p.type() == QNetworkProxy::NoProxy) { evaluated: p.type() == QNetworkProxy::NoProxy| yes Evaluation Count:37 | yes Evaluation Count:5 |
| 5-37 |
| 80 | proxy = p; | - |
| 81 | break; executed: break;Execution Count:39 | 39 |
| 82 | } | - |
| 83 | } executed: }Execution Count:5 | 5 |
| 84 | | - |
| 85 | | - |
| 86 | if (proxy.type() == QNetworkProxy::DefaultProxy) { evaluated: proxy.type() == QNetworkProxy::DefaultProxy| yes Evaluation Count:3 | yes Evaluation Count:39 |
| 3-39 |
| 87 | | - |
| 88 | error(QNetworkReply::ProxyNotFoundError, | - |
| 89 | tr("No suitable proxy found")); | - |
| 90 | finished(); | - |
| 91 | return; executed: return;Execution Count:3 | 3 |
| 92 | } | - |
| 93 | | - |
| 94 | | - |
| 95 | | - |
| 96 | QUrl url = this->url(); | - |
| 97 | if (url.path().isEmpty()) { evaluated: url.path().isEmpty()| yes Evaluation Count:1 | yes Evaluation Count:38 |
| 1-38 |
| 98 | url.setPath(QLatin1String("/")); | - |
| 99 | setUrl(url); | - |
| 100 | } executed: }Execution Count:1 | 1 |
| 101 | if (url.path().endsWith(QLatin1Char('/'))) { evaluated: url.path().endsWith(QLatin1Char('/'))| yes Evaluation Count:1 | yes Evaluation Count:38 |
| 1-38 |
| 102 | error(QNetworkReply::ContentOperationNotPermittedError, | - |
| 103 | tr("Cannot open %1: is a directory").arg(url.toString())); | - |
| 104 | finished(); | - |
| 105 | return; executed: return;Execution Count:1 | 1 |
| 106 | } | - |
| 107 | state = LoggingIn; | - |
| 108 | | - |
| 109 | QNetworkAccessCache* objectCache = QNetworkAccessManagerPrivate::getObjectCache(this); | - |
| 110 | QByteArray cacheKey = makeCacheKey(url); | - |
| 111 | if (!objectCache->requestEntry(cacheKey, this, | 1-37 |
| 112 | "1""ftpConnectionReady(QNetworkAccessCache::CacheableObject*)")) { evaluated: !objectCache->requestEntry(cacheKey, this, "1""ftpConnectionReady(QNetworkAccessCache::CacheableObject*)")| yes Evaluation Count:37 | yes Evaluation Count:1 |
| 1-37 |
| 113 | ftp = new QNetworkAccessCachedFtpConnection; | - |
| 114 | | - |
| 115 | | - |
| 116 | ftp->setProperty("_q_networksession", property("_q_networksession")); | - |
| 117 | | - |
| 118 | | - |
| 119 | if (proxy.type() == QNetworkProxy::FtpCachingProxy) evaluated: proxy.type() == QNetworkProxy::FtpCachingProxy| yes Evaluation Count:2 | yes Evaluation Count:35 |
| 2-35 |
| 120 | ftp->setProxy(proxy.hostName(), proxy.port()); executed: ftp->setProxy(proxy.hostName(), proxy.port());Execution Count:2 | 2 |
| 121 | | - |
| 122 | ftp->connectToHost(url.host(), url.port(DefaultFtpPort)); | - |
| 123 | ftp->login(url.userName(), url.password()); | - |
| 124 | | - |
| 125 | objectCache->addEntry(cacheKey, ftp); | - |
| 126 | ftpConnectionReady(ftp); | - |
| 127 | } executed: }Execution Count:37 | 37 |
| 128 | | - |
| 129 | | - |
| 130 | if (operation() == QNetworkAccessManager::PutOperation) { evaluated: operation() == QNetworkAccessManager::PutOperation| yes Evaluation Count:11 | yes Evaluation Count:27 |
| 11-27 |
| 131 | uploadDevice = QNonContiguousByteDeviceFactory::wrap(createUploadByteDevice()); | - |
| 132 | uploadDevice->setParent(this); | - |
| 133 | } executed: }Execution Count:11 | 11 |
| 134 | } executed: }Execution Count:38 | 38 |
| 135 | | - |
| 136 | void QNetworkAccessFtpBackend::closeDownstreamChannel() | - |
| 137 | { | - |
| 138 | state = Disconnecting; | - |
| 139 | if (operation() == QNetworkAccessManager::GetOperation) partially evaluated: operation() == QNetworkAccessManager::GetOperation| yes Evaluation Count:1 | no Evaluation Count:0 |
| 0-1 |
| 140 | ftp->abort(); executed: ftp->abort();Execution Count:1 | 1 |
| 141 | } executed: }Execution Count:1 | 1 |
| 142 | | - |
| 143 | void QNetworkAccessFtpBackend::downstreamReadyWrite() | - |
| 144 | { | - |
| 145 | if (state == Transferring && ftp && ftp->bytesAvailable()) evaluated: state == Transferring| yes Evaluation Count:787 | yes Evaluation Count:27 |
partially evaluated: ftp| yes Evaluation Count:787 | no Evaluation Count:0 |
partially evaluated: ftp->bytesAvailable()| no Evaluation Count:0 | yes Evaluation Count:787 |
| 0-787 |
| 146 | ftpReadyRead(); never executed: ftpReadyRead(); | 0 |
| 147 | } executed: }Execution Count:814 | 814 |
| 148 | | - |
| 149 | void QNetworkAccessFtpBackend::ftpConnectionReady(QNetworkAccessCache::CacheableObject *o) | - |
| 150 | { | - |
| 151 | ftp = static_cast<QNetworkAccessCachedFtpConnection *>(o); | - |
| 152 | connect(ftp, "2""done(bool)", "1""ftpDone()"); | - |
| 153 | connect(ftp, "2""rawCommandReply(int,QString)", "1""ftpRawCommandReply(int,QString)"); | - |
| 154 | connect(ftp, "2""readyRead()", "1""ftpReadyRead()"); | - |
| 155 | | - |
| 156 | | - |
| 157 | if (ftp->state() == QFtp::LoggedIn) evaluated: ftp->state() == QFtp::LoggedIn| yes Evaluation Count:1 | yes Evaluation Count:37 |
| 1-37 |
| 158 | ftpDone(); executed: ftpDone();Execution Count:1 | 1 |
| 159 | | - |
| 160 | | - |
| 161 | } executed: }Execution Count:38 | 38 |
| 162 | | - |
| 163 | void QNetworkAccessFtpBackend::disconnectFromFtp() | - |
| 164 | { | - |
| 165 | state = Disconnecting; | - |
| 166 | | - |
| 167 | if (ftp) { evaluated: ftp| yes Evaluation Count:36 | yes Evaluation Count:41 |
| 36-41 |
| 168 | disconnect(ftp, 0, this, 0); | - |
| 169 | | - |
| 170 | QByteArray key = makeCacheKey(url()); | - |
| 171 | QNetworkAccessManagerPrivate::getObjectCache(this)->releaseEntry(key); | - |
| 172 | | - |
| 173 | ftp = 0; | - |
| 174 | } executed: }Execution Count:36 | 36 |
| 175 | } executed: }Execution Count:77 | 77 |
| 176 | | - |
| 177 | void QNetworkAccessFtpBackend::ftpDone() | - |
| 178 | { | - |
| 179 | | - |
| 180 | if (state == LoggingIn && ftp->state() != QFtp::LoggedIn) { evaluated: state == LoggingIn| yes Evaluation Count:38 | yes Evaluation Count:104 |
evaluated: ftp->state() != QFtp::LoggedIn| yes Evaluation Count:2 | yes Evaluation Count:36 |
| 2-104 |
| 181 | if (ftp->state() == QFtp::Connected) { evaluated: ftp->state() == QFtp::Connected| yes Evaluation Count:1 | yes Evaluation Count:1 |
| 1 |
| 182 | | - |
| 183 | QUrl newUrl = url(); | - |
| 184 | QString userInfo = newUrl.userInfo(); | - |
| 185 | newUrl.setUserInfo(QString()); | - |
| 186 | setUrl(newUrl); | - |
| 187 | | - |
| 188 | QAuthenticator auth; | - |
| 189 | authenticationRequired(&auth); | - |
| 190 | | - |
| 191 | if (!auth.isNull()) { partially evaluated: !auth.isNull()| no Evaluation Count:0 | yes Evaluation Count:1 |
| 0-1 |
| 192 | | - |
| 193 | newUrl.setUserName(auth.user()); | - |
| 194 | ftp->login(auth.user(), auth.password()); | - |
| 195 | return; | 0 |
| 196 | } | - |
| 197 | | - |
| 198 | | - |
| 199 | newUrl.setUserInfo(userInfo); | - |
| 200 | setUrl(newUrl); | - |
| 201 | | - |
| 202 | error(QNetworkReply::AuthenticationRequiredError, | - |
| 203 | tr("Logging in to %1 failed: authentication required") | - |
| 204 | .arg(url().host())); | - |
| 205 | } else { executed: }Execution Count:1 | 1 |
| 206 | | - |
| 207 | QNetworkReply::NetworkError code; | - |
| 208 | switch (ftp->error()) { | - |
| 209 | case QFtp::HostNotFound: | - |
| 210 | code = QNetworkReply::HostNotFoundError; | - |
| 211 | break; executed: break;Execution Count:1 | 1 |
| 212 | | - |
| 213 | case QFtp::ConnectionRefused: | - |
| 214 | code = QNetworkReply::ConnectionRefusedError; | - |
| 215 | break; | 0 |
| 216 | | - |
| 217 | default: | - |
| 218 | code = QNetworkReply::ProtocolFailure; | - |
| 219 | break; | 0 |
| 220 | } | - |
| 221 | | - |
| 222 | error(code, ftp->errorString()); | - |
| 223 | } executed: }Execution Count:1 | 1 |
| 224 | | - |
| 225 | | - |
| 226 | QByteArray key = makeCacheKey(url()); | - |
| 227 | QNetworkAccessManagerPrivate::getObjectCache(this)->removeEntry(key); | - |
| 228 | | - |
| 229 | disconnect(ftp, 0, this, 0); | - |
| 230 | ftp->dispose(); | - |
| 231 | ftp = 0; | - |
| 232 | | - |
| 233 | state = Disconnecting; | - |
| 234 | finished(); | - |
| 235 | return; executed: return;Execution Count:2 | 2 |
| 236 | } | - |
| 237 | | - |
| 238 | | - |
| 239 | if (ftp->error() != QFtp::NoError) { evaluated: ftp->error() != QFtp::NoError| yes Evaluation Count:4 | yes Evaluation Count:136 |
| 4-136 |
| 240 | QString msg; | - |
| 241 | if (operation() == QNetworkAccessManager::GetOperation) partially evaluated: operation() == QNetworkAccessManager::GetOperation| yes Evaluation Count:4 | no Evaluation Count:0 |
| 0-4 |
| 242 | msg = tr("Error while downloading %1: %2"); executed: msg = tr("Error while downloading %1: %2");Execution Count:4 | 4 |
| 243 | else | - |
| 244 | msg = tr("Error while uploading %1: %2"); never executed: msg = tr("Error while uploading %1: %2"); | 0 |
| 245 | msg = msg.arg(url().toString(), ftp->errorString()); | - |
| 246 | | - |
| 247 | if (state == Statting) evaluated: state == Statting| yes Evaluation Count:3 | yes Evaluation Count:1 |
| 1-3 |
| 248 | | - |
| 249 | error(QNetworkReply::ContentNotFoundError, msg); executed: error(QNetworkReply::ContentNotFoundError, msg);Execution Count:3 | 3 |
| 250 | else | - |
| 251 | error(QNetworkReply::ContentAccessDenied, msg); executed: error(QNetworkReply::ContentAccessDenied, msg);Execution Count:1 | 1 |
| 252 | | - |
| 253 | disconnectFromFtp(); | - |
| 254 | finished(); | - |
| 255 | } executed: }Execution Count:4 | 4 |
| 256 | | - |
| 257 | if (state == LoggingIn) { evaluated: state == LoggingIn| yes Evaluation Count:36 | yes Evaluation Count:104 |
| 36-104 |
| 258 | state = CheckingFeatures; | - |
| 259 | if (operation() == QNetworkAccessManager::GetOperation) { evaluated: operation() == QNetworkAccessManager::GetOperation| yes Evaluation Count:25 | yes Evaluation Count:11 |
| 11-25 |
| 260 | | - |
| 261 | QString command = url().path(); | - |
| 262 | command.prepend(QLatin1String("%1 ")); | - |
| 263 | helpId = ftp->rawCommand(QLatin1String("HELP")); | - |
| 264 | } else { executed: }Execution Count:25 | 25 |
| 265 | ftpDone(); | - |
| 266 | } executed: }Execution Count:11 | 11 |
| 267 | } else if (state == CheckingFeatures) { evaluated: state == CheckingFeatures| yes Evaluation Count:36 | yes Evaluation Count:68 |
| 36-68 |
| 268 | state = Statting; | - |
| 269 | if (operation() == QNetworkAccessManager::GetOperation) { evaluated: operation() == QNetworkAccessManager::GetOperation| yes Evaluation Count:25 | yes Evaluation Count:11 |
| 11-25 |
| 270 | | - |
| 271 | QString command = url().path(); | - |
| 272 | command.prepend(QLatin1String("%1 ")); | - |
| 273 | if (supportsSize) { partially evaluated: supportsSize| yes Evaluation Count:25 | no Evaluation Count:0 |
| 0-25 |
| 274 | ftp->rawCommand(QLatin1String("TYPE I")); | - |
| 275 | sizeId = ftp->rawCommand(command.arg(QLatin1String("SIZE"))); | - |
| 276 | } executed: }Execution Count:25 | 25 |
| 277 | if (supportsMdtm) partially evaluated: supportsMdtm| yes Evaluation Count:25 | no Evaluation Count:0 |
| 0-25 |
| 278 | mdtmId = ftp->rawCommand(command.arg(QLatin1String("MDTM"))); executed: mdtmId = ftp->rawCommand(command.arg(QLatin1String("MDTM")));Execution Count:25 | 25 |
| 279 | if (!supportsSize && !supportsMdtm) partially evaluated: !supportsSize| no Evaluation Count:0 | yes Evaluation Count:25 |
never evaluated: !supportsMdtm | 0-25 |
| 280 | ftpDone(); never executed: ftpDone(); | 0 |
| 281 | } else { executed: }Execution Count:25 | 25 |
| 282 | ftpDone(); | - |
| 283 | } executed: }Execution Count:11 | 11 |
| 284 | } else if (state == Statting) { evaluated: state == Statting| yes Evaluation Count:33 | yes Evaluation Count:35 |
| 33-35 |
| 285 | | - |
| 286 | metaDataChanged(); | - |
| 287 | state = Transferring; | - |
| 288 | | - |
| 289 | QFtp::TransferType type = QFtp::Binary; | - |
| 290 | if (operation() == QNetworkAccessManager::GetOperation) { evaluated: operation() == QNetworkAccessManager::GetOperation| yes Evaluation Count:22 | yes Evaluation Count:11 |
| 11-22 |
| 291 | setCachingEnabled(true); | - |
| 292 | ftp->get(url().path(), 0, type); | - |
| 293 | } else { executed: }Execution Count:22 | 22 |
| 294 | ftp->put(uploadDevice, url().path(), type); | - |
| 295 | } executed: }Execution Count:11 | 11 |
| 296 | | - |
| 297 | } else if (state == Transferring) { evaluated: state == Transferring| yes Evaluation Count:31 | yes Evaluation Count:4 |
| 4-31 |
| 298 | | - |
| 299 | disconnectFromFtp(); | - |
| 300 | finished(); | - |
| 301 | } executed: }Execution Count:31 | 31 |
| 302 | } | - |
| 303 | | - |
| 304 | void QNetworkAccessFtpBackend::ftpReadyRead() | - |
| 305 | { | - |
| 306 | QByteArray data = ftp->readAll(); | - |
| 307 | QByteDataBuffer list; | - |
| 308 | list.append(data); | - |
| 309 | data.clear(); | - |
| 310 | writeDownstreamData(list); | - |
| 311 | } executed: }Execution Count:788 | 788 |
| 312 | | - |
| 313 | void QNetworkAccessFtpBackend::ftpRawCommandReply(int code, const QString &text) | - |
| 314 | { | - |
| 315 | | - |
| 316 | int id = ftp->currentId(); | - |
| 317 | | - |
| 318 | if ((id == helpId) && ((code == 200) || (code == 214))) { partially evaluated: (code == 200)| no Evaluation Count:0 | yes Evaluation Count:25 |
partially evaluated: (code == 214)| yes Evaluation Count:25 | no Evaluation Count:0 |
evaluated: (id == helpId)| yes Evaluation Count:25 | yes Evaluation Count:72 |
| 0-72 |
| 319 | | - |
| 320 | | - |
| 321 | | - |
| 322 | if (text.contains(QLatin1String("SIZE"), Qt::CaseSensitive)) partially evaluated: text.contains(QLatin1String("SIZE"), Qt::CaseSensitive)| yes Evaluation Count:25 | no Evaluation Count:0 |
| 0-25 |
| 323 | supportsSize = true; executed: supportsSize = true;Execution Count:25 | 25 |
| 324 | if (text.contains(QLatin1String("MDTM"), Qt::CaseSensitive)) partially evaluated: text.contains(QLatin1String("MDTM"), Qt::CaseSensitive)| yes Evaluation Count:25 | no Evaluation Count:0 |
| 0-25 |
| 325 | supportsMdtm = true; executed: supportsMdtm = true;Execution Count:25 | 25 |
| 326 | } else if (code == 213) { executed: }Execution Count:25 evaluated: code == 213| yes Evaluation Count:44 | yes Evaluation Count:28 |
| 25-44 |
| 327 | if (id == sizeId) { evaluated: id == sizeId| yes Evaluation Count:22 | yes Evaluation Count:22 |
| 22 |
| 328 | | - |
| 329 | setHeader(QNetworkRequest::ContentLengthHeader, text.toLongLong()); | - |
| 330 | | - |
| 331 | } else if (id == mdtmId) { executed: }Execution Count:22 partially evaluated: id == mdtmId| yes Evaluation Count:22 | no Evaluation Count:0 |
| 0-22 |
| 332 | QDateTime dt = QDateTime::fromString(text, QLatin1String("yyyyMMddHHmmss")); | - |
| 333 | setHeader(QNetworkRequest::LastModifiedHeader, dt); | - |
| 334 | | - |
| 335 | } executed: }Execution Count:22 | 22 |
| 336 | } | - |
| 337 | } | - |
| 338 | | - |
| 339 | | - |
| 340 | | - |
| | |