UI: DriverManager: Refactor error handling.

This commit is contained in:
Nodir Temirkhodjaev 2020-01-15 09:05:03 +05:00
parent 3545fa1518
commit 8b4d06320a
12 changed files with 25 additions and 26 deletions

View File

@ -91,4 +91,7 @@ DEFINE_GUID(FORT_GUID_FILTER_REAUTH_OUT,
#define NT_SUCCESS(status) ((LONG) (status) >= 0)
#endif
#define FORT_STATUS_USER_ERROR STATUS_INVALID_PARAMETER
#define FORT_ERROR_USER_ERROR ERROR_INVALID_PARAMETER
#endif COMMON_H

View File

@ -227,7 +227,7 @@ fort_conf_ref_exe_add_path_locked (PFORT_CONF_REF conf_ref,
return TRUE;
} else {
if (flags.is_new)
return STATUS_INVALID_PARAMETER;
return FORT_STATUS_USER_ERROR;
// Replace flags
{

View File

@ -991,7 +991,7 @@ fort_device_control (PDEVICE_OBJECT device, PIRP irp)
PIO_STACK_LOCATION irp_stack;
ULONG_PTR info = 0;
ULONG control_code;
NTSTATUS status = STATUS_INVALID_PARAMETER;
NTSTATUS status = STATUS_UNSUCCESSFUL;
irp_stack = IoGetCurrentIrpStackLocation(irp);
control_code = irp_stack->Parameters.DeviceIoControl.IoControlCode;
@ -1102,7 +1102,7 @@ fort_device_control (PDEVICE_OBJECT device, PIRP irp)
default: break;
}
if (!NT_SUCCESS(status)) {
if (!NT_SUCCESS(status) && status != FORT_STATUS_USER_ERROR) {
DbgPrintEx(DPFLTR_IHVNETWORK_ID, DPFLTR_ERROR_LEVEL,
"FORT: Device Control: Error: %x\n", status);
}

View File

@ -486,7 +486,7 @@ fort_defer_stream_add (PFORT_DEFER defer,
if (dataOffset->streamDataOffset != 0
&& (dataOffset->netBuffer != netBuf
|| dataOffset->mdl != NET_BUFFER_CURRENT_MDL(netBuf)))
return STATUS_INVALID_PARAMETER;
return STATUS_FWP_CANNOT_PEND;
}
KeAcquireInStackQueuedSpinLock(&defer->lock, &lock_queue);

View File

@ -23,24 +23,22 @@ DriverManager::~DriverManager()
abortWorker();
}
void DriverManager::setErrorMessage(const QString &errorMessage)
QString DriverManager::errorMessage() const
{
if (m_errorMessage != errorMessage) {
m_errorMessage = errorMessage;
emit errorMessageChanged();
}
return (m_errorCode == 0) ? QString()
: OsUtil::errorMessage(m_errorCode);
}
void DriverManager::updateError(bool success)
{
m_errorCode = success ? 0 : OsUtil::lastErrorCode();
setErrorMessage(success ? QString()
: OsUtil::lastErrorMessage(m_errorCode));
emit errorMessageChanged();
}
bool DriverManager::isDeviceError() const
{
return m_errorCode == OsUtil::userErrorCode();
return m_errorCode != 0
&& m_errorCode != FortCommon::userErrorCode();
}
void DriverManager::setupWorker()

View File

@ -22,7 +22,7 @@ public:
DriverWorker *driverWorker() const { return m_driverWorker; }
QString errorMessage() const { return m_errorMessage; }
QString errorMessage() const;
bool isDeviceError() const;
bool isDeviceOpened() const;
@ -59,8 +59,6 @@ private:
Device *m_device = nullptr;
DriverWorker *m_driverWorker = nullptr;
QString m_errorMessage;
};
#endif // DRIVERMANAGER_H

View File

@ -109,7 +109,7 @@ void DriverWorker::readLog()
if (success) {
m_logBuffer->reset(nr);
} else if (!m_cancelled) {
errorMessage = OsUtil::lastErrorMessage();
errorMessage = OsUtil::errorMessage();
}
emitReadLogResult(success, errorMessage);

View File

@ -310,13 +310,12 @@ void OptionsPage::setupDriverIcon()
: ":/images/plugin_disabled.png";
m_iconDriver->setPixmap(QPixmap(iconPath));
retranslateDriverMessage();
};
refreshDriverIcon();
connect(driverManager(), &DriverManager::isDeviceOpenedChanged, this, refreshDriverIcon);
connect(driverManager(), &DriverManager::errorMessageChanged, this, &OptionsPage::retranslateDriverMessage);
}
void OptionsPage::setupNewVersionBox()

View File

@ -53,6 +53,11 @@ quint32 FortCommon::ioctlDelApp()
return FORT_IOCTL_DELAPP;
}
quint32 FortCommon::userErrorCode()
{
return FORT_ERROR_USER_ERROR;
}
int FortCommon::bufferSize()
{
return FORT_BUFFER_SIZE;

View File

@ -20,6 +20,8 @@ public:
static quint32 ioctlAddApp();
static quint32 ioctlDelApp();
static quint32 userErrorCode();
static int bufferSize();
static quint32 confIoConfOff();

View File

@ -28,17 +28,12 @@ bool OsUtil::createGlobalMutex(const char *name)
&& GetLastError() != ERROR_ALREADY_EXISTS;
}
quint32 OsUtil::userErrorCode()
{
return STATUS_INVALID_PARAMETER;
}
quint32 OsUtil::lastErrorCode()
{
return GetLastError();
}
QString OsUtil::lastErrorMessage(quint32 errorCode)
QString OsUtil::errorMessage(quint32 errorCode)
{
LPWSTR buf = nullptr;

View File

@ -14,9 +14,8 @@ public:
static bool createGlobalMutex(const char *name);
static quint32 userErrorCode();
static quint32 lastErrorCode();
static QString lastErrorMessage(quint32 errorCode = lastErrorCode());
static QString errorMessage(quint32 errorCode = lastErrorCode());
static qint32 getTickCount();
};