00001 #ifndef gBHTTP_X_H
00002 #define gBHTTP_X_H
00003
00004 #include "ghttp.h"
00005 #include "gBNetHttpRequest.h"
00006
00007 class gXHttpReplyHeader : public gList {
00008 public:
00009 gXHttpReplyHeader () ;
00010 virtual ~gXHttpReplyHeader () {
00011 }
00012
00013
00014 int htmlCode;
00015 gString sHtmlCode;
00016 gList kindsL;
00017 gList linesL;
00018
00019
00020 virtual bool IsText () ;
00021 virtual bool IsChunked () {
00022 return isTransferEncodingChunked;
00023 }
00024
00025 virtual bool GetLine (char* sKind, gString& sResult) ;
00026 virtual bool AddLine (gString& s) ;
00027 virtual t_uint32 GetLength (bool& hasFound, bool& isLengthOk) ;
00028
00029 virtual bool IsCodeNotFound () {
00030 return htmlCode>=400 && htmlCode<500;
00031 }
00032 virtual bool IsCodeRedirect () {
00033 return htmlCode>=300 && htmlCode<400;
00034 }
00035
00036 protected:
00037 bool isTransferEncodingChunked;
00038
00039 int thisAddLine (char* sKind, char* sContent) ;
00040 int thisAddLine (gString& sKind, gString& sContent) ;
00041
00042 private:
00043
00044 gXHttpReplyHeader (gXHttpReplyHeader& ) ;
00045 gXHttpReplyHeader& operator= (gXHttpReplyHeader& ) ;
00046 };
00047
00048 class gXHttpGeneric : public gHttpGeneric {
00049 public:
00050 virtual ~gXHttpGeneric () ;
00051
00052
00053 int ioOpErrCode;
00054 gList getHeaderL;
00055 gList strHeaderL;
00056 gXHttpReplyHeader replyHeader;
00057 gHttpRequestList lReq;
00058
00059 t_uint64 contentBytesRead;
00060 t_uint64 totalBytesRead;
00061 const static short nStat=4;
00062 gUInt vStat[nStat];
00063 int keepAliveTimeout;
00064 int keepAliveMax;
00065 FILE* fRepErr;
00066
00067
00068 virtual gBigBuffer& GetBuffer () ;
00069 virtual gUCharBuffer& GetBaseBuffer () ;
00070 virtual gString& GetProtocolString () ;
00071 virtual gVersion& GetVersion () ;
00072
00073 virtual gTcpConnect& Connection () ;
00074 virtual gTcpConnect* ConnectionPtr () ;
00075
00076 virtual bool GetContent (eContentMethod method,
00077 gString& sHost,
00078 gString& sPath,
00079 gString& sReply) ;
00080
00081
00082 virtual bool SetProtocolVersion (char* str) ;
00083
00084 virtual int AddHead (gString& s, bool doCrNl=true) ;
00085 virtual int AddHeadStr (char* str) ;
00086 virtual int WriteHead (bool doFlush=false) ;
00087
00088
00089 virtual int SecSleep (t_uint32 aSec) ;
00090 virtual int MiliSecSleep (t_uint32 aMiliSec) ;
00091
00092 protected:
00093 gXHttpGeneric (gTcpConnect& connection) ;
00094
00095 gBigBuffer* pBuf;
00096 gTimerTic mStat[nStat];
00097
00098 int thisReadHeadReply (gTcpConnect& connection, unsigned& count, gString& sResult) ;
00099
00100 int thisParseServerReply (gString& sReply, gXHttpReplyHeader& serverReply) ;
00101
00102 private:
00103 gVersion httpVersion;
00104 gString sProtocol;
00105 gString sProtoVersion;
00106
00107
00108 gXHttpGeneric (gXHttpGeneric& ) ;
00109 gXHttpGeneric& operator= (gXHttpGeneric& ) ;
00110 };
00111
00112 class gXHttpCont : public gXHttpGeneric {
00113 public:
00114 gXHttpCont (gTcpConnect& connection) ;
00115 virtual ~gXHttpCont () ;
00116
00117
00118 gString strUserAgent;
00119
00120
00121 virtual bool IsText () {
00122 return isContText;
00123 }
00124 virtual bool GetContent (eContentMethod method,
00125 gString& sHost,
00126 gString& sPath,
00127 gString& sReply) ;
00128
00129 virtual char* GetHeadUserAgentStr () ;
00130 virtual char* GetHeadRefererStr () ;
00131
00132 protected:
00133 bool isContText;
00134 gString sHostname;
00135 gString sHeadTempStr;
00136
00137 virtual int ReadReplyText (gTcpConnect& connection, eContentImport contImport, gBigBuffer& bBuf, unsigned& count) ;
00138 virtual int ReadReplyBin (gTcpConnect& connection, gBigBuffer& bBuf, unsigned& count) ;
00139 int ReadReplyUnsized (gTcpConnect& connection, eContentImport contImport, gBigBuffer& bBuf, unsigned& count) ;
00140 int ReadReplyChunked (gTcpConnect& connection, gBigBuffer& bBuf, unsigned& count) ;
00141
00142 t_uint32 thisReadChunkSize (gTcpConnect& connection, int& error) ;
00143
00144 int thisGetHtmlContrl (eContentMethod method,
00145 gString& sPath,
00146 gString& sReply) ;
00147
00148 private:
00149
00150 gXHttpCont (gXHttpCont& ) ;
00151 gXHttpCont& operator= (gXHttpCont& ) ;
00152 };
00153
00154 #endif //gBHTTP_X_H
00155