diff options
author | Olivier Goffart <ogoffart@woboq.com> | 2014-03-20 16:26:40 +0400 |
---|---|---|
committer | Olivier Goffart <ogoffart@woboq.com> | 2014-03-20 16:31:42 +0400 |
commit | ebeb668a621b7c800324549d3c9d9a64ef20ab05 (patch) | |
tree | 6ea17dd545498d903474372cb795b48c6c5f3b5f /src/mirall/propagator_qnam.cpp | |
parent | d2e19236943b3cf48d55af513103a2f0b97ba9fb (diff) |
QNAM jobs: Make sure there is an etag is proper and not changed when one resume
Those tests are existing on the legacy jobs.
We check there is an etag so we make sure a proxy is not in between.
(We have seen user complaining because their proxy is replacing the
pages with one that says they need to enter their login and password)
Also it is important to check that the etag has not changed if we resume
(this may happen if the file is changed on the server between the update
phase and the propagate phase, and that we resume this file)
Diffstat (limited to 'src/mirall/propagator_qnam.cpp')
-rw-r--r-- | src/mirall/propagator_qnam.cpp | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/mirall/propagator_qnam.cpp b/src/mirall/propagator_qnam.cpp index fa4cc2b1c..280382e0e 100644 --- a/src/mirall/propagator_qnam.cpp +++ b/src/mirall/propagator_qnam.cpp @@ -288,12 +288,31 @@ void GETFileJob::start() { qWarning() << Q_FUNC_INFO << " Network error: " << reply()->errorString(); } + connect(reply(), SIGNAL(metaDataChanged()), this, SLOT(slotMetaDataChanged())); connect(reply(), SIGNAL(readyRead()), this, SLOT(slotReadyRead())); connect(reply(), SIGNAL(downloadProgress(qint64,qint64)), this, SIGNAL(downloadProgress(qint64,qint64))); AbstractNetworkJob::start(); } +void GETFileJob::slotMetaDataChanged() +{ + QByteArray etag = parseEtag(reply()->rawHeader("Etag")); + + if (etag.isEmpty()) { + qDebug() << Q_FUNC_INFO << "No E-Tag reply by server, considering it invalid"; + _errorString = tr("No E-Tag received from server, check Proxy/Gateway"); + reply()->abort(); + return; + } else if (!_expectedEtagForResume.isEmpty() && _expectedEtagForResume != etag) { + qDebug() << Q_FUNC_INFO << "We received a different E-Tag for resuming!" + << _expectedEtagForResume << "vs" << etag; + _errorString = tr("We received a different E-Tag for resuming. Retrying next time."); + reply()->abort(); + return; + } +} + void GETFileJob::slotReadyRead() { int bufferSize = qMax(1024*8ll , reply()->bytesAvailable()); @@ -319,6 +338,7 @@ void GETFileJob::slotReadyRead() } + void PropagateDownloadFileQNAM::start() { if (_propagator->_abortRequested.fetchAndAddRelaxed(0)) @@ -329,6 +349,7 @@ void PropagateDownloadFileQNAM::start() emit progress(_item, 0); QString tmpFileName; + QByteArray expectedEtagForResume; const SyncJournalDb::DownloadInfo progressInfo = _propagator->_journal->getDownloadInfo(_item._file); if (progressInfo._valid) { // if the etag has changed meanwhile, remove the already downloaded part. @@ -337,7 +358,7 @@ void PropagateDownloadFileQNAM::start() _propagator->_journal->setDownloadInfo(_item._file, SyncJournalDb::DownloadInfo()); } else { tmpFileName = progressInfo._tmpfile; - _expectedEtagForResume = progressInfo._etag; + expectedEtagForResume = progressInfo._etag; } } @@ -386,7 +407,9 @@ void PropagateDownloadFileQNAM::start() _startSize = done; } - _job = new GETFileJob(AccountManager::instance()->account(), _propagator->_remoteFolder + _item._file, &_tmpFile, headers); + _job = new GETFileJob(AccountManager::instance()->account(), + _propagator->_remoteFolder + _item._file, + &_tmpFile, headers, expectedEtagForResume); connect(_job, SIGNAL(finishedSignal()), this, SLOT(slotGetFinished())); connect(_job, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(slotDownloadProgress(qint64,qint64))); _propagator->_activeJobs ++; |