ascii-chat 0.8.38
Real-time terminal-based video chat with ASCII art conversion
Loading...
Searching...
No Matches
acds_server.c File Reference

Go to the source code of this file.

Functions

asciichat_error_t acip_server_validate_session_create (const acip_session_create_t *req)
 
asciichat_error_t acip_server_validate_session_join (const acip_session_join_t *req)
 
asciichat_error_t acip_server_send_error (socket_t sockfd, acip_error_code_t error_code, const char *error_message)
 

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 
)

Definition at line 74 of file acds_server.c.

74 {
75 if (sockfd == INVALID_SOCKET_VALUE) {
76 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid socket");
77 }
78
79 if (!error_message) {
80 error_message = "Unknown error";
81 }
82
83 acip_error_t error_packet;
84 memset(&error_packet, 0, sizeof(error_packet));
85 error_packet.error_code = (uint8_t)error_code;
86
87 // Safely copy error message (truncate if needed)
88 size_t msg_len = strlen(error_message);
89 if (msg_len >= sizeof(error_packet.error_message)) {
90 msg_len = sizeof(error_packet.error_message) - 1;
91 }
92 memcpy(error_packet.error_message, error_message, msg_len);
93 error_packet.error_message[msg_len] = '\0';
94
95 // Send ACIP_ERROR packet
96 int result = send_packet(sockfd, PACKET_TYPE_ACIP_ERROR, &error_packet, sizeof(error_packet));
97 if (result < 0) {
98 return SET_ERRNO(ERROR_NETWORK, "Failed to send ACIP error packet");
99 }
100
101 return ASCIICHAT_OK;
102}
asciichat_error_t error_code
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:753

References error_code, and send_packet().

◆ acip_server_validate_session_create()

asciichat_error_t acip_server_validate_session_create ( const acip_session_create_t *  req)

Definition at line 27 of file acds_server.c.

27 {
28 if (!req) {
29 return SET_ERRNO(ERROR_INVALID_PARAM, "Session create request is NULL");
30 }
31
32 // Validate capabilities (only bits 0-1 should be set)
33 if (req->capabilities & ~0x03) {
34 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid capabilities bits (only 0-1 allowed)");
35 }
36
37 // Validate max_participants (1-8)
38 if (req->max_participants < 1 || req->max_participants > 8) {
39 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid max_participants (must be 1-8)");
40 }
41
42 // Server address can be empty - ACDS will auto-detect from connection source IP
43
44 // Validate server port is non-zero
45 if (req->server_port == 0) {
46 return SET_ERRNO(ERROR_INVALID_PARAM, "Server port is zero");
47 }
48
49 return ASCIICHAT_OK;
50}

◆ acip_server_validate_session_join()

asciichat_error_t acip_server_validate_session_join ( const acip_session_join_t *  req)

Definition at line 52 of file acds_server.c.

52 {
53 if (!req) {
54 return SET_ERRNO(ERROR_INVALID_PARAM, "Session join request is NULL");
55 }
56
57 // Validate session string length
58 if (req->session_string_len == 0 || req->session_string_len > ACIP_MAX_SESSION_STRING_LEN) {
59 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid session string length");
60 }
61
62 // Validate session string is not empty
63 if (req->session_string[0] == '\0') {
64 return SET_ERRNO(ERROR_INVALID_PARAM, "Session string is empty");
65 }
66
67 return ASCIICHAT_OK;
68}