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: 19008 $
00027  * $Author: rjongbloed $
00028  * $Date: 2007-11-29 09:17:41 +0000 (Thu, 29 Nov 2007) $
00029  */
00030 
00031 #ifndef _PHTTP
00032 #define _PHTTP
00033 
00034 #ifdef P_USE_PRAGMA
00035 #pragma interface
00036 #endif
00037 
00038 #include <ptclib/inetprot.h>
00039 #include <ptclib/mime.h>
00040 #include <ptclib/url.h>
00041 #include <ptlib/ipsock.h>
00042 
00043 
00044 #include <ptclib/html.h>
00045 
00047 // PHTTPSpace
00048 
00049 class PHTTPResource;
00050 
00055 class PHTTPSpace : public PContainer
00056 {
00057   PCONTAINERINFO(PHTTPSpace, PContainer)
00058   public:
00060     PHTTPSpace();
00061 
00062 
00063   // New functions for class.
00064     enum AddOptions {
00066       ErrorOnExist,
00068       Overwrite
00069     };
00070 
00071 
00083     PBoolean AddResource(
00084       PHTTPResource * resource, 
00085       AddOptions overwrite = ErrorOnExist
00087     );
00088 
00096     PBoolean DelResource(
00097       const PURL & url          
00098     );
00099 
00105     PHTTPResource * FindResource(
00106       const PURL & url   
00107     );
00108 
00111     void StartRead() const
00112       { mutex->StartRead(); }
00113 
00116     void EndRead() const
00117       { mutex->EndRead(); }
00118 
00121     void StartWrite() const
00122       { mutex->StartWrite(); }
00123 
00126     void EndWrite() const
00127       { mutex->EndWrite(); }
00128 
00129 
00130   protected:
00131     PReadWriteMutex * mutex;
00132 
00133     class Node;
00134     PSORTED_LIST(ChildList, Node);
00135     class Node : public PString
00136     {
00137       PCLASSINFO(Node, PString)
00138       public:
00139         Node(const PString & name, Node * parentNode);
00140         ~Node();
00141 
00142         Node          * parent;
00143         ChildList       children;
00144         PHTTPResource * resource;
00145     } * root;
00146 
00147   private:
00148     PBoolean SetSize(PINDEX) { return PFalse; }
00149 };
00150 
00151 #ifdef _WIN32_WCE
00152 #undef TRACE
00153 #endif
00154 
00156 // PHTTP
00157 
00161 class PHTTP : public PInternetProtocol
00162 {
00163   PCLASSINFO(PHTTP, PInternetProtocol)
00164 
00165   public:
00166   // New functions for class.
00167     enum Commands {
00168       // HTTP/1.0 commands
00169       GET, HEAD, POST,
00170       // HTTP/1.1 commands
00171       PUT, DELETE, TRACE, OPTIONS,
00172       // HTTPS command
00173       CONNECT,
00174       NumCommands
00175     };
00176 
00177     enum StatusCode {
00178       Continue = 100,              
00179       SwitchingProtocols,          
00180       RequestOK = 200,             
00181       Created,                     
00182       Accepted,                    
00183       NonAuthoritativeInformation, 
00184       NoContent,                   
00185       ResetContent,                
00186       PartialContent,              
00187       MultipleChoices = 300,       
00188       MovedPermanently,            
00189       MovedTemporarily,            
00190       SeeOther,                    
00191       NotModified,                 
00192       UseProxy,                    
00193       BadRequest = 400,            
00194       UnAuthorised,                
00195       PaymentRequired,             
00196       Forbidden,                   
00197       NotFound,                    
00198       MethodNotAllowed,            
00199       NoneAcceptable,              
00200       ProxyAuthenticationRequired, 
00201       RequestTimeout,              
00202       Conflict,                    
00203       Gone,                        
00204       LengthRequired,              
00205       UnlessTrue,                  
00206       InternalServerError = 500,   
00207       NotImplemented,              
00208       BadGateway,                  
00209       ServiceUnavailable,          
00210       GatewayTimeout               
00211     };
00212 
00213     // Common MIME header tags
00214     static const PString & AllowTag();
00215     static const PString & AuthorizationTag();
00216     static const PString & ContentEncodingTag();
00217     static const PString & ContentLengthTag();
00218     static const PString & ContentTypeTag();
00219     static const PString & DateTag();
00220     static const PString & ExpiresTag();
00221     static const PString & FromTag();
00222     static const PString & IfModifiedSinceTag();
00223     static const PString & LastModifiedTag();
00224     static const PString & LocationTag();
00225     static const PString & PragmaTag();
00226     static const PString & PragmaNoCacheTag();
00227     static const PString & RefererTag();
00228     static const PString & ServerTag();
00229     static const PString & UserAgentTag();
00230     static const PString & WWWAuthenticateTag();
00231     static const PString & MIMEVersionTag();
00232     static const PString & ConnectionTag();
00233     static const PString & KeepAliveTag();
00234     static const PString & TransferEncodingTag();
00235     static const PString & ChunkedTag();
00236     static const PString & ProxyConnectionTag();
00237     static const PString & ProxyAuthorizationTag();
00238     static const PString & ProxyAuthenticateTag();
00239     static const PString & ForwardedTag();
00240     static const PString & SetCookieTag();
00241     static const PString & CookieTag();
00242 
00243   protected:
00246     PHTTP();
00247 
00259     virtual PINDEX ParseResponse(
00260       const PString & line    
00261     );
00262 };
00263 
00264 
00266 // PHTTPClient
00267 
00288 class PHTTPClient : public PHTTP
00289 {
00290   PCLASSINFO(PHTTPClient, PHTTP)
00291 
00292   public:
00294     PHTTPClient();
00295     PHTTPClient(
00296       const PString & userAgentName
00297     );
00298 
00299 
00300   // New functions for class.
00308     int ExecuteCommand(
00309       Commands cmd,
00310       const PURL & url,
00311       PMIMEInfo & outMIME,
00312       const PString & dataBody,
00313       PMIMEInfo & replyMime,
00314       PBoolean persist = PTrue
00315     );
00316     int ExecuteCommand(
00317       const PString & cmdName,
00318       const PURL & url,
00319       PMIMEInfo & outMIME,
00320       const PString & dataBody,
00321       PMIMEInfo & replyMime,
00322       PBoolean persist = PTrue
00323     );
00324 
00326     PBoolean WriteCommand(
00327       Commands cmd,
00328       const PString & url,
00329       PMIMEInfo & outMIME,
00330       const PString & dataBody
00331     );
00332     PBoolean WriteCommand(
00333       const PString & cmdName,
00334       const PString & url,
00335       PMIMEInfo & outMIME,
00336       const PString & dataBody
00337     );
00338 
00340     PBoolean ReadResponse(
00341       PMIMEInfo & replyMIME
00342     );
00343 
00345     PBoolean ReadContentBody(
00346       PMIMEInfo & replyMIME,
00347       PBYTEArray & body
00348     );
00349     PBoolean ReadContentBody(
00350       PMIMEInfo & replyMIME,
00351       PString & body
00352     );
00353 
00354 
00360     PBoolean GetTextDocument(
00361       const PURL & url,         
00362       PString & document,       
00363       PBoolean persist = PTrue       
00364     );
00365 
00371     PBoolean GetDocument(
00372       const PURL & url,         
00373       PMIMEInfo & outMIME,      
00374       PMIMEInfo & replyMIME,    
00375       PBoolean persist = PTrue       
00376     );
00377 
00383     PBoolean GetHeader(
00384       const PURL & url,         
00385       PMIMEInfo & outMIME,      
00386       PMIMEInfo & replyMIME,    
00387       PBoolean persist = PTrue       
00388     );
00389 
00390 
00396     PBoolean PostData(
00397       const PURL & url,       
00398       PMIMEInfo & outMIME,    
00399       const PString & data,   
00400       PMIMEInfo & replyMIME,  
00401       PBoolean persist = PTrue     
00402     );
00403 
00409     PBoolean PostData(
00410       const PURL & url,       
00411       PMIMEInfo & outMIME,    
00412       const PString & data,   
00413       PMIMEInfo & replyMIME,  
00414       PString & replyBody,    
00415       PBoolean persist = PTrue     
00416     );
00417 
00418   protected:
00419     PBoolean AssureConnect(const PURL & url, PMIMEInfo & outMIME);
00420     PBoolean InternalReadContentBody(
00421       PMIMEInfo & replyMIME,
00422       PAbstractArray & body
00423     );
00424 
00425     PString userAgentName;
00426 };
00427 
00429 // PMultipartFormInfo
00430 
00435 class PMultipartFormInfo : public PObject
00436 {
00437   PCLASSINFO(PMultipartFormInfo, PObject);
00438   public:
00439     PMIMEInfo mime;
00440     PString body;
00441 };
00442 
00443 PARRAY(PMultipartFormInfoArray, PMultipartFormInfo);
00444 
00446 // PHTTPConnectionInfo
00447 
00448 class PHTTPServer;
00449 
00454 class PHTTPConnectionInfo : public PObject
00455 {
00456   PCLASSINFO(PHTTPConnectionInfo, PObject)
00457   public:
00458     PHTTPConnectionInfo();
00459 
00460     PHTTP::Commands GetCommandCode() const { return commandCode; }
00461     const PString & GetCommandName() const { return commandName; }
00462 
00463     const PURL & GetURL() const       { return url; }
00464 
00465     const PMIMEInfo & GetMIME() const { return mimeInfo; }
00466     void SetMIME(const PString & tag, const PString & value);
00467 
00468     PBoolean IsCompatible(int major, int minor) const;
00469 
00470     PBoolean IsPersistant() const         { return isPersistant; }
00471     PBoolean WasPersistant() const        { return wasPersistant; }
00472     PBoolean IsProxyConnection() const    { return isProxyConnection; }
00473     int  GetMajorVersion() const      { return majorVersion; }
00474     int  GetMinorVersion() const      { return minorVersion; }
00475 
00476     long GetEntityBodyLength() const  { return entityBodyLength; }
00477 
00480     PTimeInterval GetPersistenceTimeout() const { return persistenceTimeout; }
00481 
00484     void SetPersistenceTimeout(const PTimeInterval & t) { persistenceTimeout = t; }
00485 
00489     unsigned GetPersistenceMaximumTransations() const { return persistenceMaximum; }
00490 
00494     void SetPersistenceMaximumTransations(unsigned m) { persistenceMaximum = m; }
00495 
00496     const PMultipartFormInfoArray & GetMultipartFormInfo() const
00497       { return multipartFormInfoArray; }
00498 
00499     void ResetMultipartFormInfo()
00500       { multipartFormInfoArray.RemoveAll(); }
00501 
00502     PString GetEntityBody() const   { return entityBody; }
00503 
00504   protected:
00505     PBoolean Initialise(PHTTPServer & server, PString & args);
00506     void DecodeMultipartFormInfo(const PString & type, const PString & entityBody);
00507 
00508     PHTTP::Commands commandCode;
00509     PString         commandName;
00510     PURL            url;
00511     PMIMEInfo       mimeInfo;
00512     PBoolean            isPersistant;
00513     PBoolean            wasPersistant;
00514     PBoolean            isProxyConnection;
00515     int             majorVersion;
00516     int             minorVersion;
00517     PString         entityBody;        // original entity body (POST only)
00518     long            entityBodyLength;
00519     PTimeInterval   persistenceTimeout;
00520     unsigned        persistenceMaximum;
00521     PMultipartFormInfoArray multipartFormInfoArray;
00522 
00523   friend class PHTTPServer;
00524 };
00525 
00526 
00528 // PHTTPServer
00529 
00542 class PHTTPServer : public PHTTP
00543 {
00544   PCLASSINFO(PHTTPServer, PHTTP)
00545 
00546   public:
00554     PHTTPServer();
00555     PHTTPServer(
00556      const PHTTPSpace & urlSpace  
00557     );
00558 
00559 
00560   // New functions for class.
00566     virtual PString GetServerName() const;
00567 
00573     PHTTPSpace & GetURLSpace() { return urlSpace; }
00574 
00576     void SetURLSpace(
00577       const PHTTPSpace & space   
00578     );
00579 
00580 
00590     virtual PBoolean ProcessCommand();
00591 
00603     virtual PBoolean OnGET(
00604       const PURL & url,                    
00605       const PMIMEInfo & info,              
00606       const PHTTPConnectionInfo & conInfo  
00607     );
00608 
00609 
00610 
00622     virtual PBoolean OnHEAD(
00623       const PURL & url,                   
00624       const PMIMEInfo & info,             
00625       const PHTTPConnectionInfo & conInfo 
00626     );
00627 
00639     virtual PBoolean OnPOST(
00640       const PURL & url,                   
00641       const PMIMEInfo & info,             
00642       const PStringToString & data,       
00643       const PHTTPConnectionInfo & conInfo 
00644     );
00645 
00658     virtual PBoolean OnProxy(
00659       const PHTTPConnectionInfo & conInfo   
00660     );
00661 
00662 
00669     virtual PString ReadEntityBody();
00670 
00676     virtual PBoolean OnUnknown(
00677       const PCaselessString & command,         
00678       const PHTTPConnectionInfo & connectInfo  
00679     );
00680 
00699     PBoolean StartResponse(
00700       StatusCode code,      
00701       PMIMEInfo & headers,  
00702       long bodySize         
00703     );
00704 
00714     virtual PBoolean OnError(
00715       StatusCode code,                         
00716       const PCaselessString & extra,           
00717       const PHTTPConnectionInfo & connectInfo  
00718     );
00719 
00722     void SetDefaultMIMEInfo(
00723       PMIMEInfo & info,      
00724       const PHTTPConnectionInfo & connectInfo
00725     );
00726 
00729     PHTTPConnectionInfo & GetConnectionInfo() { return connectInfo; }
00730 
00731   protected:
00732     void Construct();
00733 
00734     PHTTPSpace          urlSpace;
00735     PHTTPConnectionInfo connectInfo;
00736     unsigned            transactionCount;
00737     PTimeInterval       nextTimeout;
00738 };
00739 
00740 
00742 // PHTTPRequest
00743 
00748 class PHTTPRequest : public PObject
00749 {
00750   PCLASSINFO(PHTTPRequest, PObject)
00751 
00752   public:
00753     PHTTPRequest(
00754       const PURL & url,             
00755       const PMIMEInfo & inMIME,     
00756       const PMultipartFormInfoArray & multipartFormInfo, 
00757       PHTTPServer & server          
00758     );
00759 
00760     PHTTPServer & server;           
00761     const PURL & url;               
00762     const PMIMEInfo & inMIME;       
00763     const PMultipartFormInfoArray & multipartFormInfo; 
00764     PHTTP::StatusCode code;         
00765     PMIMEInfo outMIME;              
00766     PString entityBody;             
00767     PINDEX contentSize;             
00768     PIPSocket::Address origin;      
00769     PIPSocket::Address localAddr;   
00770     WORD               localPort;   
00771 };
00772 
00773 
00775 // PHTTPAuthority
00776 
00780 class PHTTPAuthority : public PObject
00781 {
00782   PCLASSINFO(PHTTPAuthority, PObject)
00783 
00784   public:
00785   // New functions for class.
00792     virtual PString GetRealm(
00793       const PHTTPRequest & request   
00794     ) const = 0;
00795 
00802     virtual PBoolean Validate(
00803       const PHTTPRequest & request,  
00804       const PString & authInfo       
00805     ) const = 0;
00806 
00816     virtual PBoolean IsActive() const;
00817 
00818   protected:
00819     static void DecodeBasicAuthority(
00820       const PString & authInfo,   
00821       PString & username,         
00822       PString & password          
00823     );
00824 };
00825 
00826 
00828 // PHTTPSimpleAuth
00829 
00833 class PHTTPSimpleAuth : public PHTTPAuthority
00834 {
00835   PCLASSINFO(PHTTPSimpleAuth, PHTTPAuthority)
00836 
00837   public:
00838     PHTTPSimpleAuth(
00839       const PString & realm,      
00840       const PString & username,   
00841       const PString & password    
00842     );
00843     // Construct the simple authorisation structure.
00844 
00845 
00846   // Overrides from class PObject.
00854     virtual PObject * Clone() const;
00855 
00856 
00857   // Overrides from class PHTTPAuthority.
00864     virtual PString GetRealm(
00865       const PHTTPRequest & request   
00866     ) const;
00867 
00874     virtual PBoolean Validate(
00875       const PHTTPRequest & request,  
00876       const PString & authInfo       
00877     ) const;
00878 
00888     virtual PBoolean IsActive() const;
00889 
00895     const PString & GetUserName() const { return username; }
00896 
00902     const PString & GetPassword() const { return password; }
00903 
00904 
00905   protected:
00906     PString realm;
00907     PString username;
00908     PString password;
00909 };
00910 
00911 
00913 // PHTTPMultiSimpAuth
00914 
00918 class PHTTPMultiSimpAuth : public PHTTPAuthority
00919 {
00920   PCLASSINFO(PHTTPMultiSimpAuth, PHTTPAuthority)
00921 
00922   public:
00923     PHTTPMultiSimpAuth(
00924       const PString & realm      
00925     );
00926     PHTTPMultiSimpAuth(
00927       const PString & realm,           
00928       const PStringToString & userList 
00929     );
00930     // Construct the simple authorisation structure.
00931 
00932 
00933   // Overrides from class PObject.
00941     virtual PObject * Clone() const;
00942 
00943 
00944   // Overrides from class PHTTPAuthority.
00951     virtual PString GetRealm(
00952       const PHTTPRequest & request   
00953     ) const;
00954 
00961     virtual PBoolean Validate(
00962       const PHTTPRequest & request,  
00963       const PString & authInfo       
00964     ) const;
00965 
00975     virtual PBoolean IsActive() const;
00976 
00982     void AddUser(
00983       const PString & username,   
00984       const PString & password    
00985     );
00986 
00987 
00988   protected:
00989     PString realm;
00990     PStringToString users;
00991 };
00992 
00993 
00995 // PHTTPResource
00996 
01000 class PHTTPResource : public PObject
01001 {
01002   PCLASSINFO(PHTTPResource, PObject)
01003 
01004   protected:
01005     PHTTPResource(
01006       const PURL & url               
01007     );
01008     PHTTPResource(
01009       const PURL & url,              
01010       const PHTTPAuthority & auth    
01011     );
01012     PHTTPResource(
01013       const PURL & url,              
01014       const PString & contentType    
01015     );
01016     PHTTPResource(
01017       const PURL & url,              
01018       const PString & contentType,   
01019       const PHTTPAuthority & auth    
01020     );
01021     // Create a new HTTP Resource.
01022 
01023 
01024   public:
01025     virtual ~PHTTPResource();
01026     // Destroy the HTTP Resource.
01027 
01028 
01029   // New functions for class.
01035     const PURL & GetURL() const { return baseURL; }
01036 
01042     const PString & GetContentType() const { return contentType; }
01043 
01050     PHTTPAuthority * GetAuthority() const { return authority; }
01051 
01054     void SetAuthority(
01055       const PHTTPAuthority & auth      
01056     );
01057 
01060     void ClearAuthority();
01061 
01068     DWORD GetHitCount() const { return hitCount; }
01069 
01070     void ClearHitCount() { hitCount = 0; }
01071     // Clear the hit count for the resource.
01072 
01073 
01085     virtual PBoolean OnGET(
01086       PHTTPServer & server,       
01087       const PURL & url,           
01088       const PMIMEInfo & info,     
01089       const PHTTPConnectionInfo & conInfo   
01090     );
01091 
01101     virtual PBoolean OnGETData(
01102       PHTTPServer & server,                       
01103       const PURL & url,                           
01104       const PHTTPConnectionInfo & connectInfo,    
01105       PHTTPRequest & request                      
01106     );
01107 
01119     virtual PBoolean OnHEAD(
01120       PHTTPServer & server,       
01121       const PURL & url,           
01122       const PMIMEInfo & info,     
01123       const PHTTPConnectionInfo & conInfo  
01124     );
01125 
01137     virtual PBoolean OnPOST(
01138       PHTTPServer & server,         
01139       const PURL & url,             
01140       const PMIMEInfo & info,       
01141       const PStringToString & data, 
01142       const PHTTPConnectionInfo & conInfo  
01143     );
01144 
01154     virtual PBoolean OnPOSTData(
01155       PHTTPRequest & request,        
01156       const PStringToString & data   
01157     );
01158 
01165     virtual PBoolean IsModifiedSince(
01166       const PTime & when    
01167     );
01168 
01174     virtual PBoolean GetExpirationDate(
01175       PTime & when          
01176     );
01177 
01185     virtual PHTTPRequest * CreateRequest(
01186       const PURL & url,                   
01187       const PMIMEInfo & inMIME,           
01188       const PMultipartFormInfoArray & multipartFormInfo,  
01189       PHTTPServer & socket                                
01190     );
01191 
01199     virtual PBoolean LoadHeaders(
01200       PHTTPRequest & request    
01201     ) = 0;
01202 
01208     virtual void SendData(
01209       PHTTPRequest & request    
01210     );
01211 
01220     virtual PBoolean LoadData(
01221       PHTTPRequest & request,    
01222       PCharArray & data          
01223     );
01224 
01233     virtual PString LoadText(
01234       PHTTPRequest & request    
01235     );
01236 
01243     virtual void OnLoadedText(
01244       PHTTPRequest & request,    
01245       PString & text             
01246     );
01247 
01256     virtual PBoolean Post(
01257       PHTTPRequest & request,       
01258       const PStringToString & data, 
01259       PHTML & replyMessage          
01260     );
01261 
01262 
01263   protected:
01266     virtual PBoolean CheckAuthority(
01267       PHTTPServer & server,               
01268       const PHTTPRequest & request,       
01269       const PHTTPConnectionInfo & conInfo 
01270     );
01271     static PBoolean CheckAuthority(
01272                    PHTTPAuthority & authority,
01273                       PHTTPServer & server,
01274                const PHTTPRequest & request,
01275         const PHTTPConnectionInfo & connectInfo
01276     );
01277 
01278 
01280     virtual PBoolean OnGETOrHEAD(
01281       PHTTPServer & server,       
01282       const PURL & url,           
01283       const PMIMEInfo & info,     
01284       const PHTTPConnectionInfo & conInfo,
01285       PBoolean  IsGet
01286     );
01287 
01289     PURL             baseURL;
01291     PString          contentType;
01293     PHTTPAuthority * authority;
01295     volatile DWORD   hitCount;
01296 };
01297 
01298 
01300 // PHTTPString
01301 
01306 class PHTTPString : public PHTTPResource
01307 {
01308   PCLASSINFO(PHTTPString, PHTTPResource)
01309 
01310   public:
01314     PHTTPString(
01315       const PURL & url             // Name of the resource in URL space.
01316     );
01317     PHTTPString(
01318       const PURL & url,            // Name of the resource in URL space.
01319       const PHTTPAuthority & auth  // Authorisation for the resource.
01320     );
01321     PHTTPString(
01322       const PURL & url,            // Name of the resource in URL space.
01323       const PString & str          // String to return in this resource.
01324     );
01325     PHTTPString(
01326       const PURL & url,            // Name of the resource in URL space.
01327       const PString & str,         // String to return in this resource.
01328       const PString & contentType  // MIME content type for the file.
01329     );
01330     PHTTPString(
01331       const PURL & url,            // Name of the resource in URL space.
01332       const PString & str,         // String to return in this resource.
01333       const PHTTPAuthority & auth  // Authorisation for the resource.
01334     );
01335     PHTTPString(
01336       const PURL & url,            // Name of the resource in URL space.
01337       const PString & str,         // String to return in this resource.
01338       const PString & contentType, // MIME content type for the file.
01339       const PHTTPAuthority & auth  // Authorisation for the resource.
01340     );
01341 
01342 
01343   // Overrides from class PHTTPResource
01351     virtual PBoolean LoadHeaders(
01352       PHTTPRequest & request    // Information on this request.
01353     );
01354 
01363     virtual PString LoadText(
01364       PHTTPRequest & request    // Information on this request.
01365     );
01366 
01367   // New functions for class.
01373     const PString & GetString() { return string; }
01374 
01377     void SetString(
01378       const PString & str   // New string for the resource.
01379     ) { string = str; }
01380 
01381 
01382   protected:
01383     PString string;
01384 };
01385 
01386 
01388 // PHTTPFile
01389 
01395 class PHTTPFile : public PHTTPResource
01396 {
01397   PCLASSINFO(PHTTPFile, PHTTPResource)
01398 
01399   public:
01406     PHTTPFile(
01407       const PString & filename     // file in file system and URL name.
01408     );
01409     PHTTPFile(
01410       const PString & filename,    // file in file system and URL name.
01411       const PHTTPAuthority & auth  // Authorisation for the resource.
01412     );
01413     PHTTPFile(
01414       const PURL & url,            // Name of the resource in URL space.
01415       const PFilePath & file       // Location of file in file system.
01416     );
01417     PHTTPFile(
01418       const PURL & url,            // Name of the resource in URL space.
01419       const PFilePath & file,      // Location of file in file system.
01420       const PString & contentType  // MIME content type for the file.
01421     );
01422     PHTTPFile(
01423       const PURL & url,            // Name of the resource in URL space.
01424       const PFilePath & file,      // Location of file in file system.
01425       const PHTTPAuthority & auth  // Authorisation for the resource.
01426     );
01427     PHTTPFile(
01428       const PURL & url,            // Name of the resource in URL space.
01429       const PFilePath & file,      // Location of file in file system.
01430       const PString & contentType, // MIME content type for the file.
01431       const PHTTPAuthority & auth  // Authorisation for the resource.
01432     );
01433 
01434 
01435   // Overrides from class PHTTPResource
01441     virtual PHTTPRequest * CreateRequest(
01442       const PURL & url,                  // Universal Resource Locator for document.
01443       const PMIMEInfo & inMIME,          // Extra MIME information in command.
01444       const PMultipartFormInfoArray & multipartFormInfo,
01445       PHTTPServer & socket
01446     );
01447 
01455     virtual PBoolean LoadHeaders(
01456       PHTTPRequest & request    // Information on this request.
01457     );
01458 
01464     virtual PBoolean LoadData(
01465       PHTTPRequest & request,    // Information on this request.
01466       PCharArray & data          // Data used in reply.
01467     );
01468 
01477     virtual PString LoadText(
01478       PHTTPRequest & request    // Information on this request.
01479     );
01480 
01481 
01482   protected:
01483     PHTTPFile(
01484       const PURL & url,       // Name of the resource in URL space.
01485       int dummy
01486     );
01487     // Constructor used by PHTTPDirectory
01488 
01489 
01490     PFilePath filePath;
01491 };
01492 
01493 
01494 class PHTTPFileRequest : public PHTTPRequest
01495 {
01496   PCLASSINFO(PHTTPFileRequest, PHTTPRequest)
01497   public:
01498     PHTTPFileRequest(
01499       const PURL & url,             // Universal Resource Locator for document.
01500       const PMIMEInfo & inMIME,     // Extra MIME information in command.
01501       const PMultipartFormInfoArray & multipartFormInfo,
01502       PHTTPServer & server
01503     );
01504 
01505     PFile file;
01506 };
01507 
01508 
01510 // PHTTPTailFile
01511 
01520 class PHTTPTailFile : public PHTTPFile
01521 {
01522   PCLASSINFO(PHTTPTailFile, PHTTPFile)
01523 
01524   public:
01531     PHTTPTailFile(
01532       const PString & filename     // file in file system and URL name.
01533     );
01534     PHTTPTailFile(
01535       const PString & filename,    // file in file system and URL name.
01536       const PHTTPAuthority & auth  // Authorisation for the resource.
01537     );
01538     PHTTPTailFile(
01539       const PURL & url,            // Name of the resource in URL space.
01540       const PFilePath & file       // Location of file in file system.
01541     );
01542     PHTTPTailFile(
01543       const PURL & url,            // Name of the resource in URL space.
01544       const PFilePath & file,      // Location of file in file system.
01545       const PString & contentType  // MIME content type for the file.
01546     );
01547     PHTTPTailFile(
01548       const PURL & url,            // Name of the resource in URL space.
01549       const PFilePath & file,      // Location of file in file system.
01550       const PHTTPAuthority & auth  // Authorisation for the resource.
01551     );
01552     PHTTPTailFile(
01553       const PURL & url,            // Name of the resource in URL space.
01554       const PFilePath & file,      // Location of file in file system.
01555       const PString & contentType, // MIME content type for the file.
01556       const PHTTPAuthority & auth  // Authorisation for the resource.
01557     );
01558 
01559 
01560   // Overrides from class PHTTPResource
01568     virtual PBoolean LoadHeaders(
01569       PHTTPRequest & request    // Information on this request.
01570     );
01571 
01577     virtual PBoolean LoadData(
01578       PHTTPRequest & request,    // Information on this request.
01579       PCharArray & data          // Data used in reply.
01580     );
01581 };
01582 
01583 
01585 // PHTTPDirectory
01586 
01599 class PHTTPDirectory : public PHTTPFile
01600 {
01601   PCLASSINFO(PHTTPDirectory, PHTTPFile)
01602 
01603   public:
01604     PHTTPDirectory(
01605       const PURL & url,            
01606       const PDirectory & dir       
01607     );
01608     PHTTPDirectory(
01609       const PURL & url,            
01610       const PDirectory & dir,      
01611       const PHTTPAuthority & auth  
01612     );
01613     // Construct a new directory resource for HTTP.
01614 
01615 
01616   // Overrides from class PHTTPResource
01622     virtual PHTTPRequest * CreateRequest(
01623       const PURL & url,                  // Universal Resource Locator for document.
01624       const PMIMEInfo & inMIME,          // Extra MIME information in command.
01625       const PMultipartFormInfoArray & multipartFormInfo,
01626       PHTTPServer & socket
01627     );
01628 
01636     virtual PBoolean LoadHeaders(
01637       PHTTPRequest & request    
01638     );
01639 
01648     virtual PString LoadText(
01649       PHTTPRequest & request    
01650     );
01651 
01660     void EnableAuthorisation(const PString & realm);
01661 
01664     void AllowDirectories(PBoolean enable = PTrue);
01665 
01666   protected:
01667     PBoolean CheckAuthority(
01668       PHTTPServer & server,               // Server to send response to.
01669       const PHTTPRequest & request,       // Information on this request.
01670       const PHTTPConnectionInfo & conInfo // Information on the connection
01671     );
01672 
01673     PBoolean FindAuthorisations(const PDirectory & dir, PString & realm, PStringToString & authorisations);
01674 
01675     PDirectory basePath;
01676     PString authorisationRealm;
01677     PBoolean allowDirectoryListing;
01678 };
01679 
01680 
01681 class PHTTPDirRequest : public PHTTPFileRequest
01682 {
01683   PCLASSINFO(PHTTPDirRequest, PHTTPFileRequest)
01684   public:
01685     PHTTPDirRequest(
01686       const PURL & url,             // Universal Resource Locator for document.
01687       const PMIMEInfo & inMIME,     // Extra MIME information in command.
01688       const PMultipartFormInfoArray & multipartFormInfo, 
01689       PHTTPServer & server
01690     );
01691 
01692     PString fakeIndex;
01693     PFilePath realPath;
01694 };
01695 
01696 #endif // _PHTTP
01697 
01698 
01699 // End Of File ///////////////////////////////////////////////////////////////

Generated on Mon Dec 10 11:18:57 2007 for PTLib by  doxygen 1.5.1