mirror of
https://github.com/tnodir/fort
synced 2024-11-15 08:46:03 +00:00
UI: DriverManager: Refactor error handling.
This commit is contained in:
parent
3545fa1518
commit
8b4d06320a
@ -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
|
||||||
|
@ -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
|
||||||
{
|
{
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
@ -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()
|
||||||
|
@ -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
|
||||||
|
@ -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);
|
||||||
|
@ -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()
|
||||||
|
@ -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;
|
||||||
|
@ -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();
|
||||||
|
@ -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;
|
||||||
|
|
||||||
|
@ -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();
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user