ascii-chat 0.8.38
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
options/registry/mode_defaults.c
Go to the documentation of this file.
1
12#include <ascii-chat/options/registry/common.h>
13#include <ascii-chat/options/options.h>
14#include <ascii-chat/platform/system.h>
15#include <string.h>
16#include <stdio.h>
17
18// ============================================================================
19// Mode-Aware Default: log-file
20// ============================================================================
21
32const void *get_default_log_file(asciichat_mode_t mode) {
33 (void)mode; // Unused
34 // Return empty string - let options_get_log_filepath() handle the defaults
35 return "";
36}
37
38// ============================================================================
39// Mode-Aware Default: port
40// ============================================================================
41
42static const int g_port_server = OPT_PORT_INT_DEFAULT; // 27224
43static const int g_port_client = OPT_PORT_INT_DEFAULT; // 27224
44static const int g_port_discovery_service = OPT_ACDS_PORT_INT_DEFAULT; // 27225
45static const int g_port_discovery = OPT_PORT_INT_DEFAULT; // 27224 (connects via discovery)
46
50const void *get_default_port(asciichat_mode_t mode) {
51 switch (mode) {
52 case MODE_SERVER:
53 return &g_port_server;
54 case MODE_CLIENT:
55 return &g_port_client;
56 case MODE_DISCOVERY_SERVICE:
57 return &g_port_discovery_service;
58 case MODE_DISCOVERY:
59 return &g_port_discovery;
60 case MODE_MIRROR:
61 case MODE_INVALID:
62 default:
63 // Fallback
64 return &g_port_server;
65 }
66}
67
68// ============================================================================
69// Mode-Aware Default: websocket-port
70// ============================================================================
71
72static const int g_websocket_port_server = OPT_WEBSOCKET_PORT_SERVER_DEFAULT; // 27226
73static const int g_websocket_port_discovery_service = OPT_WEBSOCKET_PORT_ACDS_DEFAULT; // 27227
74
78const void *get_default_websocket_port(asciichat_mode_t mode) {
79 switch (mode) {
80 case MODE_SERVER:
81 return &g_websocket_port_server;
82 case MODE_DISCOVERY_SERVICE:
83 return &g_websocket_port_discovery_service;
84 case MODE_CLIENT:
85 case MODE_MIRROR:
86 case MODE_DISCOVERY:
87 case MODE_INVALID:
88 default:
89 // Fallback (should not be used for client/mirror/discovery)
90 return &g_websocket_port_server;
91 }
92}
93
94// ============================================================================
95// Mode-Aware Default Application
96// ============================================================================
97
107void apply_mode_specific_defaults(options_t *opts) {
108 if (!opts) {
109 return;
110 }
111
112 // Apply port default based on mode
113 const int *mode_port = (const int *)get_default_port(opts->detected_mode);
114 if (mode_port) {
115 // Only update if still at a generic default (27224 or 27225)
116 if (opts->port == OPT_PORT_INT_DEFAULT || opts->port == OPT_ACDS_PORT_INT_DEFAULT) {
117 opts->port = *mode_port;
118 }
119 }
120
121 // Apply websocket-port default based on mode
122 const int *mode_websocket_port = (const int *)get_default_websocket_port(opts->detected_mode);
123 if (mode_websocket_port) {
124 // Only update if still at a generic default (27226 or 27227)
125 if (opts->websocket_port == OPT_WEBSOCKET_PORT_SERVER_DEFAULT ||
126 opts->websocket_port == OPT_WEBSOCKET_PORT_ACDS_DEFAULT) {
127 opts->websocket_port = *mode_websocket_port;
128 }
129 }
130}
void apply_mode_specific_defaults(options_t *opts)
Apply mode-specific defaults to an options struct after mode detection.
const void * get_default_websocket_port(asciichat_mode_t mode)
Get mode-specific default value for –websocket-port.
const void * get_default_port(asciichat_mode_t mode)
Get mode-specific default value for –port.
const void * get_default_log_file(asciichat_mode_t mode)
Get mode-specific default value for –log-file.