acl/lib_protocol/include/http/lib_http.h

746 lines
31 KiB
C
Raw Normal View History

#ifndef __LIB_HTTP_INCLUDE_H__
2014-11-19 00:25:21 +08:00
#define __LIB_HTTP_INCLUDE_H__
#include "lib_http_status.h"
#include "lib_http_struct.h"
#ifdef __cplusplus
extern "C" {
#endif
/*---------------------------- 通用 HTTP 头操作函数 --------------------------*/
2014-11-19 00:25:21 +08:00
/* in http_hdr.c */
/**
* HTTP协议头的结构对象
* @param size {size_t} , HTTP_HDR_REQ HTTP_HDR_RES
* @return {HTTP_HDR*} !NULL: HTTP_HDR结构指针; NULL: .
2014-11-19 00:25:21 +08:00
*/
HTTP_API HTTP_HDR *http_hdr_new(size_t size);
/**
* HTTP通用头拷贝内部成员变量至一个新的HTTP通用头结构中
* @param src {const HTTP_HDR*} HTTP通用头对象
* @param dst {HTTP_HDR*} HTTP通用头对象
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_hdr_clone(const HTTP_HDR *src, HTTP_HDR *dst);
/**
* HTTP_HDR结构内存
* @param hh {HTTP_HDR*}
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_hdr_free(HTTP_HDR *hh);
/**
* HTTP通用头的状态keep-alive的长连接多次请求
* @param hh {HTTP_HDR*} HTTP通用头类型的数据指针
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_hdr_reset(HTTP_HDR *hh);
/**
* HTTP_HDR
* @param hh {HTTP_HDR*}
* @param entry {HTTP_HDR_ENTRY*} HTTP头条目结构指针,
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_hdr_append_entry(HTTP_HDR *hh, HTTP_HDR_ENTRY *entry);
/**
* , , /HTTP头结构内
* @param hh {HTTP_HDR*}
* @param data {const char*} : HTTP/1.0
2014-11-19 00:25:21 +08:00
* @return {int} 0: OK; < 0: error.
*/
HTTP_API int http_hdr_parse_version(HTTP_HDR *hh, const char *data);
/**
* HTTP协议头并存储在 hh
* @param hh {HTTP_HDR*} HTTP头类型的数据指针
2014-11-19 00:25:21 +08:00
* @return {int} 0: ok; < 0: error
*/
HTTP_API int http_hdr_parse(HTTP_HDR *hh);
/**
* name, value HTTP_HDR_ENTRY
* @param name {const char*}
* @param value {const char*}
* @return {HTTP_HDR_ENTRY*}
2014-11-19 00:25:21 +08:00
*/
HTTP_API HTTP_HDR_ENTRY *http_hdr_entry_build(const char *name, const char *value);
/**
* , HTTP_HDR_ENTRY
* @param data {const char*} HTTP , : Content-Length: 200
2014-11-19 00:25:21 +08:00
* @return {HTTP_HDR_ENTRY*} !NULL: ok; NULL: err.
*/
HTTP_API HTTP_HDR_ENTRY *http_hdr_entry_new(const char *data);
HTTP_API HTTP_HDR_ENTRY *http_hdr_entry_head(char *data);
HTTP_API HTTP_HDR_ENTRY *http_hdr_entry_new2(char *data);
/**
* HTTP_HDR_ENTRY
* @param hh {HTTP_HDR*} HTTP头类型的数据指针
* @param name {const char*} HTTP_HDR_ENTRY , . : Content-Length.
* @return ret {HTTP_HDR_ENTRY *} ret != NULL: ok; ret == NULL: .
2014-11-19 00:25:21 +08:00
*/
HTTP_API HTTP_HDR_ENTRY *http_hdr_entry(const HTTP_HDR *hh, const char *name);
/**
* HTTP协议头里某个实体头的变量值Host: www.test.com
* Host 便 www.test.com
* @param hh {HTTP_HDR*} HTTP头类型的数据指针
* @param name {const char*} HTTP_HDR_ENTRY , . : Content-Length
* @return ret {char*} ret != NULL: ok; ret == NULL: .
2014-11-19 00:25:21 +08:00
*/
HTTP_API char *http_hdr_entry_value(const HTTP_HDR *hh, const char *name);
/**
* HTTP , keep-alive
* @param hh {HTTP_HDR*} HTTP头类型的数据指针
* @param name {const char*} HTTP_HDR_ENTRY , . : Content-Length
* @param value {const char*} name
* @param force {int} HTTP请求里不存在, entry
* , 0, name在请求里不存在则不添加.
* @return {int} 0 ; < 0 name HTTP请求头里不存在
2014-11-19 00:25:21 +08:00
*/
HTTP_API int http_hdr_entry_replace(HTTP_HDR *hh, const char *name, const char *value, int force);
/**
* HTTP ,
* @param hh {HTTP_HDR*} HTTP头类型的数据指针
* @param name {const char*} HTTP_HDR_ENTRY , . : Cookie
* @param from {const char*}
* @param to {const char*}
* @param ignore_case {int}
* @return {int} 0: , > 0:
2014-11-19 00:25:21 +08:00
*/
HTTP_API int http_hdr_entry_replace2(HTTP_HDR *hh, const char *name,
const char *from, const char *to, int ignore_case);
/**
* HTTP协议头中的某项
* @param hh {HTTP_HDR* } HTTP头类型的数据指针
* @param name {const char*} HTTP_HDR_ENTRY , . : Content-Length
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_hdr_entry_off(HTTP_HDR *hh, const char *name);
/**
* HTTP协议头部数据
* @param hh {HTTP_HDR*} HTTP头类型的数据指针
* @param msg {const char*} ,
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_hdr_print(const HTTP_HDR *hh, const char *msg);
/**
* HTTP协议头部数据
* @param fp {ACL_VSTREAM*} ()
* @param hh {HTTP_HDR*} HTTP头类型的数据指针
* @param msg {const char*} ,
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_hdr_fprint(ACL_VSTREAM *fp, const HTTP_HDR *hh, const char *msg);
2015-02-02 16:50:06 +08:00
/**
* HTTP协议头部数据
* @param bf {ACL_VSTRING*}
* @param hh {HTTP_HDR*} HTTP头类型的数据指针
* @param msg {const char*} ,
2015-02-02 16:50:06 +08:00
*/
HTTP_API void http_hdr_sprint(ACL_VSTRING *bf, const HTTP_HDR *hh, const char *msg);
/*-------------------------------- HTTP 请求头操作函数 -----------------------*/
2014-11-19 00:25:21 +08:00
/* in http_hdr_req.c */
/**
* HTTP URI ? ( %3F)
* @param onoff {int} 0 1
*/
HTTP_API void http_uri_correct(int onoff);
2014-11-19 00:25:21 +08:00
/**
* HTTP协议头对象
* @return {HTTP_HDR_REQ*} HTTP请求头对象
2014-11-19 00:25:21 +08:00
*/
HTTP_API HTTP_HDR_REQ *http_hdr_req_new(void);
/**
* URLHTTP版本创建一个HTTP请求头对象
* @param url {const char*} URLURL
2014-11-19 00:25:21 +08:00
* http://www.test.com/path/proc?name=value
* http://www.test.com/path/proc
* http://www.test.com/
* @param method {const char*} HTTP请求方法
* GET, POST, CONNECT, HEAD,
* @param version {const char *} HTTP版本
2014-11-19 00:25:21 +08:00
* HTTP/1.0, HTTP/1.1
* @return {HTTP_HDR_REQ*} HTTP请求头对象
2014-11-19 00:25:21 +08:00
*/
HTTP_API HTTP_HDR_REQ *http_hdr_req_create(const char *url,
const char *method, const char *version);
/**
* HTTP请求头对象 chat_ctx, chat_free_ctx_fn
*
* @param hdr_req {const HTTP_HDR_REQ*} HTTP请求头对象
* @return {HTTP_HDR_REQ*} HTTP请求头对象
2014-11-19 00:25:21 +08:00
*/
HTTP_API HTTP_HDR_REQ *http_hdr_req_clone(const HTTP_HDR_REQ* hdr_req);
/**
* HTTP请求头内容及重定向的URL产生一个新的HTTP请求头
* @param hh {const HTTP_HDR_REQ*} HTTP请求头对象
* @param url {const char *} URL http[s]:// 前缀,则认为
* URL Host URL中提取HTTP请求头中
* Host
* @return {HTTP_HDR_REQ*} HTTP请求头
2014-11-19 00:25:21 +08:00
*/
HTTP_API HTTP_HDR_REQ *http_hdr_req_rewrite(const HTTP_HDR_REQ *hh, const char *url);
/**
* HTTP请求头内容及重定向的URL重新设置该HTTP请求头的信息
* @param hh {const HTTP_HDR_REQ*} HTTP请求头对象
* @param url {const char *} URL http[s]:// 前缀,则认为
* URL Host URL中提取HTTP请求头中
* Host
2014-11-19 00:25:21 +08:00
* @return {int} 0: ok; < 0: error
*/
HTTP_API int http_hdr_req_rewrite2(HTTP_HDR_REQ *hh, const char *url);
/**
* HTTP请求头对象
* @param hh {HTTP_HDR_REQ*} HTTP请求头对象
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_hdr_req_free(HTTP_HDR_REQ *hh);
/**
* HTTP请求头对象的成员变量释放并重新初始化
* @param hh {HTTP_HDR_REQ*} HTTP请求头对象
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_hdr_req_reset(HTTP_HDR_REQ *hh);
/**
* HTTP协议头的cookies
* @param hh {HTTP_HDR_REQ*} HTTP请求头类型的数据指针
2014-11-19 00:25:21 +08:00
* @return {int} 0: ok; -1: err.
*/
HTTP_API int http_hdr_req_cookies_parse(HTTP_HDR_REQ *hh);
/**
* HTTP请求首行数据(: GET /cgi-bin/test.cgi?name=value&name2=value2 HTTP/1.0)
* (GET)-->hdr_request_method
* URL数据分析结果(name=value)-->hdr_request_table
* HTTP协议版本号(HTTP/1.0)-->hdr_request_proto
* URL数据中的路径部分(/cgi-bin/test.cgi)-->hdr_request_url
* @param hh {HTTP_HDR_REQ*} HTTP请求头类型的数据指针
2014-11-19 00:25:21 +08:00
* @return {int} 0: ok; -1: err.
*/
HTTP_API int http_hdr_req_line_parse(HTTP_HDR_REQ *hh);
/**
* HTTP请求头协议数据, http_hdr_req_line_parse, http_hdr_req_cookies_parse
* @param hh {HTTP_HDR_REQ*} HTTP请求头类型的数据指针
2014-11-19 00:25:21 +08:00
* @return {int} 0: ok; -1: err.
*/
HTTP_API int http_hdr_req_parse(HTTP_HDR_REQ *hh);
/**
* HTTP请求头协议数据, http_hdr_req_line_parse, http_hdr_req_cookies_parse
* parse_params 0 HTTP请求 url ; parse_cookie 0
* HTTP请求中的 cookie
* @param hh {HTTP_HDR_REQ*} HTTP请求头类型的数据指针
* @param parse_params {int} url
* @param parse_cookie {int} cookie
2014-11-19 00:25:21 +08:00
* @return {int} 0: ok; -1: err.
*/
HTTP_API int http_hdr_req_parse3(HTTP_HDR_REQ *hh, int parse_params, int parse_cookie);
/**
* HTTP请求头中获得某个cookie值
* @param hh {HTTP_HDR_REQ*) HTTP请求头类型的数据指针
* @param name {const char*} cookie的变量名,
* @return {const char*} !NULL: cookie; NULL: cookie不存在
2014-11-19 00:25:21 +08:00
*/
HTTP_API const char *http_hdr_req_cookie_get(HTTP_HDR_REQ *hh, const char *name);
/**
* HTTP请求头中取得HTTP请求的方法, : POST, GET, CONNECT
* @param hh {const HTTP_HDR_REQ*} HTTP请求头类型的数据指针
* @return {const char*} . NULL: error; !NULL: OK.
2014-11-19 00:25:21 +08:00
*/
2019-06-06 13:46:23 +08:00
HTTP_API const char *http_hdr_req_method(const HTTP_HDR_REQ *hh);
2014-11-19 00:25:21 +08:00
/**
* HTTP请求头中获取请求URL中某个请求字段的数据,
* : /cgi-bin/test.cgi?n1=v1&n2=v2 n2的值v2
* @param hh {const HTTP_HDR_REQ*} HTTP请求头类型的数据指针
* @param name {const char*}
* @return {const char*} !NULL: ok, ; NULL: .
2014-11-19 00:25:21 +08:00
*/
2019-06-06 13:46:23 +08:00
HTTP_API const char *http_hdr_req_param(const HTTP_HDR_REQ *hh, const char *name);
2014-11-19 00:25:21 +08:00
/**
* HTTP请求头中获取请求行中的访问路径部分, .
* :
2014-11-19 00:25:21 +08:00
* GET /cgi-bin/test.cgi?n1=v1&n2=v2 HTTP/1.1
* or
* GET http://www.test.com[:80]/cgi-bin/test.cgi?n1=v1&n2=v2 HTTP/1.1
* :
2014-11-19 00:25:21 +08:00
* /cgi-bin/test.cgi?n1=v1&n2=v2
* @param hh {const HTTP_HDR_REQ*} HTTP请求头类型的数据指针
* @return {const char*} URL. !NULL: OK; NULL: error.
2014-11-19 00:25:21 +08:00
*/
2019-06-06 13:46:23 +08:00
HTTP_API const char *http_hdr_req_url_part(const HTTP_HDR_REQ *hh);
2014-11-19 00:25:21 +08:00
/**
* HTTP请求头中获取请求行中的访问路径部分, .
* :
2014-11-19 00:25:21 +08:00
* GET /cgi-bin/test.cgi?n1=v1&n2=v2 HTTP/1.1
* or
* GET http://www.test.com[:80]/cgi-bin/test.cgi?n1=v1&n2=v2 HTTP/1.1
* :
2014-11-19 00:25:21 +08:00
* /cgi-bin/test.cgi
* @param hh {const HTTP_HDR_REQ*} HTTP请求头类型的数据指针
* @return {const char*} URL. !NULL: OK; NULL: error.
2014-11-19 00:25:21 +08:00
*/
2019-06-06 13:46:23 +08:00
HTTP_API const char *http_hdr_req_url_path(const HTTP_HDR_REQ *hh);
2014-11-19 00:25:21 +08:00
/**
* HTTP请求协议头中获得服务器的主机IP或域名IP|domain[:PORT]
* : 192.168.0.22:80, or www.test.com:8088
* @param hh {const HTTP_HDR_REQ*} HTTP请求头类型的数据指针
* @return {const char*} . !NULL: ok; NULL: error.
2014-11-19 00:25:21 +08:00
*/
2019-06-06 13:46:23 +08:00
HTTP_API const char *http_hdr_req_host(const HTTP_HDR_REQ *hh);
2014-11-19 00:25:21 +08:00
/**
* HTTP请求头协议中获得完整的URL请求字符串
* HTTP请求头为:
2014-11-19 00:25:21 +08:00
* GET /cgi-bin/test.cgi?n1=v1&n2=v2 HTTP/1.1
* HOST: www.test.com
* :
2014-11-19 00:25:21 +08:00
* http://www.test.com/cgi-bin/test.cgi?n1=v1&n2=v2
* @param hh {const HTTP_HDR_REQ*} HTTP请求头类型的数据指针
* @return {const char*} URL. !NULL: OK; NULL: error.
2014-11-19 00:25:21 +08:00
* @example:
* void test(HTTP_HDR_REQ *hh)
* {
* const char *url = http_hdr_req_url(hh);
* printf(">>> url: %s\r\n", url ? url : "null");
* }
* , http_hdr_req_url 使线,
* 使使.
2014-11-19 00:25:21 +08:00
* void test(HTTP_HDR_REQ *hh1, HTTP_HDR_REQ *hh2)
* {
* const char *url1 = http_hdr_req_url(hh1);
* const char *url2 = http_hdr_req_url(hh2);
* printf(">>> url1: %s, url2: %s\n", url1, url2);
* }
* url1, url2 , url1, url2
* . , :
2014-11-19 00:25:21 +08:00
* void test(HTTP_HDR_REQ *hh1, HTTP_HDR_REQ *hh2)
* {
* const char *ptr;
* static char dummy[1];
* char *url1 = dummy, *url2 = dummy;
* ptr = http_hdr_req_url(hh1);
* if (ptr)
* url1 = acl_mystrdup(ptr);
* ptr = http_hdr_req_url(hh2);
* if (ptr)
* url2 = acl_mystrdup(ptr);
* printf(">>> url1: %s, url2: %s\n", url1, url2);
* if (url1 != dummy)
* acl_myfree(url1);
* if (url2 != dummy)
* acl_myfree(url2);
* }
*/
2019-06-06 13:46:23 +08:00
HTTP_API const char *http_hdr_req_url(const HTTP_HDR_REQ *hh);
2014-11-19 00:25:21 +08:00
/**
* HTTP请求头中的 Range
* @param hdr_req {HTTP_HDR_REQ*} HTTP协议头,
* @param range_from {http_off_t*}
* @param range_to {http_off_t*}
* * {range_from}, {range_to} 0
* Range :
2014-11-19 00:25:21 +08:00
* Range: bytes={range_from}-, bytes={range_from}-{range_to}
*/
2019-06-06 13:46:23 +08:00
HTTP_API int http_hdr_req_range(const HTTP_HDR_REQ *hdr_req,
http_off_t *range_from, http_off_t *range_to);
2014-11-19 00:25:21 +08:00
/*---------------------------- HTTP 响应头操作函数 ---------------------------*/
2014-11-19 00:25:21 +08:00
/* in http_hdr_res.c */
/**
* HTTP响应头中的状态行
*@param hh {HTTP_HDR_RES*} HTTP响应头类型的数据指针
*@param dbuf {const char*} , : HTTP/1.0 200 OK
*@return {int} 0: ok; < 0: error hh
2014-11-19 00:25:21 +08:00
*/
HTTP_API int http_hdr_res_status_parse(HTTP_HDR_RES *hh, const char *dbuf);
/**
* HTTP响应头
2014-11-19 00:25:21 +08:00
* @return {HTTP_HDR_RES*}
*/
HTTP_API HTTP_HDR_RES *http_hdr_res_new(void);
/**
* HTTP响应头
* @param hdr_res {const HTTP_HDR_RES*} HTTP响应头
* @return {HTTP_HDR_RES *} HTTP响应头
2014-11-19 00:25:21 +08:00
*/
HTTP_API HTTP_HDR_RES *http_hdr_res_clone(const HTTP_HDR_RES *hdr_res);
/**
* HTTP响应头
* @param hh {HTTP_HDR_RES*} HTTP响应头
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_hdr_res_free(HTTP_HDR_RES *hh);
/**
* HTTP响应头重新初始化并释放其中的成员变量
* @param hh {HTTP_HDR_RES*} HTTP响应头
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_hdr_res_reset(HTTP_HDR_RES *hh);
/**
* HTTP响应头里的数据
* @param hdr_res {HTTP_HDR_RES*} HTTP响应头
2014-11-19 00:25:21 +08:00
*/
HTTP_API int http_hdr_res_parse(HTTP_HDR_RES *hdr_res);
/**
* HTTP响应头中的 Range
* @param hdr_res {HTTP_HDR_RES*} HTTP协议头,
* @param range_from {http_off_t*} ,
* @param range_to {http_off_t*} ,
* @param total_length {http_off_t*} ,
* @return {int} 0 -1
* * {range_from}, {range_to} 0
* Range :
2014-11-19 00:25:21 +08:00
* Content-Range: bytes {range_from}-{range_to}/{total_length}
*/
2019-06-06 13:46:23 +08:00
HTTP_API int http_hdr_res_range(const HTTP_HDR_RES *hdr_res,
http_off_t *range_from, http_off_t *range_to, http_off_t *total_length);
2014-11-19 00:25:21 +08:00
/* in http_rfc1123.c */
/**
* RFC1123所要求的格式
* @param buf {char*}
* @param size {size_t} buf
* @param t {time_t}
2014-11-19 00:25:21 +08:00
*/
HTTP_API const char *http_mkrfc1123(char *buf, size_t size, time_t t);
/*----------------------- HTTP 异步读操作函数 --------------------------------*/
2014-11-19 00:25:21 +08:00
/* in http_chat_async.c */
/**
* HTTP REQUEST协议头hdr中, HTTP头或
* notify
* @param hdr {HTTP_HDR_REQ*} HTTP请求头类型结构指针
* @param astream {ACL_ASTREAM*} ,
* @param notify {HTTP_HDR_NOTIFY} HTTP协议头读完或出错时调用的用户的注册函数
* @param arg {void*} notify
* @param timeout {int}
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_hdr_req_get_async(HTTP_HDR_REQ *hdr, ACL_ASTREAM *astream,
HTTP_HDR_NOTIFY notify, void *arg, int timeout);
/**
* HTTP RESPOND协议头hdr中, HTTP头或
* notify
* @param hdr {HTTP_HDR_REQ*} HTTP响应头类型结构指针
* @param astream {ACL_ASTREAM*} ,
* @param notify {HTTP_HDR_NOTIFY} HTTP协议头读完或出错时调用的用户的注册函数
* @param arg {void*} notify
* @param timeout {int}
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_hdr_res_get_async(HTTP_HDR_RES *hdr, ACL_ASTREAM *astream,
HTTP_HDR_NOTIFY notify, void *arg, int timeout);
/**
* BODY协议体, notify
* , notify 0 ,
* @param request {HTTP_REQ*} HTTP请求体类型指针, , request->hdr
* @param astream {ACL_ASTREAM*} ,
* @param notify {HTTP_BODY_NOTIFY}
* @param arg {void*} notify
* @param timeout {int}
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_req_body_get_async(HTTP_REQ *request, ACL_ASTREAM *astream,
HTTP_BODY_NOTIFY notify, void *arg, int timeout);
/*
* BODY协议体,
* notify , notify 0 ,
* @param respond {HTTP_RES*} HTTP响应体类型指针, , respond->hdr
* @param astream {ACL_ASTREAM*} ,
* @param notify {HTTP_BODY_NOTIFY}
* @param arg {void*} notify
* @param timeout {int}
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_res_body_get_async(HTTP_RES *respond, ACL_ASTREAM *astream,
HTTP_BODY_NOTIFY notify, void *arg, int timeout);
/*----------------------- HTTP 同步读操作函数 --------------------------------*/
2014-11-19 00:25:21 +08:00
/* in http_chat_sync.c */
/**
* HTTP REQUEST协议头hdr中, HTTP头或
* notify
* @param hdr {HTTP_HDR_REQ*} HTTP请求头类型结构指针
* @param stream {ACL_VSTREAM*} ,
* @param timeout {int}
* @return {int} 0: ; < 0:
2014-11-19 00:25:21 +08:00
*/
HTTP_API int http_hdr_req_get_sync(HTTP_HDR_REQ *hdr,
ACL_VSTREAM *stream, int timeout);
/**
* HTTP RESPOND协议头hdr中, HTTP头或
* notify
* @param hdr {HTTP_HDR_REQ*} HTTP响应头类型结构指针
* @param stream {ACL_VSTREAM*} ,
* @param timeout {int}
* @return {int} 0: ; < 0:
2014-11-19 00:25:21 +08:00
*/
HTTP_API int http_hdr_res_get_sync(HTTP_HDR_RES *hdr,
ACL_VSTREAM *stream, int timeout);
/**
* BODY协议体
* @param request {HTTP_REQ*} HTTP请求体类型指针, , request->hdr
* @param stream {ACL_VSTREAM*} ,
* @param buf {void *}
* @param size {int} buf
* @return ret {http_off_t} HTTP请求体的内容
* 0: HTTP数据体内容;
* < 0: ;
* > 0: ret
2014-11-19 00:25:21 +08:00
*/
HTTP_API http_off_t http_req_body_get_sync(HTTP_REQ *request, ACL_VSTREAM *stream,
void *buf, int size);
#define http_req_body_get_sync2 http_req_body_get_sync
/**
* BODY协议体
* @param respond {HTTP_RES*} HTTP响应体类型指针, , respond->hdr
* @param stream {ACL_VSTREAM*} ,
* @param buf {void *}
* @param size {int} buf
* @return ret {http_off_t} HTTP响应体的内容
* 0: HTTP数据体内容;
* < 0: ;
* > 0: ret
2014-11-19 00:25:21 +08:00
*/
HTTP_API http_off_t http_res_body_get_sync(HTTP_RES *respond, ACL_VSTREAM *stream,
void *buf, int size);
#define http_res_body_get_sync2 http_res_body_get_sync
/**
*
* @param request {HTTP_REQ*} HTTP请求体类型指针, , request->hdr
* @param name {int} HTTP_CHAT_SYNC_CTL_END
*
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_chat_sync_reqctl(HTTP_REQ *request, int name, ...);
/**
*
* @param respond {HTTP_RES*} HTTP响应体类型指针, , respond->hdr
* @param name {int} HTTP_CHAT_SYNC_CTL_END
*
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_chat_sync_resctl(HTTP_RES *respond, int name, ...);
#define HTTP_CHAT_SYNC_CTL_END 0 /**< 结束标志位 */
#define HTTP_CHAT_CTL_BUFF_ONOFF 1 /**< 是否打开数据接收时的预缓冲策略 */
2014-11-19 00:25:21 +08:00
/*------------------------ HTTP 请求体构造及释放函数 ------------------------*/
2014-11-19 00:25:21 +08:00
/* in http_req.c */
/**
* HTTP请求头分配一个请求体对象
* @param hdr_req {HTTP_HDR_REQ*}
* @return {HTTP_REQ*}
2014-11-19 00:25:21 +08:00
*/
HTTP_API HTTP_REQ *http_req_new(HTTP_HDR_REQ *hdr_req);
/**
*
* @param request {HTTP_REQ*}
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_req_free(HTTP_REQ *request);
/*------------------------ HTTP 响应体构造及释放函数 ------------------------*/
2014-11-19 00:25:21 +08:00
/* in http_res.c */
/**
* HTTP响应头分配一个响应体对象
* @param hdr_res {HTTP_HDR_RES*}
* @return {HTTP_RES*}
2014-11-19 00:25:21 +08:00
*/
HTTP_API HTTP_RES *http_res_new(HTTP_HDR_RES *hdr_res);
/**
*
* @param respond {HTTP_RES*}
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_res_free(HTTP_RES *respond);
/*------------------------------ HTTP 头构造函数 -----------------------------*/
2014-11-19 00:25:21 +08:00
/* in http_hdr_build.c */
/**
* HTTP头中添加数据
* @param hdr {HTTP_HDR*} HTTP头对象
* @param name {const char*} Accept-Encoding: deflate, gzip Accept-Encoding
* @param value {const char*} Accept-Encoding: deflate, gzip deflate, gzip
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_hdr_put_str(HTTP_HDR *hdr, const char *name, const char *value);
/**
* HTTP头中添加数据
* @param hdr {HTTP_HDR*} HTTP头对象
* @param name {const char*} Content-Length: 1024 Conteng-Length
* @param value {const int} Content-Length: 1024 1024
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_hdr_put_int(HTTP_HDR *hdr, const char *name, int value);
/**
* HTTP头中添加数据
* @param hdr {HTTP_HDR*} HTTP头对象
* @param name {const char*} Accept-Encoding: deflate, gzip Accept-Encoding
* @param fmt {const char*}
2014-11-19 00:25:21 +08:00
*/
# if defined(WIN32) || defined(WIN64)
2014-11-19 00:25:21 +08:00
HTTP_API void http_hdr_put_fmt(HTTP_HDR *hdr, const char *name, const char *fmt, ...);
#else
HTTP_API void __attribute__((format(printf,3,4)))
http_hdr_put_fmt(HTTP_HDR *hdr, const char *name, const char *fmt, ...);
#endif
/**
* HTTP头中添加时间数据
* @param hdr {HTTP_HDR*} HTTP头对象
* @param name {const char*}
* @param t {time_t}
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_hdr_put_time(HTTP_HDR *hdr, const char *name, time_t t);
/**
* HTTP请求头的字段来设置是否与服务端保持长连接, HTTP响应头中
* @param req {const HTTP_HDR_REQ*} HTTP请求头
* @param res {HTTP_HDR_RES*} HTTP响应头
2014-11-19 00:25:21 +08:00
*/
HTTP_API int http_hdr_set_keepalive(const HTTP_HDR_REQ *req, HTTP_HDR_RES *res);
/**
* (1xx, 2xx, 3xx, 4xx, 5xx) HTTP响应头
* @param hdr_res {HTTP_HDR_RES*} HTTP响应头
* @param status {int} nxx(1xx, 2xx, 3xx, 4xx, 5xx)
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_hdr_res_init(HTTP_HDR_RES *hdr_res, int status);
/**
* (nxx)HTTP响应头
* @param status {int} nxx(1xx, 2xx, 3xx, 4xx, 5xx)
* @return {HTTP_HDR_RES*} HTTP响应头
2014-11-19 00:25:21 +08:00
*/
HTTP_API HTTP_HDR_RES *http_hdr_res_static(int status);
/**
* (nxx)HTTP响应头
* @param status {int} nxx(4xx, 5xx)
* @return {HTTP_HDR_RES*} HTTP响应头
2014-11-19 00:25:21 +08:00
*/
HTTP_API HTTP_HDR_RES *http_hdr_res_error(int status);
/**
* HTTP通用头生成头的完整内容于BUF中
* @param hdr {const HTTP_HDR*} HTTP头
* @param strbuf {ACL_VSTRING*}
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_hdr_build(const HTTP_HDR *hdr, ACL_VSTRING *strbuf);
/**
* HTTP请求头生成请求头内容于BUF中
* @param hdr_req {const HTTP_HDR_REQ*} HTTP请求头
* @param strbuf {ACL_VSTRING*}
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_hdr_build_request(const HTTP_HDR_REQ *hdr_req, ACL_VSTRING *strbuf);
/*----------------------------- HTTP 响应状态信息函数 ------------------------*/
2014-11-19 00:25:21 +08:00
/* in http_status.c */
/**
* HTTP响应号(nxx)
* @param status {int} nxx(1xx, 2xx, 3xx, 4xx, 5xx)
* @return {const char*}
2014-11-19 00:25:21 +08:00
*/
HTTP_API const char *http_status_line(int status);
/*---------------------------- HTTP HTML 模板操作函数 ------------------------*/
2014-11-19 00:25:21 +08:00
/* in http_tmpl.c */
/**
* HTTP响应代码的HTML模板
* @param tmpl_path {const char*} HTML模板文件所在的路径
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_tmpl_load(const char *tmpl_path);
/**
* HTTP响应状态码的模板信息
* @param status {int} HTTP
* @return {const ACL_VSTRING*} HTTP响应状态码的模板信息
2014-11-19 00:25:21 +08:00
*/
HTTP_API const ACL_VSTRING *http_tmpl_get(int status);
/**
* HTTP响应状态码的标题提示信息
* @param status {int} HTTP
* @return {const char*} HTTP响应状态码的标题提示信息
2014-11-19 00:25:21 +08:00
*/
HTTP_API const char *http_tmpl_title(int status);
/**
* HTTP响应状态码的模板提示信息的长度大小
* @param status {int} HTTP
* @return {int}
2014-11-19 00:25:21 +08:00
*/
HTTP_API int http_tmpl_size(int status);
/*---------------------------- HTTP HTML 模板初始化函数 ----------------------*/
2014-11-19 00:25:21 +08:00
/* in http_init.c */
/**
* HTTP应用协议
* @param tmpl_path {const char*}
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_init(const char *tmpl_path);
/**
* HTTP 使使,
*
* @param max {int} > 0 便 HTTP
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_hdr_cache(int max);
/**
* HTTP
* @param size {http_off_t}
2014-11-19 00:25:21 +08:00
*/
HTTP_API void http_buf_size_set(http_off_t size);
/**
* HTTP
* @return {http_off_t}
2014-11-19 00:25:21 +08:00
*/
HTTP_API http_off_t http_buf_size_get(void);
#ifdef __cplusplus
}
#endif
#endif