forked from yongboy/c_socket.io_server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
socket_io.h
executable file
·114 lines (92 loc) · 2.64 KB
/
socket_io.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#ifndef _WEBSERVER_H
#define _WEBSERVER_H
#include <glib.h>
#include "include/ev.h"
#include "include/http-parser/http_parser.h"
#include "log.h"
#define RESPONSE_404 \
"HTTP/1.1 404 Not Found\r\n"
#define RESPONSE_400 \
"HTTP/1.1 400 Bad Request\r\n"
#define RESPONSE_TEMPLATE \
"HTTP/1.1 200 OK\r\n" \
"Connection: keep-alive\r\n" \
"Content-Type: %s\r\n" \
"Content-Length: %d\r\n" \
"\r\n"
#define RESPONSE_PLAIN \
"HTTP/1.1 200 OK\r\n" \
"Connection: keep-alive\r\n" \
"Content-Type: text/plain\r\n" \
"Content-Length: %d\r\n" \
"\r\n" \
"%s\n"
#define FLASH_SECURITY_REQ "<policy-file-request/>"
#define FLASH_SECURITY_FILE "<cross-domain-policy><allow-access-from domain='*' to-ports='*' /></cross-domain-policy>"
#define TRANSPORT_WEBSOCKET_VERSION 4
#define REQUEST_BUFFER_SIZE 8192
struct _ext_to_content_type {
char *extnsn[6];
char *contentname;
};
typedef struct {
char *transport;
char *sessionid;
char *i;
char *oriurl;
} transport_info;
typedef struct {
int fd;
ev_io ev_read;
http_parser parser;
ev_timer timeout;
transport_info trans_info;
int trans_version;
// int header_done;
void *data;
} client_t;
typedef struct {
char *sessionid;
client_t *client;
GQueue *queue;
char *endpoint;
int state; /* -2:disconnected; -1:disconnecting; 0:connecting; 1:connected; */
ev_timer close_timeout;
} session_t;
enum SESSION_STATE{
DISCONNECTED_STATE = -2,
DISCONNECTING_STATE = -1,
CONNECTING_STATE = 0,
CONNECTED_STATE = 1
};
typedef struct {
char *transports;
int heartbeat_timeout;
int close_timeout;
int server_close_timeout;
int heartbeat_interval;
int enable_flash_policy;
int flash_policy_port;
char *static_path;
} config;
typedef struct {
char name[20];
char heartbeat[4];
void (*output_callback)(session_t *session);
void (*output_header)(client_t *client);
void (*output_body)(client_t *client, char *http_msg);
void (*output_whole)(client_t *client, char *output_msg);
void (*timeout_callback)(ev_timer *timer);
void (*heartbeat_callback)(client_t *client, char *sessionid);
void (*init_connect)(client_t *client, char *sessionid);
void (*end_connect)(char *sessionid);
} transports_fn;
void init_config();
void store_init();
void transports_fn_init();
void endpoints_init();
int on_url_cb(http_parser *parser, const char *at, size_t length);
int on_body_cb(http_parser *parser, const char *at, size_t length);
void timeout_cb(EV_P_ struct ev_timer *timer, int revents);
void on_close(client_t *client);
#endif