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
Go to the documentation of this file.
1
6
9
10#include <limits.h>
11#include <math.h>
12#include <stdlib.h>
13#include <string.h>
14#include <sys/stat.h>
15
16#include <ascii-chat/common.h>
17#include <ascii-chat/log/log.h>
18#include <libplatform/terminal.h>
19#include <ascii-chat/util/ip.h>
24
26 if (!opts)
27 return SET_ERRNO(ERROR_INVALID_PARAM, "Missing options for glyph palette validation");
28 if (opts->renderer != ASCII_RENDERER_GLYPH || !opts->palette_explicit)
29 return ASCIICHAT_OK;
30 const palette_def_t *builtin = get_builtin_palette(opts->palette_type);
31 const char *palette = opts->palette_type == PALETTE_CUSTOM ? opts->palette_custom : builtin ? builtin->chars : NULL;
33 return SET_ERRNO(ERROR_INVALID_PARAM, "Glyph palette contains characters without glyph masks");
34 return ASCIICHAT_OK;
35}
36
37// ============================================================================
38// Generic Integer Range Validator
39// ============================================================================
40
55static int validate_int_range(const char *value_str, int min, int max, const char *param_name, char *error_msg, size_t error_msg_size) {
56 if (!value_str || strlen(value_str) == 0) {
57 if (error_msg) {
58 SAFE_SNPRINTF(error_msg, error_msg_size, "%s value is required", param_name);
59 }
60 return INT_MIN;
61 }
62
63 int val = strtoint_safe(value_str);
64 if (val == INT_MIN || val < min || val > max) {
65 if (error_msg) {
66 if (min == max) {
67 SAFE_SNPRINTF(error_msg, error_msg_size, "Invalid %s '%s'. Must be exactly %d.", param_name, value_str, min);
68 } else if (min == 1 && max == INT_MAX) {
69 SAFE_SNPRINTF(error_msg, error_msg_size, "Invalid %s '%s'. Must be a positive integer.", param_name, value_str);
70 } else if (min == 0 && max == INT_MAX) {
71 SAFE_SNPRINTF(error_msg, error_msg_size, "Invalid %s '%s'. Must be a non-negative integer.", param_name, value_str);
72 } else {
73 SAFE_SNPRINTF(error_msg, error_msg_size, "Invalid %s '%s'. Must be between %d and %d.", param_name, value_str, min, max);
74 }
75 }
76 return INT_MIN;
77 }
78 return val;
79}
80
85int validate_opt_port(const char *value_str, char *error_msg, size_t error_msg_size) {
86 if (!value_str || strlen(value_str) == 0) {
87 if (error_msg) {
88 SAFE_SNPRINTF(error_msg, error_msg_size, "Port value is required");
89 }
90 return -1;
91 }
92
93 // Use safe integer parsing with range validation
94 uint16_t port_num;
95 if (parse_port(value_str, &port_num) != ASCIICHAT_OK) {
96 if (error_msg) {
97 SAFE_SNPRINTF(error_msg, error_msg_size, "Invalid port value '%s'. Port must be a number between 1 and 65535.", value_str);
98 }
99 return -1;
100 }
101 return 0;
102}
103
108bool validate_port_callback(const void *options_struct) {
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}
124
129int validate_opt_positive_int(const char *value_str, char *error_msg, size_t error_msg_size) {
130 int result = validate_int_range(value_str, 1, INT_MAX, "Value", error_msg, error_msg_size);
131 return (result == INT_MIN) ? -1 : result;
132}
133
138int validate_opt_non_negative_int(const char *value_str, char *error_msg, size_t error_msg_size) {
139 int result = validate_int_range(value_str, 0, INT_MAX, "Value", error_msg, error_msg_size);
140 return (result == INT_MIN) ? -1 : result;
141}
142
147int validate_opt_color_mode(const char *value_str, char *error_msg, size_t error_msg_size) {
148 if (!value_str) {
149 if (error_msg) {
150 SAFE_SNPRINTF(error_msg, error_msg_size, "Color mode value is required");
151 }
152 return -1;
153 }
154
155 if (strcmp(value_str, OPT_VALUE_AUTO) == 0) {
156 return COLOR_MODE_AUTO;
157 }
158 if (strcmp(value_str, OPT_COLOR_MODE_NONE) == 0 || strcmp(value_str, OPT_COLOR_MODE_MONO) == 0) {
159 return COLOR_MODE_NONE;
160 }
161 if (strcmp(value_str, OPT_COLOR_MODE_16) == 0 || strcmp(value_str, "16color") == 0) {
162 return COLOR_MODE_16_COLOR;
163 }
164 if (strcmp(value_str, OPT_COLOR_MODE_256) == 0 || strcmp(value_str, "256color") == 0) {
166 }
167 if (strcmp(value_str, OPT_COLOR_MODE_TRUECOLOR) == 0 || strcmp(value_str, "24bit") == 0) {
169 }
170 if (error_msg) {
171 SAFE_SNPRINTF(error_msg, error_msg_size, "Invalid color mode '%s'. Valid modes: auto, none, mono, 16, 256, truecolor", value_str);
172 }
173 return -1;
174}
175
180int validate_opt_render_mode(const char *value_str, char *error_msg, size_t error_msg_size) {
181 if (!value_str) {
182 if (error_msg) {
183 SAFE_SNPRINTF(error_msg, error_msg_size, "Render mode value is required");
184 }
185 return -1;
186 }
187
188 if (strcmp(value_str, OPT_RENDER_MODE_FOREGROUND) == 0 || strcmp(value_str, OPT_RENDER_MODE_FG) == 0) {
189 return RENDER_MODE_FOREGROUND;
190 }
191 if (strcmp(value_str, OPT_RENDER_MODE_BACKGROUND) == 0 || strcmp(value_str, OPT_RENDER_MODE_BG) == 0) {
192 return RENDER_MODE_BACKGROUND;
193 }
194 if (strcmp(value_str, OPT_RENDER_MODE_HALF_BLOCK) == 0 || strcmp(value_str, "halfblock") == 0) {
195 return RENDER_MODE_HALF_BLOCK;
196 }
197 if (error_msg) {
198 SAFE_SNPRINTF(error_msg, error_msg_size, "Invalid render mode '%s'. Valid modes: foreground, background, half-block", value_str);
199 }
200 return -1;
201}
202
207int validate_opt_palette(const char *value_str, char *error_msg, size_t error_msg_size) {
208 if (!value_str) {
209 if (error_msg) {
210 SAFE_SNPRINTF(error_msg, error_msg_size, "Palette value is required");
211 }
212 return -1;
213 }
214
215 if (strcmp(value_str, OPT_PALETTE_STANDARD) == 0) {
216 return PALETTE_STANDARD;
217 } else if (strcmp(value_str, OPT_PALETTE_BLOCKS) == 0) {
218 return PALETTE_BLOCKS;
219 } else if (strcmp(value_str, OPT_PALETTE_DIGITAL) == 0) {
220 return PALETTE_DIGITAL;
221 } else if (strcmp(value_str, OPT_PALETTE_MINIMAL) == 0) {
222 return PALETTE_MINIMAL;
223 } else if (strcmp(value_str, OPT_PALETTE_COOL) == 0) {
224 return PALETTE_COOL;
225 } else if (strcmp(value_str, OPT_PALETTE_CUSTOM) == 0) {
226 return PALETTE_CUSTOM;
227 } else {
228 if (error_msg) {
229 SAFE_SNPRINTF(error_msg, error_msg_size, "Invalid palette '%s'. Valid palettes: standard, blocks, digital, minimal, cool, custom", value_str);
230 }
231 return -1;
232 }
233}
234
239int validate_opt_log_level(const char *value_str, char *error_msg, size_t error_msg_size) {
240 if (!value_str) {
241 if (error_msg) {
242 SAFE_SNPRINTF(error_msg, error_msg_size, "Log level value is required");
243 }
244 return -1;
245 }
246
247 if (platform_strcasecmp(value_str, OPT_LOG_LEVEL_DEV) == 0) {
248 return LOG_DEV;
249 } else if (platform_strcasecmp(value_str, OPT_LOG_LEVEL_DEBUG) == 0) {
250 return LOG_DEBUG;
251 } else if (platform_strcasecmp(value_str, OPT_LOG_LEVEL_INFO) == 0) {
252 return LOG_INFO;
253 } else if (platform_strcasecmp(value_str, OPT_LOG_LEVEL_WARN) == 0) {
254 return LOG_WARN;
255 } else if (platform_strcasecmp(value_str, OPT_LOG_LEVEL_ERROR) == 0) {
256 return LOG_ERROR;
257 } else if (platform_strcasecmp(value_str, OPT_LOG_LEVEL_FATAL) == 0) {
258 return LOG_FATAL;
259 } else {
260 if (error_msg) {
261 SAFE_SNPRINTF(error_msg, error_msg_size, "Invalid log level '%s'. Valid levels: dev, debug, info, warn, error, fatal", value_str);
262 }
263 return -1;
264 }
265}
266
272int 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) {
273 (void)is_client; // Parameter not used but kept for API consistency
274 if (!value_str || strlen(value_str) == 0) {
275 if (error_msg) {
276 SAFE_SNPRINTF(error_msg, error_msg_size, "Address value is required");
277 }
278 return -1;
279 }
280
281 // Parse IPv6 address (remove brackets if present)
282 char parsed_addr[OPTIONS_BUFF_SIZE];
283 if (parse_ipv6_address(value_str, parsed_addr, sizeof(parsed_addr)) == 0) {
284 value_str = parsed_addr;
285 }
286
287 // Check if it's a valid IPv4 address
288 if (is_valid_ipv4(value_str)) {
289 SAFE_SNPRINTF(parsed_address, address_size, "%s", value_str);
290 return 0;
291 }
292 // Check if it's a valid IPv6 address
293 if (is_valid_ipv6(value_str)) {
294 SAFE_SNPRINTF(parsed_address, address_size, "%s", value_str);
295 return 0;
296 }
297 // Check if it looks like an invalid IP (has dots but not valid IPv4 format)
298 if (strchr(value_str, '.') != NULL) {
299 if (error_msg) {
300 SAFE_SNPRINTF(error_msg, error_msg_size, "Invalid IP address format '%s'. IPv4 addresses must have exactly 4 octets.", value_str);
301 }
302 return -1;
303 }
304
305 // Otherwise, try to resolve as hostname
306 char resolved_ip[OPTIONS_BUFF_SIZE];
307 if (platform_resolve_hostname_to_ipv4(value_str, resolved_ip, sizeof(resolved_ip)) == 0) {
308 SAFE_SNPRINTF(parsed_address, address_size, "%s", resolved_ip);
309 return 0;
310 } else {
311 if (error_msg) {
312 SAFE_SNPRINTF(error_msg, error_msg_size, "Failed to resolve hostname '%s' to IP address.", value_str);
313 }
314 return -1;
315 }
316}
317
322float validate_opt_float_non_negative(const char *value_str, char *error_msg, size_t error_msg_size) {
323 if (!value_str || strlen(value_str) == 0) {
324 if (error_msg) {
325 SAFE_SNPRINTF(error_msg, error_msg_size, "Value is required");
326 }
327 return -1.0f;
328 }
329
330 char *endptr;
331 float val = strtof(value_str, &endptr);
332 if (*endptr != '\0' || value_str == endptr || !isfinite(val)) {
333 if (error_msg) {
334 SAFE_SNPRINTF(error_msg, error_msg_size, "Invalid float value '%s'. Must be a number.", value_str);
335 }
336 return -1.0f;
337 }
338 if (val < 0.0f) {
339 if (error_msg) {
340 SAFE_SNPRINTF(error_msg, error_msg_size, "Value must be non-negative (got %.2f)", val);
341 }
342 return -1.0f;
343 }
344 return val;
345}
346
351float validate_opt_volume(const char *value_str, char *error_msg, size_t error_msg_size) {
352 if (!value_str || strlen(value_str) == 0) {
353 if (error_msg) {
354 SAFE_SNPRINTF(error_msg, error_msg_size, "Volume value is required");
355 }
356 return -1.0f;
357 }
358
359 char *endptr;
360 float val = strtof(value_str, &endptr);
361 if (*endptr != '\0' || value_str == endptr || !isfinite(val)) {
362 if (error_msg) {
363 SAFE_SNPRINTF(error_msg, error_msg_size, "Invalid volume value '%s'. Must be a number.", value_str);
364 }
365 return -1.0f;
366 }
367 if (val < 0.0f || val > 1.0f) {
368 if (error_msg) {
369 SAFE_SNPRINTF(error_msg, error_msg_size, "Volume must be between 0.0 and 1.0 (got %.2f)", val);
370 }
371 return -1.0f;
372 }
373 return val;
374}
375
380int validate_opt_max_clients(const char *value_str, char *error_msg, size_t error_msg_size) {
381 int result = validate_int_range(value_str, 1, MAX_SESSION_PARTICIPANTS, "Max clients", error_msg, error_msg_size);
382 return (result == INT_MIN) ? -1 : result;
383}
384
389int validate_opt_compression_level(const char *value_str, char *error_msg, size_t error_msg_size) {
390 int result = validate_int_range(value_str, 1, 9, "Compression level", error_msg, error_msg_size);
391 return (result == INT_MIN) ? -1 : result;
392}
393
398int validate_opt_fps(const char *value_str, char *error_msg, size_t error_msg_size) {
399 int result = validate_int_range(value_str, 0, 144, "FPS", error_msg, error_msg_size);
400 return (result == INT_MIN) ? -1 : result;
401}
402
411int validate_opt_reconnect(const char *value_str, char *error_msg, size_t error_msg_size) {
412 if (!value_str || strlen(value_str) == 0) {
413 if (error_msg) {
414 SAFE_SNPRINTF(error_msg, error_msg_size, "Reconnect value is required");
415 }
416 return INT_MIN;
417 }
418
419 // Check for string values first
420 if (platform_strcasecmp(value_str, "off") == 0) {
421 return 0; // No retries
422 }
423 if (platform_strcasecmp(value_str, OPT_VALUE_AUTO) == 0) {
424 return -1; // Unlimited retries
425 }
426
427 // Parse as integer
428 int val = strtoint_safe(value_str);
429 if (val == INT_MIN) {
430 if (error_msg) {
431 SAFE_SNPRINTF(error_msg, error_msg_size, "Invalid reconnect value '%s'. Use 'off', 'auto', or a number 0-999.", value_str);
432 }
433 return INT_MIN;
434 }
435
436 // 0 means off, -1 means auto, 1-999 is valid range
437 if (val == 0) {
438 return 0; // No retries
439 }
440 if (val == -1) {
441 return -1; // Unlimited retries
442 }
443 if (val < 1 || val > 999) {
444 if (error_msg) {
445 SAFE_SNPRINTF(error_msg, error_msg_size, "Invalid reconnect count '%s'. Must be 'off', 'auto', or 1-999.", value_str);
446 }
447 return INT_MIN;
448 }
449 return val;
450}
451
456int validate_opt_device_index(const char *value_str, char *error_msg, size_t error_msg_size) {
457 if (!value_str || strlen(value_str) == 0) {
458 if (error_msg) {
459 SAFE_SNPRINTF(error_msg, error_msg_size, "Device index value is required");
460 }
461 return INT_MIN;
462 }
463
464 int index = strtoint_safe(value_str);
465 if (index == INT_MIN) {
466 if (error_msg) {
467 SAFE_SNPRINTF(error_msg, error_msg_size, "Invalid device index '%s'. Must be -1 (default) or a non-negative integer.", value_str);
468 }
469 return INT_MIN;
470 }
471
472 // -1 is valid (system default), otherwise must be >= 0
473 if (index < -1) {
474 if (error_msg) {
475 SAFE_SNPRINTF(error_msg, error_msg_size, "Invalid device index '%d'. Must be -1 (default) or a non-negative integer.", index);
476 }
477 return INT_MIN;
478 }
479 return index;
480}
481
486int validate_opt_password(const char *value_str, char *error_msg, size_t error_msg_size) {
487 if (!value_str) {
488 if (error_msg) {
489 SAFE_SNPRINTF(error_msg, error_msg_size, "Password value is required");
490 }
491 return -1;
492 }
493
494 size_t len = strlen(value_str);
495 if (len < 8) {
496 if (error_msg) {
497 SAFE_SNPRINTF(error_msg, error_msg_size, "Password too short (%zu chars). Must be at least 8 characters.", len);
498 }
499 return -1;
500 }
501 if (len > 256) {
502 if (error_msg) {
503 SAFE_SNPRINTF(error_msg, error_msg_size, "Password too long (%zu chars). Must be at most 256 characters.", len);
504 }
505 return -1;
506 }
507
508 // Note: No need to check for embedded null bytes - strlen() already stopped at the first null,
509 // so by definition there are no null bytes within [0, len).
510
511 return 0;
512}
513
525int options_collect_identity_keys(options_t *opts, int argc, char *argv[]) {
526 if (!opts || !argv) {
527 log_error("Invalid arguments");
528 return -1;
529 }
530
531 size_t key_count = 0;
532
533 // Scan argv for all --key or -K flags
534 for (int i = 1; i < argc; i++) {
535 const char *arg = argv[i];
536
537 // Check if this is a --key or -K flag
538 bool is_key_flag = false;
539 const char *key_value = NULL;
540
541 if (strcmp(arg, "--key") == 0 || strcmp(arg, "-K") == 0) {
542 // Next argument is the key path
543 if (i + 1 < argc) {
544 key_value = argv[i + 1];
545 is_key_flag = true;
546 i++; // Skip the value argument
547 }
548 } else if (strncmp(arg, "--key=", 6) == 0) {
549 // --key=value format
550 key_value = arg + 6;
551 is_key_flag = true;
552 }
553
554 if (is_key_flag && key_value && strlen(key_value) > 0) {
555 if (key_count >= MAX_SESSION_KEYS || strlen(key_value) >= sizeof(opts->identity_keys[0])) {
556 SET_ERRNO(ERROR_INVALID_PARAM, "Too many identity keys or key path exceeds storage capacity");
557 return -1;
558 }
559 // Validate that local key files exist (skip for remote/virtual keys)
560 if (!is_remote_key_path(key_value)) {
561 struct stat st;
562 if (stat(key_value, &st) != 0) {
563 log_error("Key file not found: %s", key_value);
564 SET_ERRNO(ERROR_CRYPTO_KEY, "Key file not found: %s", key_value);
565 return -1;
566 }
567 // Check if it's a regular file (S_IFREG) - works on both Windows and Unix
568 if ((st.st_mode & S_IFMT) != S_IFREG) {
569 log_error("Key path is not a regular file: %s", key_value);
570 SET_ERRNO(ERROR_CRYPTO_KEY, "Key path is not a regular file: %s", key_value);
571 return -1;
572 }
573 }
574
575 // Store in identity_keys array
576 SAFE_STRNCPY(opts->identity_keys[key_count], key_value, OPTIONS_BUFF_SIZE);
577
578 // First key also goes into encrypt_key for backward compatibility
579 if (key_count == 0) {
580 SAFE_STRNCPY(opts->encrypt_key, key_value, OPTIONS_BUFF_SIZE);
581 }
582
583 key_count++;
584 log_debug("Collected identity key #%zu: %s", key_count, key_value);
585 }
586 }
587
588 opts->num_identity_keys = key_count;
589
590 if (key_count > 0) {
591 log_info("Collected %zu identity key(s) for multi-key support", key_count);
592 }
593
594 return (int)key_count;
595}
596
597bool is_remote_key_path(const char *key_path) {
598 if (!key_path || key_path[0] == '\0') {
599 return false;
600 }
601 return (strncmp(key_path, "github:", 7) == 0 || strncmp(key_path, "gitlab:", 7) == 0 || strncmp(key_path, "gpg:", 4) == 0 || strncmp(key_path, "http://", 7) == 0 ||
602 strncmp(key_path, "https://", 8) == 0);
603}
#define SET_ERRNO(code,...)
Option enum value definitions - single source of truth.
#define OPT_PALETTE_CUSTOM
Definition enums.h:125
#define OPT_LOG_LEVEL_DEV
Definition enums.h:89
#define OPT_PALETTE_COOL
Definition enums.h:124
#define OPT_RENDER_MODE_BG
Definition enums.h:131
#define OPT_RENDER_MODE_FOREGROUND
Definition enums.h:128
#define OPT_LOG_LEVEL_FATAL
Definition enums.h:94
#define OPT_LOG_LEVEL_ERROR
Definition enums.h:93
#define OPT_RENDER_MODE_HALF_BLOCK
Definition enums.h:132
#define OPT_COLOR_MODE_256
Definition enums.h:101
#define OPT_RENDER_MODE_FG
Definition enums.h:129
#define OPT_LOG_LEVEL_INFO
Definition enums.h:91
#define OPT_LOG_LEVEL_DEBUG
Definition enums.h:90
#define OPT_COLOR_MODE_NONE
Definition enums.h:98
#define OPT_PALETTE_MINIMAL
Definition enums.h:123
#define OPT_PALETTE_BLOCKS
Definition enums.h:121
#define OPT_PALETTE_STANDARD
Definition enums.h:120
#define OPT_VALUE_AUTO
Definition enums.h:77
#define OPT_COLOR_MODE_TRUECOLOR
Definition enums.h:102
#define OPT_PALETTE_DIGITAL
Definition enums.h:122
#define OPT_LOG_LEVEL_WARN
Definition enums.h:92
#define OPT_RENDER_MODE_BACKGROUND
Definition enums.h:130
#define OPT_COLOR_MODE_MONO
Definition enums.h:99
#define OPT_COLOR_MODE_16
Definition enums.h:100
unsigned short uint16_t
#define SAFE_STRNCPY(dst, src, size)
#define SAFE_SNPRINTF(buffer, buffer_size,...)
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:48
@ ERROR_CRYPTO_KEY
Definition error_codes.h:98
@ ASCIICHAT_OK
Definition error_codes.h:50
@ ERROR_USAGE
Definition error_codes.h:52
@ ERROR_INVALID_PARAM
#define MAX_SESSION_PARTICIPANTS
#define MAX_SESSION_KEYS
#define log_error(...)
Log an ERROR message.
Definition log/log.h:628
#define log_info(...)
Log an INFO message.
Definition log/log.h:602
#define log_debug(...)
Log a DEBUG message.
Definition log/log.h:589
float validate_opt_volume(const char *value_str, char *error_msg, size_t error_msg_size)
Validate volume value (0.0-1.0).
Definition validation.c:351
int validate_opt_positive_int(const char *value_str, char *error_msg, size_t error_msg_size)
Validate positive integer.
Definition validation.c:129
#define COLOR_MODE_16_COLOR
16-color mode (full name)
Definition options.h:226
#define COLOR_MODE_256_COLOR
256-color mode (full name)
Definition options.h:228
#define COLOR_MODE_TRUECOLOR
24-bit truecolor mode
Definition options.h:229
int validate_opt_render_mode(const char *value_str, char *error_msg, size_t error_msg_size)
Validate render mode string.
Definition validation.c:180
#define COLOR_MODE_AUTO
Backward compatibility aliases for color mode enum values.
Definition options.h:223
int validate_opt_color_mode(const char *value_str, char *error_msg, size_t error_msg_size)
Validate color mode string.
Definition validation.c:147
struct options_state options_t
Immutable, RCU-published snapshot of the application's runtime configuration.
int strtoint_safe(const char *str)
Safely parse string to integer with validation.
int validate_opt_palette(const char *value_str, char *error_msg, size_t error_msg_size)
Validate palette type string.
Definition validation.c:207
int validate_opt_non_negative_int(const char *value_str, char *error_msg, size_t error_msg_size)
Validate non-negative integer.
Definition validation.c:138
asciichat_error_t validate_glyph_palette(const options_t *opts)
Definition validation.c:25
int validate_opt_password(const char *value_str, char *error_msg, size_t error_msg_size)
Validate password (8-256 characters).
Definition validation.c:486
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).
Definition validation.c:398
#define OPTIONS_BUFF_SIZE
Buffer size for option string values.
Definition options.h:305
float validate_opt_float_non_negative(const char *value_str, char *error_msg, size_t error_msg_size)
Validate non-negative float value.
Definition validation.c:322
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).
Definition validation.c:456
int validate_opt_reconnect(const char *value_str, char *error_msg, size_t error_msg_size)
Validate reconnect value.
Definition validation.c:411
#define COLOR_MODE_NONE
Monochrome mode.
Definition options.h:224
int validate_opt_max_clients(const char *value_str, char *error_msg, size_t error_msg_size)
Validate max clients value (1-128).
Definition validation.c:380
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.
Definition validation.c:272
bool is_remote_key_path(const char *key_path)
Check if a key path is a remote/virtual key (not a local file).
Definition validation.c:597
int validate_opt_port(const char *value_str, char *error_msg, size_t error_msg_size)
Validate port number (1-65535).
Definition validation.c:85
int options_collect_identity_keys(options_t *opts, int argc, char *argv[])
Collect multiple –key flags into identity_keys array.
Definition validation.c:525
int validate_opt_compression_level(const char *value_str, char *error_msg, size_t error_msg_size)
Validate compression level (1-9).
Definition validation.c:389
int validate_opt_log_level(const char *value_str, char *error_msg, size_t error_msg_size)
Validate log level string.
Definition validation.c:239
const palette_def_t * get_builtin_palette(palette_type_t type)
Get built-in palette definition.
Definition palette.c:45
const char * chars
Character sequence (ordered from dark to light).
Definition palette.h:134
@ PALETTE_BLOCKS
Unicode block characters: " ░░▒▒▓▓██".
Definition palette.h:102
@ PALETTE_CUSTOM
User-defined via –palette-chars.
Definition palette.h:110
@ PALETTE_COOL
Ascending blocks: " ▁▂▃▄▅▆▇█".
Definition palette.h:108
@ PALETTE_STANDARD
Standard ASCII palette: " ...',;:clodxkO0KXNWM".
Definition palette.h:100
@ PALETTE_DIGITAL
Digital/glitch aesthetic: " -=≡≣▰▱◼".
Definition palette.h:104
@ PALETTE_MINIMAL
Simple ASCII: " .-+*#".
Definition palette.h:106
int is_valid_ipv4(const char *ip)
Check if a string is a valid IPv4 address.
Definition ip.c:32
int is_valid_ipv6(const char *ip)
Check if a string is a valid IPv6 address.
Definition ip.c:63
int parse_ipv6_address(const char *input, char *output, size_t output_size)
Parse IPv6 address, removing brackets if present.
Definition ip.c:116
⚙️ Common definitions, error codes, macros, and types shared throughout the application
🌍 IP Address Parsing and Formatting Utilities
bool ascii_render_palette_supported(ascii_renderer_t kind, const char *palette)
📝 Logging API with multiple log levels and terminal output control
🔢 Mathematical Utility Functions
Validation functions for options parsing.
⚙️ Unified options parsing system for ascii-chat with builder pattern and lock-free access
ASCII Palette Management for Video-to-ASCII Conversion.
static bool size_t index
Definition queries.h:8
int platform_strcasecmp(const char *s1, const char *s2)
🔤 String Manipulation and Shell Escaping Utilities
size_t num_identity_keys
Number of identity keys loaded (0 means single-key mode using encrypt_key).
Definition options.h:1183
bool palette_explicit
Palette explicitly selected.
Definition options.h:1223
char identity_keys[32][256]
All identity keys (populated when –key is used multiple times).
Definition options.h:1182
char palette_custom[256]
Custom palette characters.
Definition options.h:1221
ascii_renderer_t renderer
Character selection algorithm.
Definition options.h:1133
int port
Server port number.
Definition options.h:1004
palette_type_t palette_type
Selected palette type.
Definition options.h:1220
char encrypt_key[256]
SSH/GPG key file path (first –key flag, kept for compatibility).
Definition options.h:1172
Validated luminance palette used to turn brightness into characters.
Definition palette.h:130
#define LOG_DEV
Definition types.h:42
#define LOG_DEBUG
Definition types.h:43
#define LOG_FATAL
Definition types.h:47
#define LOG_ERROR
Definition types.h:46
#define LOG_WARN
Definition types.h:45
#define LOG_INFO
Definition types.h:44
asciichat_error_t parse_port(const char *str, uint16_t *out_port)
Parse port number (1-65535) from string.
🔍 Safe Parsing Utilities
bool validate_port_callback(const void *options_struct)
Definition validation.c:108