acl/lib_protocol/include/http/lib_http_struct.h

194 lines
6.3 KiB
C
Raw Normal View History

2014-11-19 00:25:21 +08:00
#ifndef __LIB_HTTP_STRUCT_INCLUDE_H__
#define __LIB_HTTP_STRUCT_INCLUDE_H__
#include "lib_acl.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef HTTP_LIB
# ifndef HTTP_API
# define HTTP_API
# endif
#elif defined(HTTP_DLL) || defined(_WINDLL)
# if defined(HTTP_EXPORTS) || defined(protocol_EXPORTS)
# ifndef HTTP_API
# define HTTP_API __declspec(dllexport)
# endif
# elif !defined(HTTP_API)
2014-11-19 00:25:21 +08:00
# define HTTP_API __declspec(dllimport)
# endif
#elif !defined(HTTP_API)
# define HTTP_API
2014-11-19 00:25:21 +08:00
#endif
typedef acl_int64 http_off_t;
/* <20><EFBFBD><E1B9B9><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD> */
typedef struct HTTP_HDR HTTP_HDR;
typedef struct HTTP_HDR_REQ HTTP_HDR_REQ;
typedef struct HTTP_HDR_RES HTTP_HDR_RES;
typedef struct HTTP_REQ HTTP_REQ;
typedef struct HTTP_RES HTTP_RES;
typedef struct HTTP_HDR_ENTRY HTTP_HDR_ENTRY;
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD> */
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еĻػص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><EFBFBD><EFBFBD>
* @param status {int} HTTP_CHAT_XXX
* status:
* HTTP_CHAT_OK: <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ
* HTTP_CHAT_ERR_TOO_MANY_LINES: <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̫<EFBFBD><EFBFBD>
* @param arg {void*} <EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD>
* @return {int} <EFBFBD>ûص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵΪ -1 <EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߱<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>; <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0
* <EFBFBD>ϼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߼<EFBFBD><EFBFBD><EFBFBD>
*/
typedef int (*HTTP_HDR_NOTIFY)(int status, void *arg);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еĻص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ͷ<EFBFBD><EFBFBD><EFBFBD>
* @param status {int} HTTP_CHAT_XXX
* status:
* HTTP_CHAT_OK: <EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> data <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EF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ʾ<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>ÿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* HTTP_CHAT_ERR_PROTO: <EFBFBD><EFBFBD>ʾЭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param data {char *} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD>ʼ<EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>
* @param dlen {int} <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ǰ data <EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
* @return {int} <EFBFBD>ûص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵΪ -1 <EFBFBD><EFBFBD><EFBFBD>ϼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߱<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>; <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 0
* <EFBFBD>ϼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>߼<EFBFBD><EFBFBD><EFBFBD>
*/
typedef int (*HTTP_BODY_NOTIFY)(int status, char *data, int dlen, void *arg);
/* ͨ<>Ź<EFBFBD><C5B9><EFBFBD>״̬<D7B4>ֶ<EFBFBD><D6B6><EFBFBD> */
#define HTTP_CHAT_OK 0 /**< <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#define HTTP_CHAT_CONTINUE 1 /**< <20>ڲ<EFBFBD><DAB2><EFBFBD> */
#define HTTP_CHAT_DATA 2 /**< <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еIJ<D0B5><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#define HTTP_CHAT_CHUNK_HDR 3 /**< <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>е<EFBFBD><D0B5><EFBFBD><EFBFBD><EFBFBD> */
#define HTTP_CHAT_CHUNK_DATA_ENDL 4 /**< <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еķָ<C4B7><D6B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#define HTTP_CHAT_CHUNK_TRAILER 5 /**< <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#define HTTP_CHAT_ERR_MIN 100 /**< <20><>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>Сֵ */
#define HTTP_CHAT_ERR_IO 101 /**< IO<49><4F><EFBFBD><EFBFBD> */
#define HTTP_CHAT_ERR_PROTO 102 /**< <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><DDBB><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD>ݵ<EFBFBD>Э<EFBFBD><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
#define HTTP_CHAT_ERR_TOO_MANY_LINES 103 /**< <20><><EFBFBD><EFBFBD>ͷ̫<CDB7><CCAB><EFBFBD><EFBFBD> */
#define HTTP_CHAT_ERR_MAX 1000 /**< <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Χ */
/* <20><><EFBFBD>õı<C3B5>־λ */
#define HTTP_CHAT_FLAG_BUFFED 0x0001
/* HTTP Э<><D0AD>ͷ<EFBFBD><CDB7><EFBFBD>ֶεĶ<CEB5><C4B6><EFBFBD> */
#define HTTP_HDR_ENTRY_VIA "via" /**< HTTP ͷ<><CDB7><EFBFBD><EFBFBD><EFBFBD>ֶΣ<D6B6><CEA3><EFBFBD>ֹ<EFBFBD>ݹ<EFBFBD><DDB9><EFBFBD><EFBFBD><EFBFBD> */
#define HTTP_HDR_ENTRY_FORWARD_FOR "X-Forwarded-For" /**< HTTP <20><><EFBFBD><EFBFBD>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD>ֶ<EFBFBD> */
/* HTTP Э<><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ṹ */
struct HTTP_REQ {
HTTP_HDR_REQ *hdr_req; /**< <20><> client <20><><EFBFBD><EFBFBD> */
int status; /**< <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>, defined above: HTTP_STATUS_ */
unsigned int flag; /**< defined as: HTTP_CHAT_FLAG_XXX */
void *ctx;
void (*free_ctx)(void*);
};
struct HTTP_RES {
HTTP_HDR_RES *hdr_res; /**< <20><> client <20><><EFBFBD><EFBFBD> */
int read_cnt;
int status; /**< <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>, defined above: HTTP_STATUS_ */
unsigned int flag; /**< defined as: HTTP_CHAT_FLAG_XXX */
void *ctx;
void (*free_ctx)(void*);
};
/* name-value <20><>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD>Ŀ */
struct HTTP_HDR_ENTRY {
char *name;
char *value;
int off;
};
/* HTTP Э<><D0AD>ͷ */
struct HTTP_HDR {
/* ͨ<><CDA8>ʵ<EFBFBD><CAB5> */
char proto[32]; /**< ֧<>ֵ<EFBFBD>Э<EFBFBD><D0AD>: HTTP */
struct {
unsigned int major; /**< <20><><EFBFBD><EFBFBD><E6B1BE> */
unsigned int minor; /**< <20>ΰ汾<CEB0><E6B1BE> */
} version;
int keep_alive; /**< <20>Ƿ񱣳ֳ<F1B1A3B3><D6B3><EFBFBD><EFBFBD><EFBFBD> */
http_off_t content_length; /**< HTTPЭ<50><D0AD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><DDB3><EFBFBD> */
int chunked; /**
* <EFBFBD><EFBFBD><EFBFBD>ֶα<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>HTTPЭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,
* Ϊ<EFBFBD>˽<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ, <EFBFBD>ʶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD>
*/
/* <20>ڲ<EFBFBD><DAB2><EFBFBD><EFBFBD><EFBFBD> */
int cur_lines;
int max_lines;
int valid_lines;
int status;
int keep_alive_count; /**< <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
ACL_ARRAY *entry_lnk; /**< <20><EFBFBD><E6B4A2> HTTP_HDR_ENTRY <20><><EFBFBD>͵<EFBFBD>Ԫ<EFBFBD><D4AA> */
void *chat_ctx;
void (*chat_free_ctx_fn)(void*);
int debug; /**< <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣͷ<CFA2>ı<EFBFBD>־λ */
};
#define HDR_RESTORE(hdr_ptr, hdr_type, hdr_member) \
((hdr_type *) (((char *) (hdr_ptr)) - offsetof(hdr_type, hdr_member)))
/* HTTP <20><><EFBFBD><EFBFBD>ͷ */
struct HTTP_HDR_REQ {
HTTP_HDR hdr; /**< <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD>õ<EFBFBD>HDRͷ, <20><><EFBFBD><EFBFBD>ͨ<EFBFBD>÷<EFBFBD><C3B7><EFBFBD> */
int port; /**< <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD><EFBFBD>˵ķ<CBB5><C4B7><EFBFBD><EFBFBD>˿ں<CBBF> */
/* <20><><EFBFBD><EFBFBD>ʵ<EFBFBD><CAB5> */
char method[32]; /**< <20><><EFBFBD>󷽷<EFBFBD>: POST, GET, CONNECT */
char host[512]; /**< <20><><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IP<49><50>ַ */
ACL_VSTRING *url_part; /**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> URL <EFBFBD>еĺ<EFBFBD><EFBFBD>벿<EFBFBD><EFBFBD>,
* <EFBFBD><EFBFBD>:
* 1) http://test.com.cn/cgi-bin/test?name=value
* => /cgi-bin/test?name=value
*/
ACL_VSTRING *url_path; /**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> URL <EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><EFBFBD><EFBFBD><EFBFBD>(<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>),
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> /path/test.cgi?name=value,
* <EFBFBD><EFBFBD><EFBFBD> /path/test.cgi, ʣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> url_params <EFBFBD>.
*/
ACL_VSTRING *url_params; /**< <20><EFBFBD><E6B4A2> URL <20>еIJ<D0B5><C4B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
ACL_VSTRING *file_path;
ACL_HTABLE *params_table; /**< <20><EFBFBD><E6B4A2> URL <20><><EFBFBD><EFBFBD><EFBFBD>еĸ<D0B5><C4B8><EFBFBD><EFBFBD>ֶε<D6B6><CEB5><EFBFBD><EFBFBD><EFBFBD> */
ACL_HTABLE *cookies_table; /**< <20><EFBFBD>ŵ<EFBFBD> cookie <20><> */
unsigned int flag; /**< <20><>־λ */
#define HTTP_HDR_REQ_FLAG_PARSE_PARAMS (1 << 0)
#define HTTP_HDR_REQ_FLAG_PARSE_COOKIE (1 << 1)
};
/* HTTP <20><>Ӧͷ */
struct HTTP_HDR_RES {
HTTP_HDR hdr; /**< <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD>õ<EFBFBD>HDRͷ, <20><><EFBFBD><EFBFBD>ͨ<EFBFBD>÷<EFBFBD><C3B7><EFBFBD> */
/* <20><>Ӧʵ<D3A6><CAB5> */
int reply_status; /**< <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EBA3AC>: 100, 200, 404, 304, 500 */
};
#ifdef __cplusplus
}
#endif
#endif