1
0
mirror of https://github.com/falk-werner/webfused synced 2026-03-02 04:09:19 +00:00

added skeleton of config

This commit is contained in:
Falk Werner
2020-03-08 16:14:55 +01:00
parent d304c843bc
commit b5943bd7b6
7 changed files with 367 additions and 7 deletions

View File

@@ -0,0 +1,96 @@
#include "webfused/config/config.h"
#include "webfused/config/config_intern.h"
#include <stdlib.h>
#include <string.h>
#define WFD_CONFIG_DEFAULT_PORT (8080)
#define WFD_CONFIG_DEFAULT_VHOSTNAME ("localhost")
extern struct wfd_config *
wfd_config_create(void)
{
struct wfd_config * config = malloc(sizeof(struct wfd_config));
config->port = WFD_CONFIG_DEFAULT_PORT;
config->vhost_name = strdup(WFD_CONFIG_DEFAULT_VHOSTNAME);
config->server_key = NULL;
config->server_cert = NULL;
config->server_doc_root = NULL;
return config;
}
void wfd_config_dispose(
struct wfd_config * config)
{
free(config->vhost_name);
free(config->server_cert);
free(config->server_key);
free(config->server_doc_root);
free(config);
}
int
wfd_config_get_server_port(
struct wfd_config * config)
{
return config->port;
}
char const *
wfd_config_get_server_vhostname(
struct wfd_config * config)
{
return config->vhost_name;
}
char const *
wfd_config_get_server_cert(
struct wfd_config * config)
{
return config->server_cert;
}
char const *
wfd_config_get_server_key(
struct wfd_config * config)
{
return config->server_key;
}
char const *
wfd_config_get_server_document_root(
struct wfd_config * config)
{
return config->server_doc_root;
}
char const *
wfd_config_get_auth_provider(
struct wfd_config * config)
{
return NULL;
}
struct wfd_auth_settings *
wfd_config_get_auth_settings(
struct wfd_config * config)
{
return NULL;
}
size_t
wfd_config_get_filesystem_count(
struct wfd_config * config)
{
return 0;
}
struct wfd_filesystem_info *
wfd_confi_get_filesystem(
struct wfd_config * config,
size_t fs_index)
{
return NULL;
}

View File

@@ -0,0 +1,64 @@
#ifndef WFD_CONFIG_H
#define WFD_CONFIG_H
#ifndef __cplusplus
#include <stddef.h>
#else
#include <cstddef>
#endif
#ifdef __cplusplus
extern "C"
{
#endif
struct wfd_config;
struct wfd_auth_settins;
struct wfd_filesystem_info;
extern void wfd_config_dispose(
struct wfd_config * config);
extern int
wfd_config_get_server_port(
struct wfd_config * config);
extern char const *
wfd_config_get_server_vhostname(
struct wfd_config * config);
extern char const *
wfd_config_get_server_cert(
struct wfd_config * config);
extern char const *
wfd_config_get_server_key(
struct wfd_config * config);
extern char const *
wfd_config_get_server_document_root(
struct wfd_config * config);
extern char const *
wfd_config_get_auth_provider(
struct wfd_config * config);
extern struct wfd_auth_settings *
wfd_config_get_auth_settings(
struct wfd_config * config);
extern size_t
wfd_config_get_filesystem_count(
struct wfd_config * config);
extern struct wfd_filesystem_info *
wfd_confi_get_filesystem(
struct wfd_config * config,
size_t fs_index);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,25 @@
#ifndef WFD_CONFIG_INTERN_H
#define WFD_CONFIG_INTERN_H
#ifdef _cplusplus
extern "C"
{
#endif
struct wfd_config
{
char * vhost_name;
char * server_cert;
char * server_key;
char * server_doc_root;
int port;
};
extern struct wfd_config *
wfd_config_create(void);
#ifdef _cplusplus
}
#endif
#endif

View File

@@ -0,0 +1,106 @@
#include "webfused/config/factory.h"
#include "webfused/config/config_intern.h"
#include "webfused/config/config.h"
#include <libconfig.h>
#include <stdlib.h>
#include <stdbool.h>
#if ((LIBCONFIG_VER_MAJOR != 1) || (LIBCONFIG_VER_MINOR < 5))
#error "linconfig 1.5 or higher needed"
#endif
#define WFD_CONFIG_VERSION_MAJOR 1
#define WFD_CONFIG_VERSION_MINOR 0
static bool
wfd_config_check_version(
config_t * config)
{
int version_major;
int rc = config_lookup_int(config, "version.major", &version_major);
if (CONFIG_TRUE != rc)
{
// error: missing major version
return false;
}
if (WFD_CONFIG_VERSION_MAJOR != version_major)
{
// error: incompatible version, expected WFD_CONFIG_VERSION_MAJOR
return false;
}
int version_minor;
rc = config_lookup_int(config, "version.minor", &version_minor);
if (CONFIG_TRUE != rc)
{
// error: missing minor version
return false;
}
if (WFD_CONFIG_VERSION_MINOR < version_minor)
{
// warn: some features might be disabled
}
else if (WFD_CONFIG_VERSION_MINOR > version_minor)
{
// info: use default values
}
return true;
}
static struct wfd_config *
wfd_config_load(config_t * config)
{
struct wfd_config * result = wfd_config_create();
bool success = wfd_config_check_version(config);
if (!success)
{
wfd_config_dispose(result);
result = NULL;
}
return result;
}
struct wfd_config *
wfd_config_load_file(
char const * filename)
{
struct wfd_config * result = NULL;
config_t config;
config_init(&config);
int rc = config_read_file(&config, filename);
if (CONFIG_TRUE == rc)
{
result = wfd_config_load(&config);
config_destroy(&config);
}
return result;
}
struct wfd_config *
wfd_config_load_string(
char const * contents)
{
struct wfd_config * result = NULL;
config_t config;
config_init(&config);
int rc = config_read_string(&config, contents);
if (CONFIG_TRUE == rc)
{
result = wfd_config_load(&config);
config_destroy(&config);
}
return result;
}

View File

@@ -0,0 +1,21 @@
#ifndef WFD_CONFIG_FACTORY_H
#define WFD_CONFIG_FACTORY_H
#ifdef __cplusplus
extern "C"
{
#endif
extern struct wfd_config *
wfd_config_load_file(
char const * filename);
extern struct wfd_config *
wfd_config_load_string(
char const * contents);
#ifdef __cplusplus
}
#endif
#endif