#ifndef WEBSOCKET_H
#define WEBSOCKET_H
#include "../public/nsapi.h"
#ifdef __cplusplus
extern "C" {
#endif
#define WS_FRAMEHEADER_BUFLEN 16
typedef struct WSParser WSParser;
typedef struct WSFrame WSFrame;
struct WSFrame {
uint8_t header_complete;
uint8_t fin;
uint8_t mask;
uint8_t opcode;
uint32_t masking_key;
uint64_t payload_length;
};
struct WSParser {
const char *inbuf;
size_t length;
size_t pos;
WSMessage *current;
int state;
size_t cur_plen;
WSFrame frame;
char tmpbuf[
WS_FRAMEHEADER_BUFLEN];
size_t tmplen;
pool_handle_t *pool;
};
WSParser* websocket_parser(Session *sn);
void websocket_input(WSParser *parser,
const char *data,
size_t length);
WSMessage* websocket_get_message(WSParser *parser,
int *error);
ssize_t websocket_get_frameheader(WSFrame *frame,
const char *buf,
size_t len);
void websocket_mask_data(
char *buf,
size_t len,
uint32_t mask);
#ifdef __cplusplus
}
#endif
#endif