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: 24540 $
00027  * $Author: rjongbloed $
00028  * $Date: 2010-06-28 20:44:22 -0500 (Mon, 28 Jun 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 {
00069       ErrorOnExist,
00071       Overwrite
00072     };
00073 
00074 
00086     PBoolean AddResource(
00087       PHTTPResource * resource, 
00088       AddOptions overwrite = ErrorOnExist
00090     );
00091 
00099     PBoolean DelResource(
00100       const PURL & url          
00101     );
00102 
00108     PHTTPResource * FindResource(
00109       const PURL & url   
00110     );
00111 
00114     void StartRead() const
00115       { mutex->StartRead(); }
00116 
00119     void EndRead() const
00120       { mutex->EndRead(); }
00121 
00124     void StartWrite() const
00125       { mutex->StartWrite(); }
00126 
00129     void EndWrite() const
00130       { mutex->EndWrite(); }
00131 
00132 
00133   protected:
00134     PReadWriteMutex * mutex;
00135 
00136     class Node;
00137     PSORTED_LIST(ChildList, Node);
00138     class Node : public PString
00139     {
00140       PCLASSINFO(Node, PString)
00141       public:
00142         Node(const PString & name, Node * parentNode);
00143         ~Node();
00144 
00145         Node          * parent;
00146         ChildList       children;
00147         PHTTPResource * resource;
00148     } * root;
00149 
00150   private:
00151     PBoolean SetSize(PINDEX) { return PFalse; }
00152 };
00153 
00154 #ifdef TRACE
00155 #undef TRACE
00156 #endif
00157 
00159 // PHTTP
00160 
00164 class PHTTP : public PInternetProtocol
00165 {
00166   PCLASSINFO(PHTTP, PInternetProtocol)
00167 
00168   public:
00169   // New functions for class.
00170     enum Commands {
00171       // HTTP/1.0 commands
00172       GET, HEAD, POST,
00173       // HTTP/1.1 commands
00174       PUT, DELETE, TRACE, OPTIONS,
00175       // HTTPS command
00176       CONNECT,
00177       NumCommands
00178     };
00179 
00180     enum StatusCode {
00181       Continue = 100,              
00182       SwitchingProtocols,          
00183       RequestOK = 200,             
00184       Created,                     
00185       Accepted,                    
00186       NonAuthoritativeInformation, 
00187       NoContent,                   
00188       ResetContent,                
00189       PartialContent,              
00190       MultipleChoices = 300,       
00191       MovedPermanently,            
00192       MovedTemporarily,            
00193       SeeOther,                    
00194       NotModified,                 
00195       UseProxy,                    
00196       BadRequest = 400,            
00197       UnAuthorised,                
00198       PaymentRequired,             
00199       Forbidden,                   
00200       NotFound,                    
00201       MethodNotAllowed,            
00202       NoneAcceptable,              
00203       ProxyAuthenticationRequired, 
00204       RequestTimeout,              
00205       Conflict,                    
00206       Gone,                        
00207       LengthRequired,              
00208       UnlessTrue,                  
00209       InternalServerError = 500,   
00210       NotImplemented,              
00211       BadGateway,                  
00212       ServiceUnavailable,          
00213       GatewayTimeout               
00214     };
00215 
00216     // Common MIME header tags
00217     static const PString & AllowTag();
00218     static const PString & AuthorizationTag();
00219     static const PString & ContentEncodingTag();
00220     static const PString & ContentLengthTag();
00221     static const PString & ContentTypeTag() { return PMIMEInfo::ContentTypeTag(); }
00222     static const PString & DateTag();
00223     static const PString & ExpiresTag();
00224     static const PString & FromTag();
00225     static const PString & IfModifiedSinceTag();
00226     static const PString & LastModifiedTag();
00227     static const PString & LocationTag();
00228     static const PString & PragmaTag();
00229     static const PString & PragmaNoCacheTag();
00230     static const PString & RefererTag();
00231     static const PString & ServerTag();
00232     static const PString & UserAgentTag();
00233     static const PString & WWWAuthenticateTag();
00234     static const PString & MIMEVersionTag();
00235     static const PString & ConnectionTag();
00236     static const PString & KeepAliveTag();
00237     static const PString & TransferEncodingTag();
00238     static const PString & ChunkedTag();
00239     static const PString & ProxyConnectionTag();
00240     static const PString & ProxyAuthorizationTag();
00241     static const PString & ProxyAuthenticateTag();
00242     static const PString & ForwardedTag();
00243     static const PString & SetCookieTag();
00244     static const PString & CookieTag();
00245 
00246   protected:
00249     PHTTP();
00250 
00262     virtual PINDEX ParseResponse(
00263       const PString & line    
00264     );
00265 };
00266 
00267 
00268 
00269 class PHTTPClientAuthentication : public PObject
00270 {
00271   PCLASSINFO(PHTTPClientAuthentication, PObject);
00272   public:
00273     class AuthObject {
00274       public:
00275         virtual ~AuthObject() { }
00276         virtual PMIMEInfo & GetMIME() = 0;
00277         virtual PString GetURI() = 0;
00278         virtual PString GetEntityBody() = 0;
00279         virtual PString GetMethod() = 0;
00280     };
00281 
00282     PHTTPClientAuthentication();
00283 
00284     virtual Comparison Compare(
00285       const PObject & other
00286     ) const;
00287 
00288     virtual PBoolean Parse(
00289       const PString & auth,
00290       PBoolean proxy
00291     ) = 0;
00292 
00293     virtual PBoolean Authorise(
00294       AuthObject & pdu
00295     ) const =  0;
00296 
00297     virtual PBoolean IsProxy() const               { return isProxy; }
00298 
00299     virtual PString GetUsername() const   { return username; }
00300     virtual PString GetPassword() const   { return password; }
00301     virtual PString GetAuthRealm() const  { return PString::Empty(); }
00302 
00303     virtual void SetUsername(const PString & user) { username = user; }
00304     virtual void SetPassword(const PString & pass) { password = pass; }
00305     virtual void SetAuthRealm(const PString &)     { }
00306 
00307     PString GetAuthParam(const PString & auth, const char * name) const;
00308     PString AsHex(PMessageDigest5::Code & digest) const;
00309     PString AsHex(const PBYTEArray & data) const;
00310 
00311     static PHTTPClientAuthentication * ParseAuthenticationRequired(bool isProxy, const PMIMEInfo & line, PString & errorMsg);
00312 
00313 
00314   protected:
00315     PBoolean  isProxy;
00316     PString   username;
00317     PString   password;
00318 };
00319 
00320 typedef PFactory<PHTTPClientAuthentication> PHTTPClientAuthenticationFactory;
00321 
00322 class PHTTPClientAuthenticator : public PHTTPClientAuthentication::AuthObject
00323 {
00324   public:
00325     PHTTPClientAuthenticator(
00326       const PString & cmdName, 
00327       const PString & uri, 
00328       PMIMEInfo & mime, 
00329       const PString & body
00330     );
00331     virtual PMIMEInfo & GetMIME();
00332     virtual PString GetURI();
00333     virtual PString GetEntityBody();
00334     virtual PString GetMethod();
00335   protected:
00336     PString m_method;
00337     PString m_uri;
00338     PMIMEInfo & m_mime;
00339     PString m_body;
00340 };
00341 
00343 
00344 class PHTTPClientBasicAuthentication : public PHTTPClientAuthentication
00345 {
00346   PCLASSINFO(PHTTPClientBasicAuthentication, PHTTPClientAuthentication);
00347   public:
00348     PHTTPClientBasicAuthentication();
00349 
00350     virtual Comparison Compare(
00351       const PObject & other
00352     ) const;
00353 
00354     virtual PBoolean Parse(
00355       const PString & auth,
00356       PBoolean proxy
00357     );
00358 
00359     virtual PBoolean Authorise(
00360       AuthObject & pdu
00361     ) const;
00362 };
00363 
00365 
00366 class PHTTPClientDigestAuthentication : public PHTTPClientAuthentication
00367 {
00368   PCLASSINFO(PHTTPClientDigestAuthentication, PHTTPClientAuthentication);
00369   public:
00370     PHTTPClientDigestAuthentication();
00371 
00372     PHTTPClientDigestAuthentication & operator =(
00373       const PHTTPClientDigestAuthentication & auth
00374     );
00375 
00376     virtual Comparison Compare(
00377       const PObject & other
00378     ) const;
00379 
00380     virtual PBoolean Parse(
00381       const PString & auth,
00382       PBoolean proxy
00383     );
00384 
00385     virtual PBoolean Authorise(
00386       AuthObject & pdu
00387     ) const;
00388 
00389     virtual PString GetAuthRealm() const         { return authRealm; }
00390     virtual void SetAuthRealm(const PString & r) { authRealm = r; }
00391 
00392     enum Algorithm {
00393       Algorithm_MD5,
00394       NumAlgorithms
00395     };
00396     const PString & GetNonce() const       { return nonce; }
00397     Algorithm GetAlgorithm() const         { return algorithm; }
00398     const PString & GetOpaque() const      { return opaque; }
00399     bool GetStale() const                  { return stale; }
00400 
00401   protected:
00402     PString   authRealm;
00403     PString   nonce;
00404     Algorithm algorithm;
00405     PString   opaque;
00406 
00407     bool    qopAuth;
00408     bool    qopAuthInt;
00409     bool    stale;
00410     PString cnonce;
00411     mutable PAtomicInteger nonceCount;
00412 };
00413 
00414 
00416 // PHTTPClient
00417 
00438 class PHTTPClient : public PHTTP
00439 {
00440   PCLASSINFO(PHTTPClient, PHTTP)
00441 
00442   public:
00444     PHTTPClient(
00445       const PString & userAgentName = PString::Empty()
00446     );
00447 
00448 
00449   // New functions for class.
00457     int ExecuteCommand(
00458       Commands cmd,
00459       const PURL & url,
00460       PMIMEInfo & outMIME,
00461       const PString & dataBody,
00462       PMIMEInfo & replyMime
00463     );
00464     int ExecuteCommand(
00465       const PString & cmdName,
00466       const PURL & url,
00467       PMIMEInfo & outMIME,
00468       const PString & dataBody,
00469       PMIMEInfo & replyMime
00470     );
00471 
00473     PBoolean WriteCommand(
00474       Commands cmd,
00475       const PString & url,
00476       PMIMEInfo & outMIME,
00477       const PString & dataBody
00478     );
00479     PBoolean WriteCommand(
00480       const PString & cmdName,
00481       const PString & url,
00482       PMIMEInfo & outMIME,
00483       const PString & dataBody
00484     );
00485 
00487     PBoolean ReadResponse(
00488       PMIMEInfo & replyMIME
00489     );
00490 
00492     PBoolean ReadContentBody(
00493       PMIMEInfo & replyMIME,
00494       PBYTEArray & body
00495     );
00496     PBoolean ReadContentBody(
00497       PMIMEInfo & replyMIME,
00498       PString & body
00499     );
00500 
00501 
00510     PBoolean GetTextDocument(
00511       const PURL & url,         
00512       PString & document,       
00513       const PString & contentType = PString::Empty() 
00514     );
00515 
00521     PBoolean GetDocument(
00522       const PURL & url,         
00523       PMIMEInfo & outMIME,      
00524       PMIMEInfo & replyMIME     
00525     );
00526 
00532     PBoolean GetHeader(
00533       const PURL & url,         
00534       PMIMEInfo & outMIME,      
00535       PMIMEInfo & replyMIME     
00536     );
00537 
00538 
00544     PBoolean PostData(
00545       const PURL & url,       
00546       PMIMEInfo & outMIME,    
00547       const PString & data,   
00548       PMIMEInfo & replyMIME   
00549     );
00550 
00556     PBoolean PostData(
00557       const PURL & url,       
00558       PMIMEInfo & outMIME,    
00559       const PString & data,   
00560       PMIMEInfo & replyMIME,  
00561       PString & replyBody     
00562     );
00563 
00569     bool PutTextDocument(
00570       const PURL & url,         
00571       const PString & document,       
00572       const PString & contentType = "text/plain" 
00573     );
00574 
00580     bool PutDocument(
00581       const PURL & url,         
00582       PMIMEInfo & outMIME,      
00583       PMIMEInfo & replyMIME     
00584     );
00585 
00591     bool DeleteDocument(
00592       const PURL & url        
00593     );
00594 
00597     void SetAuthenticationInfo(
00598       const PString & userName,
00599       const PString & password
00600     );
00601 
00603     void SetPersistent(
00604       bool persist = true
00605     ) { m_persist = persist; }
00606 
00608     bool GetPersistent() const { return m_persist; }
00609 
00610   protected:
00611     PBoolean AssureConnect(const PURL & url, PMIMEInfo & outMIME);
00612     bool InternalReadContentBody(
00613       PMIMEInfo & replyMIME,
00614       PAbstractArray * body
00615     );
00616 
00617     PString m_userAgentName;
00618     bool    m_persist;
00619     PString m_userName;
00620     PString m_password;
00621     PHTTPClientAuthentication * m_authentication;
00622 };
00623 
00624 
00626 // PHTTPConnectionInfo
00627 
00628 class PHTTPServer;
00629 
00634 class PHTTPConnectionInfo : public PObject
00635 {
00636   PCLASSINFO(PHTTPConnectionInfo, PObject)
00637   public:
00638     PHTTPConnectionInfo();
00639 
00640     PHTTP::Commands GetCommandCode() const { return commandCode; }
00641     const PString & GetCommandName() const { return commandName; }
00642 
00643     const PURL & GetURL() const       { return url; }
00644 
00645     const PMIMEInfo & GetMIME() const { return mimeInfo; }
00646     void SetMIME(const PString & tag, const PString & value);
00647 
00648     PBoolean IsCompatible(int major, int minor) const;
00649 
00650     bool IsPersistent() const         { return isPersistent; }
00651     bool WasPersistent() const        { return wasPersistent; }
00652     bool IsProxyConnection() const    { return isProxyConnection; }
00653     int  GetMajorVersion() const      { return majorVersion; }
00654     int  GetMinorVersion() const      { return minorVersion; }
00655 
00656     long GetEntityBodyLength() const  { return entityBodyLength; }
00657 
00660     PTimeInterval GetPersistenceTimeout() const { return persistenceTimeout; }
00661 
00664     void SetPersistenceTimeout(const PTimeInterval & t) { persistenceTimeout = t; }
00665 
00669     unsigned GetPersistenceMaximumTransations() const { return persistenceMaximum; }
00670 
00674     void SetPersistenceMaximumTransations(unsigned m) { persistenceMaximum = m; }
00675 
00676     const PMultiPartList & GetMultipartFormInfo() const
00677       { return m_multipartFormInfo; }
00678 
00679     void ResetMultipartFormInfo()
00680       { m_multipartFormInfo.RemoveAll(); }
00681 
00682     PString GetEntityBody() const   { return entityBody; }
00683 
00684   protected:
00685     PBoolean Initialise(PHTTPServer & server, PString & args);
00686     bool DecodeMultipartFormInfo() { return mimeInfo.DecodeMultiPartList(m_multipartFormInfo, entityBody); }
00687 
00688     PHTTP::Commands commandCode;
00689     PString         commandName;
00690     PURL            url;
00691     PMIMEInfo       mimeInfo;
00692     bool            isPersistent;
00693     bool            wasPersistent;
00694     bool            isProxyConnection;
00695     int             majorVersion;
00696     int             minorVersion;
00697     PString         entityBody;        // original entity body (POST only)
00698     long            entityBodyLength;
00699     PTimeInterval   persistenceTimeout;
00700     unsigned        persistenceMaximum;
00701     PMultiPartList  m_multipartFormInfo;
00702 
00703   friend class PHTTPServer;
00704 };
00705 
00706 
00708 // PHTTPServer
00709 
00722 class PHTTPServer : public PHTTP
00723 {
00724   PCLASSINFO(PHTTPServer, PHTTP)
00725 
00726   public:
00734     PHTTPServer();
00735     PHTTPServer(
00736      const PHTTPSpace & urlSpace  
00737     );
00738 
00739 
00740   // New functions for class.
00746     virtual PString GetServerName() const;
00747 
00753     PHTTPSpace & GetURLSpace() { return urlSpace; }
00754 
00756     void SetURLSpace(
00757       const PHTTPSpace & space   
00758     );
00759 
00760 
00770     virtual PBoolean ProcessCommand();
00771 
00783     virtual PBoolean OnGET(
00784       const PURL & url,                    
00785       const PMIMEInfo & info,              
00786       const PHTTPConnectionInfo & conInfo  
00787     );
00788 
00789 
00790 
00802     virtual PBoolean OnHEAD(
00803       const PURL & url,                   
00804       const PMIMEInfo & info,             
00805       const PHTTPConnectionInfo & conInfo 
00806     );
00807 
00819     virtual PBoolean OnPOST(
00820       const PURL & url,                   
00821       const PMIMEInfo & info,             
00822       const PStringToString & data,       
00823       const PHTTPConnectionInfo & conInfo 
00824     );
00825 
00838     virtual PBoolean OnProxy(
00839       const PHTTPConnectionInfo & conInfo   
00840     );
00841 
00842 
00849     virtual PString ReadEntityBody();
00850 
00856     virtual PBoolean OnUnknown(
00857       const PCaselessString & command,         
00858       const PHTTPConnectionInfo & connectInfo  
00859     );
00860 
00879     PBoolean StartResponse(
00880       StatusCode code,      
00881       PMIMEInfo & headers,  
00882       long bodySize         
00883     );
00884 
00894     virtual PBoolean OnError(
00895       StatusCode code,                         
00896       const PCaselessString & extra,           
00897       const PHTTPConnectionInfo & connectInfo  
00898     );
00899 
00902     void SetDefaultMIMEInfo(
00903       PMIMEInfo & info,      
00904       const PHTTPConnectionInfo & connectInfo
00905     );
00906 
00909     PHTTPConnectionInfo & GetConnectionInfo() { return connectInfo; }
00910 
00911   protected:
00912     void Construct();
00913 
00914     PHTTPSpace          urlSpace;
00915     PHTTPConnectionInfo connectInfo;
00916     unsigned            transactionCount;
00917     PTimeInterval       nextTimeout;
00918 };
00919 
00920 
00922 // PHTTPRequest
00923 
00928 class PHTTPRequest : public PObject
00929 {
00930   PCLASSINFO(PHTTPRequest, PObject)
00931 
00932   public:
00933     PHTTPRequest(
00934       const PURL & url,             
00935       const PMIMEInfo & inMIME,     
00936       const PMultiPartList & multipartFormInfo, 
00937       PHTTPResource * resource,     
00938       PHTTPServer & server          
00939     );
00940 
00941     PHTTPServer & server;           
00942     const PURL & url;               
00943     const PMIMEInfo & inMIME;       
00944     const PMultiPartList & multipartFormInfo; 
00945     PHTTP::StatusCode code;         
00946     PMIMEInfo outMIME;              
00947     PString entityBody;             
00948     PINDEX contentSize;             
00949     PIPSocket::Address origin;      
00950     PIPSocket::Address localAddr;   
00951     WORD               localPort;   
00952     PHTTPResource    * m_resource;  
00953 };
00954 
00955 
00957 // PHTTPAuthority
00958 
00962 class PHTTPAuthority : public PObject
00963 {
00964   PCLASSINFO(PHTTPAuthority, PObject)
00965 
00966   public:
00967   // New functions for class.
00974     virtual PString GetRealm(
00975       const PHTTPRequest & request   
00976     ) const = 0;
00977 
00984     virtual PBoolean Validate(
00985       const PHTTPRequest & request,  
00986       const PString & authInfo       
00987     ) const = 0;
00988 
00998     virtual PBoolean IsActive() const;
00999 
01000   protected:
01001     static void DecodeBasicAuthority(
01002       const PString & authInfo,   
01003       PString & username,         
01004       PString & password          
01005     );
01006 };
01007 
01008 
01010 // PHTTPSimpleAuth
01011 
01015 class PHTTPSimpleAuth : public PHTTPAuthority
01016 {
01017   PCLASSINFO(PHTTPSimpleAuth, PHTTPAuthority)
01018 
01019   public:
01020     PHTTPSimpleAuth(
01021       const PString & realm,      
01022       const PString & username,   
01023       const PString & password    
01024     );
01025     // Construct the simple authorisation structure.
01026 
01027 
01028   // Overrides from class PObject.
01036     virtual PObject * Clone() const;
01037 
01038 
01039   // Overrides from class PHTTPAuthority.
01046     virtual PString GetRealm(
01047       const PHTTPRequest & request   
01048     ) const;
01049 
01056     virtual PBoolean Validate(
01057       const PHTTPRequest & request,  
01058       const PString & authInfo       
01059     ) const;
01060 
01070     virtual PBoolean IsActive() const;
01071 
01077     const PString & GetUserName() const { return username; }
01078 
01084     const PString & GetPassword() const { return password; }
01085 
01086 
01087   protected:
01088     PString realm;
01089     PString username;
01090     PString password;
01091 };
01092 
01093 
01095 // PHTTPMultiSimpAuth
01096 
01100 class PHTTPMultiSimpAuth : public PHTTPAuthority
01101 {
01102   PCLASSINFO(PHTTPMultiSimpAuth, PHTTPAuthority)
01103 
01104   public:
01105     PHTTPMultiSimpAuth(
01106       const PString & realm      
01107     );
01108     PHTTPMultiSimpAuth(
01109       const PString & realm,           
01110       const PStringToString & userList 
01111     );
01112     // Construct the simple authorisation structure.
01113 
01114 
01115   // Overrides from class PObject.
01123     virtual PObject * Clone() const;
01124 
01125 
01126   // Overrides from class PHTTPAuthority.
01133     virtual PString GetRealm(
01134       const PHTTPRequest & request   
01135     ) const;
01136 
01143     virtual PBoolean Validate(
01144       const PHTTPRequest & request,  
01145       const PString & authInfo       
01146     ) const;
01147 
01157     virtual PBoolean IsActive() const;
01158 
01164     void AddUser(
01165       const PString & username,   
01166       const PString & password    
01167     );
01168 
01169 
01170   protected:
01171     PString realm;
01172     PStringToString users;
01173 };
01174 
01175 
01177 // PHTTPResource
01178 
01182 class PHTTPResource : public PObject
01183 {
01184   PCLASSINFO(PHTTPResource, PObject)
01185 
01186   protected:
01187     PHTTPResource(
01188       const PURL & url               
01189     );
01190     PHTTPResource(
01191       const PURL & url,              
01192       const PHTTPAuthority & auth    
01193     );
01194     PHTTPResource(
01195       const PURL & url,              
01196       const PString & contentType    
01197     );
01198     PHTTPResource(
01199       const PURL & url,              
01200       const PString & contentType,   
01201       const PHTTPAuthority & auth    
01202     );
01203     // Create a new HTTP Resource.
01204 
01205 
01206   public:
01207     virtual ~PHTTPResource();
01208     // Destroy the HTTP Resource.
01209 
01210 
01211   // New functions for class.
01217     const PURL & GetURL() const { return baseURL; }
01218 
01224     const PString & GetContentType() const { return contentType; }
01225 
01232     PHTTPAuthority * GetAuthority() const { return authority; }
01233 
01236     void SetAuthority(
01237       const PHTTPAuthority & auth      
01238     );
01239 
01242     void ClearAuthority();
01243 
01250     DWORD GetHitCount() const { return hitCount; }
01251 
01252     void ClearHitCount() { hitCount = 0; }
01253     // Clear the hit count for the resource.
01254 
01255 
01267     virtual PBoolean OnGET(
01268       PHTTPServer & server,       
01269       const PURL & url,           
01270       const PMIMEInfo & info,     
01271       const PHTTPConnectionInfo & conInfo   
01272     );
01273 
01283     virtual PBoolean OnGETData(
01284       PHTTPServer & server,                       
01285       const PURL & url,                           
01286       const PHTTPConnectionInfo & connectInfo,    
01287       PHTTPRequest & request                      
01288     );
01289 
01301     virtual PBoolean OnHEAD(
01302       PHTTPServer & server,       
01303       const PURL & url,           
01304       const PMIMEInfo & info,     
01305       const PHTTPConnectionInfo & conInfo  
01306     );
01307 
01319     virtual PBoolean OnPOST(
01320       PHTTPServer & server,         
01321       const PURL & url,             
01322       const PMIMEInfo & info,       
01323       const PStringToString & data, 
01324       const PHTTPConnectionInfo & conInfo  
01325     );
01326 
01336     virtual PBoolean OnPOSTData(
01337       PHTTPRequest & request,        
01338       const PStringToString & data   
01339     );
01340 
01347     virtual PBoolean IsModifiedSince(
01348       const PTime & when    
01349     );
01350 
01356     virtual PBoolean GetExpirationDate(
01357       PTime & when          
01358     );
01359 
01367     virtual PHTTPRequest * CreateRequest(
01368       const PURL & url,                   
01369       const PMIMEInfo & inMIME,           
01370       const PMultiPartList & multipartFormInfo,  
01371       PHTTPServer & socket                                
01372     );
01373 
01381     virtual PBoolean LoadHeaders(
01382       PHTTPRequest & request    
01383     ) = 0;
01384 
01390     virtual void SendData(
01391       PHTTPRequest & request    
01392     );
01393 
01402     virtual PBoolean LoadData(
01403       PHTTPRequest & request,    
01404       PCharArray & data          
01405     );
01406 
01415     virtual PString LoadText(
01416       PHTTPRequest & request    
01417     );
01418 
01425     virtual void OnLoadedText(
01426       PHTTPRequest & request,    
01427       PString & text             
01428     );
01429 
01438     virtual PBoolean Post(
01439       PHTTPRequest & request,       
01440       const PStringToString & data, 
01441       PHTML & replyMessage          
01442     );
01443 
01444 
01445   protected:
01448     virtual PBoolean CheckAuthority(
01449       PHTTPServer & server,               
01450       const PHTTPRequest & request,       
01451       const PHTTPConnectionInfo & conInfo 
01452     );
01453     static PBoolean CheckAuthority(
01454                    PHTTPAuthority & authority,
01455                       PHTTPServer & server,
01456                const PHTTPRequest & request,
01457         const PHTTPConnectionInfo & connectInfo
01458     );
01459 
01460 
01462     virtual PBoolean OnGETOrHEAD(
01463       PHTTPServer & server,       
01464       const PURL & url,           
01465       const PMIMEInfo & info,     
01466       const PHTTPConnectionInfo & conInfo,
01467       PBoolean  IsGet
01468     );
01469 
01471     PURL             baseURL;
01473     PString          contentType;
01475     PHTTPAuthority * authority;
01477     volatile DWORD   hitCount;
01478 };
01479 
01480 
01482 // PHTTPString
01483 
01488 class PHTTPString : public PHTTPResource
01489 {
01490   PCLASSINFO(PHTTPString, PHTTPResource)
01491 
01492   public:
01496     PHTTPString(
01497       const PURL & url             // Name of the resource in URL space.
01498     );
01499     PHTTPString(
01500       const PURL & url,            // Name of the resource in URL space.
01501       const PHTTPAuthority & auth  // Authorisation for the resource.
01502     );
01503     PHTTPString(
01504       const PURL & url,            // Name of the resource in URL space.
01505       const PString & str          // String to return in this resource.
01506     );
01507     PHTTPString(
01508       const PURL & url,            // Name of the resource in URL space.
01509       const PString & str,         // String to return in this resource.
01510       const PString & contentType  // MIME content type for the file.
01511     );
01512     PHTTPString(
01513       const PURL & url,            // Name of the resource in URL space.
01514       const PString & str,         // String to return in this resource.
01515       const PHTTPAuthority & auth  // Authorisation for the resource.
01516     );
01517     PHTTPString(
01518       const PURL & url,            // Name of the resource in URL space.
01519       const PString & str,         // String to return in this resource.
01520       const PString & contentType, // MIME content type for the file.
01521       const PHTTPAuthority & auth  // Authorisation for the resource.
01522     );
01523 
01524 
01525   // Overrides from class PHTTPResource
01533     virtual PBoolean LoadHeaders(
01534       PHTTPRequest & request    // Information on this request.
01535     );
01536 
01545     virtual PString LoadText(
01546       PHTTPRequest & request    // Information on this request.
01547     );
01548 
01549   // New functions for class.
01555     const PString & GetString() { return string; }
01556 
01559     void SetString(
01560       const PString & str   // New string for the resource.
01561     ) { string = str; }
01562 
01563 
01564   protected:
01565     PString string;
01566 };
01567 
01568 
01570 // PHTTPFile
01571 
01577 class PHTTPFile : public PHTTPResource
01578 {
01579   PCLASSINFO(PHTTPFile, PHTTPResource)
01580 
01581   public:
01588     PHTTPFile(
01589       const PString & filename     // file in file system and URL name.
01590     );
01591     PHTTPFile(
01592       const PString & filename,    // file in file system and URL name.
01593       const PHTTPAuthority & auth  // Authorisation for the resource.
01594     );
01595     PHTTPFile(
01596       const PURL & url,            // Name of the resource in URL space.
01597       const PFilePath & file       // Location of file in file system.
01598     );
01599     PHTTPFile(
01600       const PURL & url,            // Name of the resource in URL space.
01601       const PFilePath & file,      // Location of file in file system.
01602       const PString & contentType  // MIME content type for the file.
01603     );
01604     PHTTPFile(
01605       const PURL & url,            // Name of the resource in URL space.
01606       const PFilePath & file,      // Location of file in file system.
01607       const PHTTPAuthority & auth  // Authorisation for the resource.
01608     );
01609     PHTTPFile(
01610       const PURL & url,            // Name of the resource in URL space.
01611       const PFilePath & file,      // Location of file in file system.
01612       const PString & contentType, // MIME content type for the file.
01613       const PHTTPAuthority & auth  // Authorisation for the resource.
01614     );
01615 
01616 
01617   // Overrides from class PHTTPResource
01623     virtual PHTTPRequest * CreateRequest(
01624       const PURL & url,                  // Universal Resource Locator for document.
01625       const PMIMEInfo & inMIME,          // Extra MIME information in command.
01626       const PMultiPartList & multipartFormInfo,
01627       PHTTPServer & socket
01628     );
01629 
01637     virtual PBoolean LoadHeaders(
01638       PHTTPRequest & request    // Information on this request.
01639     );
01640 
01646     virtual PBoolean LoadData(
01647       PHTTPRequest & request,    // Information on this request.
01648       PCharArray & data          // Data used in reply.
01649     );
01650 
01659     virtual PString LoadText(
01660       PHTTPRequest & request    // Information on this request.
01661     );
01662 
01663 
01664   protected:
01665     PHTTPFile(
01666       const PURL & url,       // Name of the resource in URL space.
01667       int dummy
01668     );
01669     // Constructor used by PHTTPDirectory
01670 
01671 
01672     PFilePath filePath;
01673 };
01674 
01675 
01676 class PHTTPFileRequest : public PHTTPRequest
01677 {
01678   PCLASSINFO(PHTTPFileRequest, PHTTPRequest)
01679   public:
01680     PHTTPFileRequest(
01681       const PURL & url,             // Universal Resource Locator for document.
01682       const PMIMEInfo & inMIME,     // Extra MIME information in command.
01683       const PMultiPartList & multipartFormInfo,
01684       PHTTPResource * resource,
01685       PHTTPServer & server
01686     );
01687 
01688     PFile file;
01689 };
01690 
01691 
01693 // PHTTPTailFile
01694 
01703 class PHTTPTailFile : public PHTTPFile
01704 {
01705   PCLASSINFO(PHTTPTailFile, PHTTPFile)
01706 
01707   public:
01714     PHTTPTailFile(
01715       const PString & filename     // file in file system and URL name.
01716     );
01717     PHTTPTailFile(
01718       const PString & filename,    // file in file system and URL name.
01719       const PHTTPAuthority & auth  // Authorisation for the resource.
01720     );
01721     PHTTPTailFile(
01722       const PURL & url,            // Name of the resource in URL space.
01723       const PFilePath & file       // Location of file in file system.
01724     );
01725     PHTTPTailFile(
01726       const PURL & url,            // Name of the resource in URL space.
01727       const PFilePath & file,      // Location of file in file system.
01728       const PString & contentType  // MIME content type for the file.
01729     );
01730     PHTTPTailFile(
01731       const PURL & url,            // Name of the resource in URL space.
01732       const PFilePath & file,      // Location of file in file system.
01733       const PHTTPAuthority & auth  // Authorisation for the resource.
01734     );
01735     PHTTPTailFile(
01736       const PURL & url,            // Name of the resource in URL space.
01737       const PFilePath & file,      // Location of file in file system.
01738       const PString & contentType, // MIME content type for the file.
01739       const PHTTPAuthority & auth  // Authorisation for the resource.
01740     );
01741 
01742 
01743   // Overrides from class PHTTPResource
01751     virtual PBoolean LoadHeaders(
01752       PHTTPRequest & request    // Information on this request.
01753     );
01754 
01760     virtual PBoolean LoadData(
01761       PHTTPRequest & request,    // Information on this request.
01762       PCharArray & data          // Data used in reply.
01763     );
01764 };
01765 
01766 
01768 // PHTTPDirectory
01769 
01782 class PHTTPDirectory : public PHTTPFile
01783 {
01784   PCLASSINFO(PHTTPDirectory, PHTTPFile)
01785 
01786   public:
01787     PHTTPDirectory(
01788       const PURL & url,            
01789       const PDirectory & dir       
01790     );
01791     PHTTPDirectory(
01792       const PURL & url,            
01793       const PDirectory & dir,      
01794       const PHTTPAuthority & auth  
01795     );
01796     // Construct a new directory resource for HTTP.
01797 
01798 
01799   // Overrides from class PHTTPResource
01805     virtual PHTTPRequest * CreateRequest(
01806       const PURL & url,                  // Universal Resource Locator for document.
01807       const PMIMEInfo & inMIME,          // Extra MIME information in command.
01808       const PMultiPartList & multipartFormInfo,
01809       PHTTPServer & socket
01810     );
01811 
01819     virtual PBoolean LoadHeaders(
01820       PHTTPRequest & request    
01821     );
01822 
01831     virtual PString LoadText(
01832       PHTTPRequest & request    
01833     );
01834 
01843     void EnableAuthorisation(const PString & realm);
01844 
01847     void AllowDirectories(PBoolean enable = PTrue);
01848 
01849   protected:
01850     PBoolean CheckAuthority(
01851       PHTTPServer & server,               // Server to send response to.
01852       const PHTTPRequest & request,       // Information on this request.
01853       const PHTTPConnectionInfo & conInfo // Information on the connection
01854     );
01855 
01856     PBoolean FindAuthorisations(const PDirectory & dir, PString & realm, PStringToString & authorisations);
01857 
01858     PDirectory basePath;
01859     PString authorisationRealm;
01860     PBoolean allowDirectoryListing;
01861 };
01862 
01863 
01864 class PHTTPDirRequest : public PHTTPFileRequest
01865 {
01866   PCLASSINFO(PHTTPDirRequest, PHTTPFileRequest)
01867   public:
01868     PHTTPDirRequest(
01869       const PURL & url,             // Universal Resource Locator for document.
01870       const PMIMEInfo & inMIME,     // Extra MIME information in command.
01871       const PMultiPartList & multipartFormInfo, 
01872       PHTTPResource * resource,
01873       PHTTPServer & server
01874     );
01875 
01876     PString fakeIndex;
01877     PFilePath realPath;
01878 };
01879 
01880 #endif // P_HTTP
01881 
01882 #endif // PTLIB_HTTP_H
01883 
01884 
01885 // End Of File ///////////////////////////////////////////////////////////////

Generated on Mon Feb 21 20:10:42 2011 for PTLib by  doxygen 1.4.7