1
0
mirror of https://github.com/falk-werner/webfuse synced 2024-10-27 20:34:10 +00:00
falk-werner_webfuse/lib/webfuse/adapter/impl/server_config.c

142 lines
3.5 KiB
C
Raw Normal View History

2019-03-26 22:04:53 +00:00
#include "webfuse/adapter/impl/server_config.h"
2020-02-16 20:03:17 +00:00
#include "webfuse/adapter/impl/uuid_mountpoint_factory.h"
2019-03-26 22:04:53 +00:00
#include <stdlib.h>
#include <string.h>
static char * wf_impl_server_config_strdup(char const * value)
{
char * result = NULL;
if (NULL != value)
{
result = strdup(value);
}
return result;
}
void wf_impl_server_config_init(
struct wf_server_config * config)
{
memset(config, 0, sizeof(struct wf_server_config));
wf_impl_authenticators_init(&config->authenticators);
2020-02-16 20:03:17 +00:00
wf_impl_mountpoint_factory_init_default(&config->mountpoint_factory);
2019-03-26 22:04:53 +00:00
}
void wf_impl_server_config_cleanup(
struct wf_server_config * config)
{
wf_impl_authenticators_cleanup(&config->authenticators);
2020-02-16 20:03:17 +00:00
wf_impl_mountpoint_factory_cleanup(&config->mountpoint_factory);
2019-03-26 22:04:53 +00:00
free(config->document_root);
free(config->key_path);
free(config->cert_path);
free(config->vhost_name);
wf_impl_server_config_init(config);
}
void wf_impl_server_config_clone(
struct wf_server_config * config,
struct wf_server_config * clone)
{
clone->document_root = wf_impl_server_config_strdup(config->document_root);
clone->key_path = wf_impl_server_config_strdup(config->key_path);
clone->cert_path = wf_impl_server_config_strdup(config->cert_path);
clone->vhost_name = wf_impl_server_config_strdup(config->vhost_name);
clone->port = config->port;
wf_impl_authenticators_clone(&config->authenticators, &clone->authenticators);
2020-02-16 20:03:17 +00:00
// ToDo: remove this: move is not clone :-/
wf_impl_mountpoint_factory_move(&config->mountpoint_factory, &clone->mountpoint_factory);
2019-03-26 22:04:53 +00:00
}
struct wf_server_config * wf_impl_server_config_create(void)
{
struct wf_server_config * config = malloc(sizeof(struct wf_server_config));
if (NULL != config)
{
wf_impl_server_config_init(config);
}
return config;
}
void wf_impl_server_config_dispose(
struct wf_server_config * config)
{
wf_impl_server_config_cleanup(config);
free(config);
}
void wf_impl_server_config_set_mountpoint(
struct wf_server_config * config,
char const * mount_point)
{
2020-02-16 20:03:17 +00:00
wf_impl_uuid_mountpoint_factory_init(&config->mountpoint_factory,
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);
2019-03-26 22:04:53 +00:00
}
2020-02-16 20:03:17 +00:00
2019-03-26 22:04:53 +00:00
void wf_impl_server_config_set_documentroot(
struct wf_server_config * config,
char const * document_root)
{
free(config->document_root);
config->document_root = strdup(document_root);
}
void wf_impl_server_config_set_keypath(
struct wf_server_config * config,
char const * key_path)
{
free(config->key_path);
config->key_path = strdup(key_path);
}
void wf_impl_server_config_set_certpath(
struct wf_server_config * config,
char const * cert_path)
{
free(config->cert_path);
config->cert_path = strdup(cert_path);
}
void wf_impl_server_config_set_vhostname(
struct wf_server_config * config,
char const * vhost_name)
{
free(config->vhost_name);
config->vhost_name = strdup(vhost_name);
}
void wf_impl_server_config_set_port(
struct wf_server_config * config,
int port)
{
config->port = port;
}
void wf_impl_server_config_add_authenticator(
struct wf_server_config * config,
char const * type,
wf_authenticate_fn * authenticate,
void * user_data
)
{
wf_impl_authenticators_add(&config->authenticators, type, authenticate, user_data);
}