2020-03-08 15:14:55 +00:00
|
|
|
#include "webfused/config/config.h"
|
2020-03-19 16:25:26 +00:00
|
|
|
#include "webfused/config/config_intern.h"
|
2020-03-17 15:49:17 +00:00
|
|
|
#include "webfused/auth/factory.h"
|
|
|
|
#include "webfused/auth/authenticator.h"
|
2020-03-17 20:51:04 +00:00
|
|
|
#include "webfused/mountpoint_factory.h"
|
2020-03-18 16:33:31 +00:00
|
|
|
#include "webfused/log/manager.h"
|
2020-03-08 15:14:55 +00:00
|
|
|
|
2020-07-05 09:19:00 +00:00
|
|
|
#include <webfuse/server_config.h>
|
|
|
|
|
2020-03-08 15:14:55 +00:00
|
|
|
#include <stdlib.h>
|
2020-03-19 11:42:47 +00:00
|
|
|
#include <string.h>
|
2020-03-08 15:14:55 +00:00
|
|
|
|
|
|
|
#define WFD_CONFIG_DEFAULT_PORT (8080)
|
|
|
|
#define WFD_CONFIG_DEFAULT_VHOSTNAME ("localhost")
|
|
|
|
|
2020-03-09 22:59:36 +00:00
|
|
|
struct wfd_config
|
|
|
|
{
|
2020-03-15 21:35:57 +00:00
|
|
|
struct wf_server_config * server;
|
2020-03-17 15:49:17 +00:00
|
|
|
bool has_authenticator;
|
|
|
|
struct wfd_authenticator authenticator;
|
2020-03-17 20:51:04 +00:00
|
|
|
struct wfd_mountpoint_factory * mountpoint_factory;
|
2020-03-19 11:42:47 +00:00
|
|
|
char * user;
|
|
|
|
char * group;
|
2020-03-09 22:59:36 +00:00
|
|
|
};
|
|
|
|
|
2020-03-19 16:25:26 +00:00
|
|
|
struct wfd_config *
|
|
|
|
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);
|
|
|
|
wf_server_config_set_mountpoint_factory(config->server,
|
|
|
|
wfd_mountpoint_factory_create_mountpoint,
|
|
|
|
config->mountpoint_factory);
|
|
|
|
config->user = NULL;
|
|
|
|
config->group = NULL;
|
|
|
|
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
wfd_config_dispose(
|
|
|
|
struct wfd_config * config)
|
|
|
|
{
|
|
|
|
wf_server_config_dispose(config->server);
|
|
|
|
if (config->has_authenticator)
|
|
|
|
{
|
|
|
|
wfd_authenticator_dispose(config->authenticator);
|
|
|
|
}
|
|
|
|
wfd_mountpoint_factory_dispose(config->mountpoint_factory);
|
|
|
|
|
|
|
|
free(config->user);
|
|
|
|
free(config->group);
|
|
|
|
free(config);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2020-03-15 21:35:57 +00:00
|
|
|
wfd_config_set_server_vhostname(
|
2020-03-19 16:25:26 +00:00
|
|
|
struct wfd_config * config,
|
2020-03-15 21:35:57 +00:00
|
|
|
char const * vhost_name)
|
2020-03-08 15:14:55 +00:00
|
|
|
{
|
2020-03-15 21:35:57 +00:00
|
|
|
wf_server_config_set_vhostname(config->server, vhost_name);
|
2020-03-08 15:14:55 +00:00
|
|
|
}
|
|
|
|
|
2020-03-19 16:25:26 +00:00
|
|
|
void
|
2020-03-09 22:59:36 +00:00
|
|
|
wfd_config_set_server_port(
|
2020-03-19 16:25:26 +00:00
|
|
|
struct wfd_config * config,
|
2020-03-09 22:59:36 +00:00
|
|
|
int port)
|
|
|
|
{
|
2020-03-15 21:35:57 +00:00
|
|
|
wf_server_config_set_port(config->server, port);
|
2020-03-09 22:59:36 +00:00
|
|
|
}
|
|
|
|
|
2020-03-19 16:25:26 +00:00
|
|
|
void
|
2020-03-15 21:35:57 +00:00
|
|
|
wfd_config_set_server_key(
|
2020-03-19 16:25:26 +00:00
|
|
|
struct wfd_config * config,
|
2020-03-15 21:35:57 +00:00
|
|
|
char const * key_path)
|
2020-03-08 15:14:55 +00:00
|
|
|
{
|
2020-03-15 21:35:57 +00:00
|
|
|
wf_server_config_set_keypath(config->server, key_path);
|
2020-03-08 15:14:55 +00:00
|
|
|
}
|
|
|
|
|
2020-03-19 16:25:26 +00:00
|
|
|
void
|
2020-03-15 21:35:57 +00:00
|
|
|
wfd_config_set_server_cert(
|
2020-03-19 16:25:26 +00:00
|
|
|
struct wfd_config * config,
|
2020-03-15 21:35:57 +00:00
|
|
|
char const * cert_path)
|
2020-03-09 22:59:36 +00:00
|
|
|
{
|
2020-03-15 21:35:57 +00:00
|
|
|
wf_server_config_set_certpath(config->server, cert_path);
|
2020-03-09 22:59:36 +00:00
|
|
|
}
|
|
|
|
|
2020-03-19 16:25:26 +00:00
|
|
|
void
|
2020-03-15 21:35:57 +00:00
|
|
|
wfd_config_set_server_document_root(
|
2020-03-19 16:25:26 +00:00
|
|
|
struct wfd_config * config,
|
2020-03-15 21:35:57 +00:00
|
|
|
char const * document_root)
|
2020-03-09 22:59:36 +00:00
|
|
|
{
|
2020-03-15 21:35:57 +00:00
|
|
|
wf_server_config_set_documentroot(config->server, document_root);
|
2020-03-09 22:59:36 +00:00
|
|
|
}
|
|
|
|
|
2020-03-19 16:25:26 +00:00
|
|
|
bool
|
2020-03-17 15:49:17 +00:00
|
|
|
wfd_config_add_auth_provider(
|
2020-03-19 16:25:26 +00:00
|
|
|
struct wfd_config * config,
|
2020-03-18 09:17:17 +00:00
|
|
|
char const * provider,
|
|
|
|
struct wfd_settings * settings)
|
2020-03-17 15:49:17 +00:00
|
|
|
{
|
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
if (!config->has_authenticator)
|
|
|
|
{
|
2020-03-18 09:17:17 +00:00
|
|
|
result = wfd_authenticator_create(provider, settings, &config->authenticator);
|
2020-03-17 15:49:17 +00:00
|
|
|
if (result)
|
|
|
|
{
|
|
|
|
wf_server_config_add_authenticator(
|
2020-11-13 18:29:03 +00:00
|
|
|
config->server,
|
|
|
|
wfd_authenticator_get_type(config->authenticator),
|
2020-03-17 15:49:17 +00:00
|
|
|
config->authenticator.vtable->authenticate,
|
|
|
|
config->authenticator.data);
|
|
|
|
|
|
|
|
config->has_authenticator = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-03-19 16:25:26 +00:00
|
|
|
bool
|
2020-03-17 20:51:04 +00:00
|
|
|
wfd_config_add_filesystem(
|
2020-03-19 16:25:26 +00:00
|
|
|
struct wfd_config * config,
|
2020-03-17 20:51:04 +00:00
|
|
|
char const * name,
|
2020-11-13 18:29:03 +00:00
|
|
|
char const * mount_point,
|
|
|
|
struct wfd_string_list const * mount_options)
|
2020-03-17 20:51:04 +00:00
|
|
|
{
|
|
|
|
return wfd_mountpoint_factory_add_filesystem(
|
2020-11-13 18:29:03 +00:00
|
|
|
config->mountpoint_factory, name, mount_point, mount_options);
|
2020-03-17 20:51:04 +00:00
|
|
|
}
|
2020-03-17 15:49:17 +00:00
|
|
|
|
2020-03-19 16:25:26 +00:00
|
|
|
bool
|
2020-03-18 16:33:31 +00:00
|
|
|
wfd_config_set_logger(
|
2020-03-19 16:25:26 +00:00
|
|
|
struct wfd_config * config,
|
2020-03-18 16:33:31 +00:00
|
|
|
char const * provider,
|
|
|
|
int level,
|
|
|
|
struct wfd_settings * settings)
|
|
|
|
{
|
|
|
|
return wfd_log_manager_set_logger(provider, level, settings);
|
|
|
|
}
|
|
|
|
|
2020-03-19 16:25:26 +00:00
|
|
|
void
|
2020-03-19 11:42:47 +00:00
|
|
|
wfd_config_set_user(
|
2020-03-19 16:25:26 +00:00
|
|
|
struct wfd_config * config,
|
2020-03-19 11:42:47 +00:00
|
|
|
char const * user,
|
|
|
|
char const * group)
|
|
|
|
{
|
|
|
|
config->user = strdup(user);
|
|
|
|
config->group = strdup(group);
|
|
|
|
}
|
|
|
|
|
2020-03-15 21:35:57 +00:00
|
|
|
struct wf_server_config *
|
|
|
|
wfd_config_get_server_config(
|
2020-03-08 15:14:55 +00:00
|
|
|
struct wfd_config * config)
|
|
|
|
{
|
2020-03-15 21:35:57 +00:00
|
|
|
return config->server;
|
2020-03-08 15:14:55 +00:00
|
|
|
}
|
|
|
|
|
2020-03-19 11:42:47 +00:00
|
|
|
char const *
|
|
|
|
wfd_config_get_user(
|
|
|
|
struct wfd_config * config)
|
|
|
|
{
|
|
|
|
return config->user;
|
|
|
|
}
|
|
|
|
|
|
|
|
char const *
|
|
|
|
wfd_config_get_group(
|
|
|
|
struct wfd_config * config)
|
|
|
|
{
|
|
|
|
return config->group;
|
|
|
|
}
|