1
0
mirror of https://github.com/falk-werner/webfuse-provider synced 2024-10-27 20:44:10 +00:00

integrated uuid_mountpoint_factory

This commit is contained in:
Falk Werner 2020-02-16 21:03:17 +01:00
parent 2b91f159cf
commit 77627b7c8b
19 changed files with 304 additions and 168 deletions

View File

@ -16,6 +16,7 @@ add_library(webfuse-adapter-static STATIC
lib/webfuse/adapter/impl/credentials.c lib/webfuse/adapter/impl/credentials.c
lib/webfuse/adapter/impl/operations.c lib/webfuse/adapter/impl/operations.c
lib/webfuse/adapter/impl/mountpoint.c lib/webfuse/adapter/impl/mountpoint.c
lib/webfuse/adapter/impl/mountpoint_factory.c
lib/webfuse/adapter/impl/uuid_mountpoint_factory.c lib/webfuse/adapter/impl/uuid_mountpoint_factory.c
lib/webfuse/adapter/impl/uuid_mountpoint.c lib/webfuse/adapter/impl/uuid_mountpoint.c
lib/webfuse/adapter/impl/time/timepoint.c lib/webfuse/adapter/impl/time/timepoint.c

View File

@ -3,6 +3,7 @@
#include <webfuse/adapter/api.h> #include <webfuse/adapter/api.h>
#include <webfuse/adapter/authenticate.h> #include <webfuse/adapter/authenticate.h>
#include <webfuse/adapter/mountpoint_factory.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
@ -15,6 +16,10 @@ struct lws_protocols;
extern WF_API struct wf_server_protocol * wf_server_protocol_create( extern WF_API struct wf_server_protocol * wf_server_protocol_create(
char * mount_point); char * mount_point);
extern WF_API struct wf_server_protocol * wf_server_protocol_create2(
wf_create_mountpoint_fn * create_mountpoint,
void * create_mountpoint_context);
extern WF_API void wf_server_protocol_dispose( extern WF_API void wf_server_protocol_dispose(
struct wf_server_protocol * protocol); struct wf_server_protocol * protocol);

View File

@ -35,6 +35,13 @@ struct wf_server_protocol * wf_server_protocol_create(
return wf_impl_server_protocol_create(mount_point); return wf_impl_server_protocol_create(mount_point);
} }
struct wf_server_protocol * wf_server_protocol_create2(
wf_create_mountpoint_fn * create_mountpoint,
void * create_mountpoint_context)
{
return wf_impl_server_protocol_create2(create_mountpoint, create_mountpoint_context);
}
void wf_server_protocol_dispose( void wf_server_protocol_dispose(
struct wf_server_protocol * protocol) struct wf_server_protocol * protocol)
{ {
@ -77,6 +84,15 @@ void wf_server_config_set_mountpoint(
wf_impl_server_config_set_mountpoint(config, mount_point); wf_impl_server_config_set_mountpoint(config, mount_point);
} }
void wf_server_config_set_mountpoint_factory(
struct wf_server_config * config,
wf_create_mountpoint_fn * create_mountpoint,
void * user_data)
{
wf_impl_server_config_set_mountpoint_factory(
config, create_mountpoint, user_data);
}
void wf_server_config_set_documentroot( void wf_server_config_set_documentroot(
struct wf_server_config * config, struct wf_server_config * config,
char const * document_root) char const * document_root)

View File

@ -1,6 +1,7 @@
#include "webfuse/adapter/impl/filesystem.h" #include "webfuse/adapter/impl/filesystem.h"
#include "webfuse/adapter/impl/operations.h" #include "webfuse/adapter/impl/operations.h"
#include "webfuse/adapter/impl/session.h" #include "webfuse/adapter/impl/session.h"
#include "webfuse/adapter/impl/mountpoint.h"
#include "webfuse/core/string.h" #include "webfuse/core/string.h"
@ -27,58 +28,6 @@ static struct fuse_lowlevel_ops const filesystem_operations =
.read = &wf_impl_operation_read .read = &wf_impl_operation_read
}; };
static char * wf_impl_filesystem_create_id(void)
{
uuid_t uuid;
uuid_generate(uuid);
char id[UUID_STR_LEN];
uuid_unparse(uuid, id);
return strdup(id);
}
static bool wf_impl_filesystem_is_link_broken(char const * path, char const * id)
{
bool result = false;
char buffer[UUID_STR_LEN];
ssize_t count = readlink(path, buffer, UUID_STR_LEN);
if ((0 < count) && (count < UUID_STR_LEN))
{
buffer[count] = '\0';
result = (0 == strcmp(buffer, id));
}
return result;
}
static bool wf_impl_filesystem_link_first_subdir(
char const * link_path,
char const * path)
{
bool result = false;
DIR * dir = opendir(path);
if (NULL != dir)
{
struct dirent * entry = readdir(dir);
while (NULL != entry)
{
if ((DT_DIR == entry->d_type) && ('.' != entry->d_name[0]))
{
symlink(entry->d_name, link_path);
result = true;
break;
}
entry = readdir(dir);
}
closedir(dir);
}
return result;
}
static void wf_impl_filesystem_cleanup( static void wf_impl_filesystem_cleanup(
struct wf_impl_filesystem * filesystem) struct wf_impl_filesystem * filesystem)
{ {
@ -90,32 +39,17 @@ static void wf_impl_filesystem_cleanup(
free(filesystem->buffer.mem); free(filesystem->buffer.mem);
fuse_opt_free_args(&filesystem->args); fuse_opt_free_args(&filesystem->args);
rmdir(filesystem->root_path); wf_mountpoint_dispose(filesystem->mountpoint);
if (wf_impl_filesystem_is_link_broken(filesystem->default_path, filesystem->id))
{
unlink(filesystem->default_path);
bool const success = wf_impl_filesystem_link_first_subdir(filesystem->default_path, filesystem->service_path);
if (!success)
{
rmdir(filesystem->service_path);
}
}
free(filesystem->user_data.name); free(filesystem->user_data.name);
free(filesystem->id);
free(filesystem->root_path);
free(filesystem->default_path);
free(filesystem->service_path);
} }
static bool wf_impl_filesystem_init( static bool wf_impl_filesystem_init(
struct wf_impl_filesystem * filesystem, struct wf_impl_filesystem * filesystem,
struct wf_impl_session * session, struct wf_impl_session * session,
char const * name) char const * name,
struct wf_mountpoint * mountpoint)
{ {
bool result = false; bool result = false;
@ -129,15 +63,7 @@ static bool wf_impl_filesystem_init(
filesystem->user_data.name = strdup(name); filesystem->user_data.name = strdup(name);
memset(&filesystem->buffer, 0, sizeof(struct fuse_buf)); memset(&filesystem->buffer, 0, sizeof(struct fuse_buf));
filesystem->service_path = wf_create_string("%s/%s", session->mount_point, name); filesystem->mountpoint = mountpoint;
mkdir(filesystem->service_path, 0755);
filesystem->id = wf_impl_filesystem_create_id();
filesystem->root_path = wf_create_string("%s/%s/%s", session->mount_point, name, filesystem->id);
mkdir(filesystem->root_path, 0755);
filesystem->default_path = wf_create_string("%s/%s/default", session->mount_point, name);
symlink(filesystem->id, filesystem->default_path);
filesystem->session = fuse_session_new( filesystem->session = fuse_session_new(
&filesystem->args, &filesystem->args,
@ -146,7 +72,8 @@ static bool wf_impl_filesystem_init(
&filesystem->user_data); &filesystem->user_data);
if (NULL != filesystem->session) if (NULL != filesystem->session)
{ {
result = (0 == fuse_session_mount(filesystem->session, filesystem->root_path)); char const * path = wf_mountpoint_get_path(filesystem->mountpoint);
result = (0 == fuse_session_mount(filesystem->session, path));
} }
if (result) if (result)
@ -169,12 +96,13 @@ static bool wf_impl_filesystem_init(
struct wf_impl_filesystem * wf_impl_filesystem_create( struct wf_impl_filesystem * wf_impl_filesystem_create(
struct wf_impl_session * session, struct wf_impl_session * session,
char const * name) char const * name,
struct wf_mountpoint * mountpoint)
{ {
struct wf_impl_filesystem * filesystem = malloc(sizeof(struct wf_impl_filesystem)); struct wf_impl_filesystem * filesystem = malloc(sizeof(struct wf_impl_filesystem));
if (NULL != filesystem) if (NULL != filesystem)
{ {
bool success = wf_impl_filesystem_init(filesystem, session, name); bool success = wf_impl_filesystem_init(filesystem, session, name, mountpoint);
if (!success) if (!success)
{ {
free(filesystem); free(filesystem);

View File

@ -14,6 +14,7 @@ extern "C"
{ {
#endif #endif
struct wf_mountpoint;
struct wf_impl_session; struct wf_impl_session;
struct lws; struct lws;
@ -25,16 +26,13 @@ struct wf_impl_filesystem
struct fuse_buf buffer; struct fuse_buf buffer;
struct wf_impl_operations_context user_data; struct wf_impl_operations_context user_data;
struct lws * wsi; struct lws * wsi;
char * name; struct wf_mountpoint * mountpoint;
char * id;
char * service_path;
char * default_path;
char * root_path;
}; };
extern struct wf_impl_filesystem * wf_impl_filesystem_create( extern struct wf_impl_filesystem * wf_impl_filesystem_create(
struct wf_impl_session * session, struct wf_impl_session * session,
char const * name); char const * name,
struct wf_mountpoint * mountpoint);
extern void wf_impl_filesystem_dispose( extern void wf_impl_filesystem_dispose(
struct wf_impl_filesystem * filesystem); struct wf_impl_filesystem * filesystem);

View File

@ -0,0 +1,67 @@
#include "webfuse/adapter/impl/mountpoint_factory.h"
#include <stddef.h>
void
wf_impl_mountpoint_factory_init_default(
struct wf_impl_mountpoint_factory * factory)
{
factory->create_mountpoint = NULL;
factory->user_data = NULL;
factory->dispose = NULL;
}
void
wf_impl_mountpoint_factory_init(
struct wf_impl_mountpoint_factory * factory,
wf_create_mountpoint_fn * create_mountpoint,
void * user_data,
wf_impl_mountpoint_factory_dispose_fn * dispose)
{
factory->create_mountpoint = create_mountpoint;
factory->user_data = user_data;
factory->dispose = dispose;
}
void
wf_impl_mountpoint_factory_move(
struct wf_impl_mountpoint_factory * factory,
struct wf_impl_mountpoint_factory * other)
{
other->create_mountpoint = factory->create_mountpoint;
other->user_data = factory->user_data;
other->dispose = factory->dispose;
factory->create_mountpoint = NULL;
factory->dispose = NULL;
factory->user_data = NULL;
}
bool
wf_impl_mountpoint_factory_isvalid(
struct wf_impl_mountpoint_factory * factory)
{
return (NULL != factory->create_mountpoint);
}
void
wf_impl_mountpoint_factory_cleanup(
struct wf_impl_mountpoint_factory * factory)
{
if (NULL != factory->dispose)
{
factory->dispose(factory->user_data);
}
factory->create_mountpoint = NULL;
factory->dispose = NULL;
factory->user_data = NULL;
}
struct wf_mountpoint *
wf_impl_mountpoint_factory_create_mountpoint(
struct wf_impl_mountpoint_factory * factory,
char const * filesystem)
{
return factory->create_mountpoint(filesystem, factory->user_data);
}

View File

@ -0,0 +1,61 @@
#ifndef WF_ADAPTER_IMPL_MOUNTPOINT_FACTORY_H
#define WF_ADAPTER_IMPL_MOUNTPOINT_FACTORY_H
#include "webfuse/adapter/mountpoint_factory.h"
#include <stdbool.h>
#ifdef __cplusplus
extern "C"
{
#endif
typedef void
wf_impl_mountpoint_factory_dispose_fn(
void * user_data);
struct wf_impl_mountpoint_factory
{
wf_create_mountpoint_fn * create_mountpoint;
wf_impl_mountpoint_factory_dispose_fn * dispose;
void * user_data;
};
extern void
wf_impl_mountpoint_factory_init_default(
struct wf_impl_mountpoint_factory * factory);
extern void
wf_impl_mountpoint_factory_init(
struct wf_impl_mountpoint_factory * factory,
wf_create_mountpoint_fn * create_mountpoint,
void * user_data,
wf_impl_mountpoint_factory_dispose_fn * dispose);
extern void
wf_impl_mountpoint_factory_move(
struct wf_impl_mountpoint_factory * factory,
struct wf_impl_mountpoint_factory * other);
extern bool
wf_impl_mountpoint_factory_isvalid(
struct wf_impl_mountpoint_factory * factory);
extern void
wf_impl_mountpoint_factory_init_from(
struct wf_impl_mountpoint_factory * factory,
struct wf_impl_mountpoint_factory * other);
extern void
wf_impl_mountpoint_factory_cleanup(
struct wf_impl_mountpoint_factory * factory);
extern struct wf_mountpoint *
wf_impl_mountpoint_factory_create_mountpoint(
struct wf_impl_mountpoint_factory * factory,
char const * filesystem);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -76,37 +76,17 @@ static struct lws_context * wf_impl_server_context_create(
} }
static bool wf_impl_server_check_mountpoint(
struct wf_server_config * config)
{
bool result = false;
if (NULL != config->mount_point)
{
struct stat info;
int const rc = stat(config->mount_point, &info);
result = ((0 == rc) && (S_ISDIR(info.st_mode)));
if (!result)
{
result = (0 == mkdir(config->mount_point, 0755));
}
}
return result;
}
struct wf_server * wf_impl_server_create( struct wf_server * wf_impl_server_create(
struct wf_server_config * config) struct wf_server_config * config)
{ {
struct wf_server * server = NULL; struct wf_server * server = NULL;
if (wf_impl_server_check_mountpoint(config)) if (wf_impl_mountpoint_factory_isvalid(&config->mountpoint_factory))
{ {
server = malloc(sizeof(struct wf_server)); server = malloc(sizeof(struct wf_server));
if (NULL != server) if (NULL != server)
{ {
wf_impl_server_protocol_init(&server->protocol, config->mount_point); wf_impl_server_protocol_init(&server->protocol, &config->mountpoint_factory);
wf_impl_server_config_clone(config, &server->config); wf_impl_server_config_clone(config, &server->config);
wf_impl_authenticators_move(&server->config.authenticators, &server->protocol.authenticators); wf_impl_authenticators_move(&server->config.authenticators, &server->protocol.authenticators);
server->context = wf_impl_server_context_create(server); server->context = wf_impl_server_context_create(server);

View File

@ -1,4 +1,5 @@
#include "webfuse/adapter/impl/server_config.h" #include "webfuse/adapter/impl/server_config.h"
#include "webfuse/adapter/impl/uuid_mountpoint_factory.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -20,14 +21,15 @@ void wf_impl_server_config_init(
memset(config, 0, sizeof(struct wf_server_config)); memset(config, 0, sizeof(struct wf_server_config));
wf_impl_authenticators_init(&config->authenticators); wf_impl_authenticators_init(&config->authenticators);
wf_impl_mountpoint_factory_init_default(&config->mountpoint_factory);
} }
void wf_impl_server_config_cleanup( void wf_impl_server_config_cleanup(
struct wf_server_config * config) struct wf_server_config * config)
{ {
wf_impl_authenticators_cleanup(&config->authenticators); wf_impl_authenticators_cleanup(&config->authenticators);
wf_impl_mountpoint_factory_cleanup(&config->mountpoint_factory);
free(config->mount_point);
free(config->document_root); free(config->document_root);
free(config->key_path); free(config->key_path);
free(config->cert_path); free(config->cert_path);
@ -40,7 +42,6 @@ void wf_impl_server_config_clone(
struct wf_server_config * config, struct wf_server_config * config,
struct wf_server_config * clone) struct wf_server_config * clone)
{ {
clone->mount_point = wf_impl_server_config_strdup(config->mount_point);
clone->document_root = wf_impl_server_config_strdup(config->document_root); clone->document_root = wf_impl_server_config_strdup(config->document_root);
clone->key_path = wf_impl_server_config_strdup(config->key_path); clone->key_path = wf_impl_server_config_strdup(config->key_path);
clone->cert_path = wf_impl_server_config_strdup(config->cert_path); clone->cert_path = wf_impl_server_config_strdup(config->cert_path);
@ -48,6 +49,9 @@ void wf_impl_server_config_clone(
clone->port = config->port; clone->port = config->port;
wf_impl_authenticators_clone(&config->authenticators, &clone->authenticators); wf_impl_authenticators_clone(&config->authenticators, &clone->authenticators);
// ToDo: remove this: move is not clone :-/
wf_impl_mountpoint_factory_move(&config->mountpoint_factory, &clone->mountpoint_factory);
} }
struct wf_server_config * wf_impl_server_config_create(void) struct wf_server_config * wf_impl_server_config_create(void)
@ -72,10 +76,20 @@ void wf_impl_server_config_set_mountpoint(
struct wf_server_config * config, struct wf_server_config * config,
char const * mount_point) char const * mount_point)
{ {
free(config->mount_point); wf_impl_uuid_mountpoint_factory_init(&config->mountpoint_factory,
config->mount_point = strdup(mount_point); mount_point);
} }
void wf_impl_server_config_set_mountpoint_factory(
struct wf_server_config * config,
wf_create_mountpoint_fn * create_mountpoint,
void * create_mountpoint_context)
{
wf_impl_mountpoint_factory_init(&config->mountpoint_factory,
create_mountpoint, create_mountpoint_context, NULL);
}
void wf_impl_server_config_set_documentroot( void wf_impl_server_config_set_documentroot(
struct wf_server_config * config, struct wf_server_config * config,
char const * document_root) char const * document_root)

View File

@ -2,6 +2,7 @@
#define WF_ADAPTER_IMPL_SERVER_CONFIG_H #define WF_ADAPTER_IMPL_SERVER_CONFIG_H
#include "webfuse/adapter/impl/authenticators.h" #include "webfuse/adapter/impl/authenticators.h"
#include "webfuse/adapter/impl/mountpoint_factory.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -9,13 +10,13 @@ extern "C" {
struct wf_server_config struct wf_server_config
{ {
char * mount_point;
char * document_root; char * document_root;
char * key_path; char * key_path;
char * cert_path; char * cert_path;
char * vhost_name; char * vhost_name;
int port; int port;
struct wf_impl_authenticators authenticators; struct wf_impl_authenticators authenticators;
struct wf_impl_mountpoint_factory mountpoint_factory;
}; };
extern struct wf_server_config * wf_impl_server_config_create(void); extern struct wf_server_config * wf_impl_server_config_create(void);
@ -37,6 +38,11 @@ extern void wf_impl_server_config_set_mountpoint(
struct wf_server_config * config, struct wf_server_config * config,
char const * mount_point); char const * mount_point);
extern void wf_impl_server_config_set_mountpoint_factory(
struct wf_server_config * config,
wf_create_mountpoint_fn * create_mountpoint,
void * create_mountpoint_context);
extern void wf_impl_server_config_set_documentroot( extern void wf_impl_server_config_set_documentroot(
struct wf_server_config * config, struct wf_server_config * config,
char const * document_root); char const * document_root);

View File

@ -9,6 +9,7 @@
#include "webfuse/adapter/impl/credentials.h" #include "webfuse/adapter/impl/credentials.h"
#include "webfuse/adapter/impl/jsonrpc/request.h" #include "webfuse/adapter/impl/jsonrpc/request.h"
#include "webfuse/adapter/impl/uuid_mountpoint_factory.h"
static int wf_impl_server_protocol_callback( static int wf_impl_server_protocol_callback(
struct lws * wsi, struct lws * wsi,
@ -38,9 +39,9 @@ static int wf_impl_server_protocol_callback(
&protocol->session_manager, &protocol->session_manager,
wsi, wsi,
&protocol->authenticators, &protocol->authenticators,
&protocol->mountpoint_factory,
&protocol->timeout_manager, &protocol->timeout_manager,
&protocol->server, &protocol->server);
protocol->mount_point);
if (NULL != session) if (NULL != session)
{ {
@ -81,12 +82,34 @@ struct wf_server_protocol * wf_impl_server_protocol_create(
struct wf_server_protocol * protocol = malloc(sizeof(struct wf_server_protocol)); struct wf_server_protocol * protocol = malloc(sizeof(struct wf_server_protocol));
if (NULL != protocol) if (NULL != protocol)
{ {
wf_impl_server_protocol_init(protocol, mount_point); struct wf_impl_mountpoint_factory mountpoint_factory;
wf_impl_uuid_mountpoint_factory_init(&mountpoint_factory, mount_point);
wf_impl_server_protocol_init(protocol, &mountpoint_factory);
} }
return protocol; return protocol;
} }
struct wf_server_protocol * wf_impl_server_protocol_create2(
wf_create_mountpoint_fn * create_mountpoint,
void * create_mountpoint_context)
{
struct wf_server_protocol * protocol = malloc(sizeof(struct wf_server_protocol));
if (NULL != protocol)
{
struct wf_impl_mountpoint_factory mountpoint_factory;
wf_impl_mountpoint_factory_init(&mountpoint_factory,
create_mountpoint, create_mountpoint_context, NULL);
wf_impl_server_protocol_init(protocol, &mountpoint_factory);
}
return protocol;
}
void wf_impl_server_protocol_dispose( void wf_impl_server_protocol_dispose(
struct wf_server_protocol * protocol) struct wf_server_protocol * protocol)
{ {
@ -203,14 +226,14 @@ static void wf_impl_server_protocol_add_filesystem(
} }
void wf_impl_server_protocol_init( void wf_impl_server_protocol_init(
struct wf_server_protocol * protocol, struct wf_server_protocol * protocol,
char * mount_point) struct wf_impl_mountpoint_factory * mountpoint_factory)
{ {
protocol->mount_point = strdup(mount_point);
protocol->is_operational = false; protocol->is_operational = false;
wf_impl_mountpoint_factory_move(mountpoint_factory, &protocol->mountpoint_factory);
wf_impl_timeout_manager_init(&protocol->timeout_manager); wf_impl_timeout_manager_init(&protocol->timeout_manager);
wf_impl_session_manager_init(&protocol->session_manager); wf_impl_session_manager_init(&protocol->session_manager);
wf_impl_authenticators_init(&protocol->authenticators); wf_impl_authenticators_init(&protocol->authenticators);
@ -223,13 +246,13 @@ void wf_impl_server_protocol_init(
void wf_impl_server_protocol_cleanup( void wf_impl_server_protocol_cleanup(
struct wf_server_protocol * protocol) struct wf_server_protocol * protocol)
{ {
free(protocol->mount_point);
protocol->is_operational = false; protocol->is_operational = false;
wf_impl_jsonrpc_server_cleanup(&protocol->server); wf_impl_jsonrpc_server_cleanup(&protocol->server);
wf_impl_timeout_manager_cleanup(&protocol->timeout_manager); wf_impl_timeout_manager_cleanup(&protocol->timeout_manager);
wf_impl_authenticators_cleanup(&protocol->authenticators); wf_impl_authenticators_cleanup(&protocol->authenticators);
wf_impl_session_manager_cleanup(&protocol->session_manager); wf_impl_session_manager_cleanup(&protocol->session_manager);
wf_impl_mountpoint_factory_cleanup(&protocol->mountpoint_factory);
} }
void wf_impl_server_protocol_add_authenticator( void wf_impl_server_protocol_add_authenticator(

View File

@ -4,6 +4,7 @@
#include "webfuse/adapter/impl/jsonrpc/proxy.h" #include "webfuse/adapter/impl/jsonrpc/proxy.h"
#include "webfuse/adapter/impl/time/timeout_manager.h" #include "webfuse/adapter/impl/time/timeout_manager.h"
#include "webfuse/adapter/impl/authenticators.h" #include "webfuse/adapter/impl/authenticators.h"
#include "webfuse/adapter/impl/mountpoint_factory.h"
#include "webfuse/adapter/impl/session_manager.h" #include "webfuse/adapter/impl/session_manager.h"
#include "webfuse/adapter/impl/jsonrpc/server.h" #include "webfuse/adapter/impl/jsonrpc/server.h"
@ -20,9 +21,9 @@ struct lws_protocols;
struct wf_server_protocol struct wf_server_protocol
{ {
char * mount_point;
struct wf_impl_timeout_manager timeout_manager; struct wf_impl_timeout_manager timeout_manager;
struct wf_impl_authenticators authenticators; struct wf_impl_authenticators authenticators;
struct wf_impl_mountpoint_factory mountpoint_factory;
struct wf_impl_session_manager session_manager; struct wf_impl_session_manager session_manager;
struct wf_impl_jsonrpc_server server; struct wf_impl_jsonrpc_server server;
bool is_operational; bool is_operational;
@ -30,7 +31,7 @@ struct wf_server_protocol
extern void wf_impl_server_protocol_init( extern void wf_impl_server_protocol_init(
struct wf_server_protocol * protocol, struct wf_server_protocol * protocol,
char * mount_point); struct wf_impl_mountpoint_factory * mountpoint_factory);
extern void wf_impl_server_protocol_cleanup( extern void wf_impl_server_protocol_cleanup(
struct wf_server_protocol * protocol); struct wf_server_protocol * protocol);
@ -38,6 +39,10 @@ extern void wf_impl_server_protocol_cleanup(
extern struct wf_server_protocol * wf_impl_server_protocol_create( extern struct wf_server_protocol * wf_impl_server_protocol_create(
char * mount_point); char * mount_point);
extern WF_API struct wf_server_protocol * wf_impl_server_protocol_create2(
wf_create_mountpoint_fn * create_mountpoint,
void * create_mountpoint_context);
extern void wf_impl_server_protocol_dispose( extern void wf_impl_server_protocol_dispose(
struct wf_server_protocol * protocol); struct wf_server_protocol * protocol);

View File

@ -5,6 +5,8 @@
#include "webfuse/adapter/impl/jsonrpc/proxy.h" #include "webfuse/adapter/impl/jsonrpc/proxy.h"
#include "webfuse/adapter/impl/jsonrpc/request.h" #include "webfuse/adapter/impl/jsonrpc/request.h"
#include "webfuse/adapter/impl/jsonrpc/response.h" #include "webfuse/adapter/impl/jsonrpc/response.h"
#include "webfuse/adapter/impl/mountpoint_factory.h"
#include "webfuse/adapter/impl/mountpoint.h"
#include "webfuse/core/container_of.h" #include "webfuse/core/container_of.h"
#include "webfuse/core/util.h" #include "webfuse/core/util.h"
@ -44,7 +46,7 @@ struct wf_impl_session * wf_impl_session_create(
struct wf_impl_authenticators * authenticators, struct wf_impl_authenticators * authenticators,
struct wf_impl_timeout_manager * timeout_manager, struct wf_impl_timeout_manager * timeout_manager,
struct wf_impl_jsonrpc_server * server, struct wf_impl_jsonrpc_server * server,
char const * mount_point) struct wf_impl_mountpoint_factory * mountpoint_factory)
{ {
struct wf_impl_session * session = malloc(sizeof(struct wf_impl_session)); struct wf_impl_session * session = malloc(sizeof(struct wf_impl_session));
@ -52,11 +54,11 @@ struct wf_impl_session * wf_impl_session_create(
{ {
wf_slist_init(&session->filesystems); wf_slist_init(&session->filesystems);
session->mount_point = strdup(mount_point);
session->wsi = wsi; session->wsi = wsi;
session->is_authenticated = false; session->is_authenticated = false;
session->authenticators = authenticators; session->authenticators = authenticators;
session->server = server; session->server = server;
session->mountpoint_factory = mountpoint_factory;
wf_impl_jsonrpc_proxy_init(&session->rpc, timeout_manager, WF_DEFAULT_TIMEOUT, &wf_impl_session_send, session); wf_impl_jsonrpc_proxy_init(&session->rpc, timeout_manager, WF_DEFAULT_TIMEOUT, &wf_impl_session_send, session);
wf_slist_init(&session->messages); wf_slist_init(&session->messages);
} }
@ -88,8 +90,8 @@ void wf_impl_session_dispose(
session->is_authenticated = false; session->is_authenticated = false;
session->wsi = NULL; session->wsi = NULL;
session->authenticators = NULL; session->authenticators = NULL;
session->mountpoint_factory = NULL;
session->server = NULL; session->server = NULL;
free(session->mount_point);
free(session); free(session);
} }
@ -106,9 +108,28 @@ bool wf_impl_session_add_filesystem(
struct wf_impl_session * session, struct wf_impl_session * session,
char const * name) char const * name)
{ {
struct wf_impl_filesystem * filesystem = wf_impl_filesystem_create(session, name); bool result;
wf_slist_append(&session->filesystems, &filesystem->item);
return (NULL != filesystem); struct wf_mountpoint * mountpoint = wf_impl_mountpoint_factory_create_mountpoint(session->mountpoint_factory, name);
result = (NULL != mountpoint);
if (result)
{
struct wf_impl_filesystem * filesystem = wf_impl_filesystem_create(session, name, mountpoint);
wf_slist_append(&session->filesystems, &filesystem->item);
result = (NULL != filesystem);
}
// cleanup on error
if (!result)
{
if (NULL != mountpoint)
{
wf_impl_mountpoint_dispose(mountpoint);
}
}
return result;
} }

View File

@ -24,16 +24,17 @@ struct lws;
struct wf_message; struct wf_message;
struct wf_credentials; struct wf_credentials;
struct wf_impl_authenticators; struct wf_impl_authenticators;
struct wf_impl_mountpoint_factory;
struct wf_impl_timeout_manager; struct wf_impl_timeout_manager;
struct wf_impl_session struct wf_impl_session
{ {
struct wf_slist_item item; struct wf_slist_item item;
char * mount_point;
struct lws * wsi; struct lws * wsi;
bool is_authenticated; bool is_authenticated;
struct wf_slist messages; struct wf_slist messages;
struct wf_impl_authenticators * authenticators; struct wf_impl_authenticators * authenticators;
struct wf_impl_mountpoint_factory * mountpoint_factory;
struct wf_impl_jsonrpc_server * server; struct wf_impl_jsonrpc_server * server;
struct wf_impl_jsonrpc_proxy rpc; struct wf_impl_jsonrpc_proxy rpc;
struct wf_slist filesystems; struct wf_slist filesystems;
@ -44,7 +45,7 @@ extern struct wf_impl_session * wf_impl_session_create(
struct wf_impl_authenticators * authenticators, struct wf_impl_authenticators * authenticators,
struct wf_impl_timeout_manager * timeout_manager, struct wf_impl_timeout_manager * timeout_manager,
struct wf_impl_jsonrpc_server * server, struct wf_impl_jsonrpc_server * server,
char const * mount_point); struct wf_impl_mountpoint_factory * mountpoint_factory);
extern void wf_impl_session_dispose( extern void wf_impl_session_dispose(
struct wf_impl_session * session); struct wf_impl_session * session);

View File

@ -27,12 +27,12 @@ struct wf_impl_session * wf_impl_session_manager_add(
struct wf_impl_session_manager * manager, struct wf_impl_session_manager * manager,
struct lws * wsi, struct lws * wsi,
struct wf_impl_authenticators * authenticators, struct wf_impl_authenticators * authenticators,
struct wf_impl_mountpoint_factory * mountpoint_factory,
struct wf_impl_timeout_manager * timeout_manager, struct wf_impl_timeout_manager * timeout_manager,
struct wf_impl_jsonrpc_server * server, struct wf_impl_jsonrpc_server * server)
char const * mount_point)
{ {
struct wf_impl_session * session = wf_impl_session_create( struct wf_impl_session * session = wf_impl_session_create(
wsi, authenticators, timeout_manager, server, mount_point); wsi, authenticators, timeout_manager, server, mountpoint_factory);
if (NULL != session) if (NULL != session)
{ {
wf_slist_append(&manager->sessions, &session->item); wf_slist_append(&manager->sessions, &session->item);

View File

@ -33,9 +33,9 @@ extern struct wf_impl_session * wf_impl_session_manager_add(
struct wf_impl_session_manager * manager, struct wf_impl_session_manager * manager,
struct lws * wsi, struct lws * wsi,
struct wf_impl_authenticators * authenticators, struct wf_impl_authenticators * authenticators,
struct wf_impl_mountpoint_factory * mountpoint_factory,
struct wf_impl_timeout_manager * timeout_manager, struct wf_impl_timeout_manager * timeout_manager,
struct wf_impl_jsonrpc_server * server, struct wf_impl_jsonrpc_server * server);
char const * mount_point);
extern struct wf_impl_session * wf_impl_session_manager_get( extern struct wf_impl_session * wf_impl_session_manager_get(
struct wf_impl_session_manager * manager, struct wf_impl_session_manager * manager,

View File

@ -15,8 +15,8 @@ struct wf_impl_uuid_mountpoint_factory
bool root_created; bool root_created;
}; };
void * static void *
wf_impl_uuid_mountpoint_factory_create( wf_impl_uuid_mountpoint_factory_create_context(
char const * root_path) char const * root_path)
{ {
struct wf_impl_uuid_mountpoint_factory * factory = NULL; struct wf_impl_uuid_mountpoint_factory * factory = NULL;
@ -37,11 +37,10 @@ wf_impl_uuid_mountpoint_factory_create(
factory->root_created = root_created; factory->root_created = root_created;
} }
return factory; return factory;
} }
void static void
wf_impl_uuid_mountpoint_factory_dispose( wf_impl_uuid_mountpoint_factory_dispose(
void * user_data) void * user_data)
{ {
@ -56,7 +55,7 @@ wf_impl_uuid_mountpoint_factory_dispose(
free(factory); free(factory);
} }
struct wf_mountpoint * static struct wf_mountpoint *
wf_impl_uuid_mountpoint_factory_create_mountpoint( wf_impl_uuid_mountpoint_factory_create_mountpoint(
char const * filesystem, char const * filesystem,
void * user_data) void * user_data)
@ -65,3 +64,21 @@ wf_impl_uuid_mountpoint_factory_create_mountpoint(
return wf_impl_uuid_mountpoint_create(factory->root_path, filesystem); return wf_impl_uuid_mountpoint_create(factory->root_path, filesystem);
} }
bool
wf_impl_uuid_mountpoint_factory_init(
struct wf_impl_mountpoint_factory * factory,
char const * root_path)
{
void * context = wf_impl_uuid_mountpoint_factory_create_context(root_path);
bool const result = (NULL != context);
if (result)
{
factory->create_mountpoint = &wf_impl_uuid_mountpoint_factory_create_mountpoint;
factory->user_data = context;
factory->dispose = &wf_impl_uuid_mountpoint_factory_dispose;
}
return result;
}

View File

@ -1,27 +1,19 @@
#ifndef WF_IMPL_UUID_MOUNTPOINT_FACTORY_H #ifndef WF_IMPL_UUID_MOUNTPOINT_FACTORY_H
#define WF_IMPL_UUID_MOUNTPOINT_FACTORY_H #define WF_IMPL_UUID_MOUNTPOINT_FACTORY_H
#include "webfuse/adapter/impl/mountpoint_factory.h"
#include <stdbool.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
{ {
#endif #endif
struct wf_mountpoint; extern bool
wf_impl_uuid_mountpoint_factory_init(
extern void * struct wf_impl_mountpoint_factory * factory,
wf_impl_uuid_mountpoint_factory_create(
char const * root_path); char const * root_path);
extern void
wf_impl_uuid_mountpoint_factory_dispose(
void * user_data);
extern struct wf_mountpoint *
wf_impl_uuid_mountpoint_factory_create_mountpoint(
char const * filesystem,
void * user_data);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -11,19 +11,19 @@ TEST(uuid_mountpoint_factory, create_existing_dir)
{ {
TempDir temp("uuid_mountpoint_factory"); TempDir temp("uuid_mountpoint_factory");
void * factory = wf_impl_uuid_mountpoint_factory_create(temp.path()); struct wf_impl_mountpoint_factory factory;
ASSERT_NE(nullptr, factory); bool factory_created = wf_impl_uuid_mountpoint_factory_init(&factory, temp.path());
ASSERT_TRUE(factory_created);
ASSERT_TRUE(is_dir(temp.path())); ASSERT_TRUE(is_dir(temp.path()));
wf_mountpoint * mountpoint = wf_impl_uuid_mountpoint_factory_create_mountpoint("dummy", factory); wf_mountpoint * mountpoint = wf_impl_mountpoint_factory_create_mountpoint(&factory, "dummy");
std::string path = wf_mountpoint_get_path(mountpoint); std::string path = wf_mountpoint_get_path(mountpoint);
ASSERT_NE(nullptr, factory);
ASSERT_TRUE(is_dir(path)); ASSERT_TRUE(is_dir(path));
wf_mountpoint_dispose(mountpoint); wf_mountpoint_dispose(mountpoint);
ASSERT_FALSE(is_dir(path)); ASSERT_FALSE(is_dir(path));
wf_impl_uuid_mountpoint_factory_dispose(factory); wf_impl_mountpoint_factory_cleanup(&factory);
// keep dir not created by factory // keep dir not created by factory
ASSERT_TRUE(is_dir(temp.path())); ASSERT_TRUE(is_dir(temp.path()));
} }
@ -33,19 +33,19 @@ TEST(uuid_mountpoint_factory, create_nonexisting_dir)
TempDir temp("uuid_mountpoint_factory"); TempDir temp("uuid_mountpoint_factory");
std::string root_path = std::string(temp.path()) + "/root"; std::string root_path = std::string(temp.path()) + "/root";
void * factory = wf_impl_uuid_mountpoint_factory_create(root_path.c_str()); struct wf_impl_mountpoint_factory factory;
ASSERT_NE(nullptr, factory); bool factory_created = wf_impl_uuid_mountpoint_factory_init(&factory, root_path.c_str());
ASSERT_TRUE(factory_created);
ASSERT_TRUE(is_dir(root_path)); ASSERT_TRUE(is_dir(root_path));
wf_mountpoint * mountpoint = wf_impl_uuid_mountpoint_factory_create_mountpoint("dummy", factory); wf_mountpoint * mountpoint = wf_impl_mountpoint_factory_create_mountpoint(&factory, "dummy");
std::string path = wf_mountpoint_get_path(mountpoint); std::string path = wf_mountpoint_get_path(mountpoint);
ASSERT_NE(nullptr, factory);
ASSERT_TRUE(is_dir(path)); ASSERT_TRUE(is_dir(path));
wf_mountpoint_dispose(mountpoint); wf_mountpoint_dispose(mountpoint);
ASSERT_FALSE(is_dir(path)); ASSERT_FALSE(is_dir(path));
wf_impl_uuid_mountpoint_factory_dispose(factory); wf_impl_mountpoint_factory_cleanup(&factory);
// remove dir, created by factory // remove dir, created by factory
ASSERT_FALSE(is_dir(root_path)); ASSERT_FALSE(is_dir(root_path));
} }
@ -55,6 +55,7 @@ TEST(uuid_mountpoint_factory, fail_to_created_nested_dir)
TempDir temp("uuid_mountpoint_factory"); TempDir temp("uuid_mountpoint_factory");
std::string root_path = std::string(temp.path()) + "/nested/root"; std::string root_path = std::string(temp.path()) + "/nested/root";
void * factory = wf_impl_uuid_mountpoint_factory_create(root_path.c_str()); struct wf_impl_mountpoint_factory factory;
ASSERT_EQ(nullptr, factory); bool factory_created = wf_impl_uuid_mountpoint_factory_init(&factory, root_path.c_str());
ASSERT_FALSE(factory_created);
} }