增加HTTP解析层目录结构,增加插件自注册功能。
* 增加HTTP解析层目录结构,集成CMakeLists.txt编译文件; * 调整编译顺序,先编译插件再编译平台; * 增加TFE_PLUGIN_REGISTER宏,在TFE启动时自注册插件; * 修改了stream_open接口,在插件流初始化接口不传入数据。
This commit is contained in:
@@ -1,55 +1,58 @@
|
||||
|
||||
#include <tfe_future.h>
|
||||
#include <tfe_connection.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct tfe_http_req_spec
|
||||
{
|
||||
int method;
|
||||
char* uri;
|
||||
char* host;
|
||||
char* url; //uri+host
|
||||
char* accept_encoding;
|
||||
char * uri;
|
||||
char * host;
|
||||
char * url; //uri+host
|
||||
char * accept_encoding;
|
||||
};
|
||||
struct tfe_http_resp_spec
|
||||
{
|
||||
int resp_code;
|
||||
int major_version; //HTTP/1.x or HTTP/ 2
|
||||
int minor_version; //HTTP 1.1 or 1.0
|
||||
char* content_encoding;
|
||||
int major_version; //HTTP/1.x or HTTP/ 2
|
||||
int minor_version; //HTTP 1.1 or 1.0
|
||||
char * content_encoding;
|
||||
};
|
||||
|
||||
#define HTTP_REQUEST 1
|
||||
#define HTTP_RESPONSE 2
|
||||
enum tfe_http_direction
|
||||
{
|
||||
TFE_HTTP_REQUEST = 1,
|
||||
TFE_HTTP_RESPONSE = 2
|
||||
};
|
||||
|
||||
struct tfe_http_half
|
||||
{
|
||||
int direction; //HTTP_REQUEST or HTTP_RESPONSE
|
||||
enum tfe_http_direction direction;
|
||||
union
|
||||
{
|
||||
struct tfe_http_req_spec req_spec;
|
||||
struct tfe_http_resp_spec resp_spec;
|
||||
};
|
||||
|
||||
size_t field_cnt;
|
||||
uint64_t cont_len;
|
||||
uint64_t cont_range_from;
|
||||
uint64_t cont_range_to;
|
||||
struct evbuffer *body;
|
||||
void * fields; //hide by protocol layer
|
||||
struct evbuffer * body;
|
||||
void * fields; //hide by protocol layer
|
||||
};
|
||||
|
||||
struct tfe_http_session
|
||||
{
|
||||
int session_sequence;//?
|
||||
int major_version;//1:HTTP 1.x, 2:HTTP 2
|
||||
struct tfe_http_half* req;
|
||||
struct tfe_http_half* resp;//value is NULL before response received.
|
||||
void* proto_spec;
|
||||
struct tfe_http_half * req;
|
||||
struct tfe_http_half * resp;//value is NULL before response received.
|
||||
void * proto_spec;
|
||||
};
|
||||
|
||||
enum tfe_http_std_field
|
||||
{
|
||||
HTTP_UNKNOWN_FIELD=0,
|
||||
HTTP_UNKNOWN_FIELD = 0,
|
||||
HTTP_MESSAGE_URL,
|
||||
HTTP_URI,
|
||||
HTTP_HOST,
|
||||
@@ -60,9 +63,9 @@ enum tfe_http_std_field
|
||||
HTTP_AUTHORIZATION,
|
||||
HTTP_LOCATION,
|
||||
HTTP_SERVER,
|
||||
HTTP_ETAG ,
|
||||
HTTP_DATE ,
|
||||
HTTP_TRAILER ,
|
||||
HTTP_ETAG,
|
||||
HTTP_DATE,
|
||||
HTTP_TRAILER,
|
||||
HTTP_TRANSFER_ENCODING,
|
||||
HTTP_VIA,
|
||||
HTTP_PRAGMA,
|
||||
@@ -77,18 +80,18 @@ enum tfe_http_std_field
|
||||
HTTP_CHARSET,
|
||||
HTTP_EXPIRES,
|
||||
HTTP_X_FLASH_VERSION,
|
||||
HTTP_TRANSFER_LENGTH
|
||||
HTTP_TRANSFER_LENGTH
|
||||
};
|
||||
|
||||
struct http_field_name
|
||||
{
|
||||
enum tfe_http_std_field field_id;
|
||||
char* field_name; //Non-NULL when field_id isHTTP_UNKNOWN_FIELD.
|
||||
char * field_name; //Non-NULL when field_id isHTTP_UNKNOWN_FIELD.
|
||||
};
|
||||
|
||||
const char* tfe_http_field_read(const struct tfe_http_half* half, const struct http_field_name* name);
|
||||
int tfe_http_field_to_range(const char* field_value, long* range_from, long* range_to);
|
||||
int tfe_http_field_to_digit(const char* field_value, long* digit);
|
||||
const char * tfe_http_field_read(const struct tfe_http_half * half, const struct http_field_name * name);
|
||||
int tfe_http_field_to_range(const char * field_value, long * range_from, long * range_to);
|
||||
int tfe_http_field_to_digit(const char * field_value, long * digit);
|
||||
|
||||
//******obsolete
|
||||
//long tfe_http_read_num_field(const struct tfe_http_half* half, const struct http_field_name* name);
|
||||
@@ -96,13 +99,13 @@ int tfe_http_field_to_digit(const char* field_value, long* digit);
|
||||
//@Input param interator: NULL to get the first field.
|
||||
//@Output param name:
|
||||
//@return: field value.
|
||||
const char* tfe_http_field_iterate(const struct tfe_http_half* half, void* interator, struct http_field_name* name);
|
||||
const char * tfe_http_field_iterate(const struct tfe_http_half * half, void * interator, struct http_field_name * name);
|
||||
|
||||
struct tfe_http_half* tfe_http_allow_write(const struct tfe_http_half* half);
|
||||
struct tfe_http_half * tfe_http_allow_write(const struct tfe_http_half * half);
|
||||
|
||||
//@param value: NULL for delete
|
||||
//@param name: Could be CHUNK/ENCODING
|
||||
int tfe_http_field_write(struct tfe_http_half* half, const struct http_field_name* name, const char* value);
|
||||
int tfe_http_field_write(struct tfe_http_half * half, const struct http_field_name * name, const char * value);
|
||||
|
||||
//******obsolete
|
||||
|
||||
@@ -110,7 +113,7 @@ int tfe_http_field_write(struct tfe_http_half* half, const struct http_field_nam
|
||||
|
||||
enum http_ev_bit_number
|
||||
{
|
||||
REQ_HDR_BITNUM=0,
|
||||
REQ_HDR_BITNUM = 0,
|
||||
REQ_BODY_BEGIN_BITNUM,
|
||||
REQ_BODY_CONT_BITNUM,
|
||||
REQ_BODY_END_BITNUM,
|
||||
@@ -119,20 +122,21 @@ enum http_ev_bit_number
|
||||
RESP_BODY_CONT_BITNUM,
|
||||
RESP_BODY_END_BITNUM
|
||||
};
|
||||
#define EV_HTTP_REQ_HDR ((uint64_t)1<<REQ_HDR_BITNUM)
|
||||
#define EV_HTTP_SESSION_BEGIN EV_HTTP_REQ_HDR
|
||||
#define EV_HTTP_REQ_BODY_BEGIN ((uint64_t)1<<REQ_HDR_BITNUM)
|
||||
#define EV_HTTP_REQ_BODY_CONT ((uint64_t)1<<REQ_BODY_CONT_BITNUM)
|
||||
#define EV_HTTP_REQ_BODY_END ((uint64_t)1<<REQ_BODY_END_BITNUM)
|
||||
#define EV_HTTP_REQ_BODY_FULL (EV_HTTP_REQ_BODY_BEGIN|EV_HTTP_REQ_BODY_CONT|EV_HTTP_REQ_BODY_END)
|
||||
#define EV_HTTP_REQ_END EV_HTTP_REQ_BODY_END
|
||||
#define EV_HTTP_RESP_HDR ((uint64_t)1<<RESP_HDR_BITNUM)
|
||||
#define EV_HTTP_RESP_BODY_BEGIN ((uint64_t)1<<RESP_BODY_BEGIN_BITNUM)
|
||||
#define EV_HTTP_RESP_BODY_CONT ((uint64_t)1<<RESP_BODY_CONT_BITNUM)
|
||||
#define EV_HTTP_RESP_BODY_END ((uint64_t)1<<RESP_BODY_END_BITNUM)
|
||||
#define EV_HTTP_RESP_BODY_FULL (EV_HTTP_RESP_BODY_BEGIN|EV_HTTP_RESP_BODY_CONT|EV_HTTP_RESP_BODY_END)
|
||||
#define EV_HTTP_RESP_END EV_HTTP_RESP_BODY_END
|
||||
#define EV_HTTP_SESSION_END EV_HTTP_RESP_END
|
||||
|
||||
#define EV_HTTP_REQ_HDR ((uint64_t)1<<REQ_HDR_BITNUM)
|
||||
#define EV_HTTP_SESSION_BEGIN EV_HTTP_REQ_HDR
|
||||
#define EV_HTTP_REQ_BODY_BEGIN ((uint64_t)1<<REQ_HDR_BITNUM)
|
||||
#define EV_HTTP_REQ_BODY_CONT ((uint64_t)1<<REQ_BODY_CONT_BITNUM)
|
||||
#define EV_HTTP_REQ_BODY_END ((uint64_t)1<<REQ_BODY_END_BITNUM)
|
||||
#define EV_HTTP_REQ_BODY_FULL (EV_HTTP_REQ_BODY_BEGIN|EV_HTTP_REQ_BODY_CONT|EV_HTTP_REQ_BODY_END)
|
||||
#define EV_HTTP_REQ_END EV_HTTP_REQ_BODY_END
|
||||
#define EV_HTTP_RESP_HDR ((uint64_t)1<<RESP_HDR_BITNUM)
|
||||
#define EV_HTTP_RESP_BODY_BEGIN ((uint64_t)1<<RESP_BODY_BEGIN_BITNUM)
|
||||
#define EV_HTTP_RESP_BODY_CONT ((uint64_t)1<<RESP_BODY_CONT_BITNUM)
|
||||
#define EV_HTTP_RESP_BODY_END ((uint64_t)1<<RESP_BODY_END_BITNUM)
|
||||
#define EV_HTTP_RESP_BODY_FULL (EV_HTTP_RESP_BODY_BEGIN|EV_HTTP_RESP_BODY_CONT|EV_HTTP_RESP_BODY_END)
|
||||
#define EV_HTTP_RESP_END EV_HTTP_RESP_BODY_END
|
||||
#define EV_HTTP_SESSION_END EV_HTTP_RESP_END
|
||||
|
||||
enum tfe_bussiness_action
|
||||
{
|
||||
@@ -145,19 +149,19 @@ enum tfe_bussiness_action
|
||||
|
||||
//@param event: bit AND of EV_HTTP_**
|
||||
//@param body_frag: NULL for no body data.
|
||||
typedef tfe_bussiness_action (*http_read_func)(const struct tfe_stream* stream,
|
||||
const struct tfe_http_session* session, uint64_t event,struct evbuffer *body_frag, void **pme);
|
||||
typedef tfe_bussiness_action (* http_read_func)(const struct tfe_stream * stream,
|
||||
const struct tfe_http_session * session, uint64_t event, struct evbuffer * body_frag, void ** pme);
|
||||
|
||||
struct tfe_http_half *tfe_http_request_create(int major_version,int method, const char* uri, const char* host);
|
||||
struct tfe_http_half *tfe_http_response_create(int major_version,int resp_code);
|
||||
struct tfe_http_half * tfe_http_request_create(int major_version, int method, const char * uri, const char * host);
|
||||
struct tfe_http_half * tfe_http_response_create(int major_version, int resp_code);
|
||||
|
||||
//@flag EV_HTTP_RESP_BODY_END, EV_HTTP_RESP_BODY_FULL,
|
||||
//suspend stream on EV_HTTP_REQ_BODY_BEGIN, resume when EV_HTTP_REQ_BODY_END.
|
||||
int tfe_http_append_body(const struct tfe_http_half* half, char* buff, size_t size, int flag);
|
||||
void tfe_http_half_free(struct tfe_http_half *half);
|
||||
int tfe_http_append_body(const struct tfe_http_half * half, char * buff, size_t size, int flag);
|
||||
void tfe_http_half_free(struct tfe_http_half * half);
|
||||
|
||||
//@param half: ownership has been transfered to session, do NOT free half after setting.
|
||||
void tfe_http_session_set_half(const struct tfe_http_session* session, struct tfe_http_half* half);
|
||||
void tfe_http_session_set_half(const struct tfe_http_session * session, struct tfe_http_half * half);
|
||||
|
||||
/*
|
||||
handler_
|
||||
@@ -179,4 +183,4 @@ rpc_finish_cb_
|
||||
{
|
||||
tfe_http_write_finish();
|
||||
};
|
||||
*/
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user