00001 
00002 #ifndef  __JBXL_HTTP_TOOL_H_
00003 #define  __JBXL_HTTP_TOOL_H_
00004 
00005 
00016 #include "txml.h"
00017 #include "protocol.h"
00018 
00019 
00020 #ifndef DISABLE_ZLIB 
00021     #include "gz_tool.h"
00022 #endif
00023 
00024 
00025 #define  HTTP_CONNECTION_CLOSE        0
00026 #define  HTTP_CONNECTION_KEEP         1
00027 #define  HTTP_HEADER_NOT_HTTP        -1990
00028 #define  HTTP_HEADER_CLOSED_SESSION  -1997
00029 #define  HTTP_HEADER_CHUNKED         -1998
00030 #define  HTTP_HEADER_UNKNOWN_LEN     -1999
00031 
00032 
00033 #define  HTTP_ERROR_METHOD           -1     
00034 #define  HTTP_UNKNOWN_METHOD          0     
00035 
00036 
00037 #define  HTTP_GET_METHOD              1
00038 #define  HTTP_PUT_METHOD              2
00039 #define  HTTP_POST_METHOD             3
00040 #define  HTTP_DELETE_METHOD           4
00041 #define  HTTP_OPTIONS_METHOD          5
00042 #define  HTTP_HEAD_METHOD             6
00043 #define  HTTP_TRACE_METHOD            7
00044 #define  HTTP_CONNECT_METHOD          8
00045 #define  HTTP_PATCH_METHOD            9
00046 #define  HTTP_LINK_METHOD            10
00047 #define  HTTP_UNLINK_METHOD          11 
00048 
00049 
00050 #define  HTTP_PROPFIND_METHOD        20
00051 #define  HTTP_PROPPATCH_METHOD       21
00052 #define  HTTP_MKCOL_METHOD           22
00053 #define  HTTP_COPY_METHOD            23
00054 #define  HTTP_MOVE_METHOD            24
00055 #define  HTTP_LOCK_METHOD            25
00056 #define  HTTP_UNLOCK_METHOD          26
00057 
00058 #define  HTTP_RESPONSE_METHOD        99
00059 
00060 #define  HTTP_TIMEOUT                60  
00061 #define  HTTP_RESPONSE_TIMEOUT       180 
00062 #define  HTTP_PROXY_TIMEOUT          60  
00063 
00064 
00065 int    recv_http_header(int sock, tList** pl, int* len, int tm, FILE* fp, int* state);
00066 int    send_http_header(int sock, tList*  pl, int mode);
00067 
00068 int    recv_http_content(int sofd, Buffer* buf, int len, int tm, FILE* fp, int* state);
00069 int    recv_http_chunked(int sofd, Buffer* buf, int tm,  FILE* fp, int* state);
00070 int    recv_http_closed (int sofd, Buffer* buf, int tm,  FILE* fp);
00071 
00072 int    recv_http_chunked_remain(int sofd, Buffer* buf, int chnksz, int tm);
00073 
00074 int    recv_http_Buffer(int sock, tList** pl, Buffer* buf, int timeout, int* hdonly, int* state, int nochunk);
00075 int    send_http_Buffer(int sock, tList*  pl, Buffer* buf);
00076 
00077 int    recv_http_file(int sock, tList** pl, const char* fn, const char* wdir, int timeout, int* hdonly, int* state);
00078 int    send_http_file(int sock, tList*  pl, const char* fn);
00079 
00080 int    save_http_xml(int sock, tList** pl, tXML** xml, char** recvfn, const char* wdir, int timeout, int* state);
00081 
00082 
00084 
00085 int    get_http_method(char* data);
00086 
00087 int    is_http_header_field(tList* pl, char* field, char* value, int n);
00088 int    get_http_header_method(tList* pl);
00089 void   set_http_host_header(tList* pl, char* hname, unsigned short hport);
00090 void   dump_http_header(FILE* fp, tList* pp);
00091 
00092 int    get_http_status_num(tList* pl);
00093 float  get_http_version_num(tList* pl);
00094 
00095 int    get_chunked_size(char* ptr, int* hdsz, int* tlsz);
00096 
00097 char*  get_http_header_date(time_t tm);             
00098 Buffer rebuild_http_Buffer(tList* pl, Buffer* buf); 
00099 
00100 
00102 
00103 void   simple_web_proxy(int bofd, char* myip, int tmout);
00104 int    www2browser_relay(int bofd, int wofd, int btm, int wtm, int keep);
00105 Buffer http_proxy_header_analyze(tList* pl, Buffer* server, unsigned short* sport, int* timeout, int* keep);
00106 
00107 
00109 
00110 int    tcp_relay(int sofd, int cofd, int tm);
00111 
00112 
00114 
00115 int    send_http_res_file(int sock, char* fn, int mode);
00116 void   send_http_passwd_req(int sock);
00117 
00118 
00119 #endif  // __JBXL_HTTP_TOOL_H_
00120