mirror of
https://github.com/falk-werner/webfused
synced 2026-03-02 04:09:19 +00:00
parse filesystem info
This commit is contained in:
@@ -48,4 +48,13 @@ wfd_config_builder_add_auth_provider(
|
||||
return builder.vtable->add_auth_provider(builder.data, settings);
|
||||
}
|
||||
|
||||
bool
|
||||
wfd_config_builder_add_filesystem(
|
||||
struct wfd_config_builder builder,
|
||||
char const * name,
|
||||
char const * mount_point)
|
||||
{
|
||||
return builder.vtable->add_filesystem(builder.data, name, mount_point);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -42,6 +42,12 @@ wfd_config_builder_add_auth_provider_fn(
|
||||
void * data,
|
||||
struct wfd_auth_settings * settings);
|
||||
|
||||
typedef bool
|
||||
wfd_config_builder_add_filesystem_fn(
|
||||
void * data,
|
||||
char const * name,
|
||||
char const * mount_point);
|
||||
|
||||
struct wfd_config_builder_vtable
|
||||
{
|
||||
wfd_config_builder_set_server_vhostname_fn * set_server_vhostname;
|
||||
@@ -50,6 +56,7 @@ struct wfd_config_builder_vtable
|
||||
wfd_config_builder_set_server_cert_fn * set_server_cert;
|
||||
wfd_config_builder_set_server_document_root_fn * set_server_document_root;
|
||||
wfd_config_builder_add_auth_provider_fn * add_auth_provider;
|
||||
wfd_config_builder_add_filesystem_fn * add_filesystem;
|
||||
};
|
||||
|
||||
struct wfd_config_builder
|
||||
@@ -88,6 +95,11 @@ wfd_config_builder_add_auth_provider(
|
||||
struct wfd_config_builder builder,
|
||||
struct wfd_auth_settings * settings);
|
||||
|
||||
extern bool
|
||||
wfd_config_builder_add_filesystem(
|
||||
struct wfd_config_builder builder,
|
||||
char const * name,
|
||||
char const * mount_point);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "webfuse/adapter/server_config.h"
|
||||
#include "webfused/auth/factory.h"
|
||||
#include "webfused/auth/authenticator.h"
|
||||
#include "webfused/mountpoint_factory.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
@@ -13,6 +14,7 @@ struct wfd_config
|
||||
struct wf_server_config * server;
|
||||
bool has_authenticator;
|
||||
struct wfd_authenticator authenticator;
|
||||
struct wfd_mountpoint_factory * mountpoint_factory;
|
||||
};
|
||||
|
||||
static void
|
||||
@@ -86,6 +88,16 @@ wfd_config_add_auth_provider(
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool
|
||||
wfd_config_add_filesystem(
|
||||
void * data,
|
||||
char const * name,
|
||||
char const * mount_point)
|
||||
{
|
||||
struct wfd_config * config = data;
|
||||
return wfd_mountpoint_factory_add_filesystem(
|
||||
config->mountpoint_factory, name, mount_point);
|
||||
}
|
||||
|
||||
static const struct wfd_config_builder_vtable
|
||||
wfd_config_vtable_config_builder =
|
||||
@@ -95,7 +107,8 @@ wfd_config_vtable_config_builder =
|
||||
.set_server_key = &wfd_config_set_server_key,
|
||||
.set_server_cert = &wfd_config_set_server_cert,
|
||||
.set_server_document_root = &wfd_config_set_server_document_root,
|
||||
.add_auth_provider = &wfd_config_add_auth_provider
|
||||
.add_auth_provider = &wfd_config_add_auth_provider,
|
||||
.add_filesystem = &wfd_config_add_filesystem
|
||||
};
|
||||
|
||||
struct wfd_config *
|
||||
@@ -103,11 +116,14 @@ wfd_config_create(void)
|
||||
{
|
||||
struct wfd_config * config = malloc(sizeof(struct wfd_config));
|
||||
|
||||
config->mountpoint_factory = wfd_mountpoint_factory_create();
|
||||
config->has_authenticator = false;
|
||||
config->server = wf_server_config_create();
|
||||
wf_server_config_set_vhostname(config->server, WFD_CONFIG_DEFAULT_VHOSTNAME);
|
||||
wf_server_config_set_port(config->server, WFD_CONFIG_DEFAULT_PORT);
|
||||
|
||||
config->has_authenticator = false;
|
||||
wf_server_config_set_mountpoint_factory(config->server,
|
||||
wfd_mountpoint_factory_create_mountpoint,
|
||||
config->mountpoint_factory);
|
||||
|
||||
return config;
|
||||
}
|
||||
@@ -121,6 +137,7 @@ wfd_config_dispose(
|
||||
{
|
||||
wfd_authenticator_dispose(config->authenticator);
|
||||
}
|
||||
wfd_mountpoint_factory_dispose(config->mountpoint_factory);
|
||||
|
||||
free(config);
|
||||
}
|
||||
|
||||
@@ -143,6 +143,55 @@ wfd_config_read_authentication(
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool
|
||||
wfd_config_read_filesystems(
|
||||
config_t * config,
|
||||
struct wfd_config_builder builder)
|
||||
{
|
||||
bool result = true;
|
||||
config_setting_t * filesystems = config_lookup(config, "filesystems");
|
||||
if (NULL != filesystems)
|
||||
{
|
||||
int length = config_setting_length(filesystems);
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
config_setting_t * fs = config_setting_get_elem(filesystems, i);
|
||||
if (NULL == fs)
|
||||
{
|
||||
WFD_ERROR("failed to load config: invalid filesystem section");
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
char const * name;
|
||||
int rc = config_setting_lookup_string(fs, "name", &name);
|
||||
if (rc != CONFIG_TRUE)
|
||||
{
|
||||
WFD_ERROR("failed to load config: missing required filesystem property \'name\'");
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
char const * mount_point;
|
||||
rc = config_setting_lookup_string(fs, "mount_point", &mount_point);
|
||||
if (rc != CONFIG_TRUE)
|
||||
{
|
||||
WFD_ERROR("failed to load config: missing required filesystem property \'mount_point\'");
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
|
||||
result = wfd_config_builder_add_filesystem(builder, name, mount_point);
|
||||
if (!result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool
|
||||
wfd_config_load(
|
||||
struct wfd_config_builder builder,
|
||||
@@ -152,6 +201,7 @@ wfd_config_load(
|
||||
bool result = wfd_config_check_version(config)
|
||||
&& wfd_config_read_server(config, builder)
|
||||
&& wfd_config_read_authentication(config, builder)
|
||||
&& wfd_config_read_filesystems(config, builder)
|
||||
;
|
||||
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user