From ab7bfabf12a5886c0b5dc6b22293bb24a5944744 Mon Sep 17 00:00:00 2001 From: Markus Goetz Date: Wed, 17 Jul 2013 16:27:18 +0200 Subject: [PATCH] Put cookies into csync We already have the auth cookies from the quota request, so put them into csync to avoid a 401 roundtrip --- src/mirall/csyncthread.cpp | 18 ++++++++++++++++++ src/mirall/csyncthread.h | 5 +++++ src/mirall/owncloudfolder.cpp | 2 ++ src/mirall/owncloudinfo.cpp | 7 +++++++ src/mirall/owncloudinfo.h | 2 ++ 5 files changed, 34 insertions(+) diff --git a/src/mirall/csyncthread.cpp b/src/mirall/csyncthread.cpp index 8293bd09c..e2947eba9 100644 --- a/src/mirall/csyncthread.cpp +++ b/src/mirall/csyncthread.cpp @@ -320,6 +320,19 @@ void CSyncThread::startSync() csync_set_module_property(_csync_ctx, "csync_context", _csync_ctx); csync_set_userdata(_csync_ctx, this); + if (_lastAuthCookies.length() > 0) { + // Stuff cookies inside csync, then we can avoid the intermediate HTTP 401 reply + // when https://github.com/owncloud/core/pull/4042 is merged. + QString cookiesAsString; + foreach(QNetworkCookie c, _lastAuthCookies) { + cookiesAsString += c.name(); + cookiesAsString += '='; + cookiesAsString += c.value(); + cookiesAsString += "; "; + } + csync_set_module_property(_csync_ctx, "session_key", cookiesAsString.toAscii().data()); + } + // csync_set_auth_callback( _csync_ctx, getauth ); qDebug() << "#### Update start #################################################### >>"; @@ -395,5 +408,10 @@ void CSyncThread::cb_progress(const char *remote_url, enum csync_notify_type_e k } } +void CSyncThread::setLastAuthCookies(QList c) +{ + _lastAuthCookies = c; +} + } diff --git a/src/mirall/csyncthread.h b/src/mirall/csyncthread.h index 350e2f4ab..2ed71f8fb 100644 --- a/src/mirall/csyncthread.h +++ b/src/mirall/csyncthread.h @@ -22,6 +22,7 @@ #include #include #include +#include #include @@ -43,6 +44,8 @@ public: Q_INVOKABLE void startSync(); + void setLastAuthCookies(QList c); + signals: void fileReceived( const QString& ); void fileRemoved( const QString& ); @@ -86,6 +89,8 @@ private: bool _hasFiles; // true if there is at least one file that is not ignored or removed + QList _lastAuthCookies; + friend class CSyncRunScopeHelper; }; } diff --git a/src/mirall/owncloudfolder.cpp b/src/mirall/owncloudfolder.cpp index b5d0265c1..cd18b379c 100644 --- a/src/mirall/owncloudfolder.cpp +++ b/src/mirall/owncloudfolder.cpp @@ -298,8 +298,10 @@ void ownCloudFolder::startSync(const QStringList &pathList) _thread->setPriority(QThread::LowPriority); setIgnoredFiles(); _csync = new CSyncThread( _csync_ctx ); + _csync->setLastAuthCookies(ownCloudInfo::instance()->getLastAuthCookies()); _csync->moveToThread(_thread); + qRegisterMetaType("SyncFileItemVector"); qRegisterMetaType("SyncFileItem::Direction"); diff --git a/src/mirall/owncloudinfo.cpp b/src/mirall/owncloudinfo.cpp index 14513fb03..fefaa198d 100644 --- a/src/mirall/owncloudinfo.cpp +++ b/src/mirall/owncloudinfo.cpp @@ -373,6 +373,13 @@ void ownCloudInfo::slotAuthentication( QNetworkReply *reply, QAuthenticator *aut } } +QList ownCloudInfo::getLastAuthCookies() +{ + QUrl url = QUrl( webdavUrl(_connection)); + QList cookies = _manager->cookieJar()->cookiesForUrl(url); + return cookies; +} + QString ownCloudInfo::configHandle(QNetworkReply *reply) { QString configHandle; diff --git a/src/mirall/owncloudinfo.h b/src/mirall/owncloudinfo.h index 9060fdd7a..e0bf50415 100644 --- a/src/mirall/owncloudinfo.h +++ b/src/mirall/owncloudinfo.h @@ -118,6 +118,8 @@ public: qint64 lastQuotaUsedBytes() const { return _lastQuotaUsedBytes; } qint64 lastQuotaTotalBytes() const { return _lastQuotaTotalBytes; } + QList getLastAuthCookies(); + signals: // result signal with url- and version string. void ownCloudInfoFound( const QString&, const QString&, const QString&, const QString& );