commit 900dc5c7ba07c86ffb57f6395e7f67455f9b0521 Author: zhengchao Date: Wed Aug 1 17:47:38 2018 +0800 第一版讨论稿。 diff --git a/interface/future.cpp b/interface/future.cpp new file mode 100644 index 0000000..43ef0c1 --- /dev/null +++ b/interface/future.cpp @@ -0,0 +1,37 @@ + +enum e_future_error +{ + FUTURE_ERROR_CANCEL + FUTURE_ERROR_EXCEPTION, + FUTURE_ERROR_TIMEOUT +} + +typedef void (*future_cb_success_t)(void * result, void * user); +typedef void (*future_cb_failed_t)(enum e_future_error err, const char * what, void * user); + +struct future +{ + void * user; + future_cb_success_t * cb_success; + future_cb_failed_t * cb_failed; +}; + +struct promise +{ + struct future f; + void * ctx; +} + +typedef void * promise_t; +void future_cancel(struct future * future) +{ + future->cancel(); +} + +void promise_success(struct promisc *, void * result); +void promise_fail(); + +struct future * XXXXXRpc() +{ + cancel = ___XXXXCancel() +}; \ No newline at end of file diff --git a/interface/tfe_connection.h b/interface/tfe_connection.h new file mode 100644 index 0000000..2d32eff --- /dev/null +++ b/interface/tfe_connection.h @@ -0,0 +1,52 @@ + +#define TFE_STRING_MAX 2048 +#define TFE_SYMBOL_MAX 64 +struct tfe_conn_ctx +{ + sockaddr_t dst; + struct pxy_conn_desc src; + struct pxy_conn_desc dst; + int cur_dir//1: c2s; 2:s2c + char* sni; +}; +struct tfe_conn_inner +{ + int a; + struct tfe_conn_ctx conn_desc; + void **proto_arg; +}; + + +//Return 1 for identify as its ttraffic; +//Return 0 for unknown traffic; +typedef int proto_pend_cb_t(const struct tfe_conn_ctx* c, struct evbuffer *data, void **pme); + +enum tfe_proto_action +{ + PROTO_ATCION_FORWARD, + PROTO_ACTION_DEFER, + PROTO_ACTION_STEAL, + PROTO_ACTION_PASSTHROUGH, + PROTO_ACTION_CLOSE +}; + +typedef tfe_proto_action proto_read_cb_t(const struct tfe_conn_ctx* ctx, struct evbuffer *data, void **pme); + +typedef void proto_close_cb_t(const struct tfe_conn_ctx* ctx, int ev, void **pme); + +//typedef int proto_onwrite_cb_t(struct tfe_conn_ctx*, struct evbuffer *data, void **pme); + +struct tfe_proto_module +{ + char symbol[TFE_SYMBOL_MAX]; + proto_pend_cb_t *on_pend; + proto_read_cb_t *on_read; + proto_close_cb_t *on_close; +// proto_onwrite_cb_t *onwrite; + +}; +int tfe_io_write(struct pxy_conn_desc* dest,int dir,struct evbuffer *data); + +int tfe_xxx_proto_init(struct tfe_proto_module*m); + + diff --git a/interface/tfe_http.h b/interface/tfe_http.h new file mode 100644 index 0000000..d514d61 --- /dev/null +++ b/interface/tfe_http.h @@ -0,0 +1,149 @@ +#include "tfe_connection.h" +#include + +struct tfe_http_req_spec +{ + int method; + 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; +}; +#define HTTP_REQUEST 1 +#define HTTP_RESPONSE 2 +struct tfe_http_half +{ + int direction; //HTTP_REQUEST or HTTP_RESPONSE + 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 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; +}; +enum tfe_http_std_field +{ + HTTP_UNKNOWN_FIELD=0, + HTTP_MESSAGE_URL, + HTTP_URI, + HTTP_HOST, + HTTP_REFERER, + HTTP_USER_AGENT, + HTTP_COOKIE, + HTTP_PROXY_AUTHORIZATION, + HTTP_AUTHORIZATION, + HTTP_LOCATION, + HTTP_SERVER, + HTTP_ETAG , + HTTP_DATE , + HTTP_TRAILER , + HTTP_TRANSFER_ENCODING, + HTTP_VIA, + HTTP_PRAGMA, + HTTP_CONNECTION, + HTTP_CONT_ENCODING, + HTTP_CONT_LANGUAGE, + HTTP_CONT_LOCATION, + HTTP_CONT_RANGE, + HTTP_CONT_LENGTH, + HTTP_CONT_TYPE, + HTTP_CONT_DISPOSITION, + HTTP_CHARSET, + HTTP_EXPIRES, + HTTP_X_FLASH_VERSION, + 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. +}; + +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); + +//@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); + +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); + +//******obsolete + +//int tfe_http_field_read_func(const struct tfe_http_half* half, const char* name, char* value, size_t size); + +enum http_ev_bit_number +{ + REQ_HDR_BITNUM=0, + REQ_BODY_BEGIN_BITNUM, + REQ_BODY_CONT_BITNUM, + REQ_BODY_END_BITNUM, + RESP_HDR_BITNUM, + RESP_BODY_BEGIN_BITNUM, + RESP_BODY_CONT_BITNUM, + RESP_BODY_END_BITNUM +}; +#define EV_HTTP_REQ_HDR ((uint64_t)1<