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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
|
/*************************************************************************
> File Name: http_stream.h
> Author:
> Mail:
> Created Time: 2018�?09�?12�? 星期�? 15�?56�?05�?
************************************************************************/
#ifndef _HTTP_STREAM_H
#define _HTTP_STREAM_H
#include <tfe_http.h>
#include <tfe_stream.h>
#include <nghttp2/nghttp2.h>
#include <sys/queue.h>
typedef int (*event_cb)(struct tfe_h2_half_private * hf_private,
tfe_http_event ev, const unsigned char * data,
size_t len, void * user);
enum h2_read_state
{
H2_READ_STATE_BEGIN,
H2_READ_STATE_READING,
H2_READ_STATE_COMPLETE,
};
struct tfe_h2_payload
{
int gzip;
uint8_t flags;
ssize_t padlen;
struct z_stream_st *inflate;
struct z_stream_st *deflate;
struct evbuffer * evbuf_body;
};
struct tfe_h2_field{
TAILQ_ENTRY(tfe_h2_field) next;
nghttp2_nv nv;
struct http_field_name *field;
};
struct tfe_h2_header{
TAILQ_HEAD(h2_field_list_head, tfe_h2_field) h2_field_list;
int nvlen;
uint8_t flag;
};
struct tfe_h2_half_private
{
/* PUBLIC STRUCTURE */
struct tfe_http_half half_public;
struct http_frame_session_ctx *frame_ctx;
/* UNDERLAY BUFFER */
int method_or_status;
int by_stream;
char * url_storage;
struct tfe_h2_payload h2_payload;
struct tfe_h2_header header;
struct tfe_h2_header promised;
/*Read Cache**/
int32_t stream_id;
nghttp2_session *session;
struct tfe_h2_session *father_session;
enum h2_read_state body_state;
enum h2_read_state message_state;
/* Callback Function */
int (*event_cb)(struct tfe_h2_half_private * half_private, tfe_http_event ev,
const unsigned char * data, size_t len, void * user);
/* Callback Function User Pointer */
void * event_cb_user;
/* Callback Function User Pointer Deleter */
void (* event_cb_user_deleter)(void *);
};
struct cache_trapper_t{
int spd_set;
int spd_valid;
int rse_set;
int spd_set_cnt;
int spd_cnt;
tfe_http_event spd_event;
};
struct tfe_h2_session{
struct tfe_http_session tfe_session;
TAILQ_ENTRY(tfe_h2_session) next;
const struct tfe_stream *tf_stream;
int32_t ngh2_stream_id;
nghttp2_session *session;
struct tfe_h2_stream *father_stream;
struct cache_trapper_t cache;
struct http_frame_session_ctx *frame_ctx;
struct tfe_h2_half_private *req, *plugin_built_req;
struct tfe_h2_half_private *resp, *plugin_built_resp;
};
struct tfe_h2_stream
{
TAILQ_HEAD(list_head, tfe_h2_session) h2_session_list;
int goaway;
int kill_signal;
enum tfe_stream_action stream_action;
unsigned int thread_id;
/** for down stream as server */
nghttp2_session *http2_server_handle;
/** for up stream as client*/
nghttp2_session *http2_client_handle;
const struct tfe_stream *tf_stream;
};
struct stream_tap_info_t
{
/** IS PREEMPTED */
unsigned int preempted;
/** sess manage */
struct tfe_h2_stream *h2_stream_info;
};
#define ACTION_USER_DATA 3
static inline const struct tfe_h2_half_private *
nghttp2_to_half_private(const struct tfe_http_half * half_public)
{
if(!half_public)
return NULL;
return container_of(half_public, struct tfe_h2_half_private, half_public);
}
static inline struct tfe_h2_half_private *
nghttp2_to_half_private(struct tfe_http_half * half_public)
{
if(!half_public)
return NULL;
return container_of(half_public, struct tfe_h2_half_private, half_public);
}
static inline struct tfe_h2_session *
nghttp2_to_stream_data(struct tfe_http_session * hs_public)
{
if (hs_public == NULL)
return NULL;
return container_of(hs_public, struct tfe_h2_session, tfe_session);
}
extern struct tfe_h2_stream* tfe_session_info_init();
extern void sess_data_ctx_fini(struct tfe_h2_stream *h2_stream_info, const struct tfe_stream * stream,
unsigned int thread_id);
extern enum tfe_stream_action
detect_down_stream_protocol(struct tfe_h2_stream *h2_stream_info, const struct tfe_stream *tfe_stream,
unsigned int thread_id, const unsigned char *data, size_t len);
extern enum tfe_stream_action
detect_up_stream_protocol(struct tfe_h2_stream *h2_stream_info, const struct tfe_stream *tfe_stream,
unsigned int thread_id, const unsigned char *data, size_t len);
enum tfe_stream_action
nghttp2_client_mem_send(struct tfe_h2_stream *h2_stream_info);
enum tfe_stream_action
nghttp2_server_mem_send(struct tfe_h2_stream *h2_stream_info);
/*for test **/
#endif
|