-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpacket.h
59 lines (48 loc) · 1.42 KB
/
packet.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
57
58
#ifndef __PACKET_H__
#define __PACKET_H__
#include "c_hashmap/hashmap.h"
#include "crc32/crc32.h"
#include "jansson/jansson.h"
#include "server_configs.h"
#include "server.h"
struct client;
struct server;
#define PACKET_TYPE_UNENCRY 0x01
#define PACKET_TYPE_ENCRY 0x02
#define PACKET_TYPE_RSA 0x02
#pragma pack (1)
struct raw_packet_head {
uint32_t crc32;
uint16_t packet_len;
uint16_t type;
};
struct raw_packet {
union {
struct {
struct raw_packet_head head;
char buffer[0];
};
char reserved[SERVER_MAX_PACKETS];
};
};
struct crc32_raw_packet {
uint32_t crc32;
uint8_t crcdata[0];
};
#pragma pack ()
struct method {
const char *name;
int (*handler)(struct server *, struct client *, json_t *);
};
#define RAW_PACKET_BUFFER_MAX (SERVER_MAX_PACKETS - sizeof(struct raw_packet_head))
int sizeof_raw_packet(struct raw_packet *packet);
struct raw_packet *alloc_raw_packet(struct server *sv, struct client *ct);
int free_raw_packet(struct server *sv, struct client *ct,
struct raw_packet *packet);
int respond_raw_packet(struct server *sv, struct client *ct,
struct raw_packet *packet);
int build_simplify_json(json_t *json, const char *method, int err);
int dispatch_packet(struct server *sv, struct client *ct, struct raw_packet *packet);
int json_to_raw_packet(json_t *json, int type, struct raw_packet *packet);
int respond_raw_packet(struct server *sv, struct client *ct, struct raw_packet *packet);
#endif /*__PACKET_H__*/