ghttp.h

Go to the documentation of this file.
00001 #ifndef gHTTP_X_H
00002 #define gHTTP_X_H
00003 
00004 #include "gnet.h"
00005 #include "gfile.h"
00006 #include "gtime.h"  // For stats
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     // Public data-members
00019     short vMajor;
00020     short vMinor;
00021 
00022     // Set methods
00023     virtual bool SetVersion (gString& s) ;
00024 
00025     // Operators,valid
00026     bool operator> (gVersion& version) ;
00027     bool operator< (gVersion& version) ;
00028 
00029 protected:
00030     int thisSetMajorOrMinor (char* s, short& ver) ;
00031 
00032 private:
00033     // Operators,etc
00034     gVersion (gVersion& ) ; //empty
00035     gVersion& operator= (gVersion& ) ; //empty
00036 };
00037 ////////////////////////////////////////////////////////////
00038 // CLASS gBigBuffer
00039 ////////////////////////////////////////////////////////////
00040 class gBigBuffer : public gControl {
00041 public:
00042     gBigBuffer (t_uint32 bufSize=0) ;
00043     virtual ~gBigBuffer () ;
00044 
00045     // Public enums
00046     enum eBufferKind {
00047         e_NormalRAM,
00048         e_NodesRAM,
00049         e_InFile
00050     };
00051 
00052     // Public data-members
00053     gUCharBuffer* baseBuf;
00054     bool isDynamic;
00055     t_uint64 usedSize;
00056 
00057     // Get methods
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     // Special methods
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;  //ranges: [0..maxNodes-1]
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     // Operators,empty
00089     gBigBuffer (gBigBuffer& ) ; //empty
00090     gBigBuffer& operator= (gBigBuffer& ) ; //empty
00091 };
00092 
00093 ////////////////////////////////////////////////////////////
00094 // CLASS gURI
00095 ////////////////////////////////////////////////////////////
00096 class gURI : public gString {
00097 public:
00098     // Public enums
00099     enum eScheme {
00100         // Schemes as signed by IANA: http://www.iana.org/assignments/uri-schemes
00101         e_ftp,     // File Transfer Protocol
00102         e_http,    // Hypertext Transfer Protocol
00103         e_gopher,  // The Gopher Protocol
00104         e_mailto,  // Electronical mail address
00105         e_news,    // USENET news
00106         e_nntp,    // USENET news using NNTP
00107         e_telnet,  // Reference to interactive sessions
00108         e_wais,    // Wide Area Information
00109         e_file,    // Host-specific file names
00110         e_prospero,// Prospero Directory Service
00111         e_z39_50s, // z39.50 Session
00112         e_z39_50r, // z39.50 Retrieval
00113         e_cid,     // content identifier
00114         e_mid,     // message identifier
00115         e_vemmi,   // versatile multimedia interface
00116         e_service, // service location
00117         e_imap,    // internet message access protocol
00118         e_nfs,     // network file system protocol
00119         e_acap,    // application configuration access protocol
00120         e_rtsp,    // real time streaming protocol
00121         e_tip,     // Transaction Internet Protocol
00122         e_pop,     // Post Office Protocol
00123         e_data,    // data
00124         e_dav,     // dav
00125         e_opaquelocktoken,// opaquelocktoken             [RFC2518]
00126         e_sip,           // session initiation protocol  [RFC3261]
00127         e_sips,          // secure session intitiaion p. [RFC3261]
00128         e_tel,           // telephone                    [RFC2806]
00129         e_fax,           // fax                          [RFC2806]
00130         e_modem,         // modem                        [RFC2806]
00131         e_ldap,          // Lightweight Directory Access Protocol
00132         e_https,         // Hypertext Transfer Protocol Secure [RFC2818]
00133 
00134         e_soap_beep,     // soap.beep
00135         e_soap_beeps,    // soap.beeps
00136 
00137         xmlrpc_beep,     // xmlrpc.beep
00138         xmlrpc_beeps,    // xmlrpc.beeps
00139 
00140         e_urn,           // Uniform Resource Names       [RFC2141]
00141                          // (http://www.iana.org/assignments/urn-namespaces)
00142         e_go,            // go                           [RFC3368]
00143         e_h323,          // H.323                        [RFC3508]
00144         e_ipp,           // Internet Printing Protocol   [RFC3510]
00145         e_tftp,          // Trivial File Transfer p.     [RFC3617]
00146         e_mupdate,       // Mailbox Update (MUPDATE) Protocol
00147         e_pres,          // Presence                     [RFC-ietf-impp-pres-04.txt]
00148         e_im,            // Instant Messaging            [RFC-ietf-impp-im-04.txt]
00149         e_mtqp,          // Message Tracking Query p.    [RFC-ietf-msgtrk-mtqp-12.txt]
00150 
00151         e_RSVD_reserved, // MARK START OF RESERVED URIs
00152 
00153         e_afs,           // Andrew File System global file names
00154         e_tn3270,        // Interactive 3270 emulation sessions
00155         e_mailserver,    // Access to data available from mail servers
00156 
00157         e_invalid
00158     };
00159 
00160     enum ePathType {
00161         e_NoType,
00162         e_Absolute,
00163         e_Relative,
00164         e_RelativeQualified  // single-slash
00165     };
00166 
00167     // Structs
00168     struct sSchemeUse {
00169         eScheme theScheme;
00170         char* name;
00171         short rfcCode;
00172     };
00173 
00174     // Public data-members
00175     int lastOpError;
00176 
00177     gURI () ;
00178     gURI (eScheme aScheme) ;
00179     virtual ~gURI () ;
00180 
00181     // Get methods
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     // Set methods
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     // Operators,empty
00230     gURI (gURI& ) ; //empty
00231     gURI& operator= (gURI& ) ; //empty
00232 };
00233 ////////////////////////////////////////////////////////////
00234 class gHttpGeneric : public gControl {
00235 public:
00236     virtual ~gHttpGeneric () ;
00237 
00238     // Public enums
00239     enum eContentImport {
00240         e_Binary,
00241         e_TextPlain
00242     };
00243 
00244     enum eContentMethod {
00245         e_Get,
00246         e_Post
00247     };
00248 
00249     // Get methods
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;  //PURE
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 

Generated on Sat Aug 18 02:40:56 2007 for xpfweb_v2x lib by  doxygen 1.4.2