From 462fd7473bf97507c8e9e414cb904606f6807440 Mon Sep 17 00:00:00 2001 From: Francesco Date: Fri, 16 Jan 2026 03:33:55 +0100 Subject: [PATCH] refactor(config): drop ssl support --- config.yaml | 16 ++++++---------- include/config/config.h | 3 --- src/config/config.c | 28 ++++++++++++++++++++-------- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/config.yaml b/config.yaml index 60ae34d..a65ad58 100644 --- a/config.yaml +++ b/config.yaml @@ -1,21 +1,17 @@ +# Default hostname hostname: localhost + +# Running port port: 3030 +# Virtual hosts setup virtual_hosts: - domain: localhost + # Root folder root: www - ssl: false + # Custom pages error_pages: - method: 404 path: pages/404.html - method: 500 path: pages/500.html - - - domain: test.local - root: www - ssl: true - cert: cert.pem - key: key.pem - error_pages: - - method: 404 - path: pages/404.html diff --git a/include/config/config.h b/include/config/config.h index c7938da..df277f9 100644 --- a/include/config/config.h +++ b/include/config/config.h @@ -11,9 +11,6 @@ typedef struct cws_error_page { typedef struct cws_vhost { char *domain; char *root; - bool ssl; - char *cert; - char *key; cws_error_page *error_pages; unsigned error_pages_count; } cws_vhost_s; diff --git a/src/config/config.c b/src/config/config.c index d05d181..634a65d 100644 --- a/src/config/config.c +++ b/src/config/config.c @@ -1,7 +1,7 @@ #include "config/config.h" #include -#include +#include #include "utils/debug.h" @@ -24,14 +24,8 @@ static cyaml_schema_value_t error_page_schema = { static const cyaml_schema_field_t virtual_hosts_fields[] = { CYAML_FIELD_STRING_PTR("domain", CYAML_FLAG_POINTER, struct cws_vhost, domain, 0, CYAML_UNLIMITED), CYAML_FIELD_STRING_PTR("root", CYAML_FLAG_POINTER, struct cws_vhost, root, 0, CYAML_UNLIMITED), - CYAML_FIELD_BOOL("ssl", CYAML_FLAG_DEFAULT, struct cws_vhost, ssl), - CYAML_FIELD_STRING_PTR("cert", CYAML_FLAG_POINTER | CYAML_FLAG_OPTIONAL, struct cws_vhost, cert, 0, - CYAML_UNLIMITED), - CYAML_FIELD_STRING_PTR("key", CYAML_FLAG_POINTER | CYAML_FLAG_OPTIONAL, struct cws_vhost, key, 0, CYAML_UNLIMITED), - CYAML_FIELD_SEQUENCE("error_pages", CYAML_FLAG_POINTER | CYAML_FLAG_OPTIONAL, struct cws_vhost, error_pages, &error_page_schema, 0, CYAML_UNLIMITED), - CYAML_FIELD_END, }; @@ -51,8 +45,18 @@ static cyaml_schema_value_t top_schema = { CYAML_VALUE_MAPPING(CYAML_FLAG_POINTER, struct cws_config, top_schema_fields), }; +static bool find_default_hostname(cws_config_s *config) { + for (unsigned i = 0; i < config->virtual_hosts_count; ++i) { + if (strcmp(config->hostname, config->virtual_hosts[i].domain) == 0) { + return true; + } + } + + return false; +} + cws_config_s *cws_config_init(void) { - char *path = "config.yaml"; + const char *path = "config.yaml"; cws_config_s *config; cyaml_err_t err = cyaml_load_file(path, &cyaml_config, &top_schema, (cyaml_data_t **)&config, NULL); @@ -62,6 +66,14 @@ cws_config_s *cws_config_init(void) { return NULL; } + bool found = find_default_hostname(config); + if (!found) { + cws_log_error("Default hostname not found in config.yaml"); + cws_config_free(config); + + return NULL; + } + return config; }