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: 20385 $
00027  * $Author: rjongbloed $
00028  * $Date: 2008-06-04 10:40:38 +0000 (Wed, 04 Jun 2008) $
00029  */
00030 
00031 #ifndef _PHTTP_H
00032 #define _PHTTP_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 
00045 
00046 #include <ptclib/html.h>
00047 
00049 // PHTTPSpace
00050 
00051 class PHTTPResource;
00052 
00057 class PHTTPSpace : public PContainer
00058 {
00059   PCONTAINERINFO(PHTTPSpace, PContainer)
00060   public:
00062     PHTTPSpace();
00063 
00064 
00065   // New functions for class.
00066     enum AddOptions {
00068       ErrorOnExist,
00070       Overwrite
00071     };
00072 
00073 
00085     PBoolean AddResource(
00086       PHTTPResource * resource, 
00087       AddOptions overwrite = ErrorOnExist
00089     );
00090 
00098     PBoolean DelResource(
00099       const PURL & url          
00100     );
00101 
00107     PHTTPResource * FindResource(
00108       const PURL & url   
00109     );
00110 
00113     void StartRead() const
00114       { mutex->StartRead(); }
00115 
00118     void EndRead() const
00119       { mutex->EndRead(); }
00120 
00123     void StartWrite() const
00124       { mutex->StartWrite(); }
00125 
00128     void EndWrite() const
00129       { mutex->EndWrite(); }
00130 
00131 
00132   protected:
00133     PReadWriteMutex * mutex;
00134 
00135     class Node;
00136     PSORTED_LIST(ChildList, Node);
00137     class Node : public PString
00138     {
00139       PCLASSINFO(Node, PString)
00140       public:
00141         Node(const PString & name, Node * parentNode);
00142         ~Node();
00143 
00144         Node          * parent;
00145         ChildList       children;
00146         PHTTPResource * resource;
00147     } * root;
00148 
00149   private:
00150     PBoolean SetSize(PINDEX) { return PFalse; }
00151 };
00152 
00153 #ifdef _WIN32_WCE
00154 #undef TRACE
00155 #endif
00156 
00158 // PHTTP
00159 
00163 class PHTTP : public PInternetProtocol
00164 {
00165   PCLASSINFO(PHTTP, PInternetProtocol)
00166 
00167   public:
00168   // New functions for class.
00169     enum Commands {
00170       // HTTP/1.0 commands
00171       GET, HEAD, POST,
00172       // HTTP/1.1 commands
00173       PUT, DELETE, TRACE, OPTIONS,
00174       // HTTPS command
00175       CONNECT,
00176       NumCommands
00177     };
00178 
00179     enum StatusCode {
00180       Continue = 100,              
00181       SwitchingProtocols,          
00182       RequestOK = 200,             
00183       Created,                     
00184       Accepted,                    
00185       NonAuthoritativeInformation, 
00186       NoContent,                   
00187       ResetContent,                
00188       PartialContent,              
00189       MultipleChoices = 300,       
00190       MovedPermanently,            
00191       MovedTemporarily,            
00192       SeeOther,                    
00193       NotModified,                 
00194       UseProxy,                    
00195       BadRequest = 400,            
00196       UnAuthorised,                
00197       PaymentRequired,             
00198       Forbidden,                   
00199       NotFound,                    
00200       MethodNotAllowed,            
00201       NoneAcceptable,              
00202       ProxyAuthenticationRequired, 
00203       RequestTimeout,              
00204       Conflict,                    
00205       Gone,                        
00206       LengthRequired,              
00207       UnlessTrue,                  
00208       InternalServerError = 500,   
00209       NotImplemented,              
00210       BadGateway,                  
00211       ServiceUnavailable,          
00212       GatewayTimeout               
00213     };
00214 
00215     // Common MIME header tags
00216     static const PString & AllowTag();
00217     static const PString & AuthorizationTag();
00218     static const PString & ContentEncodingTag();
00219     static const PString & ContentLengthTag();
00220     static const PString & ContentTypeTag();
00221     static const PString & DateTag();
00222     static const PString & ExpiresTag();
00223     static const PString & FromTag();
00224     static const PString & IfModifiedSinceTag();
00225     static const PString & LastModifiedTag();
00226     static const PString & LocationTag();
00227     static const PString & PragmaTag();
00228     static const PString & PragmaNoCacheTag();
00229     static const PString & RefererTag();
00230     static const PString & ServerTag();
00231     static const PString & UserAgentTag();
00232     static const PString & WWWAuthenticateTag();
00233     static const PString & MIMEVersionTag();
00234     static const PString & ConnectionTag();
00235     static const PString & KeepAliveTag();
00236     static const PString & TransferEncodingTag();
00237     static const PString & ChunkedTag();
00238     static const PString & ProxyConnectionTag();
00239     static const PString & ProxyAuthorizationTag();
00240     static const PString & ProxyAuthenticateTag();
00241     static const PString & ForwardedTag();
00242     static const PString & SetCookieTag();
00243     static const PString & CookieTag();
00244 
00245   protected:
00248     PHTTP();
00249 
00261     virtual PINDEX ParseResponse(
00262       const PString & line    
00263     );
00264 };
00265 
00266 
00268 // PHTTPClient
00269 
00290 class PHTTPClient : public PHTTP
00291 {
00292   PCLASSINFO(PHTTPClient, PHTTP)
00293 
00294   public:
00296     PHTTPClient();
00297     PHTTPClient(
00298       const PString & userAgentName
00299     );
00300 
00301 
00302   // New functions for class.
00310     int ExecuteCommand(
00311       Commands cmd,
00312       const PURL & url,
00313       PMIMEInfo & outMIME,
00314       const PString & dataBody,
00315       PMIMEInfo & replyMime,
00316       PBoolean persist = PTrue
00317     );
00318     int ExecuteCommand(
00319       const PString & cmdName,
00320       const PURL & url,
00321       PMIMEInfo & outMIME,
00322       const PString & dataBody,
00323       PMIMEInfo & replyMime,
00324       PBoolean persist = PTrue
00325     );
00326 
00328     PBoolean WriteCommand(
00329       Commands cmd,
00330       const PString & url,
00331       PMIMEInfo & outMIME,
00332       const PString & dataBody
00333     );
00334     PBoolean WriteCommand(
00335       const PString & cmdName,
00336       const PString & url,
00337       PMIMEInfo & outMIME,
00338       const PString & dataBody
00339     );
00340 
00342     PBoolean ReadResponse(
00343       PMIMEInfo & replyMIME
00344     );
00345 
00347     PBoolean ReadContentBody(
00348       PMIMEInfo & replyMIME,
00349       PBYTEArray & body
00350     );
00351     PBoolean ReadContentBody(
00352       PMIMEInfo & replyMIME,
00353       PString & body
00354     );
00355 
00356 
00362     PBoolean GetTextDocument(
00363       const PURL & url,         
00364       PString & document,       
00365       PBoolean persist = PTrue       
00366     );
00367 
00373     PBoolean GetDocument(
00374       const PURL & url,         
00375       PMIMEInfo & outMIME,      
00376       PMIMEInfo & replyMIME,    
00377       PBoolean persist = PTrue       
00378     );
00379 
00385     PBoolean GetHeader(
00386       const PURL & url,         
00387       PMIMEInfo & outMIME,      
00388       PMIMEInfo & replyMIME,    
00389       PBoolean persist = PTrue       
00390     );
00391 
00392 
00398     PBoolean PostData(
00399       const PURL & url,       
00400       PMIMEInfo & outMIME,    
00401       const PString & data,   
00402       PMIMEInfo & replyMIME,  
00403       PBoolean persist = PTrue     
00404     );
00405 
00411     PBoolean PostData(
00412       const PURL & url,       
00413       PMIMEInfo & outMIME,    
00414       const PString & data,   
00415       PMIMEInfo & replyMIME,  
00416       PString & replyBody,    
00417       PBoolean persist = PTrue     
00418     );
00419 
00420   protected:
00421     PBoolean AssureConnect(const PURL & url, PMIMEInfo & outMIME);
00422     PBoolean InternalReadContentBody(
00423       PMIMEInfo & replyMIME,
00424       PAbstractArray & body
00425     );
00426 
00427     PString userAgentName;
00428 };
00429 
00431 // PMultipartFormInfo
00432 
00437 class PMultipartFormInfo : public PObject
00438 {
00439   PCLASSINFO(PMultipartFormInfo, PObject);
00440   public:
00441     PMIMEInfo mime;
00442     PString body;
00443 };
00444 
00445 PARRAY(PMultipartFormInfoArray, PMultipartFormInfo);
00446 
00448 // PHTTPConnectionInfo
00449 
00450 class PHTTPServer;
00451 
00456 class PHTTPConnectionInfo : public PObject
00457 {
00458   PCLASSINFO(PHTTPConnectionInfo, PObject)
00459   public:
00460     PHTTPConnectionInfo();
00461 
00462     PHTTP::Commands GetCommandCode() const { return commandCode; }
00463     const PString & GetCommandName() const { return commandName; }
00464 
00465     const PURL & GetURL() const       { return url; }
00466 
00467     const PMIMEInfo & GetMIME() const { return mimeInfo; }
00468     void SetMIME(const PString & tag, const PString & value);
00469 
00470     PBoolean IsCompatible(int major, int minor) const;
00471 
00472     PBoolean IsPersistant() const         { return isPersistant; }
00473     PBoolean WasPersistant() const        { return wasPersistant; }
00474     PBoolean IsProxyConnection() const    { return isProxyConnection; }
00475     int  GetMajorVersion() const      { return majorVersion; }
00476     int  GetMinorVersion() const      { return minorVersion; }
00477 
00478     long GetEntityBodyLength() const  { return entityBodyLength; }
00479 
00482     PTimeInterval GetPersistenceTimeout() const { return persistenceTimeout; }
00483 
00486     void SetPersistenceTimeout(const PTimeInterval & t) { persistenceTimeout = t; }
00487 
00491     unsigned GetPersistenceMaximumTransations() const { return persistenceMaximum; }
00492 
00496     void SetPersistenceMaximumTransations(unsigned m) { persistenceMaximum = m; }
00497 
00498     const PMultipartFormInfoArray & GetMultipartFormInfo() const
00499       { return multipartFormInfoArray; }
00500 
00501     void ResetMultipartFormInfo()
00502       { multipartFormInfoArray.RemoveAll(); }
00503 
00504     PString GetEntityBody() const   { return entityBody; }
00505 
00506   protected:
00507     PBoolean Initialise(PHTTPServer & server, PString & args);
00508     void DecodeMultipartFormInfo(const PString & type, const PString & entityBody);
00509 
00510     PHTTP::Commands commandCode;
00511     PString         commandName;
00512     PURL            url;
00513     PMIMEInfo       mimeInfo;
00514     PBoolean            isPersistant;
00515     PBoolean            wasPersistant;
00516     PBoolean            isProxyConnection;
00517     int             majorVersion;
00518     int             minorVersion;
00519     PString         entityBody;        // original entity body (POST only)
00520     long            entityBodyLength;
00521     PTimeInterval   persistenceTimeout;
00522     unsigned        persistenceMaximum;
00523     PMultipartFormInfoArray multipartFormInfoArray;
00524 
00525   friend class PHTTPServer;
00526 };
00527 
00528 
00530 // PHTTPServer
00531 
00544 class PHTTPServer : public PHTTP
00545 {
00546   PCLASSINFO(PHTTPServer, PHTTP)
00547 
00548   public:
00556     PHTTPServer();
00557     PHTTPServer(
00558      const PHTTPSpace & urlSpace  
00559     );
00560 
00561 
00562   // New functions for class.
00568     virtual PString GetServerName() const;
00569 
00575     PHTTPSpace & GetURLSpace() { return urlSpace; }
00576 
00578     void SetURLSpace(
00579       const PHTTPSpace & space   
00580     );
00581 
00582 
00592     virtual PBoolean ProcessCommand();
00593 
00605     virtual PBoolean OnGET(
00606       const PURL & url,                    
00607       const PMIMEInfo & info,              
00608       const PHTTPConnectionInfo & conInfo  
00609     );
00610 
00611 
00612 
00624     virtual PBoolean OnHEAD(
00625       const PURL & url,                   
00626       const PMIMEInfo & info,             
00627       const PHTTPConnectionInfo & conInfo 
00628     );
00629 
00641     virtual PBoolean OnPOST(
00642       const PURL & url,                   
00643       const PMIMEInfo & info,             
00644       const PStringToString & data,       
00645       const PHTTPConnectionInfo & conInfo 
00646     );
00647 
00660     virtual PBoolean OnProxy(
00661       const PHTTPConnectionInfo & conInfo   
00662     );
00663 
00664 
00671     virtual PString ReadEntityBody();
00672 
00678     virtual PBoolean OnUnknown(
00679       const PCaselessString & command,         
00680       const PHTTPConnectionInfo & connectInfo  
00681     );
00682 
00701     PBoolean StartResponse(
00702       StatusCode code,      
00703       PMIMEInfo & headers,  
00704       long bodySize         
00705     );
00706 
00716     virtual PBoolean OnError(
00717       StatusCode code,                         
00718       const PCaselessString & extra,           
00719       const PHTTPConnectionInfo & connectInfo  
00720     );
00721 
00724     void SetDefaultMIMEInfo(
00725       PMIMEInfo & info,      
00726       const PHTTPConnectionInfo & connectInfo
00727     );
00728 
00731     PHTTPConnectionInfo & GetConnectionInfo() { return connectInfo; }
00732 
00733   protected:
00734     void Construct();
00735 
00736     PHTTPSpace          urlSpace;
00737     PHTTPConnectionInfo connectInfo;
00738     unsigned            transactionCount;
00739     PTimeInterval       nextTimeout;
00740 };
00741 
00742 
00744 // PHTTPRequest
00745 
00750 class PHTTPRequest : public PObject
00751 {
00752   PCLASSINFO(PHTTPRequest, PObject)
00753 
00754   public:
00755     PHTTPRequest(
00756       const PURL & url,             
00757       const PMIMEInfo & inMIME,     
00758       const PMultipartFormInfoArray & multipartFormInfo, 
00759       PHTTPServer & server          
00760     );
00761 
00762     PHTTPServer & server;           
00763     const PURL & url;               
00764     const PMIMEInfo & inMIME;       
00765     const PMultipartFormInfoArray & multipartFormInfo; 
00766     PHTTP::StatusCode code;         
00767     PMIMEInfo outMIME;              
00768     PString entityBody;             
00769     PINDEX contentSize;             
00770     PIPSocket::Address origin;      
00771     PIPSocket::Address localAddr;   
00772     WORD               localPort;   
00773 };
00774 
00775 
00777 // PHTTPAuthority
00778 
00782 class PHTTPAuthority : public PObject
00783 {
00784   PCLASSINFO(PHTTPAuthority, PObject)
00785 
00786   public:
00787   // New functions for class.
00794     virtual PString GetRealm(
00795       const PHTTPRequest & request   
00796     ) const = 0;
00797 
00804     virtual PBoolean Validate(
00805       const PHTTPRequest & request,  
00806       const PString & authInfo       
00807     ) const = 0;
00808 
00818     virtual PBoolean IsActive() const;
00819 
00820   protected:
00821     static void DecodeBasicAuthority(
00822       const PString & authInfo,   
00823       PString & username,         
00824       PString & password          
00825     );
00826 };
00827 
00828 
00830 // PHTTPSimpleAuth
00831 
00835 class PHTTPSimpleAuth : public PHTTPAuthority
00836 {
00837   PCLASSINFO(PHTTPSimpleAuth, PHTTPAuthority)
00838 
00839   public:
00840     PHTTPSimpleAuth(
00841       const PString & realm,      
00842       const PString & username,   
00843       const PString & password    
00844     );
00845     // Construct the simple authorisation structure.
00846 
00847 
00848   // Overrides from class PObject.
00856     virtual PObject * Clone() const;
00857 
00858 
00859   // Overrides from class PHTTPAuthority.
00866     virtual PString GetRealm(
00867       const PHTTPRequest & request   
00868     ) const;
00869 
00876     virtual PBoolean Validate(
00877       const PHTTPRequest & request,  
00878       const PString & authInfo       
00879     ) const;
00880 
00890     virtual PBoolean IsActive() const;
00891 
00897     const PString & GetUserName() const { return username; }
00898 
00904     const PString & GetPassword() const { return password; }
00905 
00906 
00907   protected:
00908     PString realm;
00909     PString username;
00910     PString password;
00911 };
00912 
00913 
00915 // PHTTPMultiSimpAuth
00916 
00920 class PHTTPMultiSimpAuth : public PHTTPAuthority
00921 {
00922   PCLASSINFO(PHTTPMultiSimpAuth, PHTTPAuthority)
00923 
00924   public:
00925     PHTTPMultiSimpAuth(
00926       const PString & realm      
00927     );
00928     PHTTPMultiSimpAuth(
00929       const PString & realm,           
00930       const PStringToString & userList 
00931     );
00932     // Construct the simple authorisation structure.
00933 
00934 
00935   // Overrides from class PObject.
00943     virtual PObject * Clone() const;
00944 
00945 
00946   // Overrides from class PHTTPAuthority.
00953     virtual PString GetRealm(
00954       const PHTTPRequest & request   
00955     ) const;
00956 
00963     virtual PBoolean Validate(
00964       const PHTTPRequest & request,  
00965       const PString & authInfo       
00966     ) const;
00967 
00977     virtual PBoolean IsActive() const;
00978 
00984     void AddUser(
00985       const PString & username,   
00986       const PString & password    
00987     );
00988 
00989 
00990   protected:
00991     PString realm;
00992     PStringToString users;
00993 };
00994 
00995 
00997 // PHTTPResource
00998 
01002 class PHTTPResource : public PObject
01003 {
01004   PCLASSINFO(PHTTPResource, PObject)
01005 
01006   protected:
01007     PHTTPResource(
01008       const PURL & url               
01009     );
01010     PHTTPResource(
01011       const PURL & url,              
01012       const PHTTPAuthority & auth    
01013     );
01014     PHTTPResource(
01015       const PURL & url,              
01016       const PString & contentType    
01017     );
01018     PHTTPResource(
01019       const PURL & url,              
01020       const PString & contentType,   
01021       const PHTTPAuthority & auth    
01022     );
01023     // Create a new HTTP Resource.
01024 
01025 
01026   public:
01027     virtual ~PHTTPResource();
01028     // Destroy the HTTP Resource.
01029 
01030 
01031   // New functions for class.
01037     const PURL & GetURL() const { return baseURL; }
01038 
01044     const PString & GetContentType() const { return contentType; }
01045 
01052     PHTTPAuthority * GetAuthority() const { return authority; }
01053 
01056     void SetAuthority(
01057       const PHTTPAuthority & auth      
01058     );
01059 
01062     void ClearAuthority();
01063 
01070     DWORD GetHitCount() const { return hitCount; }
01071 
01072     void ClearHitCount() { hitCount = 0; }
01073     // Clear the hit count for the resource.
01074 
01075 
01087     virtual PBoolean OnGET(
01088       PHTTPServer & server,       
01089       const PURL & url,           
01090       const PMIMEInfo & info,     
01091       const PHTTPConnectionInfo & conInfo   
01092     );
01093 
01103     virtual PBoolean OnGETData(
01104       PHTTPServer & server,                       
01105       const PURL & url,                           
01106       const PHTTPConnectionInfo & connectInfo,    
01107       PHTTPRequest & request                      
01108     );
01109 
01121     virtual PBoolean OnHEAD(
01122       PHTTPServer & server,       
01123       const PURL & url,           
01124       const PMIMEInfo & info,     
01125       const PHTTPConnectionInfo & conInfo  
01126     );
01127 
01139     virtual PBoolean OnPOST(
01140       PHTTPServer & server,         
01141       const PURL & url,             
01142       const PMIMEInfo & info,       
01143       const PStringToString & data, 
01144       const PHTTPConnectionInfo & conInfo  
01145     );
01146 
01156     virtual PBoolean OnPOSTData(
01157       PHTTPRequest & request,        
01158       const PStringToString & data   
01159     );
01160 
01167     virtual PBoolean IsModifiedSince(
01168       const PTime & when    
01169     );
01170 
01176     virtual PBoolean GetExpirationDate(
01177       PTime & when          
01178     );
01179 
01187     virtual PHTTPRequest * CreateRequest(
01188       const PURL & url,                   
01189       const PMIMEInfo & inMIME,           
01190       const PMultipartFormInfoArray & multipartFormInfo,  
01191       PHTTPServer & socket                                
01192     );
01193 
01201     virtual PBoolean LoadHeaders(
01202       PHTTPRequest & request    
01203     ) = 0;
01204 
01210     virtual void SendData(
01211       PHTTPRequest & request    
01212     );
01213 
01222     virtual PBoolean LoadData(
01223       PHTTPRequest & request,    
01224       PCharArray & data          
01225     );
01226 
01235     virtual PString LoadText(
01236       PHTTPRequest & request    
01237     );
01238 
01245     virtual void OnLoadedText(
01246       PHTTPRequest & request,    
01247       PString & text             
01248     );
01249 
01258     virtual PBoolean Post(
01259       PHTTPRequest & request,       
01260       const PStringToString & data, 
01261       PHTML & replyMessage          
01262     );
01263 
01264 
01265   protected:
01268     virtual PBoolean CheckAuthority(
01269       PHTTPServer & server,               
01270       const PHTTPRequest & request,       
01271       const PHTTPConnectionInfo & conInfo 
01272     );
01273     static PBoolean CheckAuthority(
01274                    PHTTPAuthority & authority,
01275                       PHTTPServer & server,
01276                const PHTTPRequest & request,
01277         const PHTTPConnectionInfo & connectInfo
01278     );
01279 
01280 
01282     virtual PBoolean OnGETOrHEAD(
01283       PHTTPServer & server,       
01284       const PURL & url,           
01285       const PMIMEInfo & info,     
01286       const PHTTPConnectionInfo & conInfo,
01287       PBoolean  IsGet
01288     );
01289 
01291     PURL             baseURL;
01293     PString          contentType;
01295     PHTTPAuthority * authority;
01297     volatile DWORD   hitCount;
01298 };
01299 
01300 
01302 // PHTTPString
01303 
01308 class PHTTPString : public PHTTPResource
01309 {
01310   PCLASSINFO(PHTTPString, PHTTPResource)
01311 
01312   public:
01316     PHTTPString(
01317       const PURL & url             // Name of the resource in URL space.
01318     );
01319     PHTTPString(
01320       const PURL & url,            // Name of the resource in URL space.
01321       const PHTTPAuthority & auth  // Authorisation for the resource.
01322     );
01323     PHTTPString(
01324       const PURL & url,            // Name of the resource in URL space.
01325       const PString & str          // String to return in this resource.
01326     );
01327     PHTTPString(
01328       const PURL & url,            // Name of the resource in URL space.
01329       const PString & str,         // String to return in this resource.
01330       const PString & contentType  // MIME content type for the file.
01331     );
01332     PHTTPString(
01333       const PURL & url,            // Name of the resource in URL space.
01334       const PString & str,         // String to return in this resource.
01335       const PHTTPAuthority & auth  // Authorisation for the resource.
01336     );
01337     PHTTPString(
01338       const PURL & url,            // Name of the resource in URL space.
01339       const PString & str,         // String to return in this resource.
01340       const PString & contentType, // MIME content type for the file.
01341       const PHTTPAuthority & auth  // Authorisation for the resource.
01342     );
01343 
01344 
01345   // Overrides from class PHTTPResource
01353     virtual PBoolean LoadHeaders(
01354       PHTTPRequest & request    // Information on this request.
01355     );
01356 
01365     virtual PString LoadText(
01366       PHTTPRequest & request    // Information on this request.
01367     );
01368 
01369   // New functions for class.
01375     const PString & GetString() { return string; }
01376 
01379     void SetString(
01380       const PString & str   // New string for the resource.
01381     ) { string = str; }
01382 
01383 
01384   protected:
01385     PString string;
01386 };
01387 
01388 
01390 // PHTTPFile
01391 
01397 class PHTTPFile : public PHTTPResource
01398 {
01399   PCLASSINFO(PHTTPFile, PHTTPResource)
01400 
01401   public:
01408     PHTTPFile(
01409       const PString & filename     // file in file system and URL name.
01410     );
01411     PHTTPFile(
01412       const PString & filename,    // file in file system and URL name.
01413       const PHTTPAuthority & auth  // Authorisation for the resource.
01414     );
01415     PHTTPFile(
01416       const PURL & url,            // Name of the resource in URL space.
01417       const PFilePath & file       // Location of file in file system.
01418     );
01419     PHTTPFile(
01420       const PURL & url,            // Name of the resource in URL space.
01421       const PFilePath & file,      // Location of file in file system.
01422       const PString & contentType  // MIME content type for the file.
01423     );
01424     PHTTPFile(
01425       const PURL & url,            // Name of the resource in URL space.
01426       const PFilePath & file,      // Location of file in file system.
01427       const PHTTPAuthority & auth  // Authorisation for the resource.
01428     );
01429     PHTTPFile(
01430       const PURL & url,            // Name of the resource in URL space.
01431       const PFilePath & file,      // Location of file in file system.
01432       const PString & contentType, // MIME content type for the file.
01433       const PHTTPAuthority & auth  // Authorisation for the resource.
01434     );
01435 
01436 
01437   // Overrides from class PHTTPResource
01443     virtual PHTTPRequest * CreateRequest(
01444       const PURL & url,                  // Universal Resource Locator for document.
01445       const PMIMEInfo & inMIME,          // Extra MIME information in command.
01446       const PMultipartFormInfoArray & multipartFormInfo,
01447       PHTTPServer & socket
01448     );
01449 
01457     virtual PBoolean LoadHeaders(
01458       PHTTPRequest & request    // Information on this request.
01459     );
01460 
01466     virtual PBoolean LoadData(
01467       PHTTPRequest & request,    // Information on this request.
01468       PCharArray & data          // Data used in reply.
01469     );
01470 
01479     virtual PString LoadText(
01480       PHTTPRequest & request    // Information on this request.
01481     );
01482 
01483 
01484   protected:
01485     PHTTPFile(
01486       const PURL & url,       // Name of the resource in URL space.
01487       int dummy
01488     );
01489     // Constructor used by PHTTPDirectory
01490 
01491 
01492     PFilePath filePath;
01493 };
01494 
01495 
01496 class PHTTPFileRequest : public PHTTPRequest
01497 {
01498   PCLASSINFO(PHTTPFileRequest, PHTTPRequest)
01499   public:
01500     PHTTPFileRequest(
01501       const PURL & url,             // Universal Resource Locator for document.
01502       const PMIMEInfo & inMIME,     // Extra MIME information in command.
01503       const PMultipartFormInfoArray & multipartFormInfo,
01504       PHTTPServer & server
01505     );
01506 
01507     PFile file;
01508 };
01509 
01510 
01512 // PHTTPTailFile
01513 
01522 class PHTTPTailFile : public PHTTPFile
01523 {
01524   PCLASSINFO(PHTTPTailFile, PHTTPFile)
01525 
01526   public:
01533     PHTTPTailFile(
01534       const PString & filename     // file in file system and URL name.
01535     );
01536     PHTTPTailFile(
01537       const PString & filename,    // file in file system and URL name.
01538       const PHTTPAuthority & auth  // Authorisation for the resource.
01539     );
01540     PHTTPTailFile(
01541       const PURL & url,            // Name of the resource in URL space.
01542       const PFilePath & file       // Location of file in file system.
01543     );
01544     PHTTPTailFile(
01545       const PURL & url,            // Name of the resource in URL space.
01546       const PFilePath & file,      // Location of file in file system.
01547       const PString & contentType  // MIME content type for the file.
01548     );
01549     PHTTPTailFile(
01550       const PURL & url,            // Name of the resource in URL space.
01551       const PFilePath & file,      // Location of file in file system.
01552       const PHTTPAuthority & auth  // Authorisation for the resource.
01553     );
01554     PHTTPTailFile(
01555       const PURL & url,            // Name of the resource in URL space.
01556       const PFilePath & file,      // Location of file in file system.
01557       const PString & contentType, // MIME content type for the file.
01558       const PHTTPAuthority & auth  // Authorisation for the resource.
01559     );
01560 
01561 
01562   // Overrides from class PHTTPResource
01570     virtual PBoolean LoadHeaders(
01571       PHTTPRequest & request    // Information on this request.
01572     );
01573 
01579     virtual PBoolean LoadData(
01580       PHTTPRequest & request,    // Information on this request.
01581       PCharArray & data          // Data used in reply.
01582     );
01583 };
01584 
01585 
01587 // PHTTPDirectory
01588 
01601 class PHTTPDirectory : public PHTTPFile
01602 {
01603   PCLASSINFO(PHTTPDirectory, PHTTPFile)
01604 
01605   public:
01606     PHTTPDirectory(
01607       const PURL & url,            
01608       const PDirectory & dir       
01609     );
01610     PHTTPDirectory(
01611       const PURL & url,            
01612       const PDirectory & dir,      
01613       const PHTTPAuthority & auth  
01614     );
01615     // Construct a new directory resource for HTTP.
01616 
01617 
01618   // Overrides from class PHTTPResource
01624     virtual PHTTPRequest * CreateRequest(
01625       const PURL & url,                  // Universal Resource Locator for document.
01626       const PMIMEInfo & inMIME,          // Extra MIME information in command.
01627       const PMultipartFormInfoArray & multipartFormInfo,
01628       PHTTPServer & socket
01629     );
01630 
01638     virtual PBoolean LoadHeaders(
01639       PHTTPRequest & request    
01640     );
01641 
01650     virtual PString LoadText(
01651       PHTTPRequest & request    
01652     );
01653 
01662     void EnableAuthorisation(const PString & realm);
01663 
01666     void AllowDirectories(PBoolean enable = PTrue);
01667 
01668   protected:
01669     PBoolean CheckAuthority(
01670       PHTTPServer & server,               // Server to send response to.
01671       const PHTTPRequest & request,       // Information on this request.
01672       const PHTTPConnectionInfo & conInfo // Information on the connection
01673     );
01674 
01675     PBoolean FindAuthorisations(const PDirectory & dir, PString & realm, PStringToString & authorisations);
01676 
01677     PDirectory basePath;
01678     PString authorisationRealm;
01679     PBoolean allowDirectoryListing;
01680 };
01681 
01682 
01683 class PHTTPDirRequest : public PHTTPFileRequest
01684 {
01685   PCLASSINFO(PHTTPDirRequest, PHTTPFileRequest)
01686   public:
01687     PHTTPDirRequest(
01688       const PURL & url,             // Universal Resource Locator for document.
01689       const PMIMEInfo & inMIME,     // Extra MIME information in command.
01690       const PMultipartFormInfoArray & multipartFormInfo, 
01691       PHTTPServer & server
01692     );
01693 
01694     PString fakeIndex;
01695     PFilePath realPath;
01696 };
01697 
01698 #endif // P_HTTP
01699 
01700 #endif // _PHTTP_H
01701 
01702 
01703 // End Of File ///////////////////////////////////////////////////////////////

Generated on Mon Sep 15 01:21:35 2008 for PTLib by  doxygen 1.5.1