|
Csilk 0.2.1
A lightweight, high-performance C HTTP web framework
|
YAML configuration loader and validator implementation. More...
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <yaml.h>#include "csilk/csilk.h"
Functions | |
| static csilk_log_level_t | string_to_log_level (const char *s) |
| Convert a case-insensitive log level string to its enum value. | |
| int | csilk_load_config (const char *yaml_path, csilk_config_t *config) |
| Load and parse server configuration from a YAML file. | |
| void | csilk_config_free (csilk_config_t *config) |
| Free all dynamically allocated strings within a configuration. | |
| int | csilk_config_validate (const csilk_config_t *config, const char **error_msg) |
| Validate configuration values for semantic correctness. | |
YAML configuration loader and validator implementation.
Parses a YAML configuration file (using libyaml) into a csilk_config_t struct. The parser is a simple state machine that tracks the current YAML section and key, then populates the corresponding config field.
Supported sections: port (top-level), server, logger, cors, rate_limit, static_files, middleware, ai, cipher.
The companion csilk_config_validate() checks semantic correctness (port range, non-negative timeouts, required sub-fields for enabled features). csilk_config_free() releases all dynamically allocated strings.
| void csilk_config_free | ( | csilk_config_t * | config | ) |
Free all dynamically allocated strings within a configuration.
Free all heap-allocated strings inside a configuration.
Releases memory for logger.file_path, cors allow_origin/methods/headers, static_files root_dir/prefix, and middleware.auth_token. Each pointer is set to NULL after being freed, making repeated calls safe.
| config | Configuration structure whose strings will be freed. |
| int csilk_config_validate | ( | const csilk_config_t * | config, |
| const char ** | error_msg | ||
| ) |
Validate configuration values for semantic correctness.
Checks that port is in range [1, 65535], timeouts are non-negative, max_body_size and max_header_size are positive, listen_backlog and worker_threads are >= 1, and that optional features (rate_limit, static_files, auth middleware) have their required sub-fields set when enabled. Returns the first validation error found.
| config | Configuration to validate. |
| error_msg | [out] Optional pointer to receive a human-readable error string. The error string is a static literal; do not free it. |
| int csilk_load_config | ( | const char * | yaml_path, |
| csilk_config_t * | config | ||
| ) |
Load and parse server configuration from a YAML file.
Load and parse a YAML configuration file.
Opens the specified YAML file, parses its contents, and populates the provided csilk_config_t structure. The parser recognizes top-level keys ("port") and section keys ("server", "logger", "cors", "rate_limit", "static_files", "middleware"). All fields not present in the YAML retain their default values (initialized at the start of this function).
| yaml_path | Absolute or relative path to the YAML configuration file. |
| config | [out] Pre-allocated config structure to populate. |
|
static |
Convert a case-insensitive log level string to its enum value.
Matches the input string against known level names ("TRACE", "DEBUG", "INFO", "WARN", "ERROR", "FATAL"). Comparison is case-insensitive.
| s | Log level string (e.g., "DEBUG", "debug", "Debug"). |