mirror of
https://github.com/falk-werner/webfused
synced 2026-03-02 04:09:19 +00:00
read server config
This commit is contained in:
@@ -7,6 +7,15 @@
|
||||
#define WFD_CONFIG_DEFAULT_PORT (8080)
|
||||
#define WFD_CONFIG_DEFAULT_VHOSTNAME ("localhost")
|
||||
|
||||
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)
|
||||
{
|
||||
@@ -28,7 +37,6 @@ void wfd_config_dispose(
|
||||
free(config->server_key);
|
||||
free(config->server_doc_root);
|
||||
free(config);
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
@@ -38,6 +46,14 @@ wfd_config_get_server_port(
|
||||
return config->port;
|
||||
}
|
||||
|
||||
void
|
||||
wfd_config_set_server_port(
|
||||
struct wfd_config * config,
|
||||
int port)
|
||||
{
|
||||
config->port = port;
|
||||
}
|
||||
|
||||
char const *
|
||||
wfd_config_get_server_vhostname(
|
||||
struct wfd_config * config)
|
||||
@@ -45,6 +61,23 @@ wfd_config_get_server_vhostname(
|
||||
return config->vhost_name;
|
||||
}
|
||||
|
||||
void
|
||||
wfd_config_set_server_vhostname(
|
||||
struct wfd_config * config,
|
||||
char const * vhost_name)
|
||||
{
|
||||
free(config->vhost_name);
|
||||
config->vhost_name = strdup(vhost_name);
|
||||
}
|
||||
|
||||
bool
|
||||
wfd_config_is_server_tls_enabled(
|
||||
struct wfd_config * config)
|
||||
{
|
||||
return ((NULL != config->server_key)
|
||||
&& (NULL != config->server_cert));
|
||||
}
|
||||
|
||||
char const *
|
||||
wfd_config_get_server_cert(
|
||||
struct wfd_config * config)
|
||||
@@ -52,6 +85,15 @@ wfd_config_get_server_cert(
|
||||
return config->server_cert;
|
||||
}
|
||||
|
||||
void
|
||||
wfd_config_set_server_cert(
|
||||
struct wfd_config * config,
|
||||
char const * cert)
|
||||
{
|
||||
free(config->server_cert);
|
||||
config->server_cert = strdup(cert);
|
||||
}
|
||||
|
||||
char const *
|
||||
wfd_config_get_server_key(
|
||||
struct wfd_config * config)
|
||||
@@ -59,6 +101,15 @@ wfd_config_get_server_key(
|
||||
return config->server_key;
|
||||
}
|
||||
|
||||
void
|
||||
wfd_config_set_server_key(
|
||||
struct wfd_config * config,
|
||||
char const * key)
|
||||
{
|
||||
free(config->server_key);
|
||||
config->server_key = strdup(key);
|
||||
}
|
||||
|
||||
char const *
|
||||
wfd_config_get_server_document_root(
|
||||
struct wfd_config * config)
|
||||
@@ -66,6 +117,15 @@ wfd_config_get_server_document_root(
|
||||
return config->server_doc_root;
|
||||
}
|
||||
|
||||
void
|
||||
wfd_config_set_server_document_root(
|
||||
struct wfd_config * config,
|
||||
char const * document_root)
|
||||
{
|
||||
free(config->server_doc_root);
|
||||
config->server_doc_root = strdup(document_root);
|
||||
}
|
||||
|
||||
char const *
|
||||
wfd_config_get_auth_provider(
|
||||
struct wfd_config * config)
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define WFD_CONFIG_H
|
||||
|
||||
#ifndef __cplusplus
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#else
|
||||
#include <cstddef>
|
||||
@@ -31,6 +32,10 @@ extern char const *
|
||||
wfd_config_get_server_cert(
|
||||
struct wfd_config * config);
|
||||
|
||||
extern bool
|
||||
wfd_config_is_server_tls_enabled(
|
||||
struct wfd_config * config);
|
||||
|
||||
extern char const *
|
||||
wfd_config_get_server_key(
|
||||
struct wfd_config * config);
|
||||
|
||||
@@ -6,18 +6,34 @@ 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);
|
||||
|
||||
extern void
|
||||
wfd_config_set_server_vhostname(
|
||||
struct wfd_config * config,
|
||||
char const * vhost_name);
|
||||
|
||||
extern void
|
||||
wfd_config_set_server_port(
|
||||
struct wfd_config * config,
|
||||
int port);
|
||||
|
||||
extern void
|
||||
wfd_config_set_server_cert(
|
||||
struct wfd_config * config,
|
||||
char const * cert);
|
||||
|
||||
extern void
|
||||
wfd_config_set_server_key(
|
||||
struct wfd_config * config,
|
||||
char const * key);
|
||||
|
||||
extern void
|
||||
wfd_config_set_server_document_root(
|
||||
struct wfd_config * config,
|
||||
char const * document_root);
|
||||
|
||||
#ifdef _cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -56,12 +56,57 @@ wfd_config_check_version(
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool
|
||||
wfd_config_read_server(
|
||||
config_t * config,
|
||||
struct wfd_config * result)
|
||||
{
|
||||
char const * vhost_name;
|
||||
int rc = config_lookup_string(config, "server.vhost_name", &vhost_name);
|
||||
if (CONFIG_TRUE == rc)
|
||||
{
|
||||
wfd_config_set_server_vhostname(result, vhost_name);
|
||||
}
|
||||
|
||||
int port;
|
||||
rc = config_lookup_int(config, "server.port", &port);
|
||||
if (CONFIG_TRUE == rc)
|
||||
{
|
||||
wfd_config_set_server_port(result, port);
|
||||
}
|
||||
|
||||
char const * cert;
|
||||
rc = config_lookup_string(config, "server.tls.certificate", &cert);
|
||||
if (CONFIG_TRUE == rc)
|
||||
{
|
||||
wfd_config_set_server_cert(result, cert);
|
||||
}
|
||||
|
||||
char const * key;
|
||||
rc = config_lookup_string(config, "server.tls.key", &key);
|
||||
if (CONFIG_TRUE == rc)
|
||||
{
|
||||
wfd_config_set_server_key(result, key);
|
||||
}
|
||||
|
||||
char const * doc_root;
|
||||
rc = config_lookup_string(config, "server.document_root", &doc_root);
|
||||
if (CONFIG_TRUE == rc)
|
||||
{
|
||||
wfd_config_set_server_document_root(result, doc_root);
|
||||
}
|
||||
|
||||
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);
|
||||
bool success = wfd_config_check_version(config)
|
||||
&& wfd_config_read_server(config, result)
|
||||
;
|
||||
|
||||
if (!success)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user