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  * $Log: http.h,v $
00027  * Revision 1.60  2005/11/30 12:47:37  csoutheren
00028  * Removed tabs, reformatted some code, and changed tags for Doxygen
00029  *
00030  * Revision 1.59  2005/01/03 12:48:41  csoutheren
00031  * Added new configure options and ability to disable/enable modules
00032  *
00033  * Revision 1.58  2004/10/23 11:34:59  ykiryanov
00034  * Added ifdef _WIN32_WCE for PocketPC 2003 SDK port
00035  *
00036  * Revision 1.57  2002/12/03 22:37:36  robertj
00037  * Removed get document that just returns a content length as the chunked
00038  *   transfer encoding makes this very dangerous.
00039  * Added GetTextDocument() to get a URL content into a PString.
00040  * Added a version pf PostData() that gets the reponse content into a PString.
00041  * Added ReadContentBody() that takes a PString, not just PBYTEArray.
00042  *
00043  * Revision 1.56  2002/11/06 22:47:23  robertj
00044  * Fixed header comment (copyright etc)
00045  *
00046  * Revision 1.55  2002/10/10 04:43:43  robertj
00047  * VxWorks port, thanks Martijn Roest
00048  *
00049  * Revision 1.54  2002/10/02 08:54:34  craigs
00050  * Added support for XMLRPC server
00051  *
00052  * Revision 1.53  2002/09/16 01:08:59  robertj
00053  * Added #define so can select if #pragma interface/implementation is used on
00054  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00055  *
00056  * Revision 1.52  2002/05/08 05:38:53  robertj
00057  * Added PHTTPTailFile resource to do a unix 'tail -f' of a file.
00058  *
00059  * Revision 1.51  2001/10/31 01:34:47  robertj
00060  * Added extra const for constant HTTP tag name strings.
00061  * Changes to support HTTP v1.1 chunked transfer encoding.
00062  *
00063  * Revision 1.50  2001/10/03 00:26:34  robertj
00064  * Upgraded client to HTTP/1.1 and for chunked mode entity bodies.
00065  *
00066  * Revision 1.49  2001/09/28 08:55:15  robertj
00067  * More changes to support restartable PHTTPClient
00068  *
00069  * Revision 1.48  2001/09/28 00:42:54  robertj
00070  * Added automatic setting of some outward MIME fields.
00071  * Added "user agent" string field for automatic inclusion.
00072  * Added function to read the contents of the HTTP request.
00073  *
00074  * Revision 1.47  2001/08/28 06:44:30  craigs
00075  * Added ability to override PHTTPServer creation
00076  *
00077  * Revision 1.46  2001/03/14 01:49:54  craigs
00078  * Added ability to handle multi-part form POST commands
00079  *
00080  * Revision 1.45  2001/02/22 05:26:47  robertj
00081  * Added "nicer" version of GetDocument in HTTP client class.
00082  *
00083  * Revision 1.44  2001/01/15 06:16:53  robertj
00084  * Set HTTP resource members to private to assure are not modified by
00085  *   dscendents in non-threadsafe manner.
00086  *
00087  * Revision 1.43  2000/09/04 03:57:58  robertj
00088  * Added ability to change the persistent connection parameters (timeout etc).
00089  *
00090  * Revision 1.42  2000/05/02 08:28:10  craigs
00091  * Removed "memory leaks" caused by brain-dead GNU linker
00092  *
00093  * Revision 1.41  1999/09/17 01:11:14  robertj
00094  * Fixed some documentation typos.
00095  *
00096  * Revision 1.40  1999/05/13 04:04:04  robertj
00097  * Fixed problem of initialised commandName in ConnectionInfo.
00098  *
00099  * Revision 1.39  1999/05/04 15:26:01  robertj
00100  * Improved HTTP/1.1 compatibility (pass through user commands).
00101  * Fixed problems with quicktime installer.
00102  *
00103  * Revision 1.38  1999/04/21 01:58:08  robertj
00104  * Fixed problem with reading data for request using second form of PHTTPRequestInfo constructor.
00105  *
00106  * Revision 1.37  1999/03/09 08:01:46  robertj
00107  * Changed comments for doc++ support (more to come).
00108  *
00109  * Revision 1.36  1999/02/16 08:07:10  robertj
00110  * MSVC 6.0 compatibility changes.
00111  *
00112  * Revision 1.35  1998/11/30 02:50:47  robertj
00113  * New directory structure
00114  *
00115  * Revision 1.34  1998/10/31 12:49:21  robertj
00116  * Added read/write mutex to the HTTP space variable to avoid thread crashes.
00117  *
00118  * Revision 1.33  1998/10/25 01:00:46  craigs
00119  * Added ability to specify per-directory authorisation for PHTTPDirectory
00120  *
00121  * Revision 1.32  1998/09/23 06:19:29  robertj
00122  * Added open source copyright license.
00123  *
00124  * Revision 1.31  1998/07/24 06:58:42  robertj
00125  * Changed PostData function so just has string for data instead of dictionary.
00126  *
00127  * Revision 1.30  1998/06/16 03:33:33  robertj
00128  * Changed TCP connection shutdown to be parameterised.
00129  * Propagated persistence and proxy flags in new connection info instances.
00130  *
00131  * Revision 1.29  1998/04/14 03:42:59  robertj
00132  * Fixed error code propagation in HTTP client.
00133  *
00134  * Revision 1.28  1998/02/03 06:29:38  robertj
00135  * Added local address and port to PHTTPRequest.
00136  *
00137  * Revision 1.27  1998/01/26 00:24:24  robertj
00138  * Added more information to PHTTPConnectionInfo.
00139  * Added function to allow HTTPClient to automatically connect if URL has hostname.
00140  *
00141  * Revision 1.26  1997/10/30 10:22:52  robertj
00142  * Added multiple user basic authorisation scheme.
00143  *
00144  * Revision 1.25  1997/10/03 13:30:15  craigs
00145  * Added ability to access client socket from within HTTP resources
00146  *
00147  * Revision 1.24  1997/03/28 04:40:22  robertj
00148  * Added tags for cookies.
00149  *
00150  * Revision 1.23  1997/01/12 04:15:19  robertj
00151  * Globalised MIME tag strings.
00152  *
00153  * Revision 1.22  1996/10/26 03:31:05  robertj
00154  * Changed OnError so can pass in full HTML page as parameter.
00155  *
00156  * Revision 1.21  1996/09/14 13:09:10  robertj
00157  * Major upgrade:
00158  *   rearranged sockets to help support IPX.
00159  *   added indirect channel class and moved all protocols to descend from it,
00160  *   separating the protocol from the low level byte transport.
00161  *
00162  * Revision 1.20  1996/08/22 13:20:55  robertj
00163  * Fixed bug in authorisation, missing virtual prevented polymorphism.
00164  *
00165  * Revision 1.19  1996/08/19 13:44:06  robertj
00166  * Fixed authorisation so if have no user/password on basic authentication, does not require it.
00167  *
00168  * Revision 1.18  1996/06/28 13:15:23  robertj
00169  * Modified HTTPAuthority so gets PHTTPReqest (mainly for URL) passed in.
00170  * Moved HTTP form resource to another compilation module.
00171  *
00172  * Revision 1.17  1996/06/07 13:52:20  robertj
00173  * Added PUT to HTTP proxy FTP. Necessitating redisign of entity body processing.
00174  *
00175  * Revision 1.16  1996/05/23 10:00:52  robertj
00176  * Added common function for GET and HEAD commands.
00177  * Fixed status codes to be the actual status code instead of sequential enum.
00178  * This fixed some problems with proxy pass through of status codes.
00179  *
00180  * Revision 1.14  1996/03/31 08:46:51  robertj
00181  * HTTP 1.1 upgrade.
00182  *
00183  * Revision 1.13  1996/03/17 05:41:57  robertj
00184  * Added hit count to PHTTPResource.
00185  *
00186  * Revision 1.12  1996/03/16 04:39:55  robertj
00187  * Added ParseReponse() for splitting reponse line into code and info.
00188  * Added client side support for HTTP socket.
00189  * Added hooks for proxy support in HTTP socket.
00190  *
00191  * Revision 1.11  1996/03/10 13:15:23  robertj
00192  * Redesign to make resources thread safe.
00193  *
00194  * Revision 1.10  1996/03/02 03:12:55  robertj
00195  * Added radio button and selection boxes to HTTP form resource.
00196  *
00197  * Revision 1.9  1996/02/25 11:14:21  robertj
00198  * Radio button support for forms.
00199  *
00200  * Revision 1.8  1996/02/25 02:57:48  robertj
00201  * Removed pass through HTTP resource.
00202  *
00203  * Revision 1.7  1996/02/19 13:25:43  robertj
00204  * Added overwrite option to AddResource().
00205  * Added get/set string to PHTTPString resource.
00206  * Moved nested classes from PHTTPForm.
00207  *
00208  * Revision 1.6  1996/02/13 13:09:16  robertj
00209  * Added extra parameters to callback function in PHTTPResources, required
00210  *   by descendants to make informed decisions on data being loaded.
00211  *
00212  * Revision 1.5  1996/02/08 12:04:19  robertj
00213  * Redesign of resource object callback virtuals.
00214  * Added HTML form resource type.
00215  *
00216  * Revision 1.4  1996/02/03 11:03:32  robertj
00217  * Added ismodified since and expires time checking.
00218  * Added PHTTPString that defaults to empty string.
00219  *
00220  * Revision 1.3  1996/01/28 14:15:38  robertj
00221  * Changed PCharArray in OnLoadData to PString for convenience in mangling data.
00222  * Beginning of pass through resource type.
00223  *
00224  * Revision 1.2  1996/01/26 02:24:26  robertj
00225  * Further implemetation.
00226  *
00227  * Revision 1.1  1996/01/23 13:04:20  robertj
00228  * Initial revision
00229  *
00230  */
00231 
00232 #ifndef _PHTTP
00233 #define _PHTTP
00234 
00235 #ifdef P_USE_PRAGMA
00236 #pragma interface
00237 #endif
00238 
00239 #include <ptclib/inetprot.h>
00240 #include <ptclib/mime.h>
00241 #include <ptclib/url.h>
00242 #include <ptlib/ipsock.h>
00243 
00244 
00245 #ifdef P_HTTPSVC
00246 
00247 #include <ptclib/html.h>
00248 
00250 // PHTTPSpace
00251 
00252 class PHTTPResource;
00253 
00258 class PHTTPSpace : public PContainer
00259 {
00260   PCONTAINERINFO(PHTTPSpace, PContainer)
00261   public:
00263     PHTTPSpace();
00264 
00265 
00266   // New functions for class.
00267     enum AddOptions {
00269       ErrorOnExist,
00271       Overwrite
00272     };
00273 
00274 
00286     BOOL AddResource(
00287       PHTTPResource * resource, 
00288       AddOptions overwrite = ErrorOnExist
00290     );
00291 
00299     BOOL DelResource(
00300       const PURL & url          
00301     );
00302 
00308     PHTTPResource * FindResource(
00309       const PURL & url   
00310     );
00311 
00314     void StartRead() const
00315       { mutex->StartRead(); }
00316 
00319     void EndRead() const
00320       { mutex->EndRead(); }
00321 
00324     void StartWrite() const
00325       { mutex->StartWrite(); }
00326 
00329     void EndWrite() const
00330       { mutex->EndWrite(); }
00331 
00332 
00333   protected:
00334     PReadWriteMutex * mutex;
00335 
00336     class Node;
00337     PSORTED_LIST(ChildList, Node);
00338     class Node : public PString
00339     {
00340       PCLASSINFO(Node, PString)
00341       public:
00342         Node(const PString & name, Node * parentNode);
00343         ~Node();
00344 
00345         Node          * parent;
00346         ChildList       children;
00347         PHTTPResource * resource;
00348     } * root;
00349 
00350   private:
00351     BOOL SetSize(PINDEX) { return FALSE; }
00352 };
00353 
00354 #endif // P_HTTPSVC
00355 
00356 #ifdef _WIN32_WCE
00357 #undef TRACE
00358 #endif
00359 
00361 // PHTTP
00362 
00366 class PHTTP : public PInternetProtocol
00367 {
00368   PCLASSINFO(PHTTP, PInternetProtocol)
00369 
00370   public:
00371   // New functions for class.
00372     enum Commands {
00373       // HTTP/1.0 commands
00374       GET, HEAD, POST,
00375       // HTTP/1.1 commands
00376       PUT, DELETE, TRACE, OPTIONS,
00377       // HTTPS command
00378       CONNECT,
00379       NumCommands
00380     };
00381 
00382     enum StatusCode {
00383       Continue = 100,              
00384       SwitchingProtocols,          
00385       RequestOK = 200,             
00386       Created,                     
00387       Accepted,                    
00388       NonAuthoritativeInformation, 
00389       NoContent,                   
00390       ResetContent,                
00391       PartialContent,              
00392       MultipleChoices = 300,       
00393       MovedPermanently,            
00394       MovedTemporarily,            
00395       SeeOther,                    
00396       NotModified,                 
00397       UseProxy,                    
00398       BadRequest = 400,            
00399       UnAuthorised,                
00400       PaymentRequired,             
00401       Forbidden,                   
00402       NotFound,                    
00403       MethodNotAllowed,            
00404       NoneAcceptable,              
00405       ProxyAuthenticationRequired, 
00406       RequestTimeout,              
00407       Conflict,                    
00408       Gone,                        
00409       LengthRequired,              
00410       UnlessTrue,                  
00411       InternalServerError = 500,   
00412       NotImplemented,              
00413       BadGateway,                  
00414       ServiceUnavailable,          
00415       GatewayTimeout               
00416     };
00417 
00418     // Common MIME header tags
00419     static const char * const AllowTag;
00420     static const char * const AuthorizationTag;
00421     static const char * const ContentEncodingTag;
00422     static const char * const ContentLengthTag;
00423     static const char * const ContentTypeTag;
00424     static const char * const DateTag;
00425     static const char * const ExpiresTag;
00426     static const char * const FromTag;
00427     static const char * const IfModifiedSinceTag;
00428     static const char * const LastModifiedTag;
00429     static const char * const LocationTag;
00430     static const char * const PragmaTag;
00431     static const char * const PragmaNoCacheTag;
00432     static const char * const RefererTag;
00433     static const char * const ServerTag;
00434     static const char * const UserAgentTag;
00435     static const char * const WWWAuthenticateTag;
00436     static const char * const MIMEVersionTag;
00437     static const char * const ConnectionTag;
00438     static const char * const KeepAliveTag;
00439     static const char * const TransferEncodingTag;
00440     static const char * const ChunkedTag;
00441     static const char * const ProxyConnectionTag;
00442     static const char * const ProxyAuthorizationTag;
00443     static const char * const ProxyAuthenticateTag;
00444     static const char * const ForwardedTag;
00445     static const char * const SetCookieTag;
00446     static const char * const CookieTag;
00447 
00448   protected:
00451     PHTTP();
00452 
00464     virtual PINDEX ParseResponse(
00465       const PString & line    
00466     );
00467 };
00468 
00469 
00471 // PHTTPClient
00472 
00493 class PHTTPClient : public PHTTP
00494 {
00495   PCLASSINFO(PHTTPClient, PHTTP)
00496 
00497   public:
00499     PHTTPClient();
00500     PHTTPClient(
00501       const PString & userAgentName
00502     );
00503 
00504 
00505   // New functions for class.
00513     int ExecuteCommand(
00514       Commands cmd,
00515       const PURL & url,
00516       PMIMEInfo & outMIME,
00517       const PString & dataBody,
00518       PMIMEInfo & replyMime,
00519       BOOL persist = TRUE
00520     );
00521     int ExecuteCommand(
00522       const PString & cmdName,
00523       const PURL & url,
00524       PMIMEInfo & outMIME,
00525       const PString & dataBody,
00526       PMIMEInfo & replyMime,
00527       BOOL persist = TRUE
00528     );
00529 
00531     BOOL WriteCommand(
00532       Commands cmd,
00533       const PString & url,
00534       PMIMEInfo & outMIME,
00535       const PString & dataBody
00536     );
00537     BOOL WriteCommand(
00538       const PString & cmdName,
00539       const PString & url,
00540       PMIMEInfo & outMIME,
00541       const PString & dataBody
00542     );
00543 
00545     BOOL ReadResponse(
00546       PMIMEInfo & replyMIME
00547     );
00548 
00550     BOOL ReadContentBody(
00551       PMIMEInfo & replyMIME,
00552       PBYTEArray & body
00553     );
00554     BOOL ReadContentBody(
00555       PMIMEInfo & replyMIME,
00556       PString & body
00557     );
00558 
00559 
00565     BOOL GetTextDocument(
00566       const PURL & url,         
00567       PString & document,       
00568       BOOL persist = TRUE       
00569     );
00570 
00576     BOOL GetDocument(
00577       const PURL & url,         
00578       PMIMEInfo & outMIME,      
00579       PMIMEInfo & replyMIME,    
00580       BOOL persist = TRUE       
00581     );
00582 
00588     BOOL GetHeader(
00589       const PURL & url,         
00590       PMIMEInfo & outMIME,      
00591       PMIMEInfo & replyMIME,    
00592       BOOL persist = TRUE       
00593     );
00594 
00595 
00601     BOOL PostData(
00602       const PURL & url,       
00603       PMIMEInfo & outMIME,    
00604       const PString & data,   
00605       PMIMEInfo & replyMIME,  
00606       BOOL persist = TRUE     
00607     );
00608 
00614     BOOL PostData(
00615       const PURL & url,       
00616       PMIMEInfo & outMIME,    
00617       const PString & data,   
00618       PMIMEInfo & replyMIME,  
00619       PString & replyBody,    
00620       BOOL persist = TRUE     
00621     );
00622 
00623   protected:
00624     BOOL AssureConnect(const PURL & url, PMIMEInfo & outMIME);
00625     BOOL InternalReadContentBody(
00626       PMIMEInfo & replyMIME,
00627       PAbstractArray & body
00628     );
00629 
00630     PString userAgentName;
00631 };
00632 
00633 #ifdef P_HTTPSVC
00634 
00636 // PMultipartFormInfo
00637 
00642 class PMultipartFormInfo : public PObject
00643 {
00644   PCLASSINFO(PMultipartFormInfo, PObject);
00645   public:
00646     PMIMEInfo mime;
00647     PString body;
00648 };
00649 
00650 PARRAY(PMultipartFormInfoArray, PMultipartFormInfo);
00651 
00653 // PHTTPConnectionInfo
00654 
00655 class PHTTPServer;
00656 
00661 class PHTTPConnectionInfo : public PObject
00662 {
00663   PCLASSINFO(PHTTPConnectionInfo, PObject)
00664   public:
00665     PHTTPConnectionInfo();
00666 
00667     PHTTP::Commands GetCommandCode() const { return commandCode; }
00668     const PString & GetCommandName() const { return commandName; }
00669 
00670     const PURL & GetURL() const       { return url; }
00671 
00672     const PMIMEInfo & GetMIME() const { return mimeInfo; }
00673     void SetMIME(const PString & tag, const PString & value);
00674 
00675     BOOL IsCompatible(int major, int minor) const;
00676 
00677     BOOL IsPersistant() const         { return isPersistant; }
00678     BOOL WasPersistant() const        { return wasPersistant; }
00679     BOOL IsProxyConnection() const    { return isProxyConnection; }
00680     int  GetMajorVersion() const      { return majorVersion; }
00681     int  GetMinorVersion() const      { return minorVersion; }
00682 
00683     long GetEntityBodyLength() const  { return entityBodyLength; }
00684 
00687     PTimeInterval GetPersistenceTimeout() const { return persistenceTimeout; }
00688 
00691     void SetPersistenceTimeout(const PTimeInterval & t) { persistenceTimeout = t; }
00692 
00696     unsigned GetPersistenceMaximumTransations() const { return persistenceMaximum; }
00697 
00701     void SetPersistenceMaximumTransations(unsigned m) { persistenceMaximum = m; }
00702 
00703     const PMultipartFormInfoArray & GetMultipartFormInfo() const
00704       { return multipartFormInfoArray; }
00705 
00706     void ResetMultipartFormInfo()
00707       { multipartFormInfoArray.RemoveAll(); }
00708 
00709     PString GetEntityBody() const   { return entityBody; }
00710 
00711   protected:
00712     BOOL Initialise(PHTTPServer & server, PString & args);
00713     void DecodeMultipartFormInfo(const PString & type, const PString & entityBody);
00714 
00715     PHTTP::Commands commandCode;
00716     PString         commandName;
00717     PURL            url;
00718     PMIMEInfo       mimeInfo;
00719     BOOL            isPersistant;
00720     BOOL            wasPersistant;
00721     BOOL            isProxyConnection;
00722     int             majorVersion;
00723     int             minorVersion;
00724     PString         entityBody;        // original entity body (POST only)
00725     long            entityBodyLength;
00726     PTimeInterval   persistenceTimeout;
00727     unsigned        persistenceMaximum;
00728     PMultipartFormInfoArray multipartFormInfoArray;
00729 
00730   friend class PHTTPServer;
00731 };
00732 
00733 
00735 // PHTTPServer
00736 
00749 class PHTTPServer : public PHTTP
00750 {
00751   PCLASSINFO(PHTTPServer, PHTTP)
00752 
00753   public:
00761     PHTTPServer();
00762     PHTTPServer(
00763      const PHTTPSpace & urlSpace  
00764     );
00765 
00766 
00767   // New functions for class.
00773     virtual PString GetServerName() const;
00774 
00780     PHTTPSpace & GetURLSpace() { return urlSpace; }
00781 
00783     void SetURLSpace(
00784       const PHTTPSpace & space   
00785     );
00786 
00787 
00797     virtual BOOL ProcessCommand();
00798 
00810     virtual BOOL OnGET(
00811       const PURL & url,                    
00812       const PMIMEInfo & info,              
00813       const PHTTPConnectionInfo & conInfo  
00814     );
00815 
00816 
00817 
00829     virtual BOOL OnHEAD(
00830       const PURL & url,                   
00831       const PMIMEInfo & info,             
00832       const PHTTPConnectionInfo & conInfo 
00833     );
00834 
00846     virtual BOOL OnPOST(
00847       const PURL & url,                   
00848       const PMIMEInfo & info,             
00849       const PStringToString & data,       
00850       const PHTTPConnectionInfo & conInfo 
00851     );
00852 
00865     virtual BOOL OnProxy(
00866       const PHTTPConnectionInfo & conInfo   
00867     );
00868 
00869 
00876     virtual PString ReadEntityBody();
00877 
00883     virtual BOOL OnUnknown(
00884       const PCaselessString & command,         
00885       const PHTTPConnectionInfo & connectInfo  
00886     );
00887 
00906     BOOL StartResponse(
00907       StatusCode code,      
00908       PMIMEInfo & headers,  
00909       long bodySize         
00910     );
00911 
00921     virtual BOOL OnError(
00922       StatusCode code,                         
00923       const PCaselessString & extra,           
00924       const PHTTPConnectionInfo & connectInfo  
00925     );
00926 
00929     void SetDefaultMIMEInfo(
00930       PMIMEInfo & info,      
00931       const PHTTPConnectionInfo & connectInfo
00932     );
00933 
00936     PHTTPConnectionInfo & GetConnectionInfo() { return connectInfo; }
00937 
00938   protected:
00939     void Construct();
00940 
00941     PHTTPSpace          urlSpace;
00942     PHTTPConnectionInfo connectInfo;
00943     unsigned            transactionCount;
00944     PTimeInterval       nextTimeout;
00945 };
00946 
00947 
00949 // PHTTPRequest
00950 
00955 class PHTTPRequest : public PObject
00956 {
00957   PCLASSINFO(PHTTPRequest, PObject)
00958 
00959   public:
00960     PHTTPRequest(
00961       const PURL & url,             
00962       const PMIMEInfo & inMIME,     
00963       const PMultipartFormInfoArray & multipartFormInfo, 
00964       PHTTPServer & server          
00965     );
00966 
00967     PHTTPServer & server;           
00968     const PURL & url;               
00969     const PMIMEInfo & inMIME;       
00970     const PMultipartFormInfoArray & multipartFormInfo; 
00971     PHTTP::StatusCode code;         
00972     PMIMEInfo outMIME;              
00973     PString entityBody;             
00974     PINDEX contentSize;             
00975     PIPSocket::Address origin;      
00976     PIPSocket::Address localAddr;   
00977     WORD               localPort;   
00978 };
00979 
00980 
00982 // PHTTPAuthority
00983 
00987 class PHTTPAuthority : public PObject
00988 {
00989   PCLASSINFO(PHTTPAuthority, PObject)
00990 
00991   public:
00992   // New functions for class.
00999     virtual PString GetRealm(
01000       const PHTTPRequest & request   
01001     ) const = 0;
01002 
01009     virtual BOOL Validate(
01010       const PHTTPRequest & request,  
01011       const PString & authInfo       
01012     ) const = 0;
01013 
01023     virtual BOOL IsActive() const;
01024 
01025   protected:
01026     static void DecodeBasicAuthority(
01027       const PString & authInfo,   
01028       PString & username,         
01029       PString & password          
01030     );
01031 };
01032 
01033 
01035 // PHTTPSimpleAuth
01036 
01040 class PHTTPSimpleAuth : public PHTTPAuthority
01041 {
01042   PCLASSINFO(PHTTPSimpleAuth, PHTTPAuthority)
01043 
01044   public:
01045     PHTTPSimpleAuth(
01046       const PString & realm,      
01047       const PString & username,   
01048       const PString & password    
01049     );
01050     // Construct the simple authorisation structure.
01051 
01052 
01053   // Overrides from class PObject.
01061     virtual PObject * Clone() const;
01062 
01063 
01064   // Overrides from class PHTTPAuthority.
01071     virtual PString GetRealm(
01072       const PHTTPRequest & request   
01073     ) const;
01074 
01081     virtual BOOL Validate(
01082       const PHTTPRequest & request,  
01083       const PString & authInfo       
01084     ) const;
01085 
01095     virtual BOOL IsActive() const;
01096 
01102     const PString & GetUserName() const { return username; }
01103 
01109     const PString & GetPassword() const { return password; }
01110 
01111 
01112   protected:
01113     PString realm;
01114     PString username;
01115     PString password;
01116 };
01117 
01118 
01120 // PHTTPMultiSimpAuth
01121 
01125 class PHTTPMultiSimpAuth : public PHTTPAuthority
01126 {
01127   PCLASSINFO(PHTTPMultiSimpAuth, PHTTPAuthority)
01128 
01129   public:
01130     PHTTPMultiSimpAuth(
01131       const PString & realm      
01132     );
01133     PHTTPMultiSimpAuth(
01134       const PString & realm,           
01135       const PStringToString & userList 
01136     );
01137     // Construct the simple authorisation structure.
01138 
01139 
01140   // Overrides from class PObject.
01148     virtual PObject * Clone() const;
01149 
01150 
01151   // Overrides from class PHTTPAuthority.
01158     virtual PString GetRealm(
01159       const PHTTPRequest & request   
01160     ) const;
01161 
01168     virtual BOOL Validate(
01169       const PHTTPRequest & request,  
01170       const PString & authInfo       
01171     ) const;
01172 
01182     virtual BOOL IsActive() const;
01183 
01189     void AddUser(
01190       const PString & username,   
01191       const PString & password    
01192     );
01193 
01194 
01195   protected:
01196     PString realm;
01197     PStringToString users;
01198 };
01199 
01200 
01202 // PHTTPResource
01203 
01207 class PHTTPResource : public PObject
01208 {
01209   PCLASSINFO(PHTTPResource, PObject)
01210 
01211   protected:
01212     PHTTPResource(
01213       const PURL & url               
01214     );
01215     PHTTPResource(
01216       const PURL & url,              
01217       const PHTTPAuthority & auth    
01218     );
01219     PHTTPResource(
01220       const PURL & url,              
01221       const PString & contentType    
01222     );
01223     PHTTPResource(
01224       const PURL & url,              
01225       const PString & contentType,   
01226       const PHTTPAuthority & auth    
01227     );
01228     // Create a new HTTP Resource.
01229 
01230 
01231   public:
01232     virtual ~PHTTPResource();
01233     // Destroy the HTTP Resource.
01234 
01235 
01236   // New functions for class.
01242     const PURL & GetURL() const { return baseURL; }
01243 
01249     const PString & GetContentType() const { return contentType; }
01250 
01257     PHTTPAuthority * GetAuthority() const { return authority; }
01258 
01261     void SetAuthority(
01262       const PHTTPAuthority & auth      
01263     );
01264 
01267     void ClearAuthority();
01268 
01275     DWORD GetHitCount() const { return hitCount; }
01276 
01277     void ClearHitCount() { hitCount = 0; }
01278     // Clear the hit count for the resource.
01279 
01280 
01292     virtual BOOL OnGET(
01293       PHTTPServer & server,       
01294       const PURL & url,           
01295       const PMIMEInfo & info,     
01296       const PHTTPConnectionInfo & conInfo   
01297     );
01298 
01308     virtual BOOL OnGETData(
01309       PHTTPServer & server,                       
01310       const PURL & url,                           
01311       const PHTTPConnectionInfo & connectInfo,    
01312       PHTTPRequest & request                      
01313     );
01314 
01326     virtual BOOL OnHEAD(
01327       PHTTPServer & server,       
01328       const PURL & url,           
01329       const PMIMEInfo & info,     
01330       const PHTTPConnectionInfo & conInfo  
01331     );
01332 
01344     virtual BOOL OnPOST(
01345       PHTTPServer & server,         
01346       const PURL & url,             
01347       const PMIMEInfo & info,       
01348       const PStringToString & data, 
01349       const PHTTPConnectionInfo & conInfo  
01350     );
01351 
01361     virtual BOOL OnPOSTData(
01362       PHTTPRequest & request,        
01363       const PStringToString & data   
01364     );
01365 
01372     virtual BOOL IsModifiedSince(
01373       const PTime & when    
01374     );
01375 
01381     virtual BOOL GetExpirationDate(
01382       PTime & when          
01383     );
01384 
01392     virtual PHTTPRequest * CreateRequest(
01393       const PURL & url,                   
01394       const PMIMEInfo & inMIME,           
01395       const PMultipartFormInfoArray & multipartFormInfo,  
01396       PHTTPServer & socket                                
01397     );
01398 
01406     virtual BOOL LoadHeaders(
01407       PHTTPRequest & request    
01408     ) = 0;
01409 
01415     virtual void SendData(
01416       PHTTPRequest & request    
01417     );
01418 
01427     virtual BOOL LoadData(
01428       PHTTPRequest & request,    
01429       PCharArray & data          
01430     );
01431 
01440     virtual PString LoadText(
01441       PHTTPRequest & request    
01442     );
01443 
01450     virtual void OnLoadedText(
01451       PHTTPRequest & request,    
01452       PString & text             
01453     );
01454 
01463     virtual BOOL Post(
01464       PHTTPRequest & request,       
01465       const PStringToString & data, 
01466       PHTML & replyMessage          
01467     );
01468 
01469 
01470   protected:
01473     virtual BOOL CheckAuthority(
01474       PHTTPServer & server,               
01475       const PHTTPRequest & request,       
01476       const PHTTPConnectionInfo & conInfo 
01477     );
01478     static BOOL CheckAuthority(
01479                    PHTTPAuthority & authority,
01480                       PHTTPServer & server,
01481                const PHTTPRequest & request,
01482         const PHTTPConnectionInfo & connectInfo
01483     );
01484 
01485 
01487     virtual BOOL OnGETOrHEAD(
01488       PHTTPServer & server,       
01489       const PURL & url,           
01490       const PMIMEInfo & info,     
01491       const PHTTPConnectionInfo & conInfo,
01492       BOOL  IsGet
01493     );
01494 
01496     PURL             baseURL;
01498     PString          contentType;
01500     PHTTPAuthority * authority;
01502     volatile DWORD   hitCount;
01503 };
01504 
01505 
01507 // PHTTPString
01508 
01513 class PHTTPString : public PHTTPResource
01514 {
01515   PCLASSINFO(PHTTPString, PHTTPResource)
01516 
01517   public:
01521     PHTTPString(
01522       const PURL & url             // Name of the resource in URL space.
01523     );
01524     PHTTPString(
01525       const PURL & url,            // Name of the resource in URL space.
01526       const PHTTPAuthority & auth  // Authorisation for the resource.
01527     );
01528     PHTTPString(
01529       const PURL & url,            // Name of the resource in URL space.
01530       const PString & str          // String to return in this resource.
01531     );
01532     PHTTPString(
01533       const PURL & url,            // Name of the resource in URL space.
01534       const PString & str,         // String to return in this resource.
01535       const PString & contentType  // MIME content type for the file.
01536     );
01537     PHTTPString(
01538       const PURL & url,            // Name of the resource in URL space.
01539       const PString & str,         // String to return in this resource.
01540       const PHTTPAuthority & auth  // Authorisation for the resource.
01541     );
01542     PHTTPString(
01543       const PURL & url,            // Name of the resource in URL space.
01544       const PString & str,         // String to return in this resource.
01545       const PString & contentType, // MIME content type for the file.
01546       const PHTTPAuthority & auth  // Authorisation for the resource.
01547     );
01548 
01549 
01550   // Overrides from class PHTTPResource
01558     virtual BOOL LoadHeaders(
01559       PHTTPRequest & request    // Information on this request.
01560     );
01561 
01570     virtual PString LoadText(
01571       PHTTPRequest & request    // Information on this request.
01572     );
01573 
01574   // New functions for class.
01580     const PString & GetString() { return string; }
01581 
01584     void SetString(
01585       const PString & str   // New string for the resource.
01586     ) { string = str; }
01587 
01588 
01589   protected:
01590     PString string;
01591 };
01592 
01593 
01595 // PHTTPFile
01596 
01602 class PHTTPFile : public PHTTPResource
01603 {
01604   PCLASSINFO(PHTTPFile, PHTTPResource)
01605 
01606   public:
01613     PHTTPFile(
01614       const PString & filename     // file in file system and URL name.
01615     );
01616     PHTTPFile(
01617       const PString & filename,    // file in file system and URL name.
01618       const PHTTPAuthority & auth  // Authorisation for the resource.
01619     );
01620     PHTTPFile(
01621       const PURL & url,            // Name of the resource in URL space.
01622       const PFilePath & file       // Location of file in file system.
01623     );
01624     PHTTPFile(
01625       const PURL & url,            // Name of the resource in URL space.
01626       const PFilePath & file,      // Location of file in file system.
01627       const PString & contentType  // MIME content type for the file.
01628     );
01629     PHTTPFile(
01630       const PURL & url,            // Name of the resource in URL space.
01631       const PFilePath & file,      // Location of file in file system.
01632       const PHTTPAuthority & auth  // Authorisation for the resource.
01633     );
01634     PHTTPFile(
01635       const PURL & url,            // Name of the resource in URL space.
01636       const PFilePath & file,      // Location of file in file system.
01637       const PString & contentType, // MIME content type for the file.
01638       const PHTTPAuthority & auth  // Authorisation for the resource.
01639     );
01640 
01641 
01642   // Overrides from class PHTTPResource
01648     virtual PHTTPRequest * CreateRequest(
01649       const PURL & url,                  // Universal Resource Locator for document.
01650       const PMIMEInfo & inMIME,          // Extra MIME information in command.
01651       const PMultipartFormInfoArray & multipartFormInfo,
01652       PHTTPServer & socket
01653     );
01654 
01662     virtual BOOL LoadHeaders(
01663       PHTTPRequest & request    // Information on this request.
01664     );
01665 
01671     virtual BOOL LoadData(
01672       PHTTPRequest & request,    // Information on this request.
01673       PCharArray & data          // Data used in reply.
01674     );
01675 
01684     virtual PString LoadText(
01685       PHTTPRequest & request    // Information on this request.
01686     );
01687 
01688 
01689   protected:
01690     PHTTPFile(
01691       const PURL & url,       // Name of the resource in URL space.
01692       int dummy
01693     );
01694     // Constructor used by PHTTPDirectory
01695 
01696 
01697     PFilePath filePath;
01698 };
01699 
01700 
01701 class PHTTPFileRequest : public PHTTPRequest
01702 {
01703   PCLASSINFO(PHTTPFileRequest, PHTTPRequest)
01704   public:
01705     PHTTPFileRequest(
01706       const PURL & url,             // Universal Resource Locator for document.
01707       const PMIMEInfo & inMIME,     // Extra MIME information in command.
01708       const PMultipartFormInfoArray & multipartFormInfo,
01709       PHTTPServer & server
01710     );
01711 
01712     PFile file;
01713 };
01714 
01715 
01717 // PHTTPTailFile
01718 
01727 class PHTTPTailFile : public PHTTPFile
01728 {
01729   PCLASSINFO(PHTTPTailFile, PHTTPFile)
01730 
01731   public:
01738     PHTTPTailFile(
01739       const PString & filename     // file in file system and URL name.
01740     );
01741     PHTTPTailFile(
01742       const PString & filename,    // file in file system and URL name.
01743       const PHTTPAuthority & auth  // Authorisation for the resource.
01744     );
01745     PHTTPTailFile(
01746       const PURL & url,            // Name of the resource in URL space.
01747       const PFilePath & file       // Location of file in file system.
01748     );
01749     PHTTPTailFile(
01750       const PURL & url,            // Name of the resource in URL space.
01751       const PFilePath & file,      // Location of file in file system.
01752       const PString & contentType  // MIME content type for the file.
01753     );
01754     PHTTPTailFile(
01755       const PURL & url,            // Name of the resource in URL space.
01756       const PFilePath & file,      // Location of file in file system.
01757       const PHTTPAuthority & auth  // Authorisation for the resource.
01758     );
01759     PHTTPTailFile(
01760       const PURL & url,            // Name of the resource in URL space.
01761       const PFilePath & file,      // Location of file in file system.
01762       const PString & contentType, // MIME content type for the file.
01763       const PHTTPAuthority & auth  // Authorisation for the resource.
01764     );
01765 
01766 
01767   // Overrides from class PHTTPResource
01775     virtual BOOL LoadHeaders(
01776       PHTTPRequest & request    // Information on this request.
01777     );
01778 
01784     virtual BOOL LoadData(
01785       PHTTPRequest & request,    // Information on this request.
01786       PCharArray & data          // Data used in reply.
01787     );
01788 };
01789 
01790 
01792 // PHTTPDirectory
01793 
01806 class PHTTPDirectory : public PHTTPFile
01807 {
01808   PCLASSINFO(PHTTPDirectory, PHTTPFile)
01809 
01810   public:
01811     PHTTPDirectory(
01812       const PURL & url,            
01813       const PDirectory & dir       
01814     );
01815     PHTTPDirectory(
01816       const PURL & url,            
01817       const PDirectory & dir,      
01818       const PHTTPAuthority & auth  
01819     );
01820     // Construct a new directory resource for HTTP.
01821 
01822 
01823   // Overrides from class PHTTPResource
01829     virtual PHTTPRequest * CreateRequest(
01830       const PURL & url,                  // Universal Resource Locator for document.
01831       const PMIMEInfo & inMIME,          // Extra MIME information in command.
01832       const PMultipartFormInfoArray & multipartFormInfo,
01833       PHTTPServer & socket
01834     );
01835 
01843     virtual BOOL LoadHeaders(
01844       PHTTPRequest & request    
01845     );
01846 
01855     virtual PString LoadText(
01856       PHTTPRequest & request    
01857     );
01858 
01867     void EnableAuthorisation(const PString & realm);
01868 
01871     void AllowDirectories(BOOL enable = TRUE);
01872 
01873   protected:
01874     BOOL CheckAuthority(
01875       PHTTPServer & server,               // Server to send response to.
01876       const PHTTPRequest & request,       // Information on this request.
01877       const PHTTPConnectionInfo & conInfo // Information on the connection
01878     );
01879 
01880     BOOL FindAuthorisations(const PDirectory & dir, PString & realm, PStringToString & authorisations);
01881 
01882     PDirectory basePath;
01883     PString authorisationRealm;
01884     BOOL allowDirectoryListing;
01885 };
01886 
01887 
01888 class PHTTPDirRequest : public PHTTPFileRequest
01889 {
01890   PCLASSINFO(PHTTPDirRequest, PHTTPFileRequest)
01891   public:
01892     PHTTPDirRequest(
01893       const PURL & url,             // Universal Resource Locator for document.
01894       const PMIMEInfo & inMIME,     // Extra MIME information in command.
01895       const PMultipartFormInfoArray & multipartFormInfo, 
01896       PHTTPServer & server
01897     );
01898 
01899     PString fakeIndex;
01900     PFilePath realPath;
01901 };
01902 
01903 #endif // P_HTTPSVC
01904 
01905 #endif
01906 
01907 
01908 // End Of File ///////////////////////////////////////////////////////////////

Generated on Fri Sep 21 14:40:11 2007 for PWLib by  doxygen 1.5.3