refactor event system

This commit is contained in:
2025-01-24 08:19:18 -06:00
parent ad5a1cd5ff
commit 5da7b6a51a
4 changed files with 29 additions and 28 deletions

View File

@ -29,18 +29,18 @@
namespace repertory { namespace repertory {
struct drive_mount_failed final : public i_event { struct drive_mount_failed final : public i_event {
drive_mount_failed() = default; drive_mount_failed() = default;
drive_mount_failed(std::string_view function_name_, drive_mount_failed(NTSTATUS error_, std::string_view function_name_,
std::string mount_location_, NTSTATUS status_) std::string mount_location_)
: function_name(std::string(function_name_)), : error(error_),
mount_location(std::move(mount_location_)), function_name(std::string(function_name_)),
status(status_) {} mount_location(std::move(mount_location_)) {}
static constexpr const event_level level{event_level::error}; static constexpr const event_level level{event_level::error};
static constexpr const std::string_view name{"drive_mount_failed"}; static constexpr const std::string_view name{"drive_mount_failed"};
NTSTATUS error{};
std::string function_name; std::string function_name;
std::string mount_location; std::string mount_location;
NTSTATUS status{};
[[nodiscard]] auto get_event_level() const -> event_level override { [[nodiscard]] auto get_event_level() const -> event_level override {
return level; return level;
@ -52,7 +52,7 @@ struct drive_mount_failed final : public i_event {
[[nodiscard]] auto get_single_line() const -> std::string override { [[nodiscard]] auto get_single_line() const -> std::string override {
return fmt::format("{}|func|{}|location|{}|status|{}", name, function_name, return fmt::format("{}|func|{}|location|{}|status|{}", name, function_name,
mount_location, status); mount_location, error);
} }
}; };
} // namespace repertory } // namespace repertory
@ -60,16 +60,16 @@ struct drive_mount_failed final : public i_event {
NLOHMANN_JSON_NAMESPACE_BEGIN NLOHMANN_JSON_NAMESPACE_BEGIN
template <> struct adl_serializer<repertory::drive_mount_failed> { template <> struct adl_serializer<repertory::drive_mount_failed> {
static void to_json(json &data, const repertory::drive_mount_failed &value) { static void to_json(json &data, const repertory::drive_mount_failed &value) {
data["error"] = value.error;
data["function_name"] = value.function_name; data["function_name"] = value.function_name;
data["mount_location"] = value.mount_location; data["mount_location"] = value.mount_location;
data["status"] = value.status;
} }
static void from_json(const json &data, static void from_json(const json &data,
repertory::drive_mount_failed &value) { repertory::drive_mount_failed &value) {
data.at("error").get_to<NTSTATUS>(value.error);
data.at("function_name").get_to<std::string>(value.function_name); data.at("function_name").get_to<std::string>(value.function_name);
data.at("mount_location").get_to<std::string>(value.mount_location); data.at("mount_location").get_to<std::string>(value.mount_location);
data.at("status").get_to<NTSTATUS>(value.status);
} }
}; };
NLOHMANN_JSON_NAMESPACE_END NLOHMANN_JSON_NAMESPACE_END

View File

@ -68,7 +68,7 @@ template <> struct adl_serializer<repertory::remote_server_event> {
static void from_json(const json &data, static void from_json(const json &data,
repertory::remote_server_event &value) { repertory::remote_server_event &value) {
data.at("api_path").get_to<std::string>(value.api_path); data.at("api_path").get_to<std::string>(value.api_path);
data.at("error").get_to<NTSTATUS>(value.error); data.at("error").get_to<repertory::packet::error_type>(value.error);
data.at("function_name").get_to<std::string>(value.function_name); data.at("function_name").get_to<std::string>(value.function_name);
} }
}; };

View File

@ -77,8 +77,8 @@ auto remote_winfsp_drive::winfsp_service::OnStart(ULONG, PWSTR *) -> NTSTATUS {
} }
if (ret != STATUS_SUCCESS) { if (ret != STATUS_SUCCESS) {
event_system::instance().raise<drive_mount_failed>(function_name, event_system::instance().raise<drive_mount_failed>(ret, function_name,
mount_location, ret); mount_location);
if (not lock_.set_mount_state(false, "", -1)) { if (not lock_.set_mount_state(false, "", -1)) {
utils::error::raise_error(function_name, "failed to set mount state"); utils::error::raise_error(function_name, "failed to set mount state");
} }
@ -129,8 +129,8 @@ auto remote_winfsp_drive::Create(PWSTR file_name, UINT32 create_options,
UINT32 granted_access, UINT32 attributes, UINT32 granted_access, UINT32 attributes,
PSECURITY_DESCRIPTOR /*descriptor*/, PSECURITY_DESCRIPTOR /*descriptor*/,
UINT64 allocation_size, PVOID * /*file_node*/, UINT64 allocation_size, PVOID * /*file_node*/,
PVOID *file_desc, PVOID *file_desc, OpenFileInfo *ofi)
OpenFileInfo *ofi) -> NTSTATUS { -> NTSTATUS {
remote::file_info fi{}; remote::file_info fi{};
std::string normalized_name; std::string normalized_name;
BOOLEAN exists = 0; BOOLEAN exists = 0;
@ -164,9 +164,10 @@ auto remote_winfsp_drive::GetFileInfo(PVOID /*file_node*/, PVOID file_desc,
return ret; return ret;
} }
auto remote_winfsp_drive::GetSecurityByName( auto remote_winfsp_drive::GetSecurityByName(PWSTR file_name, PUINT32 attributes,
PWSTR file_name, PUINT32 attributes, PSECURITY_DESCRIPTOR descriptor, PSECURITY_DESCRIPTOR descriptor,
SIZE_T *descriptor_size) -> NTSTATUS { SIZE_T *descriptor_size)
-> NTSTATUS {
std::wstring string_descriptor; std::wstring string_descriptor;
std::uint64_t sds = (descriptor_size == nullptr) ? 0 : *descriptor_size; std::uint64_t sds = (descriptor_size == nullptr) ? 0 : *descriptor_size;
auto ret = remote_instance_->winfsp_get_security_by_name( auto ret = remote_instance_->winfsp_get_security_by_name(
@ -262,7 +263,7 @@ auto remote_winfsp_drive::mount(const std::vector<std::string> &drive_args)
auto ret = winfsp_service(lock_, *this, parsed_drive_args, config_).Run(); auto ret = winfsp_service(lock_, *this, parsed_drive_args, config_).Run();
event_system::instance().raise<drive_mount_result>(function_name, "", event_system::instance().raise<drive_mount_result>(function_name, "",
std::to_string(ret)); std::to_string(ret));
event_system::instance().stop(); event_system::instance().stop();
c.reset(); c.reset();
return static_cast<int>(ret); return static_cast<int>(ret);
@ -286,8 +287,8 @@ auto remote_winfsp_drive::Mounted(PVOID host) -> NTSTATUS {
auto remote_winfsp_drive::Open(PWSTR file_name, UINT32 create_options, auto remote_winfsp_drive::Open(PWSTR file_name, UINT32 create_options,
UINT32 granted_access, PVOID * /*file_node*/, UINT32 granted_access, PVOID * /*file_node*/,
PVOID *file_desc, PVOID *file_desc, OpenFileInfo *ofi)
OpenFileInfo *ofi) -> NTSTATUS { -> NTSTATUS {
remote::file_info fi{}; remote::file_info fi{};
std::string normalize_name; std::string normalize_name;
auto ret = auto ret =
@ -307,8 +308,8 @@ auto remote_winfsp_drive::Open(PWSTR file_name, UINT32 create_options,
auto remote_winfsp_drive::Overwrite(PVOID /*file_node*/, PVOID file_desc, auto remote_winfsp_drive::Overwrite(PVOID /*file_node*/, PVOID file_desc,
UINT32 attributes, UINT32 attributes,
BOOLEAN replace_attributes, BOOLEAN replace_attributes,
UINT64 allocation_size, UINT64 allocation_size, FileInfo *file_info)
FileInfo *file_info) -> NTSTATUS { -> NTSTATUS {
remote::file_info info{}; remote::file_info info{};
auto ret = remote_instance_->winfsp_overwrite( auto ret = remote_instance_->winfsp_overwrite(
file_desc, attributes, replace_attributes, allocation_size, &info); file_desc, attributes, replace_attributes, allocation_size, &info);
@ -425,8 +426,8 @@ auto remote_winfsp_drive::SetBasicInfo(PVOID /*file_node*/, PVOID file_desc,
UINT32 attributes, UINT64 creation_time, UINT32 attributes, UINT64 creation_time,
UINT64 last_access_time, UINT64 last_access_time,
UINT64 last_write_time, UINT64 last_write_time,
UINT64 change_time, UINT64 change_time, FileInfo *file_info)
FileInfo *file_info) -> NTSTATUS { -> NTSTATUS {
remote::file_info fi{}; remote::file_info fi{};
auto ret = remote_instance_->winfsp_set_basic_info( auto ret = remote_instance_->winfsp_set_basic_info(
file_desc, attributes, creation_time, last_access_time, last_write_time, file_desc, attributes, creation_time, last_access_time, last_write_time,
@ -478,8 +479,8 @@ VOID remote_winfsp_drive::Unmounted(PVOID host) {
auto remote_winfsp_drive::Write(PVOID /*file_node*/, PVOID file_desc, auto remote_winfsp_drive::Write(PVOID /*file_node*/, PVOID file_desc,
PVOID buffer, UINT64 offset, ULONG length, PVOID buffer, UINT64 offset, ULONG length,
BOOLEAN write_to_end, BOOLEAN constrained_io, BOOLEAN write_to_end, BOOLEAN constrained_io,
PULONG bytes_transferred, PULONG bytes_transferred, FileInfo *file_info)
FileInfo *file_info) -> NTSTATUS { -> NTSTATUS {
remote::file_info fi{}; remote::file_info fi{};
auto ret = remote_instance_->winfsp_write( auto ret = remote_instance_->winfsp_write(
file_desc, buffer, offset, length, write_to_end, constrained_io, file_desc, buffer, offset, length, write_to_end, constrained_io,

View File

@ -127,8 +127,8 @@ auto winfsp_drive::winfsp_service::OnStart(ULONG /*Argc*/, PWSTR * /*Argv*/)
utils::error::raise_error(function_name, ret, "failed to set mount state"); utils::error::raise_error(function_name, ret, "failed to set mount state");
} }
event_system::instance().raise<drive_mount_failed>(function_name, event_system::instance().raise<drive_mount_failed>(ret, function_name,
mount_location, ret); mount_location);
return ret; return ret;
} }