http.h

Go to the documentation of this file.
00001 /*
00002  * http.h
00003  *
00004  * HyperText Transport Protocol classes.
00005  *
00006  * Portable Windows Library
00007  *
00008  * Copyright (c) 1993-2002 Equivalence Pty. Ltd.
00009  *
00010  * The contents of this file are subject to the Mozilla Public License
00011  * Version 1.0 (the "License"); you may not use this file except in
00012  * compliance with the License. You may obtain a copy of the License at
00013  * http://www.mozilla.org/MPL/
00014  *
00015  * Software distributed under the License is distributed on an "AS IS"
00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00017  * the License for the specific language governing rights and limitations
00018  * under the License.
00019  *
00020  * The Original Code is Portable Windows Library.
00021  *
00022  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
00023  *
00024  * Contributor(s): ______________________________________.
00025  *
00026  * $Revision: 24358 $
00027  * $Author: rjongbloed $
00028  * $Date: 2010-05-18 03:03:17 -0500 (Tue, 18 May 2010) $
00029  */
00030 
00031 #ifndef PTLIB_HTTP_H
00032 #define PTLIB_HTTP_H
00033 
00034 #ifdef P_USE_PRAGMA
00035 #pragma interface
00036 #endif
00037 
00038 #if P_HTTP
00039 
00040 #include <ptclib/inetprot.h>
00041 #include <ptclib/mime.h>
00042 #include <ptclib/url.h>
00043 #include <ptlib/ipsock.h>
00044 #include <ptlib/pfactory.h>
00045 
00046 
00047 #include <ptclib/html.h>
00048 
00050 // PHTTPSpace
00051 
00052 class PHTTPResource;
00053 
00058 class PHTTPSpace : public PContainer
00059 {
00060   PCONTAINERINFO(PHTTPSpace, PContainer)
00061   public:
00063     PHTTPSpace();
00064 
00065 
00066   // New functions for class.
00067     enum AddOptions {
00068       ErrorOnExist, 
00069       Overwrite     
00070     };
00071 
00072 
00084     PBoolean AddResource(
00085       PHTTPResource * resource, 
00086       AddOptions overwrite = ErrorOnExist
00088     );
00089 
00097     PBoolean DelResource(
00098       const PURL & url          
00099     );
00100 
00106     PHTTPResource * FindResource(
00107       const PURL & url   
00108     );
00109 
00112     void StartRead() const
00113       { mutex->StartRead(); }
00114 
00117     void EndRead() const
00118       { mutex->EndRead(); }
00119 
00122     void StartWrite() const
00123       { mutex->StartWrite(); }
00124 
00127     void EndWrite() const
00128       { mutex->EndWrite(); }
00129 
00130 
00131   protected:
00132     PReadWriteMutex * mutex;
00133 
00134     class Node;
00135     PSORTED_LIST(ChildList, Node);
00136     class Node : public PString
00137     {
00138       PCLASSINFO(Node, PString)
00139       public:
00140         Node(const PString & name, Node * parentNode);
00141         ~Node();
00142 
00143         Node          * parent;
00144         ChildList       children;
00145         PHTTPResource * resource;
00146     } * root;
00147 
00148   private:
00149     PBoolean SetSize(PINDEX) { return false; }
00150 };
00151 
00152 #ifdef TRACE
00153 #undef TRACE
00154 #endif
00155 
00157 // PHTTP
00158 
00162 class PHTTP : public PInternetProtocol
00163 {
00164   PCLASSINFO(PHTTP, PInternetProtocol)
00165 
00166   public:
00167   // New functions for class.
00168     enum Commands {
00169       // HTTP/1.0 commands
00170       GET, HEAD, POST,
00171       // HTTP/1.1 commands
00172       PUT, DELETE, TRACE, OPTIONS,
00173       // HTTPS command
00174       CONNECT,
00175       NumCommands
00176     };
00177 
00178     enum StatusCode {
00179       Continue = 100,              
00180       SwitchingProtocols,          
00181       RequestOK = 200,             
00182       Created,                     
00183       Accepted,                    
00184       NonAuthoritativeInformation, 
00185       NoContent,                   
00186       ResetContent,                
00187       PartialContent,              
00188       MultipleChoices = 300,       
00189       MovedPermanently,            
00190       MovedTemporarily,            
00191       SeeOther,                    
00192       NotModified,                 
00193       UseProxy,                    
00194       BadRequest = 400,            
00195       UnAuthorised,                
00196       PaymentRequired,             
00197       Forbidden,                   
00198       NotFound,                    
00199       MethodNotAllowed,            
00200       NoneAcceptable,              
00201       ProxyAuthenticationRequired, 
00202       RequestTimeout,              
00203       Conflict,                    
00204       Gone,                        
00205       LengthRequired,              
00206       UnlessTrue,                  
00207       InternalServerError = 500,   
00208       NotImplemented,              
00209       BadGateway,                  
00210       ServiceUnavailable,          
00211       GatewayTimeout               
00212     };
00213 
00214     // Common MIME header tags
00215     static const PString & AllowTag();
00216     static const PString & AuthorizationTag();
00217     static const PString & ContentEncodingTag();
00218     static const PString & ContentLengthTag();
00219     static const PString & ContentTypeTag() { return PMIMEInfo::ContentTypeTag(); }
00220     static const PString & DateTag();
00221     static const PString & ExpiresTag();
00222     static const PString & FromTag();
00223     static const PString & IfModifiedSinceTag();
00224     static const PString & LastModifiedTag();
00225     static const PString & LocationTag();
00226     static const PString & PragmaTag();
00227     static const PString & PragmaNoCacheTag();
00228     static const PString & RefererTag();
00229     static const PString & ServerTag();
00230     static const PString & UserAgentTag();
00231     static const PString & WWWAuthenticateTag();
00232     static const PString & MIMEVersionTag();
00233     static const PString & ConnectionTag();
00234     static const PString & KeepAliveTag();
00235     static const PString & TransferEncodingTag();
00236     static const PString & ChunkedTag();
00237     static const PString & ProxyConnectionTag();
00238     static const PString & ProxyAuthorizationTag();
00239     static const PString & ProxyAuthenticateTag();
00240     static const PString & ForwardedTag();
00241     static const PString & SetCookieTag();
00242     static const PString & CookieTag();
00243 
00244   protected:
00247     PHTTP();
00248 
00260     virtual PINDEX ParseResponse(
00261       const PString & line    
00262     );
00263 };
00264 
00265 
00266 
00267 class PHTTPClientAuthentication : public PObject
00268 {
00269   PCLASSINFO(PHTTPClientAuthentication, PObject);
00270   public:
00271     class AuthObject {
00272       public:
00273         virtual ~AuthObject() { }
00274         virtual PMIMEInfo & GetMIME() = 0;
00275         virtual PString GetURI() = 0;
00276         virtual PString GetEntityBody() = 0;
00277         virtual PString GetMethod() = 0;
00278     };
00279 
00280     PHTTPClientAuthentication();
00281 
00282     virtual Comparison Compare(
00283       const PObject & other
00284     ) const;
00285 
00286     virtual PBoolean Parse(
00287       const PString & auth,
00288       PBoolean proxy
00289     ) = 0;
00290 
00291     virtual PBoolean Authorise(
00292       AuthObject & pdu
00293     ) const =  0;
00294 
00295     virtual PBoolean IsProxy() const               { return isProxy; }
00296 
00297     virtual PString GetUsername() const   { return username; }
00298     virtual PString GetPassword() const   { return password; }
00299     virtual PString GetAuthRealm() const  { return PString::Empty(); }
00300 
00301     virtual void SetUsername(const PString & user) { username = user; }
00302     virtual void SetPassword(const PString & pass) { password = pass; }
00303     virtual void SetAuthRealm(const PString &)     { }
00304 
00305     PString GetAuthParam(const PString & auth, const char * name) const;
00306     PString AsHex(PMessageDigest5::Code & digest) const;
00307     PString AsHex(const PBYTEArray & data) const;
00308 
00309     static PHTTPClientAuthentication * ParseAuthenticationRequired(bool isProxy, const PMIMEInfo & line, PString & errorMsg);
00310 
00311 
00312   protected:
00313     PBoolean  isProxy;
00314     PString   username;
00315     PString   password;
00316 };
00317 
00318 typedef PFactory<PHTTPClientAuthentication> PHTTPClientAuthenticationFactory;
00319 
00320 class PHTTPClientAuthenticator : public PHTTPClientAuthentication::AuthObject
00321 {
00322   public:
00323     PHTTPClientAuthenticator(
00324       const PString & cmdName, 
00325       const PString & uri, 
00326       PMIMEInfo & mime, 
00327       const PString & body
00328     );
00329     virtual PMIMEInfo & GetMIME();
00330     virtual PString GetURI();
00331     virtual PString GetEntityBody();
00332     virtual PString GetMethod();
00333   protected:
00334     PString m_method;
00335     PString m_uri;
00336     PMIMEInfo & m_mime;
00337     PString m_body;
00338 };
00339 
00341 
00342 class PHTTPClientBasicAuthentication : public PHTTPClientAuthentication
00343 {
00344   PCLASSINFO(PHTTPClientBasicAuthentication, PHTTPClientAuthentication);
00345   public:
00346     PHTTPClientBasicAuthentication();
00347 
00348     virtual Comparison Compare(
00349       const PObject & other
00350     ) const;
00351 
00352     virtual PBoolean Parse(
00353       const PString & auth,
00354       PBoolean proxy
00355     );
00356 
00357     virtual PBoolean Authorise(
00358       AuthObject & pdu
00359     ) const;
00360 };
00361 
00363 
00364 class PHTTPClientDigestAuthentication : public PHTTPClientAuthentication
00365 {
00366   PCLASSINFO(PHTTPClientDigestAuthentication, PHTTPClientAuthentication);
00367   public:
00368     PHTTPClientDigestAuthentication();
00369 
00370     PHTTPClientDigestAuthentication & operator =(
00371       const PHTTPClientDigestAuthentication & auth
00372     );
00373 
00374     virtual Comparison Compare(
00375       const PObject & other
00376     ) const;
00377 
00378     virtual PBoolean Parse(
00379       const PString & auth,
00380       PBoolean proxy
00381     );
00382 
00383     virtual PBoolean Authorise(
00384       AuthObject & pdu
00385     ) const;
00386 
00387     virtual PString GetAuthRealm() const         { return authRealm; }
00388     virtual void SetAuthRealm(const PString & r) { authRealm = r; }
00389 
00390     enum Algorithm {
00391       Algorithm_MD5,
00392       NumAlgorithms
00393     };
00394     const PString & GetNonce() const       { return nonce; }
00395     Algorithm GetAlgorithm() const         { return algorithm; }
00396     const PString & GetOpaque() const      { return opaque; }
00397 
00398   protected:
00399     PString   authRealm;
00400     PString   nonce;
00401     Algorithm algorithm;
00402     PString   opaque;
00403 
00404     PBoolean qopAuth;
00405     PBoolean qopAuthInt;
00406     PString cnonce;
00407     mutable PAtomicInteger nonceCount;
00408 };
00409 
00410 
00412 // PHTTPClient
00413 
00434 class PHTTPClient : public PHTTP
00435 {
00436   PCLASSINFO(PHTTPClient, PHTTP)
00437 
00438   public:
00440     PHTTPClient(
00441       const PString & userAgentName = PString::Empty()
00442     );
00443 
00444 
00445   // New functions for class.
00453     int ExecuteCommand(
00454       Commands cmd,
00455       const PURL & url,
00456       PMIMEInfo & outMIME,
00457       const PString & dataBody,
00458       PMIMEInfo & replyMime
00459     );
00460     int ExecuteCommand(
00461       const PString & cmdName,
00462       const PURL & url,
00463       PMIMEInfo & outMIME,
00464       const PString & dataBody,
00465       PMIMEInfo & replyMime
00466     );
00467 
00469     PBoolean WriteCommand(
00470       Commands cmd,
00471       const PString & url,
00472       PMIMEInfo & outMIME,
00473       const PString & dataBody
00474     );
00475     PBoolean WriteCommand(
00476       const PString & cmdName,
00477       const PString & url,
00478       PMIMEInfo & outMIME,
00479       const PString & dataBody
00480     );
00481 
00483     PBoolean ReadResponse(
00484       PMIMEInfo & replyMIME
00485     );
00486 
00488     PBoolean ReadContentBody(
00489       PMIMEInfo & replyMIME,
00490       PBYTEArray & body
00491     );
00492     PBoolean ReadContentBody(
00493       PMIMEInfo & replyMIME,
00494       PString & body
00495     );
00496 
00497 
00506     PBoolean GetTextDocument(
00507       const PURL & url,         
00508       PString & document,       
00509       const PString & contentType = PString::Empty() 
00510     );
00511 
00517     PBoolean GetDocument(
00518       const PURL & url,         
00519       PMIMEInfo & outMIME,      
00520       PMIMEInfo & replyMIME     
00521     );
00522 
00528     PBoolean GetHeader(
00529       const PURL & url,         
00530       PMIMEInfo & outMIME,      
00531       PMIMEInfo & replyMIME     
00532     );
00533 
00534 
00540     PBoolean PostData(
00541       const PURL & url,       
00542       PMIMEInfo & outMIME,    
00543       const PString & data,   
00544       PMIMEInfo & replyMIME   
00545     );
00546 
00552     PBoolean PostData(
00553       const PURL & url,       
00554       PMIMEInfo & outMIME,    
00555       const PString & data,   
00556       PMIMEInfo & replyMIME,  
00557       PString & replyBody     
00558     );
00559 
00565     bool PutTextDocument(
00566       const PURL & url,         
00567       const PString & document,       
00568       const PString & contentType = "text/plain" 
00569     );
00570 
00576     bool PutDocument(
00577       const PURL & url,         
00578       PMIMEInfo & outMIME,      
00579       PMIMEInfo & replyMIME     
00580     );
00581 
00587     bool DeleteDocument(
00588       const PURL & url        
00589     );
00590 
00593     void SetAuthenticationInfo(
00594       const PString & userName,
00595       const PString & password
00596     );
00597 
00599     void SetPersistent(
00600       bool persist = true
00601     ) { m_persist = persist; }
00602 
00604     bool GetPersistent() const { return m_persist; }
00605 
00606   protected:
00607     PBoolean AssureConnect(const PURL & url, PMIMEInfo & outMIME);
00608     bool InternalReadContentBody(
00609       PMIMEInfo & replyMIME,
00610       PAbstractArray * body
00611     );
00612 
00613     PString m_userAgentName;
00614     bool    m_persist;
00615     PString m_userName;
00616     PString m_password;
00617     PHTTPClientAuthentication * m_authentication;
00618 };
00619 
00620 
00622 // PHTTPConnectionInfo
00623 
00624 class PHTTPServer;
00625 
00630 class PHTTPConnectionInfo : public PObject
00631 {
00632   PCLASSINFO(PHTTPConnectionInfo, PObject)
00633   public:
00634     PHTTPConnectionInfo();
00635 
00636     PHTTP::Commands GetCommandCode() const { return commandCode; }
00637     const PString & GetCommandName() const { return commandName; }
00638 
00639     const PURL & GetURL() const       { return url; }
00640 
00641     const PMIMEInfo & GetMIME() const { return mimeInfo; }
00642     void SetMIME(const PString & tag, const PString & value);
00643 
00644     PBoolean IsCompatible(int major, int minor) const;
00645 
00646     bool IsPersistent() const         { return isPersistent; }
00647     bool WasPersistent() const        { return wasPersistent; }
00648     bool IsProxyConnection() const    { return isProxyConnection; }
00649     int  GetMajorVersion() const      { return majorVersion; }
00650     int  GetMinorVersion() const      { return minorVersion; }
00651 
00652     long GetEntityBodyLength() const  { return entityBodyLength; }
00653 
00656     PTimeInterval GetPersistenceTimeout() const { return persistenceTimeout; }
00657 
00660     void SetPersistenceTimeout(const PTimeInterval & t) { persistenceTimeout = t; }
00661 
00665     unsigned GetPersistenceMaximumTransations() const { return persistenceMaximum; }
00666 
00670     void SetPersistenceMaximumTransations(unsigned m) { persistenceMaximum = m; }
00671 
00672     const PMultiPartList & GetMultipartFormInfo() const
00673       { return m_multipartFormInfo; }
00674 
00675     void ResetMultipartFormInfo()
00676       { m_multipartFormInfo.RemoveAll(); }
00677 
00678     PString GetEntityBody() const   { return entityBody; }
00679 
00680   protected:
00681     PBoolean Initialise(PHTTPServer & server, PString & args);
00682     bool DecodeMultipartFormInfo() { return mimeInfo.DecodeMultiPartList(m_multipartFormInfo, entityBody); }
00683 
00684     PHTTP::Commands commandCode;
00685     PString         commandName;
00686     PURL            url;
00687     PMIMEInfo       mimeInfo;
00688     bool            isPersistent;
00689     bool            wasPersistent;
00690     bool            isProxyConnection;
00691     int             majorVersion;
00692     int             minorVersion;
00693     PString         entityBody;        // original entity body (POST only)
00694     long            entityBodyLength;
00695     PTimeInterval   persistenceTimeout;
00696     unsigned        persistenceMaximum;
00697     PMultiPartList  m_multipartFormInfo;
00698 
00699   friend class PHTTPServer;
00700 };
00701 
00702 
00704 // PHTTPServer
00705 
00727 class PHTTPServer : public PHTTP
00728 {
00729   PCLASSINFO(PHTTPServer, PHTTP)
00730 
00731   public:
00739     PHTTPServer();
00740     PHTTPServer(
00741      const PHTTPSpace & urlSpace  
00742     );
00743 
00744 
00745   // New functions for class.
00751     virtual PString GetServerName() const;
00752 
00758     PHTTPSpace & GetURLSpace() { return urlSpace; }
00759 
00761     void SetURLSpace(
00762       const PHTTPSpace & space   
00763     );
00764 
00765 
00775     virtual PBoolean ProcessCommand();
00776 
00788     virtual PBoolean OnGET(
00789       const PURL & url,                    
00790       const PMIMEInfo & info,              
00791       const PHTTPConnectionInfo & conInfo  
00792     );
00793 
00794 
00795 
00807     virtual PBoolean OnHEAD(
00808       const PURL & url,                   
00809       const PMIMEInfo & info,             
00810       const PHTTPConnectionInfo & conInfo 
00811     );
00812 
00824     virtual PBoolean OnPOST(
00825       const PURL & url,                   
00826       const PMIMEInfo & info,             
00827       const PStringToString & data,       
00828       const PHTTPConnectionInfo & conInfo 
00829     );
00830 
00843     virtual PBoolean OnProxy(
00844       const PHTTPConnectionInfo & conInfo   
00845     );
00846 
00847 
00854     virtual PString ReadEntityBody();
00855 
00861     virtual PBoolean OnUnknown(
00862       const PCaselessString & command,         
00863       const PHTTPConnectionInfo & connectInfo  
00864     );
00865 
00884     PBoolean StartResponse(
00885       StatusCode code,      
00886       PMIMEInfo & headers,  
00887       long bodySize         
00888     );
00889 
00899     virtual PBoolean OnError(
00900       StatusCode code,                         
00901       const PCaselessString & extra,           
00902       const PHTTPConnectionInfo & connectInfo  
00903     );
00904 
00907     void SetDefaultMIMEInfo(
00908       PMIMEInfo & info,      
00909       const PHTTPConnectionInfo & connectInfo   
00910     );
00911 
00914     PHTTPConnectionInfo & GetConnectionInfo() { return connectInfo; }
00915 
00916   protected:
00917     void Construct();
00918 
00919     PHTTPSpace          urlSpace;
00920     PHTTPConnectionInfo connectInfo;
00921     unsigned            transactionCount;
00922     PTimeInterval       nextTimeout;
00923 };
00924 
00925 
00927 // PHTTPRequest
00928 
00933 class PHTTPRequest : public PObject
00934 {
00935   PCLASSINFO(PHTTPRequest, PObject)
00936 
00937   public:
00938     PHTTPRequest(
00939       const PURL & url,             
00940       const PMIMEInfo & inMIME,     
00941       const PMultiPartList & multipartFormInfo, 
00942       PHTTPResource * resource,     
00943       PHTTPServer & server          
00944     );
00945 
00946     PHTTPServer & server;           
00947     const PURL & url;               
00948     const PMIMEInfo & inMIME;       
00949     const PMultiPartList & multipartFormInfo; 
00950     PHTTP::StatusCode code;         
00951     PMIMEInfo outMIME;              
00952     PString entityBody;             
00953     PINDEX contentSize;             
00954     PIPSocket::Address origin;      
00955     PIPSocket::Address localAddr;   
00956     WORD               localPort;   
00957     PHTTPResource    * m_resource;  
00958 };
00959 
00960 
00962 // PHTTPAuthority
00963 
00967 class PHTTPAuthority : public PObject
00968 {
00969   PCLASSINFO(PHTTPAuthority, PObject)
00970 
00971   public:
00972   // New functions for class.
00979     virtual PString GetRealm(
00980       const PHTTPRequest & request   
00981     ) const = 0;
00982 
00989     virtual PBoolean Validate(
00990       const PHTTPRequest & request,  
00991       const PString & authInfo       
00992     ) const = 0;
00993 
01003     virtual PBoolean IsActive() const;
01004 
01005   protected:
01006     static void DecodeBasicAuthority(
01007       const PString & authInfo,   
01008       PString & username,         
01009       PString & password          
01010     );
01011 };
01012 
01013 
01015 // PHTTPSimpleAuth
01016 
01020 class PHTTPSimpleAuth : public PHTTPAuthority
01021 {
01022   PCLASSINFO(PHTTPSimpleAuth, PHTTPAuthority)
01023 
01024   public:
01025     PHTTPSimpleAuth(
01026       const PString & realm,      
01027       const PString & username,   
01028       const PString & password    
01029     );
01030     // Construct the simple authorisation structure.
01031 
01032 
01033   // Overrides from class PObject.
01041     virtual PObject * Clone() const;
01042 
01043 
01044   // Overrides from class PHTTPAuthority.
01051     virtual PString GetRealm(
01052       const PHTTPRequest & request   
01053     ) const;
01054 
01061     virtual PBoolean Validate(
01062       const PHTTPRequest & request,  
01063       const PString & authInfo       
01064     ) const;
01065 
01075     virtual PBoolean IsActive() const;
01076 
01082     const PString & GetUserName() const { return username; }
01083 
01089     const PString & GetPassword() const { return password; }
01090 
01091 
01092   protected:
01093     PString realm;
01094     PString username;
01095     PString password;
01096 };
01097 
01098 
01100 // PHTTPMultiSimpAuth
01101 
01105 class PHTTPMultiSimpAuth : public PHTTPAuthority
01106 {
01107   PCLASSINFO(PHTTPMultiSimpAuth, PHTTPAuthority)
01108 
01109   public:
01110     PHTTPMultiSimpAuth(
01111       const PString & realm      
01112     );
01113     PHTTPMultiSimpAuth(
01114       const PString & realm,           
01115       const PStringToString & userList 
01116     );
01117     // Construct the simple authorisation structure.
01118 
01119 
01120   // Overrides from class PObject.
01128     virtual PObject * Clone() const;
01129 
01130 
01131   // Overrides from class PHTTPAuthority.
01138     virtual PString GetRealm(
01139       const PHTTPRequest & request   
01140     ) const;
01141 
01148     virtual PBoolean Validate(
01149       const PHTTPRequest & request,  
01150       const PString & authInfo       
01151     ) const;
01152 
01162     virtual PBoolean IsActive() const;
01163 
01169     void AddUser(
01170       const PString & username,   
01171       const PString & password    
01172     );
01173 
01174 
01175   protected:
01176     PString realm;
01177     PStringToString users;
01178 };
01179 
01180 
01182 // PHTTPResource
01183 
01187 class PHTTPResource : public PObject
01188 {
01189   PCLASSINFO(PHTTPResource, PObject)
01190 
01191   protected:
01192     PHTTPResource(
01193       const PURL & url               
01194     );
01195     PHTTPResource(
01196       const PURL & url,              
01197       const PHTTPAuthority & auth    
01198     );
01199     PHTTPResource(
01200       const PURL & url,              
01201       const PString & contentType    
01202     );
01203     PHTTPResource(
01204       const PURL & url,              
01205       const PString & contentType,   
01206       const PHTTPAuthority & auth    
01207     );
01208     // Create a new HTTP Resource.
01209 
01210 
01211   public:
01212     virtual ~PHTTPResource();
01213     // Destroy the HTTP Resource.
01214 
01215 
01216   // New functions for class.
01222     const PURL & GetURL() const { return baseURL; }
01223 
01229     const PString & GetContentType() const { return contentType; }
01230 
01237     PHTTPAuthority * GetAuthority() const { return authority; }
01238 
01241     void SetAuthority(
01242       const PHTTPAuthority & auth      
01243     );
01244 
01247     void ClearAuthority();
01248 
01255     DWORD GetHitCount() const { return hitCount; }
01256 
01257     void ClearHitCount() { hitCount = 0; }
01258     // Clear the hit count for the resource.
01259 
01260 
01272     virtual PBoolean OnGET(
01273       PHTTPServer & server,       
01274       const PURL & url,           
01275       const PMIMEInfo & info,     
01276       const PHTTPConnectionInfo & conInfo   
01277     );
01278 
01288     virtual PBoolean OnGETData(
01289       PHTTPServer & server,                       
01290       const PURL & url,                           
01291       const PHTTPConnectionInfo & connectInfo,    
01292       PHTTPRequest & request                      
01293     );
01294 
01306     virtual PBoolean OnHEAD(
01307       PHTTPServer & server,       
01308       const PURL & url,           
01309       const PMIMEInfo & info,     
01310       const PHTTPConnectionInfo & conInfo  
01311     );
01312 
01324     virtual PBoolean OnPOST(
01325       PHTTPServer & server,         
01326       const PURL & url,             
01327       const PMIMEInfo & info,       
01328       const PStringToString & data, 
01329       const PHTTPConnectionInfo & conInfo  
01330     );
01331 
01341     virtual PBoolean OnPOSTData(
01342       PHTTPRequest & request,        
01343       const PStringToString & data   
01344     );
01345 
01352     virtual PBoolean IsModifiedSince(
01353       const PTime & when    
01354     );
01355 
01361     virtual PBoolean GetExpirationDate(
01362       PTime & when          
01363     );
01364 
01372     virtual PHTTPRequest * CreateRequest(
01373       const PURL & url,                   
01374       const PMIMEInfo & inMIME,           
01375       const PMultiPartList & multipartFormInfo,  
01376       PHTTPServer & socket                                
01377     );
01378 
01386     virtual PBoolean LoadHeaders(
01387       PHTTPRequest & request    
01388     ) = 0;
01389 
01395     virtual void SendData(
01396       PHTTPRequest & request    
01397     );
01398 
01407     virtual PBoolean LoadData(
01408       PHTTPRequest & request,    
01409       PCharArray & data          
01410     );
01411 
01420     virtual PString LoadText(
01421       PHTTPRequest & request    
01422     );
01423 
01430     virtual void OnLoadedText(
01431       PHTTPRequest & request,    
01432       PString & text             
01433     );
01434 
01443     virtual PBoolean Post(
01444       PHTTPRequest & request,       
01445       const PStringToString & data, 
01446       PHTML & replyMessage          
01447     );
01448 
01449 
01450   protected:
01453     virtual PBoolean CheckAuthority(
01454       PHTTPServer & server,               
01455       const PHTTPRequest & request,       
01456       const PHTTPConnectionInfo & conInfo 
01457     );
01458     static PBoolean CheckAuthority(
01459                    PHTTPAuthority & authority,
01460                       PHTTPServer & server,
01461                const PHTTPRequest & request,
01462         const PHTTPConnectionInfo & connectInfo
01463     );
01464 
01465 
01467     virtual PBoolean OnGETOrHEAD(
01468       PHTTPServer & server,       
01469       const PURL & url,           
01470       const PMIMEInfo & info,     
01471       const PHTTPConnectionInfo & conInfo,  
01472       PBoolean isGet              
01473     );
01474 
01475 
01476     PURL             baseURL;     
01477     PString          contentType; 
01478     PHTTPAuthority * authority;   
01479     volatile DWORD   hitCount;    
01480 };
01481 
01482 
01484 // PHTTPString
01485 
01490 class PHTTPString : public PHTTPResource
01491 {
01492   PCLASSINFO(PHTTPString, PHTTPResource)
01493 
01494   public:
01498     PHTTPString(
01499       const PURL & url             // Name of the resource in URL space.
01500     );
01501     PHTTPString(
01502       const PURL & url,            // Name of the resource in URL space.
01503       const PHTTPAuthority & auth  // Authorisation for the resource.
01504     );
01505     PHTTPString(
01506       const PURL & url,            // Name of the resource in URL space.
01507       const PString & str          // String to return in this resource.
01508     );
01509     PHTTPString(
01510       const PURL & url,            // Name of the resource in URL space.
01511       const PString & str,         // String to return in this resource.
01512       const PString & contentType  // MIME content type for the file.
01513     );
01514     PHTTPString(
01515       const PURL & url,            // Name of the resource in URL space.
01516       const PString & str,         // String to return in this resource.
01517       const PHTTPAuthority & auth  // Authorisation for the resource.
01518     );
01519     PHTTPString(
01520       const PURL & url,            // Name of the resource in URL space.
01521       const PString & str,         // String to return in this resource.
01522       const PString & contentType, // MIME content type for the file.
01523       const PHTTPAuthority & auth  // Authorisation for the resource.
01524     );
01525 
01526 
01527   // Overrides from class PHTTPResource
01535     virtual PBoolean LoadHeaders(
01536       PHTTPRequest & request    // Information on this request.
01537     );
01538 
01547     virtual PString LoadText(
01548       PHTTPRequest & request    // Information on this request.
01549     );
01550 
01551   // New functions for class.
01557     const PString & GetString() { return string; }
01558 
01561     void SetString(
01562       const PString & str   // New string for the resource.
01563     ) { string = str; }
01564 
01565 
01566   protected:
01567     PString string;
01568 };
01569 
01570 
01572 // PHTTPFile
01573 
01579 class PHTTPFile : public PHTTPResource
01580 {
01581   PCLASSINFO(PHTTPFile, PHTTPResource)
01582 
01583   public:
01590     PHTTPFile(
01591       const PString & filename     // file in file system and URL name.
01592     );
01593     PHTTPFile(
01594       const PString & filename,    // file in file system and URL name.
01595       const PHTTPAuthority & auth  // Authorisation for the resource.
01596     );
01597     PHTTPFile(
01598       const PURL & url,            // Name of the resource in URL space.
01599       const PFilePath & file       // Location of file in file system.
01600     );
01601     PHTTPFile(
01602       const PURL & url,            // Name of the resource in URL space.
01603       const PFilePath & file,      // Location of file in file system.
01604       const PString & contentType  // MIME content type for the file.
01605     );
01606     PHTTPFile(
01607       const PURL & url,            // Name of the resource in URL space.
01608       const PFilePath & file,      // Location of file in file system.
01609       const PHTTPAuthority & auth  // Authorisation for the resource.
01610     );
01611     PHTTPFile(
01612       const PURL & url,            // Name of the resource in URL space.
01613       const PFilePath & file,      // Location of file in file system.
01614       const PString & contentType, // MIME content type for the file.
01615       const PHTTPAuthority & auth  // Authorisation for the resource.
01616     );
01617 
01618 
01619   // Overrides from class PHTTPResource
01625     virtual PHTTPRequest * CreateRequest(
01626       const PURL & url,                  // Universal Resource Locator for document.
01627       const PMIMEInfo & inMIME,          // Extra MIME information in command.
01628       const PMultiPartList & multipartFormInfo,
01629       PHTTPServer & socket
01630     );
01631 
01639     virtual PBoolean LoadHeaders(
01640       PHTTPRequest & request    // Information on this request.
01641     );
01642 
01648     virtual PBoolean LoadData(
01649       PHTTPRequest & request,    // Information on this request.
01650       PCharArray & data          // Data used in reply.
01651     );
01652 
01661     virtual PString LoadText(
01662       PHTTPRequest & request    // Information on this request.
01663     );
01664 
01665 
01666   protected:
01667     PHTTPFile(
01668       const PURL & url,       // Name of the resource in URL space.
01669       int dummy
01670     );
01671     // Constructor used by PHTTPDirectory
01672 
01673 
01674     PFilePath filePath;
01675 };
01676 
01677 
01678 class PHTTPFileRequest : public PHTTPRequest
01679 {
01680   PCLASSINFO(PHTTPFileRequest, PHTTPRequest)
01681   public:
01682     PHTTPFileRequest(
01683       const PURL & url,             // Universal Resource Locator for document.
01684       const PMIMEInfo & inMIME,     // Extra MIME information in command.
01685       const PMultiPartList & multipartFormInfo,
01686       PHTTPResource * resource,
01687       PHTTPServer & server
01688     );
01689 
01690     PFile file;
01691 };
01692 
01693 
01695 // PHTTPTailFile
01696 
01705 class PHTTPTailFile : public PHTTPFile
01706 {
01707   PCLASSINFO(PHTTPTailFile, PHTTPFile)
01708 
01709   public:
01716     PHTTPTailFile(
01717       const PString & filename     // file in file system and URL name.
01718     );
01719     PHTTPTailFile(
01720       const PString & filename,    // file in file system and URL name.
01721       const PHTTPAuthority & auth  // Authorisation for the resource.
01722     );
01723     PHTTPTailFile(
01724       const PURL & url,            // Name of the resource in URL space.
01725       const PFilePath & file       // Location of file in file system.
01726     );
01727     PHTTPTailFile(
01728       const PURL & url,            // Name of the resource in URL space.
01729       const PFilePath & file,      // Location of file in file system.
01730       const PString & contentType  // MIME content type for the file.
01731     );
01732     PHTTPTailFile(
01733       const PURL & url,            // Name of the resource in URL space.
01734       const PFilePath & file,      // Location of file in file system.
01735       const PHTTPAuthority & auth  // Authorisation for the resource.
01736     );
01737     PHTTPTailFile(
01738       const PURL & url,            // Name of the resource in URL space.
01739       const PFilePath & file,      // Location of file in file system.
01740       const PString & contentType, // MIME content type for the file.
01741       const PHTTPAuthority & auth  // Authorisation for the resource.
01742     );
01743 
01744 
01745   // Overrides from class PHTTPResource
01753     virtual PBoolean LoadHeaders(
01754       PHTTPRequest & request    // Information on this request.
01755     );
01756 
01762     virtual PBoolean LoadData(
01763       PHTTPRequest & request,    // Information on this request.
01764       PCharArray & data          // Data used in reply.
01765     );
01766 };
01767 
01768 
01770 // PHTTPDirectory
01771 
01784 class PHTTPDirectory : public PHTTPFile
01785 {
01786   PCLASSINFO(PHTTPDirectory, PHTTPFile)
01787 
01788   public:
01789     PHTTPDirectory(
01790       const PURL & url,            
01791       const PDirectory & dir       
01792     );
01793     PHTTPDirectory(
01794       const PURL & url,            
01795       const PDirectory & dir,      
01796       const PHTTPAuthority & auth  
01797     );
01798     // Construct a new directory resource for HTTP.
01799 
01800 
01801   // Overrides from class PHTTPResource
01807     virtual PHTTPRequest * CreateRequest(
01808       const PURL & url,                  // Universal Resource Locator for document.
01809       const PMIMEInfo & inMIME,          // Extra MIME information in command.
01810       const PMultiPartList & multipartFormInfo,
01811       PHTTPServer & socket
01812     );
01813 
01821     virtual PBoolean LoadHeaders(
01822       PHTTPRequest & request    
01823     );
01824 
01833     virtual PString LoadText(
01834       PHTTPRequest & request    
01835     );
01836 
01845     void EnableAuthorisation(const PString & realm);
01846 
01849     void AllowDirectories(PBoolean enable = true);
01850 
01851   protected:
01852     PBoolean CheckAuthority(
01853       PHTTPServer & server,               // Server to send response to.
01854       const PHTTPRequest & request,       // Information on this request.
01855       const PHTTPConnectionInfo & conInfo // Information on the connection
01856     );
01857 
01858     PBoolean FindAuthorisations(const PDirectory & dir, PString & realm, PStringToString & authorisations);
01859 
01860     PDirectory basePath;
01861     PString authorisationRealm;
01862     PBoolean allowDirectoryListing;
01863 };
01864 
01865 
01866 class PHTTPDirRequest : public PHTTPFileRequest
01867 {
01868   PCLASSINFO(PHTTPDirRequest, PHTTPFileRequest)
01869   public:
01870     PHTTPDirRequest(
01871       const PURL & url,             // Universal Resource Locator for document.
01872       const PMIMEInfo & inMIME,     // Extra MIME information in command.
01873       const PMultiPartList & multipartFormInfo, 
01874       PHTTPResource * resource,
01875       PHTTPServer & server
01876     );
01877 
01878     PString fakeIndex;
01879     PFilePath realPath;
01880 };
01881 
01882 #endif // P_HTTP
01883 
01884 #endif // PTLIB_HTTP_H
01885 
01886 
01887 // End Of File ///////////////////////////////////////////////////////////////

Generated on Thu May 27 01:49:40 2010 for PTLib by  doxygen 1.4.7