ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
acds_handlers.h File Reference

ACIP Discovery Server (ACDS) packet handlers. More...

Go to the source code of this file.

Data Structures

struct  acip_acds_callbacks_t
 ACDS packet handler callbacks. More...
 

Functions

asciichat_error_t acip_handle_acds_packet (acip_transport_t *transport, packet_type_t type, const void *payload, size_t payload_len, int client_socket, const char *client_ip, const acip_acds_callbacks_t *callbacks)
 Handle incoming ACDS packet with O(1) dispatch.
 

Detailed Description

ACIP Discovery Server (ACDS) packet handlers.

Provides O(1) array-based packet dispatching for ASCII Chat Discovery Server. Handles session management, WebRTC signaling, and discovery protocol packets.

Author
Zachary Fogg me@zf.nosp@m.o.gg
Date
January 2026

Definition in file acds_handlers.h.

Function Documentation

◆ acip_handle_acds_packet()

asciichat_error_t acip_handle_acds_packet ( acip_transport_t transport,
packet_type_t  type,
const void *  payload,
size_t  payload_len,
int  client_socket,
const char *  client_ip,
const acip_acds_callbacks_t callbacks 
)

Handle incoming ACDS packet with O(1) dispatch.

Dispatches packet to appropriate callback based on type. Uses array-based lookup for constant-time handler selection.

Parameters
transportTransport instance (unused, for API consistency)
typePacket type
payloadPacket payload
payload_lenPayload length
client_socketClient socket file descriptor
client_ipClient IP address string
callbacksApplication callbacks
Returns
ASCIICHAT_OK on success, error code on failure

Definition at line 71 of file acds_handlers.c.

73 {
74 if (!callbacks) {
75 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid callbacks");
76 }
77
78 // TODO: Implement transport abstraction for ACDS responses or future protocol features
79 (void)transport;
80
81 // O(1) array-based dispatch - bounds check packet type
82 if (type >= 200) {
83 log_warn("Invalid ACDS packet type: %d (out of range)", type);
84 return ASCIICHAT_OK;
85 }
86
87 // Lookup handler in dispatch table
88 acip_acds_handler_func_t handler = g_acds_packet_handlers[type];
89 if (!handler) {
90 log_warn("Unhandled ACDS packet type: %d from %s", type, client_ip);
91 return ASCIICHAT_OK;
92 }
93
94 // Dispatch to handler
95 return handler(payload, payload_len, client_socket, client_ip, callbacks);
96}
asciichat_error_t(* acip_acds_handler_func_t)(const void *payload, size_t payload_len, int client_socket, const char *client_ip, const acip_acds_callbacks_t *callbacks)
#define SET_ERRNO(code, context_msg,...)
Set error code with custom context message and log it.
@ ASCIICHAT_OK
Definition error_codes.h:48
@ ERROR_INVALID_PARAM
#define log_warn(...)
Log a WARN message.

References ASCIICHAT_OK, ERROR_INVALID_PARAM, log_warn, and SET_ERRNO.

Referenced by acds_client_handler().