ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
acds_server.h File Reference

ACIP server-side protocol library and ACDS server utilities. More...

Go to the source code of this file.

Functions

ACIP Packet Validation
asciichat_error_t acip_server_validate_session_create (const acip_session_create_t *req)
 Validate ACIP session create request.
asciichat_error_t acip_server_validate_session_join (const acip_session_join_t *req)
 Validate ACIP session join request.
ACIP Error Response Helpers
asciichat_error_t acip_server_send_error (socket_t sockfd, acip_error_code_t error_code, const char *error_message)
 Send ACIP error response to client.

Detailed Description

ACIP server-side protocol library and ACDS server utilities.

Definition in file acds_server.h.

Function Documentation

◆ acip_server_send_error()

asciichat_error_t acip_server_send_error ( socket_t sockfd,
acip_error_code_t error_code,
const char * error_message )

Send ACIP error response to client.

Parameters
sockfdClient socket
error_codeACIP error code
error_messageHuman-readable error message (max 255 chars)
Returns
ASCIICHAT_OK on success, error code on failure

Sends PACKET_TYPE_ACIP_ERROR response to client with specified error code and message. Message will be truncated if longer than 255 characters.

Definition at line 79 of file acds_server.c.

79 {
80 if (sockfd == INVALID_SOCKET_VALUE) {
81 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid socket");
82 }
83
84 if (!error_message) {
85 error_message = "Unknown error";
86 }
87
88 acip_error_t error_packet;
89 memset(&error_packet, 0, sizeof(error_packet));
90 error_packet.error_code = (uint8_t)error_code;
91
92 // Safely copy error message (truncate if needed)
93 size_t msg_len = strlen(error_message);
94 if (msg_len >= sizeof(error_packet.error_message)) {
95 msg_len = sizeof(error_packet.error_message) - 1;
96 }
97 memcpy(error_packet.error_message, error_message, msg_len);
98 error_packet.error_message[msg_len] = '\0';
99
100 // Send ACIP_ERROR packet
101 int result = send_packet(sockfd, PACKET_TYPE_ACIP_ERROR, &error_packet, sizeof(error_packet));
102 if (result < 0) {
103 return SET_ERRNO(ERROR_NETWORK, "Failed to send ACIP error packet");
104 }
105
106 return ASCIICHAT_OK;
107}
#define SET_ERRNO(code,...)
unsigned char uint8_t
Definition common.h:60
@ ERROR_NETWORK
Definition error_codes.h:72
@ ASCIICHAT_OK
Definition error_codes.h:46
@ ERROR_INVALID_PARAM
acip_error_t
Definition acds.h:1013
int send_packet(socket_t sockfd, packet_type_t type, const void *data, size_t len)
Send a basic packet without encryption.
Definition packet.c:607
@ PACKET_TYPE_ACIP_ERROR
Generic error response (Discovery Server -> Client).
Definition packet.h:533

References acip_error_t, ASCIICHAT_OK, ERROR_INVALID_PARAM, ERROR_NETWORK, PACKET_TYPE_ACIP_ERROR, send_packet(), and SET_ERRNO.

◆ acip_server_validate_session_create()

asciichat_error_t acip_server_validate_session_create ( const acip_session_create_t * req)

Validate ACIP session create request.

Parameters
reqSession create request packet
Returns
ASCIICHAT_OK if valid, error code if invalid

Validates that a SESSION_CREATE request has all required fields populated correctly (identity, signature, capabilities, etc.).

Definition at line 28 of file acds_server.c.

28 {
29 if (!req) {
30 return SET_ERRNO(ERROR_INVALID_PARAM, "Session create request is NULL");
31 }
32
33 if (req->total_keys > MAX_SESSION_KEYS || req->key_index >= (req->total_keys ? req->total_keys : 1)) {
34 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid session key count/index");
35 }
36
37 // Validate capabilities (only bits 0-1 should be set)
38 if (req->capabilities & ~0x03) {
39 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid capabilities bits (only 0-1 allowed)");
40 }
41
42 // Validate max_participants (1-128)
43 if (req->max_participants < 1 || req->max_participants > MAX_SESSION_PARTICIPANTS) {
44 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid max_participants (must be 1-%d)", MAX_SESSION_PARTICIPANTS);
45 }
46
47 // Server address can be empty - ACDS will auto-detect from connection source IP
48
49 // Validate server port is non-zero
50 if (req->server_port == 0) {
51 return SET_ERRNO(ERROR_INVALID_PARAM, "Server port is zero");
52 }
53
54 return ASCIICHAT_OK;
55}
#define MAX_SESSION_PARTICIPANTS
#define MAX_SESSION_KEYS

References acip_session_create_t, ASCIICHAT_OK, ERROR_INVALID_PARAM, MAX_SESSION_KEYS, MAX_SESSION_PARTICIPANTS, and SET_ERRNO.

◆ acip_server_validate_session_join()

asciichat_error_t acip_server_validate_session_join ( const acip_session_join_t * req)

Validate ACIP session join request.

Parameters
reqSession join request packet
Returns
ASCIICHAT_OK if valid, error code if invalid

Validates that a SESSION_JOIN request has all required fields populated correctly (session string, identity, signature, etc.).

Definition at line 57 of file acds_server.c.

57 {
58 if (!req) {
59 return SET_ERRNO(ERROR_INVALID_PARAM, "Session join request is NULL");
60 }
61
62 // Validate session string length
63 if (req->session_string_len == 0 || req->session_string_len > ACIP_MAX_SESSION_STRING_LEN) {
64 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid session string length");
65 }
66
67 // Validate session string is not empty
68 if (req->session_string[0] == '\0') {
69 return SET_ERRNO(ERROR_INVALID_PARAM, "Session string is empty");
70 }
71
72 return ASCIICHAT_OK;
73}
#define ACIP_MAX_SESSION_STRING_LEN
Definition acds_sizes.h:6

References ACIP_MAX_SESSION_STRING_LEN, acip_session_join_t, ASCIICHAT_OK, ERROR_INVALID_PARAM, and SET_ERRNO.