Skip to content

Commit

Permalink
Cookies: Use different DB for different accounts
Browse files Browse the repository at this point in the history
This is a follow up to #5469
  • Loading branch information
guruz committed Jan 25, 2017
1 parent 268fc97 commit eb2c6e5
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 18 deletions.
6 changes: 4 additions & 2 deletions src/gui/accountmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ void AccountManager::saveAccountHelper(Account* acc, QSettings& settings, bool s
if (acc->_am) {
CookieJar* jar = qobject_cast<CookieJar*>(acc->_am->cookieJar());
if (jar) {
qDebug() << "Saving cookies.";
jar->save();
qDebug() << "Saving cookies." << acc->cookieJarPath();
jar->save(acc->cookieJarPath());
}
}
}
Expand Down Expand Up @@ -289,6 +289,8 @@ void AccountManager::deleteAccount(AccountState* account)
auto copy = *it; // keep a reference to the shared pointer so it does not delete it just yet
_accounts.erase(it);

QFile::remove(account->account()->cookieJarPath());

auto settings = Utility::settingsWithGroup(QLatin1String(accountsC));
settings->remove(account->account()->id());

Expand Down
1 change: 1 addition & 0 deletions src/gui/wizard/owncloudshibbolethcredspage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void OwncloudShibbolethCredsPage::setupBrowser()
// i.e. if someone presses "back"
QNetworkAccessManager *qnam = account->networkAccessManager();
CookieJar *jar = new CookieJar;
jar->restore(account->cookieJarPath());
// Implicitly deletes the old cookie jar, and reparents the jar
qnam->setCookieJar(jar);

Expand Down
6 changes: 6 additions & 0 deletions src/libsync/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ void Account::lendCookieJarTo(QNetworkAccessManager *guest)
jar->setParent(oldParent); // takes it back
}

QString Account::cookieJarPath()
{
ConfigFile cfg;
return cfg.configPath() + "/cookies" + id() + ".db";
}

void Account::resetNetworkAccessManager()
{
if (!_credentials || !_am) {
Expand Down
1 change: 1 addition & 0 deletions src/libsync/account.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ class OWNCLOUDSYNC_EXPORT Account : public QObject {

void clearCookieJar();
void lendCookieJarTo(QNetworkAccessManager *guest);
QString cookieJarPath();

void resetNetworkAccessManager();
QNetworkAccessManager* networkAccessManager();
Expand Down
17 changes: 5 additions & 12 deletions src/libsync/cookiejar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ QDataStream &operator>>(QDataStream &stream, QList<QNetworkCookie> &list)
CookieJar::CookieJar(QObject *parent) :
QNetworkCookieJar(parent)
{
restore();
}

CookieJar::~CookieJar()
Expand Down Expand Up @@ -97,21 +96,21 @@ void CookieJar::clearSessionCookies()
setAllCookies(removeExpired(allCookies()));
}

void CookieJar::save()
void CookieJar::save(const QString &fileName)
{
QFile file;
file.setFileName(storagePath());
qDebug() << storagePath();
file.setFileName(fileName);
qDebug() << fileName;
file.open(QIODevice::WriteOnly);
QDataStream stream(&file);
stream << removeExpired(allCookies());
file.close();
}

void CookieJar::restore()
void CookieJar::restore(const QString &fileName)
{
QFile file;
file.setFileName(storagePath());
file.setFileName(fileName);
file.open(QIODevice::ReadOnly);
QDataStream stream(&file);
QList<QNetworkCookie> list;
Expand All @@ -131,10 +130,4 @@ QList<QNetworkCookie> CookieJar::removeExpired(const QList<QNetworkCookie> &cook
return updatedList;
}

QString CookieJar::storagePath() const
{
ConfigFile cfg;
return cfg.configPath() + "/cookies.db";
}

} // namespace OCC
6 changes: 2 additions & 4 deletions src/libsync/cookiejar.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,13 @@ class OWNCLOUDSYNC_EXPORT CookieJar : public QNetworkCookieJar
using QNetworkCookieJar::setAllCookies;
using QNetworkCookieJar::allCookies;

void save();
void save(const QString &fileName);
void restore(const QString &fileName);

signals:
void newCookiesForUrl(const QList<QNetworkCookie>& cookieList, const QUrl& url);
private:
void restore();
QList<QNetworkCookie> removeExpired(const QList<QNetworkCookie> &cookies);
QString storagePath() const;

};

} // namespace OCC
Expand Down

0 comments on commit eb2c6e5

Please sign in to comment.