include/sig/http/sig_ws.h
typedef enum { SIG_WS_TEXT = 1, SIG_WS_CLOSE = 8, SIG_WS_PING = 9, SIG_WS_PONG = 10 } sig_ws_opcode;sig_status_t sig_ws_accept_key(const char * client_key, char [29] out)
| Parameter | Type |
|---|---|
client_key | const char * |
out | char [29] |
Computes the Sec-WebSocket-Accept value for `client_key` (the client's Sec-WebSocket-Key, NUL-terminated) into `out` as a NUL-terminated string. SIG_ERR_INVALID_ARG on a NULL argument.
sig_status_t sig_ws_encode(sig_ws_opcode op, const void * payload, size_t len, char ** out, size_t * out_len)
| Parameter | Type |
|---|---|
op | sig_ws_opcode |
payload | const void * |
len | size_t |
out | char ** |
out_len | size_t * |
Encodes one unmasked, unfragmented server frame. *out is sig_alloc'd (free with sig_free) and holds *out_len bytes. `payload` may be NULL when len is 0.
typedef enum {
SIG_WS_FRAME, /* one complete frame decoded into *out */
SIG_WS_INCOMPLETE, /* need more bytes */
SIG_WS_PROTOCOL_ERROR, /* unmasked client frame, reserved bits, unknown opcode,
fragmented (FIN clear or opcode 0), or control frame > 125 bytes */
SIG_WS_TOO_LARGE /* payload exceeds max_payload */
} sig_ws_decode_result;typedef struct {
sig_ws_opcode op;
unsigned char *payload; /* points into the caller's buffer, unmasked in place */
size_t len;
size_t consumed; /* bytes of the buffer this frame occupied; advance by this */
} sig_ws_frame;sig_ws_decode_result sig_ws_decode(unsigned char * buf, size_t len, size_t max_payload, sig_ws_frame * out)
| Parameter | Type |
|---|---|
buf | unsigned char * |
len | size_t |
max_payload | size_t |
out | sig_ws_frame * |
Decodes one masked client frame from the start of buf[0..len). Unmasks the payload in place. *out is only valid for SIG_WS_FRAME.