60#ifndef PROTOCORE_WEBSOCKET_H
61#define PROTOCORE_WEBSOCKET_H
65#if PROTOCORE_ENABLE_WEBSOCKET
69#if PROTOCORE_ENABLE_WS_DEFLATE
79#define PROTOCORE_PLAINTEXT_WORK_WS_SEND \
80 (DEFLATE_SCRATCH_SIZE + PROTOCORE_WS_DEFLATE_MAX + (PROTOCORE_WS_DEFLATE_MAX / 8) + 16)
88#define PROTOCORE_PLAINTEXT_WORK_WS_RECV (WS_FRAME_SIZE + 4 + WS_FRAME_SIZE + INFLATE_SCRATCH_SIZE)
90#define PROTOCORE_PLAINTEXT_WORK_WS_SEND 0
91#define PROTOCORE_PLAINTEXT_WORK_WS_RECV 0
101 WS_OP_CONTINUATION = 0x0,
112 WS_CLOSE_NORMAL = 1000,
113 WS_CLOSE_GOING_AWAY = 1001,
114 WS_CLOSE_PROTOCOL = 1002,
115 WS_CLOSE_UNSUPPORTED = 1003,
116 WS_CLOSE_INVALID_PAYLOAD = 1007,
117 WS_CLOSE_TOO_BIG = 1009
159 WsParseState parse_state;
165 uint32_t payload_len;
166 uint32_t payload_idx;
177 uint8_t ctl_buf[125 + 1];
179#if PROTOCORE_ENABLE_WS_DEFLATE
197typedef void (*WsConnectHandler)(uint8_t ws_id);
207typedef void (*WsMessageHandler)(uint8_t ws_id);
214typedef void (*WsCloseHandler)(uint8_t ws_id);
217#define PROTOCORE_WS_NONE 0xFFu
222 WsConnectHandler on_connect;
223 WsMessageHandler on_message;
224 WsCloseHandler on_close;
231 const uint8_t *payload;
293#if PROTOCORE_ENABLE_WS_DEFLATE
304 WsConnectHandler connect_handler;
305 WsMessageHandler message_handler;
306 WsCloseHandler close_handler;
315 void (*
const route_add)(uint8_t *work);
316 void (*
const route_reset)(uint8_t *work);
317 void (*
const route_connect)(uint8_t *work);
318 void (*
const route_message)(uint8_t *work);
319 void (*
const route_close)(uint8_t *work);
320 void (*
const init)(uint8_t *work);
321 void (*
const active)(uint8_t *work);
322 void (*
const payload_of)(uint8_t *work);
323 void (*
const alloc)(uint8_t *work);
324 void (*
const find)(uint8_t *work);
325 void (*
const free)(uint8_t *work);
326 void (*
const parse)(uint8_t *work);
327 void (*
const feed_byte)(uint8_t *work);
328 void (*
const reset_frame)(uint8_t *work);
329 void (*
const send_frame)(uint8_t *work);
330 void (*
const set_frag_size)(uint8_t *work);
331 void (*
const close)(uint8_t *work);
336void protocore_ws_route_add(uint8_t *work);
337void protocore_ws_route_reset(uint8_t *work);
338void protocore_ws_route_connect(uint8_t *work);
339void protocore_ws_route_message(uint8_t *work);
340void protocore_ws_route_close(uint8_t *work);
341void protocore_ws_init(uint8_t *work);
342void protocore_ws_active(uint8_t *work);
343void protocore_ws_payload_of(uint8_t *work);
344void protocore_ws_alloc(uint8_t *work);
345void protocore_ws_find(uint8_t *work);
346void protocore_ws_free(uint8_t *work);
347void protocore_ws_parse(uint8_t *work);
348void protocore_ws_feed_byte(uint8_t *work);
349void protocore_ws_reset_frame(uint8_t *work);
350void protocore_ws_send_frame(uint8_t *work);
351void protocore_ws_set_frag_size(uint8_t *work);
352void protocore_ws_close(uint8_t *work);
358static const WsNs Ws __attribute__((unused)) = {
359 .route_add = protocore_ws_route_add,
360 .route_reset = protocore_ws_route_reset,
361 .route_connect = protocore_ws_route_connect,
362 .route_message = protocore_ws_route_message,
363 .route_close = protocore_ws_route_close,
364 .init = protocore_ws_init,
365 .active = protocore_ws_active,
366 .payload_of = protocore_ws_payload_of,
367 .alloc = protocore_ws_alloc,
368 .find = protocore_ws_find,
369 .free = protocore_ws_free,
370 .parse = protocore_ws_parse,
371 .feed_byte = protocore_ws_feed_byte,
372 .reset_frame = protocore_ws_reset_frame,
373 .send_frame = protocore_ws_send_frame,
374 .set_frag_size = protocore_ws_set_frag_size,
375 .close = protocore_ws_close,
379uint8_t *protocore_ws_span(
void);
#define WS_FRAME_SIZE
Maximum WebSocket frame payload in bytes.
PROTO_ENUM_PACKED
Application protocol spoken on a listener port or connection slot.
#define MAX_WS_CONNS
Maximum simultaneous WebSocket connections.
Bounded RFC 1951 DEFLATE decompressor (INFLATE) - no heap.
Bounded RFC 1951 DEFLATE compressor (DEFLATE) - no heap.
#define PROTOCORE_BEGIN_DECLS
Give a header's declarations C linkage, so their symbol names carry no parameter types.
_Bool proto_bool
The truth value.
#define PROTOCORE_END_DECLS