Put cookies into csync

We already have the auth cookies from the quota request,
so put them into csync to avoid a 401 roundtrip
This commit is contained in:
Markus Goetz 2013-07-17 16:27:18 +02:00
parent ab72644ace
commit ab7bfabf12
5 changed files with 34 additions and 0 deletions

View file

@ -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<QNetworkCookie> c)
{
_lastAuthCookies = c;
}
}

View file

@ -22,6 +22,7 @@
#include <QThread>
#include <QString>
#include <QNetworkProxy>
#include <QNetworkCookie>
#include <csync.h>
@ -43,6 +44,8 @@ public:
Q_INVOKABLE void startSync();
void setLastAuthCookies(QList<QNetworkCookie> 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<QNetworkCookie> _lastAuthCookies;
friend class CSyncRunScopeHelper;
};
}

View file

@ -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>("SyncFileItemVector");
qRegisterMetaType<SyncFileItem::Direction>("SyncFileItem::Direction");

View file

@ -373,6 +373,13 @@ void ownCloudInfo::slotAuthentication( QNetworkReply *reply, QAuthenticator *aut
}
}
QList<QNetworkCookie> ownCloudInfo::getLastAuthCookies()
{
QUrl url = QUrl( webdavUrl(_connection));
QList<QNetworkCookie> cookies = _manager->cookieJar()->cookiesForUrl(url);
return cookies;
}
QString ownCloudInfo::configHandle(QNetworkReply *reply)
{
QString configHandle;

View file

@ -118,6 +118,8 @@ public:
qint64 lastQuotaUsedBytes() const { return _lastQuotaUsedBytes; }
qint64 lastQuotaTotalBytes() const { return _lastQuotaTotalBytes; }
QList<QNetworkCookie> getLastAuthCookies();
signals:
// result signal with url- and version string.
void ownCloudInfoFound( const QString&, const QString&, const QString&, const QString& );