forked from edwardchoh/ws-tcp-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwsparser.h
56 lines (47 loc) · 1.06 KB
/
wsparser.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdint.h>
#include <sys/types.h>
typedef struct ws_parser ws_parser;
typedef struct ws_settings ws_settings;
typedef struct ws_header ws_header;
typedef int (*ws_data_cb) (ws_parser*, const char *at, size_t len);
typedef int (*ws_cb) (ws_parser*);
enum state {
WS_HEADER = 0,
WS_BODY = 1
};
struct ws_settings {
ws_cb on_header;
ws_data_cb on_chunk;
ws_cb on_complete;
};
struct ws_header {
uint8_t fin;
uint8_t reserved[3];
uint8_t opcode;
uint32_t length;
uint8_t mask;
uint8_t maskkey[4];
};
struct ws_parser {
void* data;
ws_header header;
uint64_t index;
int state;
int payload16;
int payload64;
int maskpos;
uint64_t bodypos;
};
void ws_init(ws_parser* parser);
size_t ws_execute(ws_parser* parser, const ws_settings* settings, \
const char* data, size_t start, size_t end);
void ws_reset(ws_parser* parser);
int ws_encode_bin_hdr(const char *src, size_t srclen, char *dst, unsigned int opcode);
typedef enum {
CONT = 0x0,
TEXT = 0x1,
BIN = 0x2,
CLOSE = 0x8,
PING = 0x9,
PONG = 0xA
} HYBI_OPCODE;