Commit 18072f4f authored by Elvis Angelaccio's avatar Elvis Angelaccio
Browse files

Add support for custom error codes

This will allow plugins to emit a custom error code, in addition to the
user-visible error message.
parent 7812a75d
......@@ -42,6 +42,12 @@ namespace Kerfuffle
{
class Query;
enum {
PossiblyMaliciousArchiveError = KJob::UserDefinedError + 1,
DestinationNotWritableError
};
class KERFUFFLE_EXPORT ReadOnlyArchiveInterface: public QObject
{
Q_OBJECT
......@@ -181,7 +187,7 @@ Q_SIGNALS:
* - the user cancels the overwrite dialog
*/
void cancelled();
void error(const QString &message, const QString &details = QString());
void error(const QString &message, const QString &details = QString(), int errorCode = KJob::UserDefinedError);
void entry(Archive::Entry *archiveEntry);
void progress(double progress);
void info(const QString &info);
......
......@@ -168,12 +168,12 @@ void Job::onCancelled()
setError(KJob::KilledJobError);
}
void Job::onError(const QString & message, const QString & details)
void Job::onError(const QString & message, const QString & details, int errorCode)
{
Q_UNUSED(details)
qCDebug(ARK) << "Error emitted:" << message;
setError(KJob::UserDefinedError);
qCDebug(ARK) << "Error emitted:" << errorCode << "-" << message;
setError(errorCode);
setErrorText(message);
}
......@@ -182,7 +182,7 @@ void Job::onEntry(Archive::Entry *entry)
const QString entryFullPath = entry->fullPath();
if (QDir::cleanPath(entryFullPath).contains(QLatin1String("../"))) {
qCWarning(ARK) << "Possibly malicious archive. Detected entry that could lead to a directory traversal attack:" << entryFullPath;
onError(i18n("Could not load the archive because it contains ill-formed entries and might be a malicious archive."), QString());
onError(i18n("Could not load the archive because it contains ill-formed entries and might be a malicious archive."), QString(), Kerfuffle::PossiblyMaliciousArchiveError);
onFinished(false);
return;
}
......@@ -406,7 +406,7 @@ void BatchExtractJob::slotLoadingFinished(KJob *job)
{
if (job->error()) {
// Forward errors as well.
onError(job->errorString(), QString());
onError(job->errorString(), QString(), job->error());
onFinished(false);
return;
}
......@@ -523,7 +523,7 @@ void ExtractJob::doWork()
QFileInfo destDirInfo(m_destinationDir);
if (destDirInfo.isDir() && (!destDirInfo.isWritable() || !destDirInfo.isExecutable())) {
onError(xi18n("Could not write to destination <filename>%1</filename>.<nl/>Check whether you have sufficient permissions.", m_destinationDir), QString());
onError(xi18n("Could not write to destination <filename>%1</filename>.<nl/>Check whether you have sufficient permissions.", m_destinationDir), QString(), Kerfuffle::DestinationNotWritableError);
onFinished(false);
return;
}
......
......@@ -73,7 +73,7 @@ public Q_SLOTS:
protected Q_SLOTS:
virtual void onCancelled();
virtual void onError(const QString &message, const QString &details);
virtual void onError(const QString &message, const QString &details, int errorCode);
virtual void onInfo(const QString &info);
virtual void onEntry(Archive::Entry *entry);
virtual void onProgress(double progress);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment