30 if (!transport || !callbacks) {
47 bool enforce_encryption = (transport->
crypto_ctx != NULL);
71 return dispatch_result;
80 if (!transport || !pixel_data) {
85 size_t pixel_size = (size_t)width * height * 3;
98 if (checked_size_add(
sizeof(header), pixel_size, &total_size) !=
ASCIICHAT_OK) {
109 memcpy(buffer, &header,
sizeof(header));
110 memcpy(buffer +
sizeof(header), pixel_data, pixel_size);
158 if (!transport || !cap_data) {
166 if (!transport || !version) {
🗃️ Lock-Free Unified Memory Buffer Pool with Lazy Allocation
🔄 Network byte order conversion helpers
#define HOST_TO_NET_U32(val)
void buffer_pool_free(buffer_pool_t *pool, void *data, size_t size)
Free a buffer back to the pool (lock-free)
void * buffer_pool_alloc(buffer_pool_t *pool, size_t size)
Allocate a buffer from the pool (lock-free fast path)
#define SET_ERRNO(code, context_msg,...)
Set error code with custom context message and log it.
asciichat_error_t
Error and exit codes - unified status values (0-255)
uint32_t pixel_format
Pixel format enum (0=RGB24, 1=RGBA32, 2=BGR24, etc.)
uint32_t timestamp
Timestamp when frame was captured (milliseconds since epoch)
void * allocated_buffer
Buffer that needs to be freed by caller (may be NULL if not allocated)
size_t allocated_size
Size of allocated buffer in bytes.
size_t len
Length of payload data in bytes.
void * data
Packet payload data (decrypted and decompressed if applicable)
uint32_t compressed_size
Compressed data size (0 = not compressed, >0 = compressed)
packet_recv_result_t receive_packet_secure(socket_t sockfd, void *crypto_ctx, bool enforce_encryption, packet_envelope_t *envelope)
Receive a packet with decryption and decompression support.
uint32_t checksum
CRC32 checksum of pixel data.
uint32_t height
Image height in pixels.
packet_type_t type
Packet type (from packet_types.h)
uint32_t width
Image width in pixels.
packet_recv_result_t
Packet reception result codes.
@ PACKET_RECV_EOF
Connection closed (EOF)
@ PACKET_RECV_SECURITY_VIOLATION
Encryption policy violation (e.g., unencrypted packet when encryption required)
@ PACKET_RECV_SUCCESS
Packet received successfully.
@ PACKET_TYPE_CLIENT_LEAVE
Clean disconnect notification.
@ PACKET_TYPE_IMAGE_FRAME
Complete RGB image with dimensions.
@ PACKET_TYPE_STREAM_START
Client requests to start sending video/audio.
@ PACKET_TYPE_PROTOCOL_VERSION
Protocol version and capabilities negotiation.
@ PACKET_TYPE_CLIENT_JOIN
Client announces capability to send media.
@ PACKET_TYPE_CLIENT_CAPABILITIES
Client reports terminal capabilities.
@ PACKET_TYPE_STREAM_STOP
Client stops sending media.
asciichat_error_t acip_handle_client_packet(acip_transport_t *transport, packet_type_t type, const void *payload, size_t payload_len, const acip_client_callbacks_t *callbacks)
Handle incoming packet on client side.
ACIP protocol packet handlers (transport-agnostic)
asciichat_error_t acip_send_image_frame(acip_transport_t *transport, const void *pixel_data, uint32_t width, uint32_t height, uint32_t pixel_format)
Send image frame to server (client → server)
asciichat_error_t acip_send_stream_stop(acip_transport_t *transport, uint8_t stream_types)
Request to stop media streaming (client → server)
asciichat_error_t acip_client_receive_and_dispatch(acip_transport_t *transport, const acip_client_callbacks_t *callbacks)
Receive packet from server and dispatch to callbacks.
asciichat_error_t acip_send_stream_start(acip_transport_t *transport, uint8_t stream_types)
Request to start media streaming (client → server)
asciichat_error_t acip_send_capabilities(acip_transport_t *transport, const void *cap_data, size_t cap_len)
Send terminal capabilities to server (client → server)
asciichat_error_t acip_send_client_leave(acip_transport_t *transport)
Notify server of client leaving (client → server)
asciichat_error_t acip_send_protocol_version(acip_transport_t *transport, const protocol_version_packet_t *version)
Send protocol version to server (client → server)
asciichat_error_t acip_send_client_join(acip_transport_t *transport, uint8_t capabilities)
Announce client join to server (client → server)
ACIP client-side protocol library.
📝 Logging API with multiple log levels and terminal output control
✅ Safe Integer Arithmetic and Overflow Detection
Packet protocol implementation with encryption and compression support.
asciichat_error_t packet_send_via_transport(acip_transport_t *transport, packet_type_t type, const void *payload, size_t payload_len)
Send packet via transport with proper header (exported for generic wrappers)
ACIP shared/bidirectional packet sending functions.
Client-side packet handler callbacks.
bool(* is_connected)(acip_transport_t *transport)
Check if transport is connected.
socket_t(* get_socket)(acip_transport_t *transport)
Get underlying socket (if applicable)
Transport instance structure.
const acip_transport_methods_t * methods
Method table (virtual functions)
crypto_context_t * crypto_ctx
Optional encryption context.
Image frame packet structure (Packet Type 3)
Packet envelope containing received packet data.
Protocol version negotiation packet structure (Packet Type 1)