2019-02-22 15:42:20 +08:00
|
|
|
|
/*************************************************************************
|
|
|
|
|
|
> File Name: http_stream.h
|
|
|
|
|
|
> Author:
|
|
|
|
|
|
> Mail:
|
2019-05-31 10:21:40 +08:00
|
|
|
|
> Created Time: 2018<EFBFBD><EFBFBD>?09<EFBFBD><EFBFBD>?12<EFBFBD><EFBFBD>? 星期<EFBFBD><EFBFBD>? 15<EFBFBD><EFBFBD>?56<EFBFBD><EFBFBD>?05<EFBFBD><EFBFBD>?
|
2019-02-22 15:42:20 +08:00
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef _HTTP_STREAM_H
|
|
|
|
|
|
#define _HTTP_STREAM_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <tfe_http.h>
|
|
|
|
|
|
#include <tfe_stream.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include <nghttp2/nghttp2.h>
|
|
|
|
|
|
#include <sys/queue.h>
|
|
|
|
|
|
|
2019-05-31 10:21:40 +08:00
|
|
|
|
typedef int (*event_cb)(struct tfe_h2_half_private * hf_private,
|
2019-02-22 15:42:20 +08:00
|
|
|
|
tfe_http_event ev, const unsigned char * data,
|
|
|
|
|
|
size_t len, void * user);
|
|
|
|
|
|
|
2019-05-31 10:21:40 +08:00
|
|
|
|
enum h2_read_state
|
2019-02-22 15:42:20 +08:00
|
|
|
|
{
|
2019-05-31 10:21:40 +08:00
|
|
|
|
H2_READ_STATE_BEGIN,
|
|
|
|
|
|
H2_READ_STATE_READING,
|
|
|
|
|
|
H2_READ_STATE_COMPLETE,
|
2019-02-22 15:42:20 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2019-05-31 10:21:40 +08:00
|
|
|
|
struct tfe_h2_payload
|
2019-02-22 15:42:20 +08:00
|
|
|
|
{
|
|
|
|
|
|
int gzip;
|
|
|
|
|
|
uint8_t flags;
|
2019-03-29 15:37:18 +08:00
|
|
|
|
ssize_t padlen;
|
2019-05-31 10:21:40 +08:00
|
|
|
|
struct z_stream_st *inflate;
|
2019-02-22 15:42:20 +08:00
|
|
|
|
struct z_stream_st *deflate;
|
|
|
|
|
|
struct evbuffer * evbuf_body;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2019-05-31 10:21:40 +08:00
|
|
|
|
struct tfe_h2_field{
|
|
|
|
|
|
TAILQ_ENTRY(tfe_h2_field) next;
|
2019-02-22 15:42:20 +08:00
|
|
|
|
nghttp2_nv nv;
|
2019-05-31 10:21:40 +08:00
|
|
|
|
struct http_field_name *field;
|
2019-02-22 15:42:20 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2019-05-31 10:21:40 +08:00
|
|
|
|
struct tfe_h2_header{
|
|
|
|
|
|
TAILQ_HEAD(h2_field_list_head, tfe_h2_field) h2_field_list;
|
|
|
|
|
|
int nvlen;
|
|
|
|
|
|
uint8_t flag;
|
2019-02-22 15:42:20 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2019-05-31 10:21:40 +08:00
|
|
|
|
struct tfe_h2_half_private
|
2019-02-22 15:42:20 +08:00
|
|
|
|
{
|
|
|
|
|
|
/* PUBLIC STRUCTURE */
|
|
|
|
|
|
struct tfe_http_half half_public;
|
|
|
|
|
|
|
|
|
|
|
|
struct http_frame_session_ctx *frame_ctx;
|
|
|
|
|
|
|
|
|
|
|
|
/* UNDERLAY BUFFER */
|
|
|
|
|
|
int method_or_status;
|
2019-04-30 16:41:01 +08:00
|
|
|
|
int by_stream;
|
2019-02-22 15:42:20 +08:00
|
|
|
|
|
|
|
|
|
|
char * url_storage;
|
2019-05-31 10:21:40 +08:00
|
|
|
|
struct tfe_h2_payload body;
|
|
|
|
|
|
struct tfe_h2_header header;
|
|
|
|
|
|
struct tfe_h2_header promised;
|
2019-02-22 15:42:20 +08:00
|
|
|
|
|
2019-04-30 16:41:01 +08:00
|
|
|
|
/*Read Cache**/
|
|
|
|
|
|
int32_t stream_id;
|
|
|
|
|
|
nghttp2_session *session;
|
2019-05-31 10:21:40 +08:00
|
|
|
|
struct tfe_h2_session *father_session;
|
2019-04-30 16:41:01 +08:00
|
|
|
|
|
2019-05-31 10:21:40 +08:00
|
|
|
|
enum h2_read_state body_state;
|
|
|
|
|
|
enum h2_read_state message_state;
|
2019-02-22 15:42:20 +08:00
|
|
|
|
|
|
|
|
|
|
/* Callback Function */
|
2019-05-31 10:21:40 +08:00
|
|
|
|
int (*event_cb)(struct tfe_h2_half_private * half_private, tfe_http_event ev,
|
2019-02-22 15:42:20 +08:00
|
|
|
|
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 *);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2019-04-30 16:41:01 +08:00
|
|
|
|
struct cache_trapper_t{
|
2019-02-22 15:42:20 +08:00
|
|
|
|
int spd_set;
|
|
|
|
|
|
int spd_valid;
|
|
|
|
|
|
int rse_set;
|
2019-03-29 15:37:18 +08:00
|
|
|
|
int spd_set_cnt;
|
|
|
|
|
|
int spd_cnt;
|
2019-02-22 15:42:20 +08:00
|
|
|
|
tfe_http_event spd_event;
|
2019-04-30 16:41:01 +08:00
|
|
|
|
};
|
2019-02-22 15:42:20 +08:00
|
|
|
|
|
2019-05-31 10:21:40 +08:00
|
|
|
|
struct tfe_h2_session{
|
2019-04-30 16:41:01 +08:00
|
|
|
|
struct tfe_http_session tfe_session;
|
2019-05-31 10:21:40 +08:00
|
|
|
|
TAILQ_ENTRY(tfe_h2_session) next;
|
2019-04-30 16:41:01 +08:00
|
|
|
|
const struct tfe_stream *tf_stream;
|
|
|
|
|
|
|
2019-05-31 10:21:40 +08:00
|
|
|
|
int32_t ngh2_stream_id;
|
|
|
|
|
|
nghttp2_session *session;
|
|
|
|
|
|
struct tfe_h2_stream *father_stream;
|
2019-04-30 16:41:01 +08:00
|
|
|
|
|
|
|
|
|
|
struct cache_trapper_t cache;
|
2019-02-22 15:42:20 +08:00
|
|
|
|
struct http_frame_session_ctx *frame_ctx;
|
2019-05-31 10:21:40 +08:00
|
|
|
|
struct tfe_h2_half_private *req, *plugin_built_req;
|
|
|
|
|
|
struct tfe_h2_half_private *resp, *plugin_built_resp;
|
2019-02-22 15:42:20 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2019-05-31 10:21:40 +08:00
|
|
|
|
struct tfe_h2_stream
|
2019-02-22 15:42:20 +08:00
|
|
|
|
{
|
2019-05-31 10:21:40 +08:00
|
|
|
|
TAILQ_HEAD(list_head, tfe_h2_session) h2_session_list;
|
2019-02-22 15:42:20 +08:00
|
|
|
|
|
2019-03-29 15:37:18 +08:00
|
|
|
|
int goaway;
|
|
|
|
|
|
|
|
|
|
|
|
enum tfe_stream_action stream_action;
|
|
|
|
|
|
|
2019-02-22 15:42:20 +08:00
|
|
|
|
unsigned int thread_id;
|
2019-03-29 15:37:18 +08:00
|
|
|
|
|
2019-02-22 15:42:20 +08:00
|
|
|
|
/** for down stream as server */
|
|
|
|
|
|
nghttp2_session *as_server;
|
|
|
|
|
|
/** for up stream as client*/
|
|
|
|
|
|
nghttp2_session *as_client;
|
|
|
|
|
|
|
|
|
|
|
|
const struct tfe_stream *tf_stream;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
struct stream_tap_info_t
|
|
|
|
|
|
{
|
|
|
|
|
|
/** IS PREEMPTED */
|
|
|
|
|
|
unsigned int preempted;
|
|
|
|
|
|
/** sess manage */
|
2019-05-31 10:21:40 +08:00
|
|
|
|
struct tfe_h2_stream *h2_stream_info;
|
2019-02-22 15:42:20 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define ACTION_USER_DATA 3
|
|
|
|
|
|
|
2019-05-31 10:21:40 +08:00
|
|
|
|
static inline const struct tfe_h2_half_private *
|
2019-02-22 15:42:20 +08:00
|
|
|
|
nghttp2_to_half_private(const struct tfe_http_half * half_public)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!half_public)
|
|
|
|
|
|
return NULL;
|
2019-05-31 10:21:40 +08:00
|
|
|
|
return container_of(half_public, struct tfe_h2_half_private, half_public);
|
2019-02-22 15:42:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-31 10:21:40 +08:00
|
|
|
|
static inline struct tfe_h2_half_private *
|
2019-02-22 15:42:20 +08:00
|
|
|
|
nghttp2_to_half_private(struct tfe_http_half * half_public)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!half_public)
|
|
|
|
|
|
return NULL;
|
2019-05-31 10:21:40 +08:00
|
|
|
|
return container_of(half_public, struct tfe_h2_half_private, half_public);
|
2019-02-22 15:42:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-31 10:21:40 +08:00
|
|
|
|
static inline struct tfe_h2_session *
|
2019-02-22 15:42:20 +08:00
|
|
|
|
nghttp2_to_stream_data(struct tfe_http_session * hs_public)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (hs_public == NULL)
|
|
|
|
|
|
return NULL;
|
2019-05-31 10:21:40 +08:00
|
|
|
|
return container_of(hs_public, struct tfe_h2_session, tfe_session);
|
2019-02-22 15:42:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-05-31 10:21:40 +08:00
|
|
|
|
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,
|
2019-02-22 15:42:20 +08:00
|
|
|
|
unsigned int thread_id);
|
|
|
|
|
|
|
|
|
|
|
|
extern enum tfe_stream_action
|
2019-05-31 10:21:40 +08:00
|
|
|
|
detect_down_stream_protocol(struct tfe_h2_stream *h2_stream_info, const struct tfe_stream *tfe_stream,
|
2019-02-22 15:42:20 +08:00
|
|
|
|
unsigned int thread_id, const unsigned char *data, size_t len);
|
|
|
|
|
|
|
|
|
|
|
|
extern enum tfe_stream_action
|
2019-05-31 10:21:40 +08:00
|
|
|
|
detect_up_stream_protocol(struct tfe_h2_stream *h2_stream_info, const struct tfe_stream *tfe_stream,
|
2019-02-22 15:42:20 +08:00
|
|
|
|
unsigned int thread_id, const unsigned char *data, size_t len);
|
|
|
|
|
|
|
|
|
|
|
|
enum tfe_stream_action
|
2019-05-31 10:21:40 +08:00
|
|
|
|
nghttp2_client_mem_send(struct tfe_h2_stream *h2_stream_info);
|
2019-02-22 15:42:20 +08:00
|
|
|
|
|
|
|
|
|
|
enum tfe_stream_action
|
2019-05-31 10:21:40 +08:00
|
|
|
|
nghttp2_server_mem_send(struct tfe_h2_stream *h2_stream_info);
|
2019-02-22 15:42:20 +08:00
|
|
|
|
|
|
|
|
|
|
/*for test **/
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|