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) #define NT_SUCCESS(status) ((LONG) (status) >= 0)
#endif #endif
#define FORT_STATUS_USER_ERROR STATUS_INVALID_PARAMETER
#define FORT_ERROR_USER_ERROR ERROR_INVALID_PARAMETER
#endif COMMON_H #endif COMMON_H

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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