Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Goetz <markus@woboq.com>2014-06-03 13:50:13 +0400
committerMarkus Goetz <markus@woboq.com>2014-06-03 16:55:34 +0400
commit4d4eab8b1c0d37375d72a29698136131c47fbcd9 (patch)
tree7c30cafb6676b4d5aec707a13705357c7008a30b /src/mirall/propagator_qnam.cpp
parent4d4ae9374b5ea967e91530e9d66c29fd32e5bf2b (diff)
CSync & Propagator: Support a direct download URL
This is for server file backends that support sending a direct URL.
Diffstat (limited to 'src/mirall/propagator_qnam.cpp')
-rw-r--r--src/mirall/propagator_qnam.cpp86
1 files changed, 64 insertions, 22 deletions
diff --git a/src/mirall/propagator_qnam.cpp b/src/mirall/propagator_qnam.cpp
index 78a0cd8cc..e8e496ed1 100644
--- a/src/mirall/propagator_qnam.cpp
+++ b/src/mirall/propagator_qnam.cpp
@@ -358,13 +358,38 @@ void PropagateUploadFileQNAM::abort()
///////////////////////////////////////////////////////////////////////////////////////////////////
+// DOES NOT take owncership of the device.
+GETFileJob::GETFileJob(Account* account, const QString& path, QIODevice *device,
+ const QMap<QByteArray, QByteArray> &headers, QByteArray expectedEtagForResume,
+ QObject* parent)
+: AbstractNetworkJob(account, path, parent),
+ _device(device), _headers(headers), _expectedEtagForResume(expectedEtagForResume),
+ _errorStatus(SyncFileItem::NoStatus)
+{
+}
+
+GETFileJob::GETFileJob(Account* account, const QUrl& url, QIODevice *device,
+ const QMap<QByteArray, QByteArray> &headers,
+ QObject* parent)
+: AbstractNetworkJob(account, url.toEncoded(), parent),
+ _device(device), _headers(headers),
+ _errorStatus(SyncFileItem::NoStatus), _directDownloadUrl(url)
+{
+}
+
+
void GETFileJob::start() {
QNetworkRequest req;
for(QMap<QByteArray, QByteArray>::const_iterator it = _headers.begin(); it != _headers.end(); ++it) {
req.setRawHeader(it.key(), it.value());
}
- setReply(davRequest("GET", path(), req));
+ if (_directDownloadUrl.isEmpty()) {
+ setReply(davRequest("GET", path(), req));
+ } else {
+ // Use direct URL
+ setReply(davRequest("GET", _directDownloadUrl, req));
+ }
setupConnections(reply());
if( reply()->error() != QNetworkReply::NoError ) {
@@ -386,17 +411,21 @@ void GETFileJob::slotMetaDataChanged()
return;
}
- QByteArray etag = parseEtag(reply()->rawHeader("Etag"));
-
- if (etag.isEmpty()) {
+ _etag = parseEtag(reply()->rawHeader("Etag"));
+ if (!_directDownloadUrl.isEmpty() && !_etag.isEmpty()) {
+ qDebug() << Q_FUNC_INFO << "Direct download used, ignoring server ETag" << _etag;
+ _etag = QByteArray(); // reset received ETag
+ } else if (!_directDownloadUrl.isEmpty()) {
+ // All fine, ETag empty and directDownloadUrl used
+ } else 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");
_errorStatus = SyncFileItem::NormalError;
reply()->abort();
return;
- } else if (!_expectedEtagForResume.isEmpty() && _expectedEtagForResume != etag) {
+ } else if (!_expectedEtagForResume.isEmpty() && _expectedEtagForResume != _etag) {
qDebug() << Q_FUNC_INFO << "We received a different E-Tag for resuming!"
- << _expectedEtagForResume << "vs" << etag;
+ << _expectedEtagForResume << "vs" << _etag;
_errorString = tr("We received a different E-Tag for resuming. Retrying next time.");
_errorStatus = SyncFileItem::NormalError;
reply()->abort();
@@ -431,6 +460,13 @@ void GETFileJob::slotReadyRead()
resetTimeout();
}
+void GETFileJob::slotTimeout()
+{
+ _errorString = tr("Connection Timeout");
+ _errorStatus = SyncFileItem::FatalError;
+ reply()->abort();
+}
+
void PropagateDownloadFileQNAM::start()
{
if (_propagator->_abortRequested.fetchAndAddRelaxed(0))
@@ -438,7 +474,7 @@ void PropagateDownloadFileQNAM::start()
qDebug() << Q_FUNC_INFO << _item._file << _propagator->_activeJobs;
- // do a case clash check.
+ // do a klaas' case clash check.
if( _propagator->localFileNameClash(_item._file) ) {
done( SyncFileItem::NormalError, tr("File %1 can not be downloaded because of a local file name clash!")
.arg(QDir::toNativeSeparators(_item._file)) );
@@ -490,8 +526,6 @@ void PropagateDownloadFileQNAM::start()
QMap<QByteArray, QByteArray> headers;
- /* Allow compressed content by setting the header */
- //headers["Accept-Encoding"] = "gzip";
if (_tmpFile.size() > 0) {
quint64 done = _tmpFile.size();
@@ -506,9 +540,22 @@ void PropagateDownloadFileQNAM::start()
_startSize = done;
}
- _job = new GETFileJob(AccountManager::instance()->account(),
- _propagator->_remoteFolder + _item._file,
- &_tmpFile, headers, expectedEtagForResume);
+ if (_item._directDownloadUrl.isEmpty()) {
+ // Normal job, download from oC instance
+ _job = new GETFileJob(AccountManager::instance()->account(),
+ _propagator->_remoteFolder + _item._file,
+ &_tmpFile, headers, expectedEtagForResume);
+ } else {
+ // We were provided a direct URL, use that one
+ if (!_item._directDownloadCookies.isEmpty()) {
+ headers["Cookie"] = _item._directDownloadCookies.toUtf8();
+ }
+ QUrl url = QUrl::fromUserInput(_item._directDownloadUrl);
+ _job = new GETFileJob(AccountManager::instance()->account(),
+ url,
+ &_tmpFile, headers);
+ qDebug() << Q_FUNC_INFO << "directDownloadUrl given for " << _item._file << _item._directDownloadUrl;
+ }
_job->setTimeout(_propagator->httpTimeout() * 1000);
connect(_job, SIGNAL(finishedSignal()), this, SLOT(slotGetFinished()));
connect(_job, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(slotDownloadProgress(qint64,qint64)));
@@ -546,7 +593,11 @@ void PropagateDownloadFileQNAM::slotGetFinished()
return;
}
- _item._etag = parseEtag(job->reply()->rawHeader("Etag"));
+ if (!job->etag().isEmpty()) {
+ // The etag will be empty if we used a direct download URL.
+ // (If it was really empty by the server, the GETFileJob will have errored
+ _item._etag = parseEtag(job->etag());
+ }
_item._requestDuration = job->duration();
_item._responseTimeStamp = job->responseTimestamp();
@@ -628,13 +679,4 @@ void PropagateDownloadFileQNAM::abort()
_job->reply()->abort();
}
-void GETFileJob::slotTimeout()
-{
- _errorString = tr("Connection Timeout");
- _errorStatus = SyncFileItem::FatalError;
- reply()->abort();
-}
-
-
-
}