00001 #ifndef gHTTP_X_H
00002 #define gHTTP_X_H
00003
00004 #include "gnet.h"
00005 #include "gfile.h"
00006 #include "gtime.h"
00007
00008 #define MAX_HTTP_CHUNK_SIZE ((t_uint32)MAX_UINT16_U)
00009 #define MAX_HTTP_HUGE_CHUNK_SIZE ((t_uint32)MAX_UINT16_U*2UL)
00010
00011
00012 class gVersion : public gString {
00013 public:
00014 gVersion (short major=-1, short minor=-1) ;
00015 virtual ~gVersion () {
00016 }
00017
00018
00019 short vMajor;
00020 short vMinor;
00021
00022
00023 virtual bool SetVersion (gString& s) ;
00024
00025
00026 bool operator> (gVersion& version) ;
00027 bool operator< (gVersion& version) ;
00028
00029 protected:
00030 int thisSetMajorOrMinor (char* s, short& ver) ;
00031
00032 private:
00033
00034 gVersion (gVersion& ) ;
00035 gVersion& operator= (gVersion& ) ;
00036 };
00037
00038
00039
00040 class gBigBuffer : public gControl {
00041 public:
00042 gBigBuffer (t_uint32 bufSize=0) ;
00043 virtual ~gBigBuffer () ;
00044
00045
00046 enum eBufferKind {
00047 e_NormalRAM,
00048 e_NodesRAM,
00049 e_InFile
00050 };
00051
00052
00053 gUCharBuffer* baseBuf;
00054 bool isDynamic;
00055 t_uint64 usedSize;
00056
00057
00058 eBufferKind GetBufferKind () ;
00059 unsigned GetBaseSize () {
00060 return baseSizeBuf;
00061 }
00062 virtual unsigned GetNumberNodes () {
00063 return nNodes;
00064 }
00065
00066 virtual gUCharBuffer* GetNode (unsigned idxNode) ;
00067 virtual gFileTemp& GetFile () ;
00068
00069
00070 virtual bool NewFile () ;
00071 virtual bool WriteBuf (int fHandle, gUCharBuffer& sBuf, unsigned nBytes) ;
00072 virtual bool Flush (unsigned nBytes) ;
00073
00074 protected:
00075 unsigned nNodes, maxNodes;
00076 gUCharBuffer** bNode;
00077 gFileTemp* fTemp;
00078
00079 bool thisAllocateBuf (t_uint32 bufSize) ;
00080
00081 private:
00082 bool hasOverbuffer;
00083 unsigned baseSizeBuf;
00084
00085 int thisOverbuffer (unsigned nBytes) ;
00086 int thisWrite (int fHandle, gUCharBuffer& sBuf, unsigned nBytes) ;
00087
00088
00089 gBigBuffer (gBigBuffer& ) ;
00090 gBigBuffer& operator= (gBigBuffer& ) ;
00091 };
00092
00093
00094
00095
00096 class gURI : public gString {
00097 public:
00098
00099 enum eScheme {
00100
00101 e_ftp,
00102 e_http,
00103 e_gopher,
00104 e_mailto,
00105 e_news,
00106 e_nntp,
00107 e_telnet,
00108 e_wais,
00109 e_file,
00110 e_prospero,
00111 e_z39_50s,
00112 e_z39_50r,
00113 e_cid,
00114 e_mid,
00115 e_vemmi,
00116 e_service,
00117 e_imap,
00118 e_nfs,
00119 e_acap,
00120 e_rtsp,
00121 e_tip,
00122 e_pop,
00123 e_data,
00124 e_dav,
00125 e_opaquelocktoken,
00126 e_sip,
00127 e_sips,
00128 e_tel,
00129 e_fax,
00130 e_modem,
00131 e_ldap,
00132 e_https,
00133
00134 e_soap_beep,
00135 e_soap_beeps,
00136
00137 xmlrpc_beep,
00138 xmlrpc_beeps,
00139
00140 e_urn,
00141
00142 e_go,
00143 e_h323,
00144 e_ipp,
00145 e_tftp,
00146 e_mupdate,
00147 e_pres,
00148 e_im,
00149 e_mtqp,
00150
00151 e_RSVD_reserved,
00152
00153 e_afs,
00154 e_tn3270,
00155 e_mailserver,
00156
00157 e_invalid
00158 };
00159
00160 enum ePathType {
00161 e_NoType,
00162 e_Absolute,
00163 e_Relative,
00164 e_RelativeQualified
00165 };
00166
00167
00168 struct sSchemeUse {
00169 eScheme theScheme;
00170 char* name;
00171 short rfcCode;
00172 };
00173
00174
00175 int lastOpError;
00176
00177 gURI () ;
00178 gURI (eScheme aScheme) ;
00179 virtual ~gURI () ;
00180
00181
00182 virtual bool IsOk () ;
00183
00184 virtual bool IsOkScheme () {
00185 return isOkScheme;
00186 }
00187
00188 virtual eScheme GetScheme () {
00189 return scheme;
00190 }
00191
00192 virtual char* Str () ;
00193
00194 ePathType GetPathType () {
00195 return pathType;
00196 }
00197 virtual char* GetOriginalStr () {
00198 return sOriginal.Str();
00199 }
00200 virtual char* GetDomainStr () {
00201 return sDomain.Str();
00202 }
00203 virtual char* GetPathStr () {
00204 return sPath.Str();
00205 }
00206
00207 virtual bool IsValidDomain () ;
00208
00209
00210 virtual bool SetString (char* s) ;
00211
00212 protected:
00213 ePathType pathType;
00214 gString sOriginal;
00215 gString sDomain;
00216 gString sPath;
00217 static sSchemeUse schemeTbl[];
00218
00219 int thisParseString (char* s, eScheme aScheme) ;
00220 int thisSetDomainPath (char* s, bool hasSpecScheme, eScheme aScheme) ;
00221 int thisSetPath (char* s) ;
00222 gURI::eScheme thisGetSchemeFromString (char* s, int& error) ;
00223 int thisFetchScheme (char* s, eScheme& foundScheme) ;
00224
00225 private:
00226 eScheme scheme;
00227 bool isOkScheme;
00228
00229
00230 gURI (gURI& ) ;
00231 gURI& operator= (gURI& ) ;
00232 };
00233
00234 class gHttpGeneric : public gControl {
00235 public:
00236 virtual ~gHttpGeneric () ;
00237
00238
00239 enum eContentImport {
00240 e_Binary,
00241 e_TextPlain
00242 };
00243
00244 enum eContentMethod {
00245 e_Get,
00246 e_Post
00247 };
00248
00249
00250 virtual gBigBuffer& GetBuffer () ;
00251 virtual gUCharBuffer& GetBaseBuffer () ;
00252
00253 virtual bool GetContent (eContentMethod method,
00254 gString& sHost,
00255 gString& sPath,
00256 gString& sReply) = 0;
00257
00258 protected:
00259 gHttpGeneric (gTcpConnect& connection) ;
00260
00261 gTcpConnect* pConnection;
00262
00263 private:
00264 gBigBuffer biffBuffer;
00265 };
00266
00267 #endif //gHTTP_X_H
00268