|
ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
|
The toml text file configuration file module. More...
Files | |
| file | config.c |
| 📋 TOML configuration file parser with schema validation and CLI override support | |
| file | config.h |
| TOML configuration file support for ascii-chat. | |
Functions | |
| asciichat_error_t | config_load_and_apply (bool is_client, const char *config_path, bool strict, options_t *opts) |
| Main function to load configuration from file and apply to global options. | |
| asciichat_error_t | config_create_default (const char *config_path, const options_t *opts) |
| Create default configuration file with all default values. | |
| asciichat_error_t | config_load_system_and_user (bool is_client, const char *user_config_path, bool strict, options_t *opts) |
| Load system config first, then user config (user config overrides system) | |
The toml text file configuration file module.
This module provides functionality for loading configuration from TOML files (typically located at ~/.ascii-chat/config.toml). Configuration values are applied to global options, but command-line arguments always take precedence over config file values.
The interface provides:
$XDG_CONFIG_HOME/ascii-chat/config.toml if set, otherwise ~/.ascii-chat/config.tomlAPPDATA%\ascii-chat\config.toml if set, otherwise ~\.ascii-chat\config.tomlcrypto.password), this is strongly discouraged for security reasons. A warning is printed if a password is found in the config file. Use CLI --password or environment variables instead.ascii-chat supports two configuration methods:
Command-line arguments override configuration file settings, allowing:
~/.config/ascii-chat/config.tomlascii-chat uses TOML (Tom's Obvious, Minimal Language) for configuration files, parsed by the tomlc17 library.
Complete example configuration:
Load Config File:
Apply Defaults:
Server-specific flags:
[address1] [address2] (positional): Bind addresses, 0-2 IPv4/IPv6 addresses (default: 127.0.0.1 and ::1)--port, -p PORT: Listen port (default: 27224)--key KEY_FILE: Server identity key (SSH Ed25519)--client-keys KEYS: Comma-separated authorized client keys--max-clients N: Maximum simultaneous clients (1-9, default: 9)Client-specific flags:
[address][:port] (positional): Server address with optional port (default: localhost:27224)--port, -p PORT: Server port (default: 27224) - conflicts with port in positional argument--width, -w WIDTH: Terminal width (default: auto-detect)--height, -h HEIGHT: Terminal height (default: auto-detect)--color, -c: Enable color output--half-blocks: Use half-block characters (2x vertical resolution)--palette, -P PALETTE: ASCII palette type (standard, blocks, digital, minimal, cool, custom)--palette-chars, -C CHARS: Custom palette characters string--audio, -A: Enable audio capture/playback--server-key KEY: Expected server public key (TOFU)--key KEY_FILE: Client identity key--snapshot: Snapshot mode (capture once and exit)--snapshot-delay SECONDS: Snapshot duration before exitAvailable for both server and client:
--config FILE: Configuration file pathAll ascii-chat data files (config.toml, known_hosts) are stored in a single directory:
Linux/macOS:
$XDG_CONFIG_HOME/ascii-chat/ (if XDG_CONFIG_HOME is set)~/.ascii-chat/ (default when XDG_CONFIG_HOME is not set)Windows:
APPDATA%\ascii-chat\ (if APPDATA is set)~\.ascii-chat\ (default when APPDATA is not set)Creating a Default Config:
Using a Config File:
Overriding Config with CLI:
Settings are applied in this order (later overrides earlier):
Example:
The configuration system automatically validates all settings:
Automatic Validation:
Error Reporting:
Example validation code:
| asciichat_error_t config_create_default | ( | const char * | config_path, |
| const options_t * | opts | ||
| ) |
#include <config.c>
Create default configuration file with all default values.
| config_path | Path to config file to create (NULL uses default location) |
| opts | Options structure with values to write (use defaults for a "default" config) |
Creates a new configuration file at the specified path (or default location if config_path is NULL) with all configuration options set to values from opts.
The created file includes:
Definition at line 999 of file config.c.
References options_state::address, ASCIICHAT_OK, options_state::audio_enabled, options_state::client_keys, defer, DIR_PERM_PRIVATE, options_state::encrypt_enabled, options_state::encrypt_key, options_state::encrypt_keyfile, errno, ERROR_CONFIG, ERROR_MEMORY, expand_path(), options_state::force_utf8, get_config_dir(), options_state::height, options_state::log_file, log_plain_stderr, options_state::microphone_index, options_state::no_encrypt, options_state::password, PATH_DELIM, PATH_ROLE_CONFIG_FILE, path_validate_user_path(), platform_fopen(), platform_prompt_yes_no(), platform_strdup(), options_state::port, options_state::quiet, SAFE_FCLOSE, SAFE_FREE, SAFE_MALLOC, safe_snprintf(), options_state::server_key, SET_ERRNO, SET_ERRNO_SYS, options_state::show_capabilities, options_state::snapshot_delay, options_state::snapshot_mode, options_state::speakers_index, options_state::stretch, options_state::test_pattern, options_state::webcam_flip, options_state::webcam_index, and options_state::width.
Referenced by options_init().
| asciichat_error_t config_load_and_apply | ( | bool | is_client, |
| const char * | config_path, | ||
| bool | strict, | ||
| options_t * | opts | ||
| ) |
#include <config.c>
Main function to load configuration from file and apply to global options.
Load configuration from TOML file and apply to global options.
| is_client | true if loading client configuration, false for server configuration |
| config_path | Optional path to config file (NULL uses default location) |
| strict | If true, errors are fatal; if false, errors are non-fatal warnings |
This is the main entry point for configuration loading. It:
Configuration file errors are non-fatal if strict is false:
If strict is true, any error causes immediate return with error code.
options_init() parses command-line arguments to ensure CLI arguments can override config file values.| is_client | true if loading client configuration, false for server configuration |
| config_path | Optional path to config file (NULL uses default location) |
| strict | If true, errors are fatal; if false, errors are non-fatal warnings |
Loads configuration from the specified path (or default location if config_path is NULL) and applies values to global options.
Default config file location (when config_path is NULL):
Only applies configuration values that haven't already been set (though in practice, CLI arguments will override config values anyway since this is called before CLI parsing).
Supported configuration sections:
[network]: port[server]: bind_ipv4, bind_ipv6[client]: address, width, height, webcam_index, webcam_flip, color_mode, render_mode, fps, stretch, quiet, snapshot_mode, snapshot_delay, test_pattern, show_capabilities, force_utf8[audio]: enabled, device[palette]: type, chars[crypto]: encrypt_enabled, key, password, keyfile, no_encrypt, server_key (client only), client_keys (server only)[logging] or root: log_fileoptions_init() parses command-line arguments, so that CLI arguments can override config file values.Definition at line 842 of file config.c.
References ASCIICHAT_OK, CONFIG_DEBUG, CONFIG_WARN, defer, ERROR_CONFIG, expand_path(), get_config_dir(), PATH_ROLE_CONFIG_FILE, path_validate_user_path(), platform_strdup(), SAFE_FREE, SAFE_MALLOC, safe_snprintf(), and SET_ERRNO.
Referenced by config_load_system_and_user().
| asciichat_error_t config_load_system_and_user | ( | bool | is_client, |
| const char * | user_config_path, | ||
| bool | strict, | ||
| options_t * | opts | ||
| ) |
#include <config.h>
Load system config first, then user config (user config overrides system)
| is_client | true if loading client configuration, false for server configuration |
| user_config_path | Optional path to user config file (NULL uses default location) |
| strict | If true, user config errors are fatal; system config is always non-strict |
| opts | Options structure to write configuration to |
Loads configuration from two locations in order:
User config values override system config values. Both override defaults. This function should be called before options_init() parses command-line arguments.
Definition at line 1207 of file config.c.
References ASCIICHAT_INSTALL_PREFIX, ASCIICHAT_OK, CLEAR_ERRNO, CONFIG_DEBUG, config_load_and_apply(), and SAFE_SNPRINTF.
Referenced by options_init().