mirror of
https://github.com/falk-werner/webfuse
synced 2024-10-27 20:34:10 +00:00
moves filesystem to session
This commit is contained in:
parent
eaebd02fe7
commit
8158859576
@ -19,8 +19,8 @@ static struct fuse_lowlevel_ops const filesystem_operations =
|
||||
|
||||
bool wf_impl_filesystem_init(
|
||||
struct wf_impl_filesystem * filesystem,
|
||||
struct wf_impl_session_manager * session_manager,
|
||||
char * mount_point)
|
||||
struct wf_impl_session * session,
|
||||
char const * mount_point)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
@ -29,7 +29,7 @@ bool wf_impl_filesystem_init(
|
||||
filesystem->args.argv = argv;
|
||||
filesystem->args.allocated = 0;
|
||||
|
||||
filesystem->user_data.session_manager = session_manager;
|
||||
filesystem->user_data.session = session;
|
||||
filesystem->user_data.timeout = 1.0;
|
||||
memset(&filesystem->buffer, 0, sizeof(struct fuse_buf));
|
||||
|
||||
|
@ -13,7 +13,7 @@ extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct wf_impl_session_manager;
|
||||
struct wf_impl_session;
|
||||
|
||||
struct wf_impl_filesystem
|
||||
{
|
||||
@ -25,8 +25,8 @@ struct wf_impl_filesystem
|
||||
|
||||
extern bool wf_impl_filesystem_init(
|
||||
struct wf_impl_filesystem * filesystem,
|
||||
struct wf_impl_session_manager * session_manager,
|
||||
char * mount_point);
|
||||
struct wf_impl_session * session,
|
||||
char const * mount_point);
|
||||
|
||||
extern void wf_impl_filesystem_cleanup(
|
||||
struct wf_impl_filesystem * filesystem);
|
||||
|
@ -13,7 +13,7 @@ void wf_impl_operation_close(
|
||||
struct fuse_file_info * file_info)
|
||||
{
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data, inode);
|
||||
struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
|
@ -81,7 +81,7 @@ void wf_impl_operation_getattr (
|
||||
{
|
||||
struct fuse_ctx const * context = fuse_req_ctx(request);
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data, inode);
|
||||
struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
|
@ -90,7 +90,7 @@ void wf_impl_operation_lookup (
|
||||
{
|
||||
struct fuse_ctx const * context = fuse_req_ctx(request);
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data, parent);
|
||||
struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
|
@ -47,7 +47,7 @@ void wf_impl_operation_open(
|
||||
struct fuse_file_info * file_info)
|
||||
{
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data, inode);
|
||||
struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
|
@ -87,7 +87,7 @@ void wf_impl_operation_read(
|
||||
struct fuse_file_info * file_info)
|
||||
{
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data, inode);
|
||||
struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
|
@ -137,7 +137,7 @@ void wf_impl_operation_readdir (
|
||||
struct fuse_file_info * WF_UNUSED_PARAM(file_info))
|
||||
{
|
||||
struct wf_impl_operations_context * user_data = fuse_req_userdata(request);
|
||||
struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data, inode);
|
||||
struct wf_impl_jsonrpc_proxy * rpc = wf_impl_operations_context_get_proxy(user_data);
|
||||
|
||||
if (NULL != rpc)
|
||||
{
|
||||
|
@ -4,13 +4,11 @@
|
||||
#include <stddef.h>
|
||||
|
||||
struct wf_impl_jsonrpc_proxy * wf_impl_operations_context_get_proxy(
|
||||
struct wf_impl_operations_context * context,
|
||||
fuse_ino_t inode)
|
||||
struct wf_impl_operations_context * context)
|
||||
{
|
||||
struct wf_impl_jsonrpc_proxy * proxy = NULL;
|
||||
|
||||
struct wf_impl_session_manager * session_manger = context->session_manager;
|
||||
struct wf_impl_session * session = wf_impl_session_manager_get_by_inode(session_manger, inode);
|
||||
struct wf_impl_session * session = context->session;
|
||||
if (NULL != session)
|
||||
{
|
||||
proxy = &session->rpc;
|
||||
|
@ -7,12 +7,12 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct wf_impl_session_manager;
|
||||
struct wf_impl_session;
|
||||
struct wf_impl_jsonrpc_proxy;
|
||||
|
||||
struct wf_impl_operations_context
|
||||
{
|
||||
struct wf_impl_session_manager * session_manager;
|
||||
struct wf_impl_session * session;
|
||||
double timeout;
|
||||
};
|
||||
|
||||
@ -49,8 +49,7 @@ extern void wf_impl_operation_read(
|
||||
struct fuse_file_info *fi);
|
||||
|
||||
extern struct wf_impl_jsonrpc_proxy * wf_impl_operations_context_get_proxy(
|
||||
struct wf_impl_operations_context * context,
|
||||
fuse_ino_t inode);
|
||||
struct wf_impl_operations_context * context);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -108,18 +108,11 @@ struct wf_server * wf_impl_server_create(
|
||||
server = malloc(sizeof(struct wf_server));
|
||||
if (NULL != server)
|
||||
{
|
||||
if (wf_impl_server_protocol_init(&server->protocol, config->mount_point))
|
||||
{
|
||||
server->shutdown_requested = false;
|
||||
wf_impl_server_config_clone(config, &server->config);
|
||||
wf_impl_authenticators_move(&server->config.authenticators, &server->protocol.authenticators);
|
||||
server->context = wf_impl_server_context_create(server);
|
||||
}
|
||||
else
|
||||
{
|
||||
free(server);
|
||||
server = NULL;
|
||||
}
|
||||
wf_impl_server_protocol_init(&server->protocol, config->mount_point);
|
||||
server->shutdown_requested = false;
|
||||
wf_impl_server_config_clone(config, &server->config);
|
||||
wf_impl_authenticators_move(&server->config.authenticators, &server->protocol.authenticators);
|
||||
server->context = wf_impl_server_context_create(server);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include "webfuse/core/message.h"
|
||||
#include "webfuse/core/util.h"
|
||||
|
||||
#include "webfuse/adapter/impl/filesystem.h"
|
||||
#include "webfuse/adapter/impl/credentials.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/request.h"
|
||||
|
||||
@ -25,23 +24,15 @@ static int wf_impl_server_protocol_callback(
|
||||
|
||||
switch (reason)
|
||||
{
|
||||
case LWS_CALLBACK_PROTOCOL_INIT:
|
||||
{
|
||||
lws_sock_file_fd_type fd;
|
||||
fd.filefd = wf_impl_filesystem_get_fd(&protocol->filesystem);
|
||||
if (!lws_adopt_descriptor_vhost(lws_get_vhost(wsi), LWS_ADOPT_RAW_FILE_DESC, fd, ws_protocol->name, NULL))
|
||||
{
|
||||
fprintf(stderr, "error: unable to adopt fd");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_ESTABLISHED:
|
||||
session = wf_impl_session_manager_add(
|
||||
&protocol->session_manager,
|
||||
wsi,
|
||||
&protocol->authenticators,
|
||||
&protocol->timeout_manager,
|
||||
&protocol->server);
|
||||
&protocol->server,
|
||||
protocol->mount_point,
|
||||
ws_protocol->name);
|
||||
|
||||
if (NULL != session)
|
||||
{
|
||||
@ -64,7 +55,10 @@ static int wf_impl_server_protocol_callback(
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_RAW_RX_FILE:
|
||||
wf_impl_filesystem_process_request(&protocol->filesystem);
|
||||
if (NULL != session)
|
||||
{
|
||||
wf_impl_filesystem_process_request(&session->filesystem);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@ -79,11 +73,7 @@ struct wf_server_protocol * wf_impl_server_protocol_create(
|
||||
struct wf_server_protocol * protocol = malloc(sizeof(struct wf_server_protocol));
|
||||
if (NULL != protocol)
|
||||
{
|
||||
if (!wf_impl_server_protocol_init(protocol, mount_point))
|
||||
{
|
||||
free(protocol);
|
||||
protocol = NULL;
|
||||
}
|
||||
wf_impl_server_protocol_init(protocol, mount_point);
|
||||
}
|
||||
|
||||
return protocol;
|
||||
@ -140,35 +130,24 @@ static void wf_impl_server_protocol_authenticate(
|
||||
}
|
||||
}
|
||||
|
||||
bool wf_impl_server_protocol_init(
|
||||
void wf_impl_server_protocol_init(
|
||||
struct wf_server_protocol * protocol,
|
||||
char * mount_point)
|
||||
{
|
||||
protocol->mount_point = strdup(mount_point);
|
||||
|
||||
wf_impl_timeout_manager_init(&protocol->timeout_manager);
|
||||
wf_impl_session_manager_init(&protocol->session_manager);
|
||||
wf_impl_authenticators_init(&protocol->authenticators);
|
||||
|
||||
wf_impl_jsonrpc_server_init(&protocol->server);
|
||||
wf_impl_jsonrpc_server_add(&protocol->server, "authenticate", &wf_impl_server_protocol_authenticate, protocol);
|
||||
|
||||
bool const success = wf_impl_filesystem_init(&protocol->filesystem, &protocol->session_manager, mount_point);
|
||||
|
||||
// cleanup on error
|
||||
if (!success)
|
||||
{
|
||||
wf_impl_jsonrpc_server_cleanup(&protocol->server);
|
||||
wf_impl_authenticators_cleanup(&protocol->authenticators);
|
||||
wf_impl_timeout_manager_cleanup(&protocol->timeout_manager);
|
||||
wf_impl_session_manager_cleanup(&protocol->session_manager);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void wf_impl_server_protocol_cleanup(
|
||||
struct wf_server_protocol * protocol)
|
||||
{
|
||||
wf_impl_filesystem_cleanup(&protocol->filesystem);
|
||||
free(protocol->mount_point);
|
||||
wf_impl_jsonrpc_server_cleanup(&protocol->server);
|
||||
wf_impl_timeout_manager_cleanup(&protocol->timeout_manager);
|
||||
wf_impl_authenticators_cleanup(&protocol->authenticators);
|
||||
|
@ -1,7 +1,6 @@
|
||||
#ifndef WF_ADAPTER_IMPL_SERVER_PROTOCOL_H
|
||||
#define WF_ADAPTER_IMPL_SERVER_PROTOCOL_H
|
||||
|
||||
#include "webfuse/adapter/impl/filesystem.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/proxy.h"
|
||||
#include "webfuse/adapter/impl/time/timeout_manager.h"
|
||||
#include "webfuse/adapter/impl/authenticators.h"
|
||||
@ -17,14 +16,14 @@ struct lws_protocols;
|
||||
|
||||
struct wf_server_protocol
|
||||
{
|
||||
char * mount_point;
|
||||
struct wf_impl_timeout_manager timeout_manager;
|
||||
struct wf_impl_filesystem filesystem;
|
||||
struct wf_impl_authenticators authenticators;
|
||||
struct wf_impl_session_manager session_manager;
|
||||
struct wf_impl_jsonrpc_server server;
|
||||
};
|
||||
|
||||
extern bool wf_impl_server_protocol_init(
|
||||
extern void wf_impl_server_protocol_init(
|
||||
struct wf_server_protocol * protocol,
|
||||
char * mount_point);
|
||||
|
||||
|
@ -33,12 +33,25 @@ static bool wf_impl_session_send(
|
||||
return result;
|
||||
}
|
||||
|
||||
void wf_impl_session_init(
|
||||
void wf_impl_session_init_empty(
|
||||
struct wf_impl_session * session)
|
||||
{
|
||||
wf_message_queue_init(&session->queue);
|
||||
session->is_authenticated = false;
|
||||
session->wsi = NULL;
|
||||
session->wsi_fuse = NULL;
|
||||
session->authenticators = NULL;
|
||||
session->server = NULL;
|
||||
}
|
||||
|
||||
bool wf_impl_session_init(
|
||||
struct wf_impl_session * session,
|
||||
struct lws * wsi,
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_impl_timeout_manager * timeout_manager,
|
||||
struct wf_impl_jsonrpc_server * server)
|
||||
struct wf_impl_jsonrpc_server * server,
|
||||
char const * mount_point,
|
||||
char const * protocol_name)
|
||||
{
|
||||
session->wsi = wsi;
|
||||
session->is_authenticated = false;
|
||||
@ -46,17 +59,40 @@ void wf_impl_session_init(
|
||||
session->server = server;
|
||||
wf_impl_jsonrpc_proxy_init(&session->rpc, timeout_manager, &wf_impl_session_send, session);
|
||||
wf_message_queue_init(&session->queue);
|
||||
|
||||
bool const success = wf_impl_filesystem_init(&session->filesystem, session, mount_point);
|
||||
if (!success)
|
||||
{
|
||||
wf_impl_jsonrpc_proxy_cleanup(&session->rpc);
|
||||
wf_message_queue_cleanup(&session->queue);
|
||||
}
|
||||
|
||||
lws_sock_file_fd_type fd;
|
||||
fd.filefd = wf_impl_filesystem_get_fd(&session->filesystem);
|
||||
session->wsi_fuse = lws_adopt_descriptor_vhost(lws_get_vhost(wsi), LWS_ADOPT_RAW_FILE_DESC, fd, protocol_name, wsi);
|
||||
if (NULL == session->wsi_fuse)
|
||||
{
|
||||
fprintf(stderr, "error: unable to adopt fd");
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
void wf_impl_session_cleanup(
|
||||
struct wf_impl_session * session)
|
||||
{
|
||||
wf_impl_jsonrpc_proxy_cleanup(&session->rpc);
|
||||
wf_message_queue_cleanup(&session->queue);
|
||||
session->is_authenticated = false;
|
||||
session->wsi = NULL;
|
||||
session->authenticators = NULL;
|
||||
session->server = NULL;
|
||||
if (NULL != session->wsi)
|
||||
{
|
||||
wf_impl_filesystem_cleanup(&session->filesystem);
|
||||
|
||||
wf_impl_jsonrpc_proxy_cleanup(&session->rpc);
|
||||
wf_message_queue_cleanup(&session->queue);
|
||||
session->is_authenticated = false;
|
||||
session->wsi = NULL;
|
||||
session->wsi_fuse = NULL;
|
||||
session->authenticators = NULL;
|
||||
session->server = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool wf_impl_session_authenticate(
|
||||
|
@ -12,6 +12,7 @@ using std::size_t;
|
||||
#include "webfuse/core/message_queue.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/proxy.h"
|
||||
#include "webfuse/adapter/impl/jsonrpc/server.h"
|
||||
#include "webfuse/adapter/impl/filesystem.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
@ -27,19 +28,26 @@ struct wf_impl_timeout_manager;
|
||||
struct wf_impl_session
|
||||
{
|
||||
struct lws * wsi;
|
||||
struct lws * wsi_fuse;
|
||||
bool is_authenticated;
|
||||
struct wf_message_queue queue;
|
||||
struct wf_impl_filesystem filesystem;
|
||||
struct wf_impl_authenticators * authenticators;
|
||||
struct wf_impl_jsonrpc_server * server;
|
||||
struct wf_impl_jsonrpc_proxy rpc;
|
||||
};
|
||||
|
||||
extern void wf_impl_session_init(
|
||||
extern void wf_impl_session_init_empty(
|
||||
struct wf_impl_session * session);
|
||||
|
||||
extern bool wf_impl_session_init(
|
||||
struct wf_impl_session * session,
|
||||
struct lws * wsi,
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_impl_timeout_manager * timeout_manager,
|
||||
struct wf_impl_jsonrpc_server * server);
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_impl_timeout_manager * timeout_manager,
|
||||
struct wf_impl_jsonrpc_server * server,
|
||||
char const * mount_point,
|
||||
char const * protocol_name);
|
||||
|
||||
extern bool wf_impl_session_authenticate(
|
||||
struct wf_impl_session * session,
|
||||
|
@ -5,7 +5,7 @@
|
||||
void wf_impl_session_manager_init(
|
||||
struct wf_impl_session_manager * manager)
|
||||
{
|
||||
wf_impl_session_init(&manager->session, NULL, NULL, NULL, NULL);
|
||||
wf_impl_session_init_empty(&manager->session);
|
||||
}
|
||||
|
||||
void wf_impl_session_manager_cleanup(
|
||||
@ -19,13 +19,15 @@ struct wf_impl_session * wf_impl_session_manager_add(
|
||||
struct lws * wsi,
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_impl_timeout_manager * timeout_manager,
|
||||
struct wf_impl_jsonrpc_server * server)
|
||||
struct wf_impl_jsonrpc_server * server,
|
||||
char const * mount_point,
|
||||
char const * protocol_name)
|
||||
{
|
||||
struct wf_impl_session * session = NULL;
|
||||
if (NULL == manager->session.wsi)
|
||||
{
|
||||
session = &manager->session;
|
||||
wf_impl_session_init(&manager->session, wsi, authenticators, timeout_manager, server);
|
||||
wf_impl_session_init(&manager->session, wsi, authenticators, timeout_manager, server, mount_point, protocol_name);
|
||||
}
|
||||
|
||||
return session;
|
||||
@ -36,7 +38,7 @@ struct wf_impl_session * wf_impl_session_manager_get(
|
||||
struct lws * wsi)
|
||||
{
|
||||
struct wf_impl_session * session = NULL;
|
||||
if (wsi == manager->session.wsi)
|
||||
if ((wsi == manager->session.wsi) || (wsi == manager->session.wsi_fuse))
|
||||
{
|
||||
session = &manager->session;
|
||||
}
|
||||
@ -44,22 +46,6 @@ struct wf_impl_session * wf_impl_session_manager_get(
|
||||
return session;
|
||||
}
|
||||
|
||||
struct wf_impl_session * wf_impl_session_manager_get_by_inode(
|
||||
struct wf_impl_session_manager * manager,
|
||||
fuse_ino_t WF_UNUSED_PARAM(inode))
|
||||
{
|
||||
// ToDo: use inode to determine session manager
|
||||
|
||||
struct wf_impl_session * session = NULL;
|
||||
if (NULL != manager->session.wsi)
|
||||
{
|
||||
session = &manager->session;
|
||||
}
|
||||
|
||||
return session;
|
||||
}
|
||||
|
||||
|
||||
void wf_impl_session_manager_remove(
|
||||
struct wf_impl_session_manager * manager,
|
||||
struct lws * wsi)
|
||||
|
@ -33,16 +33,14 @@ extern struct wf_impl_session * wf_impl_session_manager_add(
|
||||
struct lws * wsi,
|
||||
struct wf_impl_authenticators * authenticators,
|
||||
struct wf_impl_timeout_manager * timeout_manager,
|
||||
struct wf_impl_jsonrpc_server * server);
|
||||
struct wf_impl_jsonrpc_server * server,
|
||||
char const * mount_point,
|
||||
char const * protocol_name);
|
||||
|
||||
extern struct wf_impl_session * wf_impl_session_manager_get(
|
||||
struct wf_impl_session_manager * manager,
|
||||
struct lws * wsi);
|
||||
|
||||
extern struct wf_impl_session * wf_impl_session_manager_get_by_inode(
|
||||
struct wf_impl_session_manager * session_manger,
|
||||
fuse_ino_t inode);
|
||||
|
||||
extern void wf_impl_session_manager_remove(
|
||||
struct wf_impl_session_manager * manager,
|
||||
struct lws * wsi);
|
||||
|
Loading…
Reference in New Issue
Block a user