From 0c702ff25f71b994ace618bed7a1345248adf216 Mon Sep 17 00:00:00 2001 From: Falk Werner Date: Fri, 12 Jun 2020 22:53:42 +0200 Subject: [PATCH] refactor: make filesystem independent of session --- lib/webfuse/adapter/impl/filesystem.c | 14 ++++++++------ lib/webfuse/adapter/impl/filesystem.h | 5 +++-- lib/webfuse/adapter/impl/operation/context.c | 10 +--------- lib/webfuse/adapter/impl/operation/context.h | 3 +-- lib/webfuse/adapter/impl/session.c | 2 +- .../tests/adapter/operation/test_context.cc | 6 ++---- 6 files changed, 16 insertions(+), 24 deletions(-) diff --git a/lib/webfuse/adapter/impl/filesystem.c b/lib/webfuse/adapter/impl/filesystem.c index a033190..4fa1d38 100644 --- a/lib/webfuse/adapter/impl/filesystem.c +++ b/lib/webfuse/adapter/impl/filesystem.c @@ -52,7 +52,8 @@ static void wf_impl_filesystem_cleanup( static bool wf_impl_filesystem_init( struct wf_impl_filesystem * filesystem, - struct wf_impl_session * session, + struct lws * session_wsi, + struct wf_jsonrpc_proxy * proxy, char const * name, struct wf_mountpoint * mountpoint) { @@ -63,7 +64,7 @@ static bool wf_impl_filesystem_init( filesystem->args.argv = argv; filesystem->args.allocated = 0; - filesystem->user_data.session = session; + filesystem->user_data.proxy = proxy; filesystem->user_data.timeout = 1.0; filesystem->user_data.name = strdup(name); memset(&filesystem->buffer, 0, sizeof(struct fuse_buf)); @@ -85,8 +86,8 @@ static bool wf_impl_filesystem_init( { lws_sock_file_fd_type fd; fd.filefd = fuse_session_fd(filesystem->session); - struct lws_protocols const * protocol = lws_get_protocol(session->wsi); - filesystem->wsi = lws_adopt_descriptor_vhost(lws_get_vhost(session->wsi), LWS_ADOPT_RAW_FILE_DESC, fd, protocol->name, session->wsi); + struct lws_protocols const * protocol = lws_get_protocol(session_wsi); + filesystem->wsi = lws_adopt_descriptor_vhost(lws_get_vhost(session_wsi), LWS_ADOPT_RAW_FILE_DESC, fd, protocol->name, session_wsi); if (NULL == filesystem->wsi) { @@ -100,12 +101,13 @@ static bool wf_impl_filesystem_init( } struct wf_impl_filesystem * wf_impl_filesystem_create( - struct wf_impl_session * session, + struct lws * session_wsi, + struct wf_jsonrpc_proxy * proxy, char const * name, struct wf_mountpoint * mountpoint) { struct wf_impl_filesystem * filesystem = malloc(sizeof(struct wf_impl_filesystem)); - bool success = wf_impl_filesystem_init(filesystem, session, name, mountpoint); + bool success = wf_impl_filesystem_init(filesystem, session_wsi, proxy, name, mountpoint); if (!success) { free(filesystem); diff --git a/lib/webfuse/adapter/impl/filesystem.h b/lib/webfuse/adapter/impl/filesystem.h index 791170a..95825f2 100644 --- a/lib/webfuse/adapter/impl/filesystem.h +++ b/lib/webfuse/adapter/impl/filesystem.h @@ -15,7 +15,7 @@ extern "C" #endif struct wf_mountpoint; -struct wf_impl_session; +struct wf_jsonrpc_proxy; struct lws; struct wf_impl_filesystem @@ -30,7 +30,8 @@ struct wf_impl_filesystem }; extern struct wf_impl_filesystem * wf_impl_filesystem_create( - struct wf_impl_session * session, + struct lws * session_wsi, + struct wf_jsonrpc_proxy * proxy, char const * name, struct wf_mountpoint * mountpoint); diff --git a/lib/webfuse/adapter/impl/operation/context.c b/lib/webfuse/adapter/impl/operation/context.c index a39978f..3e9829d 100644 --- a/lib/webfuse/adapter/impl/operation/context.c +++ b/lib/webfuse/adapter/impl/operation/context.c @@ -6,13 +6,5 @@ struct wf_jsonrpc_proxy * wf_impl_operation_context_get_proxy( struct wf_impl_operation_context * context) { - struct wf_jsonrpc_proxy * proxy = NULL; - - struct wf_impl_session * session = context->session; - if (NULL != session) - { - proxy = session->rpc; - } - - return proxy; + return context->proxy; } diff --git a/lib/webfuse/adapter/impl/operation/context.h b/lib/webfuse/adapter/impl/operation/context.h index 51d886f..1384f72 100644 --- a/lib/webfuse/adapter/impl/operation/context.h +++ b/lib/webfuse/adapter/impl/operation/context.h @@ -7,12 +7,11 @@ extern "C" { #endif -struct wf_impl_session; struct wf_jsonrpc_proxy; struct wf_impl_operation_context { - struct wf_impl_session * session; + struct wf_jsonrpc_proxy * proxy; double timeout; char * name; }; diff --git a/lib/webfuse/adapter/impl/session.c b/lib/webfuse/adapter/impl/session.c index 159f43a..aa950a7 100644 --- a/lib/webfuse/adapter/impl/session.c +++ b/lib/webfuse/adapter/impl/session.c @@ -108,7 +108,7 @@ bool wf_impl_session_add_filesystem( if (result) { - struct wf_impl_filesystem * filesystem = wf_impl_filesystem_create(session, name, mountpoint); + struct wf_impl_filesystem * filesystem = wf_impl_filesystem_create(session->wsi, session->rpc, name, mountpoint); result = (NULL != filesystem); if (result) { diff --git a/test/webfuse/tests/adapter/operation/test_context.cc b/test/webfuse/tests/adapter/operation/test_context.cc index 77aa287..75e619e 100644 --- a/test/webfuse/tests/adapter/operation/test_context.cc +++ b/test/webfuse/tests/adapter/operation/test_context.cc @@ -5,10 +5,8 @@ TEST(wf_impl_operation_context, get_proxy) { wf_jsonrpc_proxy * proxy = reinterpret_cast(42); - wf_impl_session session; - session.rpc = proxy; wf_impl_operation_context context; - context.session = &session; + context.proxy = proxy; ASSERT_EQ(proxy, wf_impl_operation_context_get_proxy(&context)); } @@ -16,7 +14,7 @@ TEST(wf_impl_operation_context, get_proxy) TEST(wf_impl_operation_context, get_proxy_fail_no_session) { wf_impl_operation_context context; - context.session = nullptr; + context.proxy = nullptr; ASSERT_EQ(nullptr, wf_impl_operation_context_get_proxy(&context));