ascii-chat
Binary v0.16.50-198-g78f51665f
Library lib/v0.3.2-2240-g78f51665f
Video chat in your terminal
Loading...
Searching...
No Matches
validation.c File Reference

Go to the source code of this file.

Functions

asciichat_error_t validate_glyph_palette (const options_t *opts)
int validate_opt_port (const char *value_str, char *error_msg, size_t error_msg_size)
 Validate port number (1-65535).
bool validate_port_callback (const void *options_struct)
int validate_opt_positive_int (const char *value_str, char *error_msg, size_t error_msg_size)
 Validate positive integer.
int validate_opt_non_negative_int (const char *value_str, char *error_msg, size_t error_msg_size)
 Validate non-negative integer.
int validate_opt_color_mode (const char *value_str, char *error_msg, size_t error_msg_size)
 Validate color mode string.
int validate_opt_render_mode (const char *value_str, char *error_msg, size_t error_msg_size)
 Validate render mode string.
int validate_opt_palette (const char *value_str, char *error_msg, size_t error_msg_size)
 Validate palette type string.
int validate_opt_log_level (const char *value_str, char *error_msg, size_t error_msg_size)
 Validate log level string.
int validate_opt_ip_address (const char *value_str, char *parsed_address, size_t address_size, bool is_client, char *error_msg, size_t error_msg_size)
 Validate IP address or hostname.
float validate_opt_float_non_negative (const char *value_str, char *error_msg, size_t error_msg_size)
 Validate non-negative float value.
float validate_opt_volume (const char *value_str, char *error_msg, size_t error_msg_size)
 Validate volume value (0.0-1.0).
int validate_opt_max_clients (const char *value_str, char *error_msg, size_t error_msg_size)
 Validate max clients value (1-128).
int validate_opt_compression_level (const char *value_str, char *error_msg, size_t error_msg_size)
 Validate compression level (1-9).
int validate_opt_fps (const char *value_str, char *error_msg, size_t error_msg_size)
 Validate FPS value (0 for auto, otherwise 1-144).
int validate_opt_reconnect (const char *value_str, char *error_msg, size_t error_msg_size)
 Validate reconnect value.
int validate_opt_device_index (const char *value_str, char *error_msg, size_t error_msg_size)
 Validate device index (-1 for default, 0+ for specific device).
int validate_opt_password (const char *value_str, char *error_msg, size_t error_msg_size)
 Validate password (8-256 characters).
int options_collect_identity_keys (options_t *opts, int argc, char *argv[])
 Collect multiple –key flags into identity_keys array.
bool is_remote_key_path (const char *key_path)
 Check if a key path is a remote/virtual key (not a local file).

Function Documentation

◆ validate_port_callback()

bool validate_port_callback ( const void * options_struct)

Validate port option callback (matches option_descriptor validate signature) Used during options parsing to validate port values with PCRE2

Definition at line 108 of file validation.c.

108 {
109 const options_t *opts = (const options_t *)options_struct;
110
111 // Port is stored as an int, but we need to validate it as a string
112 // The issue is that strtol() already accepted invalid formats like " 80", "+80", "0123"
113 // So we can't validate after parsing - we need to prevent the parse in the first place
114 // This callback runs AFTER parsing, so it's too late
115
116 // Instead, check if the port value is in range (this will catch the range but not format issues)
117 if (opts->port < 1 || opts->port > 65535) {
118 SET_ERRNO(ERROR_USAGE, "Port must be between 1 and 65535");
119 return false;
120 }
121
122 return true;
123}
#define SET_ERRNO(code,...)
@ ERROR_USAGE
Definition error_codes.h:52
struct options_state options_t
Immutable, RCU-published snapshot of the application's runtime configuration.
int port
Server port number.
Definition options.h:1004

References ERROR_USAGE, options_state::port, and SET_ERRNO.