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.61  2007/04/10 05:08:46  rjongbloed
00028  * Fixed issue with use of static C string variables in DLL environment,
00029  *   must use functional interface for correct initialisation.
00030  *
00031  * Revision 1.60  2005/11/30 12:47:37  csoutheren
00032  * Removed tabs, reformatted some code, and changed tags for Doxygen
00033  *
00034  * Revision 1.59  2005/01/03 12:48:41  csoutheren
00035  * Added new configure options and ability to disable/enable modules
00036  *
00037  * Revision 1.58  2004/10/23 11:34:59  ykiryanov
00038  * Added ifdef _WIN32_WCE for PocketPC 2003 SDK port
00039  *
00040  * Revision 1.57  2002/12/03 22:37:36  robertj
00041  * Removed get document that just returns a content length as the chunked
00042  *   transfer encoding makes this very dangerous.
00043  * Added GetTextDocument() to get a URL content into a PString.
00044  * Added a version pf PostData() that gets the reponse content into a PString.
00045  * Added ReadContentBody() that takes a PString, not just PBYTEArray.
00046  *
00047  * Revision 1.56  2002/11/06 22:47:23  robertj
00048  * Fixed header comment (copyright etc)
00049  *
00050  * Revision 1.55  2002/10/10 04:43:43  robertj
00051  * VxWorks port, thanks Martijn Roest
00052  *
00053  * Revision 1.54  2002/10/02 08:54:34  craigs
00054  * Added support for XMLRPC server
00055  *
00056  * Revision 1.53  2002/09/16 01:08:59  robertj
00057  * Added #define so can select if #pragma interface/implementation is used on
00058  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00059  *
00060  * Revision 1.52  2002/05/08 05:38:53  robertj
00061  * Added PHTTPTailFile resource to do a unix 'tail -f' of a file.
00062  *
00063  * Revision 1.51  2001/10/31 01:34:47  robertj
00064  * Added extra const for constant HTTP tag name strings.
00065  * Changes to support HTTP v1.1 chunked transfer encoding.
00066  *
00067  * Revision 1.50  2001/10/03 00:26:34  robertj
00068  * Upgraded client to HTTP/1.1 and for chunked mode entity bodies.
00069  *
00070  * Revision 1.49  2001/09/28 08:55:15  robertj
00071  * More changes to support restartable PHTTPClient
00072  *
00073  * Revision 1.48  2001/09/28 00:42:54  robertj
00074  * Added automatic setting of some outward MIME fields.
00075  * Added "user agent" string field for automatic inclusion.
00076  * Added function to read the contents of the HTTP request.
00077  *
00078  * Revision 1.47  2001/08/28 06:44:30  craigs
00079  * Added ability to override PHTTPServer creation
00080  *
00081  * Revision 1.46  2001/03/14 01:49:54  craigs
00082  * Added ability to handle multi-part form POST commands
00083  *
00084  * Revision 1.45  2001/02/22 05:26:47  robertj
00085  * Added "nicer" version of GetDocument in HTTP client class.
00086  *
00087  * Revision 1.44  2001/01/15 06:16:53  robertj
00088  * Set HTTP resource members to private to assure are not modified by
00089  *   dscendents in non-threadsafe manner.
00090  *
00091  * Revision 1.43  2000/09/04 03:57:58  robertj
00092  * Added ability to change the persistent connection parameters (timeout etc).
00093  *
00094  * Revision 1.42  2000/05/02 08:28:10  craigs
00095  * Removed "memory leaks" caused by brain-dead GNU linker
00096  *
00097  * Revision 1.41  1999/09/17 01:11:14  robertj
00098  * Fixed some documentation typos.
00099  *
00100  * Revision 1.40  1999/05/13 04:04:04  robertj
00101  * Fixed problem of initialised commandName in ConnectionInfo.
00102  *
00103  * Revision 1.39  1999/05/04 15:26:01  robertj
00104  * Improved HTTP/1.1 compatibility (pass through user commands).
00105  * Fixed problems with quicktime installer.
00106  *
00107  * Revision 1.38  1999/04/21 01:58:08  robertj
00108  * Fixed problem with reading data for request using second form of PHTTPRequestInfo constructor.
00109  *
00110  * Revision 1.37  1999/03/09 08:01:46  robertj
00111  * Changed comments for doc++ support (more to come).
00112  *
00113  * Revision 1.36  1999/02/16 08:07:10  robertj
00114  * MSVC 6.0 compatibility changes.
00115  *
00116  * Revision 1.35  1998/11/30 02:50:47  robertj
00117  * New directory structure
00118  *
00119  * Revision 1.34  1998/10/31 12:49:21  robertj
00120  * Added read/write mutex to the HTTP space variable to avoid thread crashes.
00121  *
00122  * Revision 1.33  1998/10/25 01:00:46  craigs
00123  * Added ability to specify per-directory authorisation for PHTTPDirectory
00124  *
00125  * Revision 1.32  1998/09/23 06:19:29  robertj
00126  * Added open source copyright license.
00127  *
00128  * Revision 1.31  1998/07/24 06:58:42  robertj
00129  * Changed PostData function so just has string for data instead of dictionary.
00130  *
00131  * Revision 1.30  1998/06/16 03:33:33  robertj
00132  * Changed TCP connection shutdown to be parameterised.
00133  * Propagated persistence and proxy flags in new connection info instances.
00134  *
00135  * Revision 1.29  1998/04/14 03:42:59  robertj
00136  * Fixed error code propagation in HTTP client.
00137  *
00138  * Revision 1.28  1998/02/03 06:29:38  robertj
00139  * Added local address and port to PHTTPRequest.
00140  *
00141  * Revision 1.27  1998/01/26 00:24:24  robertj
00142  * Added more information to PHTTPConnectionInfo.
00143  * Added function to allow HTTPClient to automatically connect if URL has hostname.
00144  *
00145  * Revision 1.26  1997/10/30 10:22:52  robertj
00146  * Added multiple user basic authorisation scheme.
00147  *
00148  * Revision 1.25  1997/10/03 13:30:15  craigs
00149  * Added ability to access client socket from within HTTP resources
00150  *
00151  * Revision 1.24  1997/03/28 04:40:22  robertj
00152  * Added tags for cookies.
00153  *
00154  * Revision 1.23  1997/01/12 04:15:19  robertj
00155  * Globalised MIME tag strings.
00156  *
00157  * Revision 1.22  1996/10/26 03:31:05  robertj
00158  * Changed OnError so can pass in full HTML page as parameter.
00159  *
00160  * Revision 1.21  1996/09/14 13:09:10  robertj
00161  * Major upgrade:
00162  *   rearranged sockets to help support IPX.
00163  *   added indirect channel class and moved all protocols to descend from it,
00164  *   separating the protocol from the low level byte transport.
00165  *
00166  * Revision 1.20  1996/08/22 13:20:55  robertj
00167  * Fixed bug in authorisation, missing virtual prevented polymorphism.
00168  *
00169  * Revision 1.19  1996/08/19 13:44:06  robertj
00170  * Fixed authorisation so if have no user/password on basic authentication, does not require it.
00171  *
00172  * Revision 1.18  1996/06/28 13:15:23  robertj
00173  * Modified HTTPAuthority so gets PHTTPReqest (mainly for URL) passed in.
00174  * Moved HTTP form resource to another compilation module.
00175  *
00176  * Revision 1.17  1996/06/07 13:52:20  robertj
00177  * Added PUT to HTTP proxy FTP. Necessitating redisign of entity body processing.
00178  *
00179  * Revision 1.16  1996/05/23 10:00:52  robertj
00180  * Added common function for GET and HEAD commands.
00181  * Fixed status codes to be the actual status code instead of sequential enum.
00182  * This fixed some problems with proxy pass through of status codes.
00183  *
00184  * Revision 1.14  1996/03/31 08:46:51  robertj
00185  * HTTP 1.1 upgrade.
00186  *
00187  * Revision 1.13  1996/03/17 05:41:57  robertj
00188  * Added hit count to PHTTPResource.
00189  *
00190  * Revision 1.12  1996/03/16 04:39:55  robertj
00191  * Added ParseReponse() for splitting reponse line into code and info.
00192  * Added client side support for HTTP socket.
00193  * Added hooks for proxy support in HTTP socket.
00194  *
00195  * Revision 1.11  1996/03/10 13:15:23  robertj
00196  * Redesign to make resources thread safe.
00197  *
00198  * Revision 1.10  1996/03/02 03:12:55  robertj
00199  * Added radio button and selection boxes to HTTP form resource.
00200  *
00201  * Revision 1.9  1996/02/25 11:14:21  robertj
00202  * Radio button support for forms.
00203  *
00204  * Revision 1.8  1996/02/25 02:57:48  robertj
00205  * Removed pass through HTTP resource.
00206  *
00207  * Revision 1.7  1996/02/19 13:25:43  robertj
00208  * Added overwrite option to AddResource().
00209  * Added get/set string to PHTTPString resource.
00210  * Moved nested classes from PHTTPForm.
00211  *
00212  * Revision 1.6  1996/02/13 13:09:16  robertj
00213  * Added extra parameters to callback function in PHTTPResources, required
00214  *   by descendants to make informed decisions on data being loaded.
00215  *
00216  * Revision 1.5  1996/02/08 12:04:19  robertj
00217  * Redesign of resource object callback virtuals.
00218  * Added HTML form resource type.
00219  *
00220  * Revision 1.4  1996/02/03 11:03:32  robertj
00221  * Added ismodified since and expires time checking.
00222  * Added PHTTPString that defaults to empty string.
00223  *
00224  * Revision 1.3  1996/01/28 14:15:38  robertj
00225  * Changed PCharArray in OnLoadData to PString for convenience in mangling data.
00226  * Beginning of pass through resource type.
00227  *
00228  * Revision 1.2  1996/01/26 02:24:26  robertj
00229  * Further implemetation.
00230  *
00231  * Revision 1.1  1996/01/23 13:04:20  robertj
00232  * Initial revision
00233  *
00234  */
00235 
00236 #ifndef _PHTTP
00237 #define _PHTTP
00238 
00239 #ifdef P_USE_PRAGMA
00240 #pragma interface
00241 #endif
00242 
00243 #include <ptbuildopts.h>
00244 
00245 #include <ptclib/inetprot.h>
00246 #include <ptclib/mime.h>
00247 #include <ptclib/url.h>
00248 #include <ptlib/ipsock.h>
00249 
00250 #ifdef P_HTTPSVC
00251 
00252 #include <ptclib/html.h>
00253 
00255 // PHTTPSpace
00256 
00257 class PHTTPResource;
00258 
00263 class PHTTPSpace : public PContainer
00264 {
00265   PCONTAINERINFO(PHTTPSpace, PContainer)
00266   public:
00268     PHTTPSpace();
00269 
00270 
00271   // New functions for class.
00272     enum AddOptions {
00274       ErrorOnExist,
00276       Overwrite
00277     };
00278 
00279 
00291     BOOL AddResource(
00292       PHTTPResource * resource, 
00293       AddOptions overwrite = ErrorOnExist
00295     );
00296 
00304     BOOL DelResource(
00305       const PURL & url          
00306     );
00307 
00313     PHTTPResource * FindResource(
00314       const PURL & url   
00315     );
00316 
00319     void StartRead() const
00320       { mutex->StartRead(); }
00321 
00324     void EndRead() const
00325       { mutex->EndRead(); }
00326 
00329     void StartWrite() const
00330       { mutex->StartWrite(); }
00331 
00334     void EndWrite() const
00335       { mutex->EndWrite(); }
00336 
00337 
00338   protected:
00339     PReadWriteMutex * mutex;
00340 
00341     class Node;
00342     PSORTED_LIST(ChildList, Node);
00343     class Node : public PString
00344     {
00345       PCLASSINFO(Node, PString)
00346       public:
00347         Node(const PString & name, Node * parentNode);
00348         ~Node();
00349 
00350         Node          * parent;
00351         ChildList       children;
00352         PHTTPResource * resource;
00353     } * root;
00354 
00355   private:
00356     BOOL SetSize(PINDEX) { return FALSE; }
00357 };
00358 
00359 #endif // P_HTTPSVC
00360 
00361 #ifdef _WIN32_WCE
00362 #undef TRACE
00363 #endif
00364 
00366 // PHTTP
00367 
00371 class PHTTP : public PInternetProtocol
00372 {
00373   PCLASSINFO(PHTTP, PInternetProtocol)
00374 
00375   public:
00376   // New functions for class.
00377     enum Commands {
00378       // HTTP/1.0 commands
00379       GET, HEAD, POST,
00380       // HTTP/1.1 commands
00381       PUT, DELETE, TRACE, OPTIONS,
00382       // HTTPS command
00383       CONNECT,
00384       NumCommands
00385     };
00386 
00387     enum StatusCode {
00388       Continue = 100,              
00389       SwitchingProtocols,          
00390       RequestOK = 200,             
00391       Created,                     
00392       Accepted,                    
00393       NonAuthoritativeInformation, 
00394       NoContent,                   
00395       ResetContent,                
00396       PartialContent,              
00397       MultipleChoices = 300,       
00398       MovedPermanently,            
00399       MovedTemporarily,            
00400       SeeOther,                    
00401       NotModified,                 
00402       UseProxy,                    
00403       BadRequest = 400,            
00404       UnAuthorised,                
00405       PaymentRequired,             
00406       Forbidden,                   
00407       NotFound,                    
00408       MethodNotAllowed,            
00409       NoneAcceptable,              
00410       ProxyAuthenticationRequired, 
00411       RequestTimeout,              
00412       Conflict,                    
00413       Gone,                        
00414       LengthRequired,              
00415       UnlessTrue,                  
00416       InternalServerError = 500,   
00417       NotImplemented,              
00418       BadGateway,                  
00419       ServiceUnavailable,          
00420       GatewayTimeout               
00421     };
00422 
00423     // Common MIME header tags
00424     static const PString & AllowTag();
00425     static const PString & AuthorizationTag();
00426     static const PString & ContentEncodingTag();
00427     static const PString & ContentLengthTag();
00428     static const PString & ContentTypeTag();
00429     static const PString & DateTag();
00430     static const PString & ExpiresTag();
00431     static const PString & FromTag();
00432     static const PString & IfModifiedSinceTag();
00433     static const PString & LastModifiedTag();
00434     static const PString & LocationTag();
00435     static const PString & PragmaTag();
00436     static const PString & PragmaNoCacheTag();
00437     static const PString & RefererTag();
00438     static const PString & ServerTag();
00439     static const PString & UserAgentTag();
00440     static const PString & WWWAuthenticateTag();
00441     static const PString & MIMEVersionTag();
00442     static const PString & ConnectionTag();
00443     static const PString & KeepAliveTag();
00444     static const PString & TransferEncodingTag();
00445     static const PString & ChunkedTag();
00446     static const PString & ProxyConnectionTag();
00447     static const PString & ProxyAuthorizationTag();
00448     static const PString & ProxyAuthenticateTag();
00449     static const PString & ForwardedTag();
00450     static const PString & SetCookieTag();
00451     static const PString & CookieTag();
00452 
00453   protected:
00456     PHTTP();
00457 
00469     virtual PINDEX ParseResponse(
00470       const PString & line    
00471     );
00472 };
00473 
00474 
00476 // PHTTPClient
00477 
00498 class PHTTPClient : public PHTTP
00499 {
00500   PCLASSINFO(PHTTPClient, PHTTP)
00501 
00502   public:
00504     PHTTPClient();
00505     PHTTPClient(
00506       const PString & userAgentName
00507     );
00508 
00509 
00510   // New functions for class.
00518     int ExecuteCommand(
00519       Commands cmd,
00520       const PURL & url,
00521       PMIMEInfo & outMIME,
00522       const PString & dataBody,
00523       PMIMEInfo & replyMime,
00524       BOOL persist = TRUE
00525     );
00526     int ExecuteCommand(
00527       const PString & cmdName,
00528       const PURL & url,
00529       PMIMEInfo & outMIME,
00530       const PString & dataBody,
00531       PMIMEInfo & replyMime,
00532       BOOL persist = TRUE
00533     );
00534 
00536     BOOL WriteCommand(
00537       Commands cmd,
00538       const PString & url,
00539       PMIMEInfo & outMIME,
00540       const PString & dataBody
00541     );
00542     BOOL WriteCommand(
00543       const PString & cmdName,
00544       const PString & url,
00545       PMIMEInfo & outMIME,
00546       const PString & dataBody
00547     );
00548 
00550     BOOL ReadResponse(
00551       PMIMEInfo & replyMIME
00552     );
00553 
00555     BOOL ReadContentBody(
00556       PMIMEInfo & replyMIME,
00557       PBYTEArray & body
00558     );
00559     BOOL ReadContentBody(
00560       PMIMEInfo & replyMIME,
00561       PString & body
00562     );
00563 
00564 
00570     BOOL GetTextDocument(
00571       const PURL & url,         
00572       PString & document,       
00573       BOOL persist = TRUE       
00574     );
00575 
00581     BOOL GetDocument(
00582       const PURL & url,         
00583       PMIMEInfo & outMIME,      
00584       PMIMEInfo & replyMIME,    
00585       BOOL persist = TRUE       
00586     );
00587 
00593     BOOL GetHeader(
00594       const PURL & url,         
00595       PMIMEInfo & outMIME,      
00596       PMIMEInfo & replyMIME,    
00597       BOOL persist = TRUE       
00598     );
00599 
00600 
00606     BOOL PostData(
00607       const PURL & url,       
00608       PMIMEInfo & outMIME,    
00609       const PString & data,   
00610       PMIMEInfo & replyMIME,  
00611       BOOL persist = TRUE     
00612     );
00613 
00619     BOOL PostData(
00620       const PURL & url,       
00621       PMIMEInfo & outMIME,    
00622       const PString & data,   
00623       PMIMEInfo & replyMIME,  
00624       PString & replyBody,    
00625       BOOL persist = TRUE     
00626     );
00627 
00628   protected:
00629     BOOL AssureConnect(const PURL & url, PMIMEInfo & outMIME);
00630     BOOL InternalReadContentBody(
00631       PMIMEInfo & replyMIME,
00632       PAbstractArray & body
00633     );
00634 
00635     PString userAgentName;
00636 };
00637 
00638 #ifdef P_HTTPSVC
00639 
00641 // PMultipartFormInfo
00642 
00647 class PMultipartFormInfo : public PObject
00648 {
00649   PCLASSINFO(PMultipartFormInfo, PObject);
00650   public:
00651     PMIMEInfo mime;
00652     PString body;
00653 };
00654 
00655 PARRAY(PMultipartFormInfoArray, PMultipartFormInfo);
00656 
00658 // PHTTPConnectionInfo
00659 
00660 class PHTTPServer;
00661 
00666 class PHTTPConnectionInfo : public PObject
00667 {
00668   PCLASSINFO(PHTTPConnectionInfo, PObject)
00669   public:
00670     PHTTPConnectionInfo();
00671 
00672     PHTTP::Commands GetCommandCode() const { return commandCode; }
00673     const PString & GetCommandName() const { return commandName; }
00674 
00675     const PURL & GetURL() const       { return url; }
00676 
00677     const PMIMEInfo & GetMIME() const { return mimeInfo; }
00678     void SetMIME(const PString & tag, const PString & value);
00679 
00680     BOOL IsCompatible(int major, int minor) const;
00681 
00682     BOOL IsPersistant() const         { return isPersistant; }
00683     BOOL WasPersistant() const        { return wasPersistant; }
00684     BOOL IsProxyConnection() const    { return isProxyConnection; }
00685     int  GetMajorVersion() const      { return majorVersion; }
00686     int  GetMinorVersion() const      { return minorVersion; }
00687 
00688     long GetEntityBodyLength() const  { return entityBodyLength; }
00689 
00692     PTimeInterval GetPersistenceTimeout() const { return persistenceTimeout; }
00693 
00696     void SetPersistenceTimeout(const PTimeInterval & t) { persistenceTimeout = t; }
00697 
00701     unsigned GetPersistenceMaximumTransations() const { return persistenceMaximum; }
00702 
00706     void SetPersistenceMaximumTransations(unsigned m) { persistenceMaximum = m; }
00707 
00708     const PMultipartFormInfoArray & GetMultipartFormInfo() const
00709       { return multipartFormInfoArray; }
00710 
00711     void ResetMultipartFormInfo()
00712       { multipartFormInfoArray.RemoveAll(); }
00713 
00714     PString GetEntityBody() const   { return entityBody; }
00715 
00716   protected:
00717     BOOL Initialise(PHTTPServer & server, PString & args);
00718     void DecodeMultipartFormInfo(const PString & type, const PString & entityBody);
00719 
00720     PHTTP::Commands commandCode;
00721     PString         commandName;
00722     PURL            url;
00723     PMIMEInfo       mimeInfo;
00724     BOOL            isPersistant;
00725     BOOL            wasPersistant;
00726     BOOL            isProxyConnection;
00727     int             majorVersion;
00728     int             minorVersion;
00729     PString         entityBody;        // original entity body (POST only)
00730     long            entityBodyLength;
00731     PTimeInterval   persistenceTimeout;
00732     unsigned        persistenceMaximum;
00733     PMultipartFormInfoArray multipartFormInfoArray;
00734 
00735   friend class PHTTPServer;
00736 };
00737 
00738 
00740 // PHTTPServer
00741 
00754 class PHTTPServer : public PHTTP
00755 {
00756   PCLASSINFO(PHTTPServer, PHTTP)
00757 
00758   public:
00766     PHTTPServer();
00767     PHTTPServer(
00768      const PHTTPSpace & urlSpace  
00769     );
00770 
00771 
00772   // New functions for class.
00778     virtual PString GetServerName() const;
00779 
00785     PHTTPSpace & GetURLSpace() { return urlSpace; }
00786 
00788     void SetURLSpace(
00789       const PHTTPSpace & space   
00790     );
00791 
00792 
00802     virtual BOOL ProcessCommand();
00803 
00815     virtual BOOL OnGET(
00816       const PURL & url,                    
00817       const PMIMEInfo & info,              
00818       const PHTTPConnectionInfo & conInfo  
00819     );
00820 
00821 
00822 
00834     virtual BOOL OnHEAD(
00835       const PURL & url,                   
00836       const PMIMEInfo & info,             
00837       const PHTTPConnectionInfo & conInfo 
00838     );
00839 
00851     virtual BOOL OnPOST(
00852       const PURL & url,                   
00853       const PMIMEInfo & info,             
00854       const PStringToString & data,       
00855       const PHTTPConnectionInfo & conInfo 
00856     );
00857 
00870     virtual BOOL OnProxy(
00871       const PHTTPConnectionInfo & conInfo   
00872     );
00873 
00874 
00881     virtual PString ReadEntityBody();
00882 
00888     virtual BOOL OnUnknown(
00889       const PCaselessString & command,         
00890       const PHTTPConnectionInfo & connectInfo  
00891     );
00892 
00911     BOOL StartResponse(
00912       StatusCode code,      
00913       PMIMEInfo & headers,  
00914       long bodySize         
00915     );
00916 
00926     virtual BOOL OnError(
00927       StatusCode code,                         
00928       const PCaselessString & extra,           
00929       const PHTTPConnectionInfo & connectInfo  
00930     );
00931 
00934     void SetDefaultMIMEInfo(
00935       PMIMEInfo & info,      
00936       const PHTTPConnectionInfo & connectInfo
00937     );
00938 
00941     PHTTPConnectionInfo & GetConnectionInfo() { return connectInfo; }
00942 
00943   protected:
00944     void Construct();
00945 
00946     PHTTPSpace          urlSpace;
00947     PHTTPConnectionInfo connectInfo;
00948     unsigned            transactionCount;
00949     PTimeInterval       nextTimeout;
00950 };
00951 
00952 
00954 // PHTTPRequest
00955 
00960 class PHTTPRequest : public PObject
00961 {
00962   PCLASSINFO(PHTTPRequest, PObject)
00963 
00964   public:
00965     PHTTPRequest(
00966       const PURL & url,             
00967       const PMIMEInfo & inMIME,     
00968       const PMultipartFormInfoArray & multipartFormInfo, 
00969       PHTTPServer & server          
00970     );
00971 
00972     PHTTPServer & server;           
00973     const PURL & url;               
00974     const PMIMEInfo & inMIME;       
00975     const PMultipartFormInfoArray & multipartFormInfo; 
00976     PHTTP::StatusCode code;         
00977     PMIMEInfo outMIME;              
00978     PString entityBody;             
00979     PINDEX contentSize;             
00980     PIPSocket::Address origin;      
00981     PIPSocket::Address localAddr;   
00982     WORD               localPort;   
00983 };
00984 
00985 
00987 // PHTTPAuthority
00988 
00992 class PHTTPAuthority : public PObject
00993 {
00994   PCLASSINFO(PHTTPAuthority, PObject)
00995 
00996   public:
00997   // New functions for class.
01004     virtual PString GetRealm(
01005       const PHTTPRequest & request   
01006     ) const = 0;
01007 
01014     virtual BOOL Validate(
01015       const PHTTPRequest & request,  
01016       const PString & authInfo       
01017     ) const = 0;
01018 
01028     virtual BOOL IsActive() const;
01029 
01030   protected:
01031     static void DecodeBasicAuthority(
01032       const PString & authInfo,   
01033       PString & username,         
01034       PString & password          
01035     );
01036 };
01037 
01038 
01040 // PHTTPSimpleAuth
01041 
01045 class PHTTPSimpleAuth : public PHTTPAuthority
01046 {
01047   PCLASSINFO(PHTTPSimpleAuth, PHTTPAuthority)
01048 
01049   public:
01050     PHTTPSimpleAuth(
01051       const PString & realm,      
01052       const PString & username,   
01053       const PString & password    
01054     );
01055     // Construct the simple authorisation structure.
01056 
01057 
01058   // Overrides from class PObject.
01066     virtual PObject * Clone() const;
01067 
01068 
01069   // Overrides from class PHTTPAuthority.
01076     virtual PString GetRealm(
01077       const PHTTPRequest & request   
01078     ) const;
01079 
01086     virtual BOOL Validate(
01087       const PHTTPRequest & request,  
01088       const PString & authInfo       
01089     ) const;
01090 
01100     virtual BOOL IsActive() const;
01101 
01107     const PString & GetUserName() const { return username; }
01108 
01114     const PString & GetPassword() const { return password; }
01115 
01116 
01117   protected:
01118     PString realm;
01119     PString username;
01120     PString password;
01121 };
01122 
01123 
01125 // PHTTPMultiSimpAuth
01126 
01130 class PHTTPMultiSimpAuth : public PHTTPAuthority
01131 {
01132   PCLASSINFO(PHTTPMultiSimpAuth, PHTTPAuthority)
01133 
01134   public:
01135     PHTTPMultiSimpAuth(
01136       const PString & realm      
01137     );
01138     PHTTPMultiSimpAuth(
01139       const PString & realm,           
01140       const PStringToString & userList 
01141     );
01142     // Construct the simple authorisation structure.
01143 
01144 
01145   // Overrides from class PObject.
01153     virtual PObject * Clone() const;
01154 
01155 
01156   // Overrides from class PHTTPAuthority.
01163     virtual PString GetRealm(
01164       const PHTTPRequest & request   
01165     ) const;
01166 
01173     virtual BOOL Validate(
01174       const PHTTPRequest & request,  
01175       const PString & authInfo       
01176     ) const;
01177 
01187     virtual BOOL IsActive() const;
01188 
01194     void AddUser(
01195       const PString & username,   
01196       const PString & password    
01197     );
01198 
01199 
01200   protected:
01201     PString realm;
01202     PStringToString users;
01203 };
01204 
01205 
01207 // PHTTPResource
01208 
01212 class PHTTPResource : public PObject
01213 {
01214   PCLASSINFO(PHTTPResource, PObject)
01215 
01216   protected:
01217     PHTTPResource(
01218       const PURL & url               
01219     );
01220     PHTTPResource(
01221       const PURL & url,              
01222       const PHTTPAuthority & auth    
01223     );
01224     PHTTPResource(
01225       const PURL & url,              
01226       const PString & contentType    
01227     );
01228     PHTTPResource(
01229       const PURL & url,              
01230       const PString & contentType,   
01231       const PHTTPAuthority & auth    
01232     );
01233     // Create a new HTTP Resource.
01234 
01235 
01236   public:
01237     virtual ~PHTTPResource();
01238     // Destroy the HTTP Resource.
01239 
01240 
01241   // New functions for class.
01247     const PURL & GetURL() const { return baseURL; }
01248 
01254     const PString & GetContentType() const { return contentType; }
01255 
01262     PHTTPAuthority * GetAuthority() const { return authority; }
01263 
01266     void SetAuthority(
01267       const PHTTPAuthority & auth      
01268     );
01269 
01272     void ClearAuthority();
01273 
01280     DWORD GetHitCount() const { return hitCount; }
01281 
01282     void ClearHitCount() { hitCount = 0; }
01283     // Clear the hit count for the resource.
01284 
01285 
01297     virtual BOOL OnGET(
01298       PHTTPServer & server,       
01299       const PURL & url,           
01300       const PMIMEInfo & info,     
01301       const PHTTPConnectionInfo & conInfo   
01302     );
01303 
01313     virtual BOOL OnGETData(
01314       PHTTPServer & server,                       
01315       const PURL & url,                           
01316       const PHTTPConnectionInfo & connectInfo,    
01317       PHTTPRequest & request                      
01318     );
01319 
01331     virtual BOOL OnHEAD(
01332       PHTTPServer & server,       
01333       const PURL & url,           
01334       const PMIMEInfo & info,     
01335       const PHTTPConnectionInfo & conInfo  
01336     );
01337 
01349     virtual BOOL OnPOST(
01350       PHTTPServer & server,         
01351       const PURL & url,             
01352       const PMIMEInfo & info,       
01353       const PStringToString & data, 
01354       const PHTTPConnectionInfo & conInfo  
01355     );
01356 
01366     virtual BOOL OnPOSTData(
01367       PHTTPRequest & request,        
01368       const PStringToString & data   
01369     );
01370 
01377     virtual BOOL IsModifiedSince(
01378       const PTime & when    
01379     );
01380 
01386     virtual BOOL GetExpirationDate(
01387       PTime & when          
01388     );
01389 
01397     virtual PHTTPRequest * CreateRequest(
01398       const PURL & url,                   
01399       const PMIMEInfo & inMIME,           
01400       const PMultipartFormInfoArray & multipartFormInfo,  
01401       PHTTPServer & socket                                
01402     );
01403 
01411     virtual BOOL LoadHeaders(
01412       PHTTPRequest & request    
01413     ) = 0;
01414 
01420     virtual void SendData(
01421       PHTTPRequest & request    
01422     );
01423 
01432     virtual BOOL LoadData(
01433       PHTTPRequest & request,    
01434       PCharArray & data          
01435     );
01436 
01445     virtual PString LoadText(
01446       PHTTPRequest & request    
01447     );
01448 
01455     virtual void OnLoadedText(
01456       PHTTPRequest & request,    
01457       PString & text             
01458     );
01459 
01468     virtual BOOL Post(
01469       PHTTPRequest & request,       
01470       const PStringToString & data, 
01471       PHTML & replyMessage          
01472     );
01473 
01474 
01475   protected:
01478     virtual BOOL CheckAuthority(
01479       PHTTPServer & server,               
01480       const PHTTPRequest & request,       
01481       const PHTTPConnectionInfo & conInfo 
01482     );
01483     static BOOL CheckAuthority(
01484                    PHTTPAuthority & authority,
01485                       PHTTPServer & server,
01486                const PHTTPRequest & request,
01487         const PHTTPConnectionInfo & connectInfo
01488     );
01489 
01490 
01492     virtual BOOL OnGETOrHEAD(
01493       PHTTPServer & server,       
01494       const PURL & url,           
01495       const PMIMEInfo & info,     
01496       const PHTTPConnectionInfo & conInfo,
01497       BOOL  IsGet
01498     );
01499 
01501     PURL             baseURL;
01503     PString          contentType;
01505     PHTTPAuthority * authority;
01507     volatile DWORD   hitCount;
01508 };
01509 
01510 
01512 // PHTTPString
01513 
01518 class PHTTPString : public PHTTPResource
01519 {
01520   PCLASSINFO(PHTTPString, PHTTPResource)
01521 
01522   public:
01526     PHTTPString(
01527       const PURL & url             // Name of the resource in URL space.
01528     );
01529     PHTTPString(
01530       const PURL & url,            // Name of the resource in URL space.
01531       const PHTTPAuthority & auth  // Authorisation for the resource.
01532     );
01533     PHTTPString(
01534       const PURL & url,            // Name of the resource in URL space.
01535       const PString & str          // String to return in this resource.
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 PString & contentType  // MIME content type for the file.
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 PHTTPAuthority & auth  // Authorisation for the resource.
01546     );
01547     PHTTPString(
01548       const PURL & url,            // Name of the resource in URL space.
01549       const PString & str,         // String to return in this resource.
01550       const PString & contentType, // MIME content type for the file.
01551       const PHTTPAuthority & auth  // Authorisation for the resource.
01552     );
01553 
01554 
01555   // Overrides from class PHTTPResource
01563     virtual BOOL LoadHeaders(
01564       PHTTPRequest & request    // Information on this request.
01565     );
01566 
01575     virtual PString LoadText(
01576       PHTTPRequest & request    // Information on this request.
01577     );
01578 
01579   // New functions for class.
01585     const PString & GetString() { return string; }
01586 
01589     void SetString(
01590       const PString & str   // New string for the resource.
01591     ) { string = str; }
01592 
01593 
01594   protected:
01595     PString string;
01596 };
01597 
01598 
01600 // PHTTPFile
01601 
01607 class PHTTPFile : public PHTTPResource
01608 {
01609   PCLASSINFO(PHTTPFile, PHTTPResource)
01610 
01611   public:
01618     PHTTPFile(
01619       const PString & filename     // file in file system and URL name.
01620     );
01621     PHTTPFile(
01622       const PString & filename,    // file in file system and URL name.
01623       const PHTTPAuthority & auth  // Authorisation for the resource.
01624     );
01625     PHTTPFile(
01626       const PURL & url,            // Name of the resource in URL space.
01627       const PFilePath & file       // Location of file in file system.
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 PString & contentType  // MIME content type for the file.
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 PHTTPAuthority & auth  // Authorisation for the resource.
01638     );
01639     PHTTPFile(
01640       const PURL & url,            // Name of the resource in URL space.
01641       const PFilePath & file,      // Location of file in file system.
01642       const PString & contentType, // MIME content type for the file.
01643       const PHTTPAuthority & auth  // Authorisation for the resource.
01644     );
01645 
01646 
01647   // Overrides from class PHTTPResource
01653     virtual PHTTPRequest * CreateRequest(
01654       const PURL & url,                  // Universal Resource Locator for document.
01655       const PMIMEInfo & inMIME,          // Extra MIME information in command.
01656       const PMultipartFormInfoArray & multipartFormInfo,
01657       PHTTPServer & socket
01658     );
01659 
01667     virtual BOOL LoadHeaders(
01668       PHTTPRequest & request    // Information on this request.
01669     );
01670 
01676     virtual BOOL LoadData(
01677       PHTTPRequest & request,    // Information on this request.
01678       PCharArray & data          // Data used in reply.
01679     );
01680 
01689     virtual PString LoadText(
01690       PHTTPRequest & request    // Information on this request.
01691     );
01692 
01693 
01694   protected:
01695     PHTTPFile(
01696       const PURL & url,       // Name of the resource in URL space.
01697       int dummy
01698     );
01699     // Constructor used by PHTTPDirectory
01700 
01701 
01702     PFilePath filePath;
01703 };
01704 
01705 
01706 class PHTTPFileRequest : public PHTTPRequest
01707 {
01708   PCLASSINFO(PHTTPFileRequest, PHTTPRequest)
01709   public:
01710     PHTTPFileRequest(
01711       const PURL & url,             // Universal Resource Locator for document.
01712       const PMIMEInfo & inMIME,     // Extra MIME information in command.
01713       const PMultipartFormInfoArray & multipartFormInfo,
01714       PHTTPServer & server
01715     );
01716 
01717     PFile file;
01718 };
01719 
01720 
01722 // PHTTPTailFile
01723 
01732 class PHTTPTailFile : public PHTTPFile
01733 {
01734   PCLASSINFO(PHTTPTailFile, PHTTPFile)
01735 
01736   public:
01743     PHTTPTailFile(
01744       const PString & filename     // file in file system and URL name.
01745     );
01746     PHTTPTailFile(
01747       const PString & filename,    // file in file system and URL name.
01748       const PHTTPAuthority & auth  // Authorisation for the resource.
01749     );
01750     PHTTPTailFile(
01751       const PURL & url,            // Name of the resource in URL space.
01752       const PFilePath & file       // Location of file in file system.
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 PString & contentType  // MIME content type for the file.
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 PHTTPAuthority & auth  // Authorisation for the resource.
01763     );
01764     PHTTPTailFile(
01765       const PURL & url,            // Name of the resource in URL space.
01766       const PFilePath & file,      // Location of file in file system.
01767       const PString & contentType, // MIME content type for the file.
01768       const PHTTPAuthority & auth  // Authorisation for the resource.
01769     );
01770 
01771 
01772   // Overrides from class PHTTPResource
01780     virtual BOOL LoadHeaders(
01781       PHTTPRequest & request    // Information on this request.
01782     );
01783 
01789     virtual BOOL LoadData(
01790       PHTTPRequest & request,    // Information on this request.
01791       PCharArray & data          // Data used in reply.
01792     );
01793 };
01794 
01795 
01797 // PHTTPDirectory
01798 
01811 class PHTTPDirectory : public PHTTPFile
01812 {
01813   PCLASSINFO(PHTTPDirectory, PHTTPFile)
01814 
01815   public:
01816     PHTTPDirectory(
01817       const PURL & url,            
01818       const PDirectory & dir       
01819     );
01820     PHTTPDirectory(
01821       const PURL & url,            
01822       const PDirectory & dir,      
01823       const PHTTPAuthority & auth  
01824     );
01825     // Construct a new directory resource for HTTP.
01826 
01827 
01828   // Overrides from class PHTTPResource
01834     virtual PHTTPRequest * CreateRequest(
01835       const PURL & url,                  // Universal Resource Locator for document.
01836       const PMIMEInfo & inMIME,          // Extra MIME information in command.
01837       const PMultipartFormInfoArray & multipartFormInfo,
01838       PHTTPServer & socket
01839     );
01840 
01848     virtual BOOL LoadHeaders(
01849       PHTTPRequest & request    
01850     );
01851 
01860     virtual PString LoadText(
01861       PHTTPRequest & request    
01862     );
01863 
01872     void EnableAuthorisation(const PString & realm);
01873 
01876     void AllowDirectories(BOOL enable = TRUE);
01877 
01878   protected:
01879     BOOL CheckAuthority(
01880       PHTTPServer & server,               // Server to send response to.
01881       const PHTTPRequest & request,       // Information on this request.
01882       const PHTTPConnectionInfo & conInfo // Information on the connection
01883     );
01884 
01885     BOOL FindAuthorisations(const PDirectory & dir, PString & realm, PStringToString & authorisations);
01886 
01887     PDirectory basePath;
01888     PString authorisationRealm;
01889     BOOL allowDirectoryListing;
01890 };
01891 
01892 
01893 class PHTTPDirRequest : public PHTTPFileRequest
01894 {
01895   PCLASSINFO(PHTTPDirRequest, PHTTPFileRequest)
01896   public:
01897     PHTTPDirRequest(
01898       const PURL & url,             // Universal Resource Locator for document.
01899       const PMIMEInfo & inMIME,     // Extra MIME information in command.
01900       const PMultipartFormInfoArray & multipartFormInfo, 
01901       PHTTPServer & server
01902     );
01903 
01904     PString fakeIndex;
01905     PFilePath realPath;
01906 };
01907 
01908 #endif // P_HTTPSVC
01909 
01910 #endif
01911 
01912 
01913 // End Of File ///////////////////////////////////////////////////////////////

Generated on Fri Mar 7 06:25:02 2008 for PTLib by  doxygen 1.5.1