Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

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.58  2004/10/23 11:34:59  ykiryanov
00028  * Added ifdef _WIN32_WCE for PocketPC 2003 SDK port
00029  *
00030  * Revision 1.57  2002/12/03 22:37:36  robertj
00031  * Removed get document that just returns a content length as the chunked
00032  *   transfer encoding makes this very dangerous.
00033  * Added GetTextDocument() to get a URL content into a PString.
00034  * Added a version pf PostData() that gets the reponse content into a PString.
00035  * Added ReadContentBody() that takes a PString, not just PBYTEArray.
00036  *
00037  * Revision 1.56  2002/11/06 22:47:23  robertj
00038  * Fixed header comment (copyright etc)
00039  *
00040  * Revision 1.55  2002/10/10 04:43:43  robertj
00041  * VxWorks port, thanks Martijn Roest
00042  *
00043  * Revision 1.54  2002/10/02 08:54:34  craigs
00044  * Added support for XMLRPC server
00045  *
00046  * Revision 1.53  2002/09/16 01:08:59  robertj
00047  * Added #define so can select if #pragma interface/implementation is used on
00048  *   platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
00049  *
00050  * Revision 1.52  2002/05/08 05:38:53  robertj
00051  * Added PHTTPTailFile resource to do a unix 'tail -f' of a file.
00052  *
00053  * Revision 1.51  2001/10/31 01:34:47  robertj
00054  * Added extra const for constant HTTP tag name strings.
00055  * Changes to support HTTP v1.1 chunked transfer encoding.
00056  *
00057  * Revision 1.50  2001/10/03 00:26:34  robertj
00058  * Upgraded client to HTTP/1.1 and for chunked mode entity bodies.
00059  *
00060  * Revision 1.49  2001/09/28 08:55:15  robertj
00061  * More changes to support restartable PHTTPClient
00062  *
00063  * Revision 1.48  2001/09/28 00:42:54  robertj
00064  * Added automatic setting of some outward MIME fields.
00065  * Added "user agent" string field for automatic inclusion.
00066  * Added function to read the contents of the HTTP request.
00067  *
00068  * Revision 1.47  2001/08/28 06:44:30  craigs
00069  * Added ability to override PHTTPServer creation
00070  *
00071  * Revision 1.46  2001/03/14 01:49:54  craigs
00072  * Added ability to handle multi-part form POST commands
00073  *
00074  * Revision 1.45  2001/02/22 05:26:47  robertj
00075  * Added "nicer" version of GetDocument in HTTP client class.
00076  *
00077  * Revision 1.44  2001/01/15 06:16:53  robertj
00078  * Set HTTP resource members to private to assure are not modified by
00079  *   dscendents in non-threadsafe manner.
00080  *
00081  * Revision 1.43  2000/09/04 03:57:58  robertj
00082  * Added ability to change the persistent connection parameters (timeout etc).
00083  *
00084  * Revision 1.42  2000/05/02 08:28:10  craigs
00085  * Removed "memory leaks" caused by brain-dead GNU linker
00086  *
00087  * Revision 1.41  1999/09/17 01:11:14  robertj
00088  * Fixed some documentation typos.
00089  *
00090  * Revision 1.40  1999/05/13 04:04:04  robertj
00091  * Fixed problem of initialised commandName in ConnectionInfo.
00092  *
00093  * Revision 1.39  1999/05/04 15:26:01  robertj
00094  * Improved HTTP/1.1 compatibility (pass through user commands).
00095  * Fixed problems with quicktime installer.
00096  *
00097  * Revision 1.38  1999/04/21 01:58:08  robertj
00098  * Fixed problem with reading data for request using second form of PHTTPRequestInfo constructor.
00099  *
00100  * Revision 1.37  1999/03/09 08:01:46  robertj
00101  * Changed comments for doc++ support (more to come).
00102  *
00103  * Revision 1.36  1999/02/16 08:07:10  robertj
00104  * MSVC 6.0 compatibility changes.
00105  *
00106  * Revision 1.35  1998/11/30 02:50:47  robertj
00107  * New directory structure
00108  *
00109  * Revision 1.34  1998/10/31 12:49:21  robertj
00110  * Added read/write mutex to the HTTP space variable to avoid thread crashes.
00111  *
00112  * Revision 1.33  1998/10/25 01:00:46  craigs
00113  * Added ability to specify per-directory authorisation for PHTTPDirectory
00114  *
00115  * Revision 1.32  1998/09/23 06:19:29  robertj
00116  * Added open source copyright license.
00117  *
00118  * Revision 1.31  1998/07/24 06:58:42  robertj
00119  * Changed PostData function so just has string for data instead of dictionary.
00120  *
00121  * Revision 1.30  1998/06/16 03:33:33  robertj
00122  * Changed TCP connection shutdown to be parameterised.
00123  * Propagated persistence and proxy flags in new connection info instances.
00124  *
00125  * Revision 1.29  1998/04/14 03:42:59  robertj
00126  * Fixed error code propagation in HTTP client.
00127  *
00128  * Revision 1.28  1998/02/03 06:29:38  robertj
00129  * Added local address and port to PHTTPRequest.
00130  *
00131  * Revision 1.27  1998/01/26 00:24:24  robertj
00132  * Added more information to PHTTPConnectionInfo.
00133  * Added function to allow HTTPClient to automatically connect if URL has hostname.
00134  *
00135  * Revision 1.26  1997/10/30 10:22:52  robertj
00136  * Added multiple user basic authorisation scheme.
00137  *
00138  * Revision 1.25  1997/10/03 13:30:15  craigs
00139  * Added ability to access client socket from within HTTP resources
00140  *
00141  * Revision 1.24  1997/03/28 04:40:22  robertj
00142  * Added tags for cookies.
00143  *
00144  * Revision 1.23  1997/01/12 04:15:19  robertj
00145  * Globalised MIME tag strings.
00146  *
00147  * Revision 1.22  1996/10/26 03:31:05  robertj
00148  * Changed OnError so can pass in full HTML page as parameter.
00149  *
00150  * Revision 1.21  1996/09/14 13:09:10  robertj
00151  * Major upgrade:
00152  *   rearranged sockets to help support IPX.
00153  *   added indirect channel class and moved all protocols to descend from it,
00154  *   separating the protocol from the low level byte transport.
00155  *
00156  * Revision 1.20  1996/08/22 13:20:55  robertj
00157  * Fixed bug in authorisation, missing virtual prevented polymorphism.
00158  *
00159  * Revision 1.19  1996/08/19 13:44:06  robertj
00160  * Fixed authorisation so if have no user/password on basic authentication, does not require it.
00161  *
00162  * Revision 1.18  1996/06/28 13:15:23  robertj
00163  * Modified HTTPAuthority so gets PHTTPReqest (mainly for URL) passed in.
00164  * Moved HTTP form resource to another compilation module.
00165  *
00166  * Revision 1.17  1996/06/07 13:52:20  robertj
00167  * Added PUT to HTTP proxy FTP. Necessitating redisign of entity body processing.
00168  *
00169  * Revision 1.16  1996/05/23 10:00:52  robertj
00170  * Added common function for GET and HEAD commands.
00171  * Fixed status codes to be the actual status code instead of sequential enum.
00172  * This fixed some problems with proxy pass through of status codes.
00173  *
00174  * Revision 1.14  1996/03/31 08:46:51  robertj
00175  * HTTP 1.1 upgrade.
00176  *
00177  * Revision 1.13  1996/03/17 05:41:57  robertj
00178  * Added hit count to PHTTPResource.
00179  *
00180  * Revision 1.12  1996/03/16 04:39:55  robertj
00181  * Added ParseReponse() for splitting reponse line into code and info.
00182  * Added client side support for HTTP socket.
00183  * Added hooks for proxy support in HTTP socket.
00184  *
00185  * Revision 1.11  1996/03/10 13:15:23  robertj
00186  * Redesign to make resources thread safe.
00187  *
00188  * Revision 1.10  1996/03/02 03:12:55  robertj
00189  * Added radio button and selection boxes to HTTP form resource.
00190  *
00191  * Revision 1.9  1996/02/25 11:14:21  robertj
00192  * Radio button support for forms.
00193  *
00194  * Revision 1.8  1996/02/25 02:57:48  robertj
00195  * Removed pass through HTTP resource.
00196  *
00197  * Revision 1.7  1996/02/19 13:25:43  robertj
00198  * Added overwrite option to AddResource().
00199  * Added get/set string to PHTTPString resource.
00200  * Moved nested classes from PHTTPForm.
00201  *
00202  * Revision 1.6  1996/02/13 13:09:16  robertj
00203  * Added extra parameters to callback function in PHTTPResources, required
00204  *   by descendants to make informed decisions on data being loaded.
00205  *
00206  * Revision 1.5  1996/02/08 12:04:19  robertj
00207  * Redesign of resource object callback virtuals.
00208  * Added HTML form resource type.
00209  *
00210  * Revision 1.4  1996/02/03 11:03:32  robertj
00211  * Added ismodified since and expires time checking.
00212  * Added PHTTPString that defaults to empty string.
00213  *
00214  * Revision 1.3  1996/01/28 14:15:38  robertj
00215  * Changed PCharArray in OnLoadData to PString for convenience in mangling data.
00216  * Beginning of pass through resource type.
00217  *
00218  * Revision 1.2  1996/01/26 02:24:26  robertj
00219  * Further implemetation.
00220  *
00221  * Revision 1.1  1996/01/23 13:04:20  robertj
00222  * Initial revision
00223  *
00224  */
00225 
00226 #ifndef _PHTTP
00227 #define _PHTTP
00228 
00229 #ifdef P_USE_PRAGMA
00230 #pragma interface
00231 #endif
00232 
00233 #include <ptclib/inetprot.h>
00234 #include <ptclib/mime.h>
00235 #include <ptclib/url.h>
00236 #include <ptclib/html.h>
00237 #include <ptlib/ipsock.h>
00238 
00239 
00241 // PHTTPSpace
00242 
00243 class PHTTPResource;
00244 
00249 class PHTTPSpace : public PContainer
00250 {
00251   PCONTAINERINFO(PHTTPSpace, PContainer)
00252   public:
00254     PHTTPSpace();
00255 
00256 
00257   // New functions for class.
00258     enum AddOptions {
00260       ErrorOnExist,
00262       Overwrite
00263     };
00264 
00265 
00277     BOOL AddResource(
00278       PHTTPResource * resource, 
00279       AddOptions overwrite = ErrorOnExist
00281     );
00282 
00290     BOOL DelResource(
00291       const PURL & url          
00292     );
00293 
00299     PHTTPResource * FindResource(
00300       const PURL & url   
00301     );
00302 
00305     void StartRead() const
00306       { mutex->StartRead(); }
00307 
00310     void EndRead() const
00311       { mutex->EndRead(); }
00312 
00315     void StartWrite() const
00316       { mutex->StartWrite(); }
00317 
00320     void EndWrite() const
00321       { mutex->EndWrite(); }
00322 
00323 
00324   protected:
00325     PReadWriteMutex * mutex;
00326 
00327     class Node;
00328     PSORTED_LIST(ChildList, Node);
00329     class Node : public PString
00330     {
00331       PCLASSINFO(Node, PString)
00332       public:
00333         Node(const PString & name, Node * parentNode);
00334         ~Node();
00335 
00336         Node          * parent;
00337         ChildList       children;
00338         PHTTPResource * resource;
00339     } * root;
00340 
00341   private:
00342     BOOL SetSize(PINDEX) { return FALSE; }
00343 };
00344 
00345 #ifdef _WIN32_WCE
00346 #undef TRACE
00347 #endif
00348 
00350 // PHTTP
00351 
00355 class PHTTP : public PInternetProtocol
00356 {
00357   PCLASSINFO(PHTTP, PInternetProtocol)
00358 
00359   public:
00360   // New functions for class.
00361     enum Commands {
00362       // HTTP/1.0 commands
00363       GET, HEAD, POST,
00364       // HTTP/1.1 commands
00365       PUT, DELETE, TRACE, OPTIONS,
00366       // HTTPS command
00367       CONNECT,
00368       NumCommands
00369     };
00370 
00371     enum StatusCode {
00372       Continue = 100,              // 100 - Continue
00373       SwitchingProtocols,          // 101 - upgrade allowed
00374       RequestOK = 200,             // 200 - request has succeeded
00375       Created,                     // 201 - new resource created: entity body contains URL
00376       Accepted,                    // 202 - request accepted, but not yet completed
00377       NonAuthoritativeInformation, // 203 - not definitive entity header
00378       NoContent,                   // 204 - no new information
00379       ResetContent,                // 205 - contents have been reset
00380       PartialContent,              // 206 - partial GET succeeded
00381       MultipleChoices = 300,       // 300 - requested resource available elsewehere 
00382       MovedPermanently,            // 301 - resource moved permanently: location field has new URL
00383       MovedTemporarily,            // 302 - resource moved temporarily: location field has new URL
00384       SeeOther,                    // 303 - see other URL
00385       NotModified,                 // 304 - document has not been modified
00386       UseProxy,                    // 305 - proxy redirect
00387       BadRequest = 400,            // 400 - request malformed or not understood
00388       UnAuthorised,                // 401 - request requires authentication
00389       PaymentRequired,             // 402 - reserved 
00390       Forbidden,                   // 403 - request is refused due to unsufficient authorisation
00391       NotFound,                    // 404 - resource cannot be found
00392       MethodNotAllowed,            // 405 - not allowed on this resource
00393       NoneAcceptable,              // 406 - encoding not acceptable
00394       ProxyAuthenticationRequired, // 407 - must authenticate with proxy first
00395       RequestTimeout,              // 408 - server timeout on request
00396       Conflict,                    // 409 - resource conflict on action
00397       Gone,                        // 410 - resource gone away
00398       LengthRequired,              // 411 - no Content-Length
00399       UnlessTrue,                  // 412 - no Range header for TRUE Unless
00400       InternalServerError = 500,   // 500 - server has encountered an unexpected error
00401       NotImplemented,              // 501 - server does not implement request
00402       BadGateway,                  // 502 - error whilst acting as gateway
00403       ServiceUnavailable,          // 503 - server temporarily unable to service request
00404       GatewayTimeout               // 504 - timeout whilst talking to gateway
00405     };
00406 
00407     // Common MIME header tags
00408     static const char * const AllowTag;
00409     static const char * const AuthorizationTag;
00410     static const char * const ContentEncodingTag;
00411     static const char * const ContentLengthTag;
00412     static const char * const ContentTypeTag;
00413     static const char * const DateTag;
00414     static const char * const ExpiresTag;
00415     static const char * const FromTag;
00416     static const char * const IfModifiedSinceTag;
00417     static const char * const LastModifiedTag;
00418     static const char * const LocationTag;
00419     static const char * const PragmaTag;
00420     static const char * const PragmaNoCacheTag;
00421     static const char * const RefererTag;
00422     static const char * const ServerTag;
00423     static const char * const UserAgentTag;
00424     static const char * const WWWAuthenticateTag;
00425     static const char * const MIMEVersionTag;
00426     static const char * const ConnectionTag;
00427     static const char * const KeepAliveTag;
00428     static const char * const TransferEncodingTag;
00429     static const char * const ChunkedTag;
00430     static const char * const ProxyConnectionTag;
00431     static const char * const ProxyAuthorizationTag;
00432     static const char * const ProxyAuthenticateTag;
00433     static const char * const ForwardedTag;
00434     static const char * const SetCookieTag;
00435     static const char * const CookieTag;
00436 
00437   protected:
00440     PHTTP();
00441 
00453     virtual PINDEX ParseResponse(
00454       const PString & line // Input response line to be parsed
00455     );
00456 };
00457 
00458 
00460 // PHTTPClient
00461 
00482 class PHTTPClient : public PHTTP
00483 {
00484   PCLASSINFO(PHTTPClient, PHTTP)
00485 
00486   public:
00488     PHTTPClient();
00489     PHTTPClient(
00490       const PString & userAgentName
00491     );
00492 
00493 
00494   // New functions for class.
00502     int ExecuteCommand(
00503       Commands cmd,
00504       const PURL & url,
00505       PMIMEInfo & outMIME,
00506       const PString & dataBody,
00507       PMIMEInfo & replyMime,
00508       BOOL persist = TRUE
00509     );
00510     int ExecuteCommand(
00511       const PString & cmdName,
00512       const PURL & url,
00513       PMIMEInfo & outMIME,
00514       const PString & dataBody,
00515       PMIMEInfo & replyMime,
00516       BOOL persist = TRUE
00517     );
00518 
00520     BOOL WriteCommand(
00521       Commands cmd,
00522       const PString & url,
00523       PMIMEInfo & outMIME,
00524       const PString & dataBody
00525     );
00526     BOOL WriteCommand(
00527       const PString & cmdName,
00528       const PString & url,
00529       PMIMEInfo & outMIME,
00530       const PString & dataBody
00531     );
00532 
00534     BOOL ReadResponse(
00535       PMIMEInfo & replyMIME
00536     );
00537 
00539     BOOL ReadContentBody(
00540       PMIMEInfo & replyMIME,
00541       PBYTEArray & body
00542     );
00543     BOOL ReadContentBody(
00544       PMIMEInfo & replyMIME,
00545       PString & body
00546     );
00547 
00548 
00554     BOOL GetTextDocument(
00555       const PURL & url,         // Universal Resource Locator for document.
00556       PString & document,       // Body read
00557       BOOL persist = TRUE
00558     );
00559 
00565     BOOL GetDocument(
00566       const PURL & url,         // Universal Resource Locator for document.
00567       PMIMEInfo & outMIME,      // MIME info in request
00568       PMIMEInfo & replyMIME,    // MIME info in response
00569       BOOL persist = TRUE
00570     );
00571 
00577     BOOL GetHeader(
00578       const PURL & url,         // Universal Resource Locator for document.
00579       PMIMEInfo & outMIME,      // MIME info in request
00580       PMIMEInfo & replyMIME,    // MIME info in response
00581       BOOL persist = TRUE
00582     );
00583 
00584 
00590     BOOL PostData(
00591       const PURL & url,       // Universal Resource Locator for document.
00592       PMIMEInfo & outMIME,    // MIME info in request
00593       const PString & data,   // Information posted to the HTTP server.
00594       PMIMEInfo & replyMIME,  // MIME info in response
00595       BOOL persist = TRUE
00596     );
00597 
00603     BOOL PostData(
00604       const PURL & url,       // Universal Resource Locator for document.
00605       PMIMEInfo & outMIME,    // MIME info in request
00606       const PString & data,   // Information posted to the HTTP server.
00607       PMIMEInfo & replyMIME,  // MIME info in response
00608       PString & replyBody,    // Body of response
00609       BOOL persist = TRUE
00610     );
00611 
00612   protected:
00613     BOOL AssureConnect(const PURL & url, PMIMEInfo & outMIME);
00614     BOOL InternalReadContentBody(
00615       PMIMEInfo & replyMIME,
00616       PAbstractArray & body
00617     );
00618 
00619     PString userAgentName;
00620 };
00621 
00622 
00624 // PMultipartFormInfo
00625 
00630 class PMultipartFormInfo : public PObject
00631 {
00632   PCLASSINFO(PMultipartFormInfo, PObject);
00633   public:
00634     PMIMEInfo mime;
00635     PString body;
00636 };
00637 
00638 PARRAY(PMultipartFormInfoArray, PMultipartFormInfo);
00639 
00641 // PHTTPConnectionInfo
00642 
00643 class PHTTPServer;
00644 
00649 class PHTTPConnectionInfo : public PObject
00650 {
00651   PCLASSINFO(PHTTPConnectionInfo, PObject)
00652   public:
00653     PHTTPConnectionInfo();
00654 
00655     PHTTP::Commands GetCommandCode() const { return commandCode; }
00656     const PString & GetCommandName() const { return commandName; }
00657 
00658     const PURL & GetURL() const       { return url; }
00659 
00660     const PMIMEInfo & GetMIME() const { return mimeInfo; }
00661     void SetMIME(const PString & tag, const PString & value);
00662 
00663     BOOL IsCompatible(int major, int minor) const;
00664 
00665     BOOL IsPersistant() const         { return isPersistant; }
00666     BOOL WasPersistant() const        { return wasPersistant; }
00667     BOOL IsProxyConnection() const    { return isProxyConnection; }
00668     int  GetMajorVersion() const      { return majorVersion; }
00669     int  GetMinorVersion() const      { return minorVersion; }
00670 
00671     long GetEntityBodyLength() const  { return entityBodyLength; }
00672 
00675     PTimeInterval GetPersistenceTimeout() const { return persistenceTimeout; }
00676 
00679     void SetPersistenceTimeout(const PTimeInterval & t) { persistenceTimeout = t; }
00680 
00684     unsigned GetPersistenceMaximumTransations() const { return persistenceMaximum; }
00685 
00689     void SetPersistenceMaximumTransations(unsigned m) { persistenceMaximum = m; }
00690 
00691     const PMultipartFormInfoArray & GetMultipartFormInfo() const
00692       { return multipartFormInfoArray; }
00693 
00694     void ResetMultipartFormInfo()
00695       { multipartFormInfoArray.RemoveAll(); }
00696 
00697     PString GetEntityBody() const   { return entityBody; }
00698 
00699   protected:
00700     BOOL Initialise(PHTTPServer & server, PString & args);
00701     void DecodeMultipartFormInfo(const PString & type, const PString & entityBody);
00702 
00703     PHTTP::Commands commandCode;
00704     PString         commandName;
00705     PURL            url;
00706     PMIMEInfo       mimeInfo;
00707     BOOL            isPersistant;
00708     BOOL            wasPersistant;
00709     BOOL            isProxyConnection;
00710     int             majorVersion;
00711     int             minorVersion;
00712     PString         entityBody;        // original entity body (POST only)
00713     long            entityBodyLength;
00714     PTimeInterval   persistenceTimeout;
00715     unsigned        persistenceMaximum;
00716     PMultipartFormInfoArray multipartFormInfoArray;
00717 
00718   friend class PHTTPServer;
00719 };
00720 
00721 
00723 // PHTTPServer
00724 
00737 class PHTTPServer : public PHTTP
00738 {
00739   PCLASSINFO(PHTTPServer, PHTTP)
00740 
00741   public:
00749     PHTTPServer();
00750     PHTTPServer(
00751      const PHTTPSpace & urlSpace  // Name space to use for URLs received.
00752     );
00753 
00754 
00755   // New functions for class.
00761     virtual PString GetServerName() const;
00762 
00768     PHTTPSpace & GetURLSpace() { return urlSpace; }
00769 
00771     void SetURLSpace(
00772       const PHTTPSpace & space   // New URL name space to use.
00773     );
00774 
00775 
00785     virtual BOOL ProcessCommand();
00786 
00798     virtual BOOL OnGET(
00799       const PURL & url,                    // Universal Resource Locator for document.
00800       const PMIMEInfo & info,              // Extra MIME information in command.
00801       const PHTTPConnectionInfo & conInfo
00802     );
00803 
00804 
00805 
00817     virtual BOOL OnHEAD(
00818       const PURL & url,                   // Universal Resource Locator for document.
00819       const PMIMEInfo & info,             // Extra MIME information in command.
00820       const PHTTPConnectionInfo & conInfo
00821     );
00822 
00834     virtual BOOL OnPOST(
00835       const PURL & url,                   // Universal Resource Locator for document.
00836       const PMIMEInfo & info,             // Extra MIME information in command.
00837       const PStringToString & data,       // Variables provided in the POST data.
00838       const PHTTPConnectionInfo & conInfo
00839     );
00840 
00853     virtual BOOL OnProxy(
00854       const PHTTPConnectionInfo & conInfo
00855     );
00856 
00857 
00864     virtual PString ReadEntityBody();
00865 
00871     virtual BOOL OnUnknown(
00872       const PCaselessString & command, // Complete command line received.
00873       const PHTTPConnectionInfo & connectInfo
00874     );
00875 
00894     BOOL StartResponse(
00895       StatusCode code,      // Status code for the response.
00896       PMIMEInfo & headers,  // MIME variables included in response.
00897       long bodySize         // Size of the rest of the response.
00898     );
00899 
00909     virtual BOOL OnError(
00910       StatusCode code,                         // Status code for the error response.
00911       const PCaselessString & extra,           // Extra information included in the response.
00912       const PHTTPConnectionInfo & connectInfo
00913     );
00914 
00917     void SetDefaultMIMEInfo(
00918       PMIMEInfo & info,      // Extra MIME information in command.
00919       const PHTTPConnectionInfo & connectInfo
00920     );
00921 
00924     PHTTPConnectionInfo & GetConnectionInfo() { return connectInfo; }
00925 
00926   protected:
00927     void Construct();
00928 
00929     PHTTPSpace          urlSpace;
00930     PHTTPConnectionInfo connectInfo;
00931     unsigned            transactionCount;
00932     PTimeInterval       nextTimeout;
00933 };
00934 
00935 
00937 // PHTTPRequest
00938 
00943 class PHTTPRequest : public PObject
00944 {
00945   PCLASSINFO(PHTTPRequest, PObject)
00946 
00947   public:
00948     PHTTPRequest(
00949       const PURL & url,             // Universal Resource Locator for document.
00950       const PMIMEInfo & inMIME,     // Extra MIME information in command.
00951       const PMultipartFormInfoArray & multipartFormInfo, // multipart form information (if any)
00952       PHTTPServer & server          // Server channel that request initiated on
00953     );
00954 
00955     PHTTPServer & server;           // Server channel that request initiated on
00956     const PURL & url;               // Universal Resource Locator for document.
00957     const PMIMEInfo & inMIME;       // Extra MIME information in command.
00958     const PMultipartFormInfoArray & multipartFormInfo; // multipart form information, if any
00959     PHTTP::StatusCode code;         // Status code for OnError() reply.
00960     PMIMEInfo outMIME;              // MIME information used in reply.
00961     PString entityBody;             // original entity body (POST only)
00962     PINDEX contentSize;             // Size of the body of the resource data.
00963     PIPSocket::Address origin;      // IP address of origin host for request
00964     PIPSocket::Address localAddr;   // IP address of local interface for request
00965     WORD               localPort;   // Port number of local server for request
00966 };
00967 
00968 
00970 // PHTTPAuthority
00971 
00975 class PHTTPAuthority : public PObject
00976 {
00977   PCLASSINFO(PHTTPAuthority, PObject)
00978 
00979   public:
00980   // New functions for class.
00987     virtual PString GetRealm(
00988       const PHTTPRequest & request   // Request information.
00989     ) const = 0;
00990 
00997     virtual BOOL Validate(
00998       const PHTTPRequest & request,  // Request information.
00999       const PString & authInfo       // Authority information string.
01000     ) const = 0;
01001 
01011     virtual BOOL IsActive() const;
01012 
01013   protected:
01014     static void DecodeBasicAuthority(
01015       const PString & authInfo,   // Authority information string.
01016       PString & username,         // User name decoded from authInfo
01017       PString & password          // Password decoded from authInfo
01018     );
01019 };
01020 
01021 
01023 // PHTTPSimpleAuth
01024 
01028 class PHTTPSimpleAuth : public PHTTPAuthority
01029 {
01030   PCLASSINFO(PHTTPSimpleAuth, PHTTPAuthority)
01031 
01032   public:
01033     PHTTPSimpleAuth(
01034       const PString & realm,      // Name space for the username and password.
01035       const PString & username,   // Username that this object wiull authorise.
01036       const PString & password    // Password for the above username.
01037     );
01038     // Construct the simple authorisation structure.
01039 
01040 
01041   // Overrides from class PObject.
01049     virtual PObject * Clone() const;
01050 
01051 
01052   // Overrides from class PHTTPAuthority.
01059     virtual PString GetRealm(
01060       const PHTTPRequest & request   // Request information.
01061     ) const;
01062 
01069     virtual BOOL Validate(
01070       const PHTTPRequest & request,  // Request information.
01071       const PString & authInfo       // Authority information string.
01072     ) const;
01073 
01083     virtual BOOL IsActive() const;
01084 
01090     const PString & GetUserName() const { return username; }
01091 
01097     const PString & GetPassword() const { return password; }
01098 
01099 
01100   protected:
01101     PString realm;
01102     PString username;
01103     PString password;
01104 };
01105 
01106 
01108 // PHTTPMultiSimpAuth
01109 
01113 class PHTTPMultiSimpAuth : public PHTTPAuthority
01114 {
01115   PCLASSINFO(PHTTPMultiSimpAuth, PHTTPAuthority)
01116 
01117   public:
01118     PHTTPMultiSimpAuth(
01119       const PString & realm      // Name space for the username and password.
01120     );
01121     PHTTPMultiSimpAuth(
01122       const PString & realm,             // Name space for the usernames.
01123       const PStringToString & userList // List of usernames and passwords.
01124     );
01125     // Construct the simple authorisation structure.
01126 
01127 
01128   // Overrides from class PObject.
01136     virtual PObject * Clone() const;
01137 
01138 
01139   // Overrides from class PHTTPAuthority.
01146     virtual PString GetRealm(
01147       const PHTTPRequest & request   // Request information.
01148     ) const;
01149 
01156     virtual BOOL Validate(
01157       const PHTTPRequest & request,  // Request information.
01158       const PString & authInfo       // Authority information string.
01159     ) const;
01160 
01170     virtual BOOL IsActive() const;
01171 
01177     void AddUser(
01178       const PString & username,   // Username that this object wiull authorise.
01179       const PString & password    // Password for the above username.
01180     );
01181 
01182 
01183   protected:
01184     PString realm;
01185     PStringToString users;
01186 };
01187 
01188 
01190 // PHTTPResource
01191 
01195 class PHTTPResource : public PObject
01196 {
01197   PCLASSINFO(PHTTPResource, PObject)
01198 
01199   protected:
01200     PHTTPResource(
01201       const PURL & url               // Name of the resource in URL space.
01202     );
01203     PHTTPResource(
01204       const PURL & url,              // Name of the resource in URL space.
01205       const PHTTPAuthority & auth    // Authorisation for the resource.
01206     );
01207     PHTTPResource(
01208       const PURL & url,              // Name of the resource in URL space.
01209       const PString & contentType    // MIME content type for the resource.
01210     );
01211     PHTTPResource(
01212       const PURL & url,              // Name of the resource in URL space.
01213       const PString & contentType,   // MIME content type for the resource.
01214       const PHTTPAuthority & auth    // Authorisation for the resource.
01215     );
01216     // Create a new HTTP Resource.
01217 
01218 
01219   public:
01220     virtual ~PHTTPResource();
01221     // Destroy the HTTP Resource.
01222 
01223 
01224   // New functions for class.
01230     const PURL & GetURL() const { return baseURL; }
01231 
01237     const PString & GetContentType() const { return contentType; }
01238 
01245     PHTTPAuthority * GetAuthority() const { return authority; }
01246 
01249     void SetAuthority(
01250       const PHTTPAuthority & auth
01251     );
01252 
01255     void ClearAuthority();
01256 
01263     DWORD GetHitCount() const { return hitCount; }
01264 
01265     void ClearHitCount() { hitCount = 0; }
01266     // Clear the hit count for the resource.
01267 
01268 
01280     virtual BOOL OnGET(
01281       PHTTPServer & server,       // HTTP server that received the request
01282       const PURL & url,           // Universal Resource Locator for document.
01283       const PMIMEInfo & info,     // Extra MIME information in command.
01284       const PHTTPConnectionInfo & conInfo
01285     );
01286 
01296     virtual BOOL OnGETData(
01297       PHTTPServer & server,
01298       const PURL & url,
01299       const PHTTPConnectionInfo & connectInfo,
01300       PHTTPRequest & request
01301     );
01302 
01314     virtual BOOL OnHEAD(
01315       PHTTPServer & server,       // HTTP server that received the request
01316       const PURL & url,           // Universal Resource Locator for document.
01317       const PMIMEInfo & info,     // Extra MIME information in command.
01318       const PHTTPConnectionInfo & conInfo
01319     );
01320 
01332     virtual BOOL OnPOST(
01333       PHTTPServer & server,         // HTTP server that received the request
01334       const PURL & url,             // Universal Resource Locator for document.
01335       const PMIMEInfo & info,       // Extra MIME information in command.
01336       const PStringToString & data, // Variables in the POST data.
01337       const PHTTPConnectionInfo & conInfo
01338     );
01339 
01349     virtual BOOL OnPOSTData(
01350       PHTTPRequest & request,
01351       const PStringToString & data // Variables in the POST data.
01352     );
01353 
01360     virtual BOOL IsModifiedSince(
01361       const PTime & when    // Time to see if modified later than
01362     );
01363 
01369     virtual BOOL GetExpirationDate(
01370       PTime & when          // Time that the resource expires
01371     );
01372 
01380     virtual PHTTPRequest * CreateRequest(
01381       const PURL & url,                   // Universal Resource Locator for document.
01382       const PMIMEInfo & inMIME,           // Extra MIME information in command.
01383       const PMultipartFormInfoArray & multipartFormInfo,
01384       PHTTPServer & socket
01385     );
01386 
01394     virtual BOOL LoadHeaders(
01395       PHTTPRequest & request    // Information on this request.
01396     ) = 0;
01397 
01403     virtual void SendData(
01404       PHTTPRequest & request
01405     );
01406 
01415     virtual BOOL LoadData(
01416       PHTTPRequest & request,    // Information on this request.
01417       PCharArray & data          // Data used in reply.
01418     );
01419 
01428     virtual PString LoadText(
01429       PHTTPRequest & request    // Information on this request.
01430     );
01431 
01438     virtual void OnLoadedText(
01439       PHTTPRequest & request,    // Information on this request.
01440       PString & text             // Data used in reply.
01441     );
01442 
01451     virtual BOOL Post(
01452       PHTTPRequest & request,       // Information on this request.
01453       const PStringToString & data, // Variables in the POST data.
01454       PHTML & replyMessage          // Reply message for post.
01455     );
01456 
01457 
01458   protected:
01461     virtual BOOL CheckAuthority(
01462       PHTTPServer & server,               // Server to send response to.
01463       const PHTTPRequest & request,       // Information on this request.
01464       const PHTTPConnectionInfo & conInfo // Information on the connection
01465     );
01466     static BOOL CheckAuthority(
01467                    PHTTPAuthority & authority,
01468                       PHTTPServer & server,
01469                const PHTTPRequest & request,
01470         const PHTTPConnectionInfo & connectInfo
01471     );
01472 
01473 
01475     virtual BOOL OnGETOrHEAD(
01476       PHTTPServer & server,       // HTTP server that received the request
01477       const PURL & url,           // Universal Resource Locator for document.
01478       const PMIMEInfo & info,     // Extra MIME information in command.
01479       const PHTTPConnectionInfo & conInfo,
01480       BOOL  IsGet
01481     );
01482 
01484     PURL             baseURL;
01486     PString          contentType;
01488     PHTTPAuthority * authority;
01490     volatile DWORD   hitCount;
01491 };
01492 
01493 
01495 // PHTTPString
01496 
01501 class PHTTPString : public PHTTPResource
01502 {
01503   PCLASSINFO(PHTTPString, PHTTPResource)
01504 
01505   public:
01509     PHTTPString(
01510       const PURL & url             // Name of the resource in URL space.
01511     );
01512     PHTTPString(
01513       const PURL & url,            // Name of the resource in URL space.
01514       const PHTTPAuthority & auth  // Authorisation for the resource.
01515     );
01516     PHTTPString(
01517       const PURL & url,            // Name of the resource in URL space.
01518       const PString & str          // String to return in this resource.
01519     );
01520     PHTTPString(
01521       const PURL & url,            // Name of the resource in URL space.
01522       const PString & str,         // String to return in this resource.
01523       const PString & contentType  // MIME content type for the file.
01524     );
01525     PHTTPString(
01526       const PURL & url,            // Name of the resource in URL space.
01527       const PString & str,         // String to return in this resource.
01528       const PHTTPAuthority & auth  // Authorisation for the resource.
01529     );
01530     PHTTPString(
01531       const PURL & url,            // Name of the resource in URL space.
01532       const PString & str,         // String to return in this resource.
01533       const PString & contentType, // MIME content type for the file.
01534       const PHTTPAuthority & auth  // Authorisation for the resource.
01535     );
01536 
01537 
01538   // Overrides from class PHTTPResource
01546     virtual BOOL LoadHeaders(
01547       PHTTPRequest & request    // Information on this request.
01548     );
01549 
01558     virtual PString LoadText(
01559       PHTTPRequest & request    // Information on this request.
01560     );
01561 
01562   // New functions for class.
01568     const PString & GetString() { return string; }
01569 
01572     void SetString(
01573       const PString & str   // New string for the resource.
01574     ) { string = str; }
01575 
01576 
01577   protected:
01578     PString string;
01579 };
01580 
01581 
01583 // PHTTPFile
01584 
01590 class PHTTPFile : public PHTTPResource
01591 {
01592   PCLASSINFO(PHTTPFile, PHTTPResource)
01593 
01594   public:
01601     PHTTPFile(
01602       const PString & filename     // file in file system and URL name.
01603     );
01604     PHTTPFile(
01605       const PString & filename,    // file in file system and URL name.
01606       const PHTTPAuthority & auth  // Authorisation for the resource.
01607     );
01608     PHTTPFile(
01609       const PURL & url,            // Name of the resource in URL space.
01610       const PFilePath & file       // Location of file in file system.
01611     );
01612     PHTTPFile(
01613       const PURL & url,            // Name of the resource in URL space.
01614       const PFilePath & file,      // Location of file in file system.
01615       const PString & contentType  // MIME content type for the file.
01616     );
01617     PHTTPFile(
01618       const PURL & url,            // Name of the resource in URL space.
01619       const PFilePath & file,      // Location of file in file system.
01620       const PHTTPAuthority & auth  // Authorisation for the resource.
01621     );
01622     PHTTPFile(
01623       const PURL & url,            // Name of the resource in URL space.
01624       const PFilePath & file,      // Location of file in file system.
01625       const PString & contentType, // MIME content type for the file.
01626       const PHTTPAuthority & auth  // Authorisation for the resource.
01627     );
01628 
01629 
01630   // Overrides from class PHTTPResource
01636     virtual PHTTPRequest * CreateRequest(
01637       const PURL & url,                  // Universal Resource Locator for document.
01638       const PMIMEInfo & inMIME,          // Extra MIME information in command.
01639       const PMultipartFormInfoArray & multipartFormInfo,
01640           PHTTPServer & socket
01641     );
01642 
01650     virtual BOOL LoadHeaders(
01651       PHTTPRequest & request    // Information on this request.
01652     );
01653 
01659     virtual BOOL LoadData(
01660       PHTTPRequest & request,    // Information on this request.
01661       PCharArray & data          // Data used in reply.
01662     );
01663 
01672     virtual PString LoadText(
01673       PHTTPRequest & request    // Information on this request.
01674     );
01675 
01676 
01677   protected:
01678     PHTTPFile(
01679       const PURL & url,       // Name of the resource in URL space.
01680       int dummy
01681     );
01682     // Constructor used by PHTTPDirectory
01683 
01684 
01685     PFilePath filePath;
01686 };
01687 
01688 
01689 class PHTTPFileRequest : public PHTTPRequest
01690 {
01691   PCLASSINFO(PHTTPFileRequest, PHTTPRequest)
01692   public:
01693     PHTTPFileRequest(
01694       const PURL & url,             // Universal Resource Locator for document.
01695       const PMIMEInfo & inMIME,     // Extra MIME information in command.
01696       const PMultipartFormInfoArray & multipartFormInfo,
01697       PHTTPServer & server
01698     );
01699 
01700     PFile file;
01701 };
01702 
01703 
01705 // PHTTPTailFile
01706 
01715 class PHTTPTailFile : public PHTTPFile
01716 {
01717   PCLASSINFO(PHTTPTailFile, PHTTPFile)
01718 
01719   public:
01726     PHTTPTailFile(
01727       const PString & filename     // file in file system and URL name.
01728     );
01729     PHTTPTailFile(
01730       const PString & filename,    // file in file system and URL name.
01731       const PHTTPAuthority & auth  // Authorisation for the resource.
01732     );
01733     PHTTPTailFile(
01734       const PURL & url,            // Name of the resource in URL space.
01735       const PFilePath & file       // Location of file in file system.
01736     );
01737     PHTTPTailFile(
01738       const PURL & url,            // Name of the resource in URL space.
01739       const PFilePath & file,      // Location of file in file system.
01740       const PString & contentType  // MIME content type for the file.
01741     );
01742     PHTTPTailFile(
01743       const PURL & url,            // Name of the resource in URL space.
01744       const PFilePath & file,      // Location of file in file system.
01745       const PHTTPAuthority & auth  // Authorisation for the resource.
01746     );
01747     PHTTPTailFile(
01748       const PURL & url,            // Name of the resource in URL space.
01749       const PFilePath & file,      // Location of file in file system.
01750       const PString & contentType, // MIME content type for the file.
01751       const PHTTPAuthority & auth  // Authorisation for the resource.
01752     );
01753 
01754 
01755   // Overrides from class PHTTPResource
01763     virtual BOOL LoadHeaders(
01764       PHTTPRequest & request    // Information on this request.
01765     );
01766 
01772     virtual BOOL LoadData(
01773       PHTTPRequest & request,    // Information on this request.
01774       PCharArray & data          // Data used in reply.
01775     );
01776 };
01777 
01778 
01780 // PHTTPDirectory
01781 
01794 class PHTTPDirectory : public PHTTPFile
01795 {
01796   PCLASSINFO(PHTTPDirectory, PHTTPFile)
01797 
01798   public:
01799     PHTTPDirectory(
01800       const PURL & url,            
01801       const PDirectory & dir       
01802     );
01803     PHTTPDirectory(
01804       const PURL & url,            
01805       const PDirectory & dir,      
01806       const PHTTPAuthority & auth  
01807     );
01808     // Construct a new directory resource for HTTP.
01809 
01810 
01811   // Overrides from class PHTTPResource
01817     virtual PHTTPRequest * CreateRequest(
01818       const PURL & url,                  // Universal Resource Locator for document.
01819       const PMIMEInfo & inMIME,          // Extra MIME information in command.
01820       const PMultipartFormInfoArray & multipartFormInfo,
01821           PHTTPServer & socket
01822     );
01823 
01831     virtual BOOL LoadHeaders(
01832       PHTTPRequest & request    
01833     );
01834 
01843     virtual PString LoadText(
01844       PHTTPRequest & request    
01845     );
01846 
01855     void EnableAuthorisation(const PString & realm);
01856 
01859     void AllowDirectories(BOOL enable = TRUE);
01860 
01861   protected:
01862     BOOL CheckAuthority(
01863       PHTTPServer & server,               // Server to send response to.
01864       const PHTTPRequest & request,       // Information on this request.
01865       const PHTTPConnectionInfo & conInfo // Information on the connection
01866     );
01867 
01868     BOOL FindAuthorisations(const PDirectory & dir, PString & realm, PStringToString & authorisations);
01869 
01870     PDirectory basePath;
01871     PString authorisationRealm;
01872     BOOL allowDirectoryListing;
01873 };
01874 
01875 
01876 class PHTTPDirRequest : public PHTTPFileRequest
01877 {
01878   PCLASSINFO(PHTTPDirRequest, PHTTPFileRequest)
01879   public:
01880     PHTTPDirRequest(
01881       const PURL & url,             // Universal Resource Locator for document.
01882       const PMIMEInfo & inMIME,     // Extra MIME information in command.
01883       const PMultipartFormInfoArray & multipartFormInfo, 
01884       PHTTPServer & server
01885     );
01886 
01887     PString fakeIndex;
01888     PFilePath realPath;
01889 };
01890 
01891 
01892 #endif
01893 
01894 
01895 // End Of File ///////////////////////////////////////////////////////////////

Generated on Sat Dec 22 16:46:51 2007 for PWLib by  doxygen 1.4.2