HttpCreds: Warn in log if keychain-write jobs fail #6776

Also, calling deleteLater() on jobs is unnecessary (they autodelete
after finished()) and deleting the attached QSettings is also
unnecessary because the settings object is parented to the job.
This commit is contained in:
Christian Kamm 2019-01-22 10:04:08 +01:00 committed by Kevin Ottens
parent 1a250bc3c7
commit 13890c04a7
No known key found for this signature in database
GPG key ID: 074BBBCB8DECC9E2
2 changed files with 19 additions and 14 deletions

View file

@ -480,12 +480,17 @@ void HttpCredentials::persist()
job->setBinaryData(_clientSslCertificate.toPem());
job->start();
} else {
slotWriteClientCertPEMJobDone();
slotWriteClientCertPEMJobDone(nullptr);
}
}
void HttpCredentials::slotWriteClientCertPEMJobDone()
void HttpCredentials::slotWriteClientCertPEMJobDone(Job *finishedJob)
{
if (finishedJob && finishedJob->error() != QKeychain::NoError) {
qCWarning(lcHttpCredentials) << "Could not write client cert to credentials"
<< finishedJob->error() << finishedJob->errorString();
}
// write ssl key if there is one
if (!_clientSslKey.isNull()) {
auto *job = new WritePasswordJob(Theme::instance()->appName());
@ -496,12 +501,17 @@ void HttpCredentials::slotWriteClientCertPEMJobDone()
job->setBinaryData(_clientSslKey.toPem());
job->start();
} else {
slotWriteClientKeyPEMJobDone();
slotWriteClientKeyPEMJobDone(nullptr);
}
}
void HttpCredentials::slotWriteClientKeyPEMJobDone()
void HttpCredentials::slotWriteClientKeyPEMJobDone(Job *finishedJob)
{
if (finishedJob && finishedJob->error() != QKeychain::NoError) {
qCWarning(lcHttpCredentials) << "Could not write client key to credentials"
<< finishedJob->error() << finishedJob->errorString();
}
auto *job = new WritePasswordJob(Theme::instance()->appName());
addSettingsToJob(_account, job);
job->setInsecureFallback(false);
@ -513,15 +523,10 @@ void HttpCredentials::slotWriteClientKeyPEMJobDone()
void HttpCredentials::slotWriteJobDone(QKeychain::Job *job)
{
delete job->settings();
switch (job->error()) {
case NoError:
break;
default:
qCWarning(lcHttpCredentials) << "Error while writing password" << job->errorString();
if (job && job->error() != QKeychain::NoError) {
qCWarning(lcHttpCredentials) << "Error while writing password"
<< job->error() << job->errorString();
}
auto *wjob = qobject_cast<WritePasswordJob *>(job);
wjob->deleteLater();
}
void HttpCredentials::slotAuthentication(QNetworkReply *reply, QAuthenticator *authenticator)

View file

@ -116,8 +116,8 @@ private Q_SLOTS:
void slotReadClientKeyPEMJobDone(QKeychain::Job *);
void slotReadJobDone(QKeychain::Job *);
void slotWriteClientCertPEMJobDone();
void slotWriteClientKeyPEMJobDone();
void slotWriteClientCertPEMJobDone(QKeychain::Job *);
void slotWriteClientKeyPEMJobDone(QKeychain::Job *);
void slotWriteJobDone(QKeychain::Job *);
protected: