mirror of
https://github.com/falk-werner/webfuse
synced 2024-10-27 20:34:10 +00:00
refactor: make filesystem independent of session
This commit is contained in:
parent
adaec875d9
commit
0c702ff25f
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -5,10 +5,8 @@
|
||||
TEST(wf_impl_operation_context, get_proxy)
|
||||
{
|
||||
wf_jsonrpc_proxy * proxy = reinterpret_cast<wf_jsonrpc_proxy*>(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));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user