Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookies: Use different DB for different accounts #5490

Merged
merged 1 commit into from
Jan 26, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make it private.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's accessed from 2 different files/classes which are not the account, can't do it without friending both.


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