2018-09-06 10:12:08 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
2018-09-17 15:44:44 +08:00
|
|
|
#include <tfe_http.h>
|
|
|
|
|
#include <http_parser.h>
|
|
|
|
|
#include <sys/queue.h>
|
|
|
|
|
|
|
|
|
|
typedef int (hf_private_cb)(struct http_half_private * hf_private,
|
|
|
|
|
tfe_http_event ev, const unsigned char * data, size_t len, void * user);
|
|
|
|
|
|
|
|
|
|
enum hf_private_status
|
|
|
|
|
{
|
|
|
|
|
STATUS_INIT,
|
|
|
|
|
STATUS_READING,
|
|
|
|
|
STATUS_COMPLETE,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct http_header_private
|
|
|
|
|
{
|
|
|
|
|
TAILQ_ENTRY(http_header_private) next;
|
|
|
|
|
struct http_field_name * field;
|
|
|
|
|
char * value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TAILQ_HEAD(http_header_private_list, http_header_private);
|
|
|
|
|
struct http_half_private
|
|
|
|
|
{
|
|
|
|
|
/* PUBLIC STRUCTURE */
|
|
|
|
|
struct tfe_http_half hf_public;
|
|
|
|
|
/* SESSION OF THIS REQUEST/RESPONSE */
|
|
|
|
|
struct http_session_private * session;
|
|
|
|
|
/* Callback Function */
|
|
|
|
|
hf_private_cb * event_cb;
|
|
|
|
|
/* Callback Function User Pointer */
|
|
|
|
|
void * event_cb_user;
|
|
|
|
|
/* Callback Function User Pointer Deleter */
|
|
|
|
|
void (* event_cb_user_deleter)(void *);
|
|
|
|
|
/* HTTP PARSER */
|
|
|
|
|
struct http_parser * parse_object;
|
|
|
|
|
/* HTTP PARSER SETTING */
|
|
|
|
|
struct http_parser_settings * parse_settings;
|
|
|
|
|
/* CURSOR RELATED TO DELAYED DATA */
|
|
|
|
|
size_t parse_cursor;
|
|
|
|
|
/* HTTP PARSER'S ERRNO */
|
|
|
|
|
enum http_errno parse_errno;
|
|
|
|
|
/* HEADER K-V */
|
|
|
|
|
struct http_header_private_list header_list;
|
|
|
|
|
|
|
|
|
|
/* UNDERLAY BUFFER */
|
|
|
|
|
int method_or_status;
|
|
|
|
|
short major;
|
|
|
|
|
short minor;
|
|
|
|
|
|
|
|
|
|
struct evbuffer * evbuf_uri;
|
2018-09-23 20:01:11 +08:00
|
|
|
char * url_storage;
|
2018-09-18 18:50:25 +08:00
|
|
|
|
2018-09-17 15:44:44 +08:00
|
|
|
struct evbuffer * evbuf_header_field;
|
|
|
|
|
struct evbuffer * evbuf_header_value;
|
2018-09-18 18:50:25 +08:00
|
|
|
bool is_evbuf_header_field_set;
|
|
|
|
|
bool is_evbuf_header_value_set;
|
|
|
|
|
|
2018-09-17 15:44:44 +08:00
|
|
|
struct evbuffer * evbuf_body;
|
|
|
|
|
|
|
|
|
|
enum hf_private_status body_status;
|
|
|
|
|
enum hf_private_status message_status;
|
|
|
|
|
|
|
|
|
|
/* default stream action */
|
|
|
|
|
enum tfe_stream_action stream_action;
|
|
|
|
|
enum tfe_stream_action user_stream_action;
|
|
|
|
|
};
|
|
|
|
|
|
2018-09-06 10:12:08 +08:00
|
|
|
struct http_half_private * hf_private_create(tfe_http_direction ht_dir, short major, short minor);
|
2018-09-18 18:50:25 +08:00
|
|
|
|
2018-09-06 10:12:08 +08:00
|
|
|
void hf_private_destory(struct http_half_private * hf_private);
|
|
|
|
|
|
|
|
|
|
/** Parse the raw tcp input for HTTP half structure
|
|
|
|
|
* @param hf_private
|
|
|
|
|
* hf_private handler.
|
|
|
|
|
* @param data
|
|
|
|
|
* raw tcp data, used in the stream's callback.
|
|
|
|
|
* @param len
|
|
|
|
|
* raw tcp data length.
|
|
|
|
|
* @return
|
|
|
|
|
* 0 for need more data,
|
|
|
|
|
* 1 for reach the boundary, need to call http business callbacks,
|
|
|
|
|
* -1 for error.
|
|
|
|
|
*/
|
|
|
|
|
int hf_private_parse(struct http_half_private * hf_private, const unsigned char * data, size_t len);
|
2018-09-17 15:44:44 +08:00
|
|
|
|
|
|
|
|
void hf_private_set_callback(struct http_half_private * hf_private, hf_private_cb * cb,
|
|
|
|
|
void * user, void (* fn_user_deleter)(void *));
|
|
|
|
|
|
2018-09-18 18:50:25 +08:00
|
|
|
void hf_private_set_session(struct http_half_private * hf_private, struct http_session_private * hs_private);
|
|
|
|
|
|
2018-09-17 15:44:44 +08:00
|
|
|
struct http_session_private * hs_private_create(struct http_connection_private * hc_private,
|
|
|
|
|
struct http_half_private * hf_private_req, struct http_half_private * hf_private_resp);
|
2018-09-21 15:03:33 +08:00
|
|
|
|
|
|
|
|
void hs_private_destory(struct http_session_private * hs_private);
|
2018-09-23 17:33:05 +08:00
|
|
|
|
|
|
|
|
void hs_private_hf_private_set(struct http_session_private * hs_private,
|
|
|
|
|
struct http_half_private * hf, enum tfe_http_direction);
|
|
|
|
|
|
|
|
|
|
struct http_half_private * hs_private_hf_private_release(struct http_session_private * hs_private, enum tfe_http_direction);
|