Main Page | Class Hierarchy | Class List | 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.57 2002/12/03 22:37:36 robertj 00028 * Removed get document that just returns a content length as the chunked 00029 * transfer encoding makes this very dangerous. 00030 * Added GetTextDocument() to get a URL content into a PString. 00031 * Added a version pf PostData() that gets the reponse content into a PString. 00032 * Added ReadContentBody() that takes a PString, not just PBYTEArray. 00033 * 00034 * Revision 1.56 2002/11/06 22:47:23 robertj 00035 * Fixed header comment (copyright etc) 00036 * 00037 * Revision 1.55 2002/10/10 04:43:43 robertj 00038 * VxWorks port, thanks Martijn Roest 00039 * 00040 * Revision 1.54 2002/10/02 08:54:34 craigs 00041 * Added support for XMLRPC server 00042 * 00043 * Revision 1.53 2002/09/16 01:08:59 robertj 00044 * Added #define so can select if #pragma interface/implementation is used on 00045 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan. 00046 * 00047 * Revision 1.52 2002/05/08 05:38:53 robertj 00048 * Added PHTTPTailFile resource to do a unix 'tail -f' of a file. 00049 * 00050 * Revision 1.51 2001/10/31 01:34:47 robertj 00051 * Added extra const for constant HTTP tag name strings. 00052 * Changes to support HTTP v1.1 chunked transfer encoding. 00053 * 00054 * Revision 1.50 2001/10/03 00:26:34 robertj 00055 * Upgraded client to HTTP/1.1 and for chunked mode entity bodies. 00056 * 00057 * Revision 1.49 2001/09/28 08:55:15 robertj 00058 * More changes to support restartable PHTTPClient 00059 * 00060 * Revision 1.48 2001/09/28 00:42:54 robertj 00061 * Added automatic setting of some outward MIME fields. 00062 * Added "user agent" string field for automatic inclusion. 00063 * Added function to read the contents of the HTTP request. 00064 * 00065 * Revision 1.47 2001/08/28 06:44:30 craigs 00066 * Added ability to override PHTTPServer creation 00067 * 00068 * Revision 1.46 2001/03/14 01:49:54 craigs 00069 * Added ability to handle multi-part form POST commands 00070 * 00071 * Revision 1.45 2001/02/22 05:26:47 robertj 00072 * Added "nicer" version of GetDocument in HTTP client class. 00073 * 00074 * Revision 1.44 2001/01/15 06:16:53 robertj 00075 * Set HTTP resource members to private to assure are not modified by 00076 * dscendents in non-threadsafe manner. 00077 * 00078 * Revision 1.43 2000/09/04 03:57:58 robertj 00079 * Added ability to change the persistent connection parameters (timeout etc). 00080 * 00081 * Revision 1.42 2000/05/02 08:28:10 craigs 00082 * Removed "memory leaks" caused by brain-dead GNU linker 00083 * 00084 * Revision 1.41 1999/09/17 01:11:14 robertj 00085 * Fixed some documentation typos. 00086 * 00087 * Revision 1.40 1999/05/13 04:04:04 robertj 00088 * Fixed problem of initialised commandName in ConnectionInfo. 00089 * 00090 * Revision 1.39 1999/05/04 15:26:01 robertj 00091 * Improved HTTP/1.1 compatibility (pass through user commands). 00092 * Fixed problems with quicktime installer. 00093 * 00094 * Revision 1.38 1999/04/21 01:58:08 robertj 00095 * Fixed problem with reading data for request using second form of PHTTPRequestInfo constructor. 00096 * 00097 * Revision 1.37 1999/03/09 08:01:46 robertj 00098 * Changed comments for doc++ support (more to come). 00099 * 00100 * Revision 1.36 1999/02/16 08:07:10 robertj 00101 * MSVC 6.0 compatibility changes. 00102 * 00103 * Revision 1.35 1998/11/30 02:50:47 robertj 00104 * New directory structure 00105 * 00106 * Revision 1.34 1998/10/31 12:49:21 robertj 00107 * Added read/write mutex to the HTTP space variable to avoid thread crashes. 00108 * 00109 * Revision 1.33 1998/10/25 01:00:46 craigs 00110 * Added ability to specify per-directory authorisation for PHTTPDirectory 00111 * 00112 * Revision 1.32 1998/09/23 06:19:29 robertj 00113 * Added open source copyright license. 00114 * 00115 * Revision 1.31 1998/07/24 06:58:42 robertj 00116 * Changed PostData function so just has string for data instead of dictionary. 00117 * 00118 * Revision 1.30 1998/06/16 03:33:33 robertj 00119 * Changed TCP connection shutdown to be parameterised. 00120 * Propagated persistence and proxy flags in new connection info instances. 00121 * 00122 * Revision 1.29 1998/04/14 03:42:59 robertj 00123 * Fixed error code propagation in HTTP client. 00124 * 00125 * Revision 1.28 1998/02/03 06:29:38 robertj 00126 * Added local address and port to PHTTPRequest. 00127 * 00128 * Revision 1.27 1998/01/26 00:24:24 robertj 00129 * Added more information to PHTTPConnectionInfo. 00130 * Added function to allow HTTPClient to automatically connect if URL has hostname. 00131 * 00132 * Revision 1.26 1997/10/30 10:22:52 robertj 00133 * Added multiple user basic authorisation scheme. 00134 * 00135 * Revision 1.25 1997/10/03 13:30:15 craigs 00136 * Added ability to access client socket from within HTTP resources 00137 * 00138 * Revision 1.24 1997/03/28 04:40:22 robertj 00139 * Added tags for cookies. 00140 * 00141 * Revision 1.23 1997/01/12 04:15:19 robertj 00142 * Globalised MIME tag strings. 00143 * 00144 * Revision 1.22 1996/10/26 03:31:05 robertj 00145 * Changed OnError so can pass in full HTML page as parameter. 00146 * 00147 * Revision 1.21 1996/09/14 13:09:10 robertj 00148 * Major upgrade: 00149 * rearranged sockets to help support IPX. 00150 * added indirect channel class and moved all protocols to descend from it, 00151 * separating the protocol from the low level byte transport. 00152 * 00153 * Revision 1.20 1996/08/22 13:20:55 robertj 00154 * Fixed bug in authorisation, missing virtual prevented polymorphism. 00155 * 00156 * Revision 1.19 1996/08/19 13:44:06 robertj 00157 * Fixed authorisation so if have no user/password on basic authentication, does not require it. 00158 * 00159 * Revision 1.18 1996/06/28 13:15:23 robertj 00160 * Modified HTTPAuthority so gets PHTTPReqest (mainly for URL) passed in. 00161 * Moved HTTP form resource to another compilation module. 00162 * 00163 * Revision 1.17 1996/06/07 13:52:20 robertj 00164 * Added PUT to HTTP proxy FTP. Necessitating redisign of entity body processing. 00165 * 00166 * Revision 1.16 1996/05/23 10:00:52 robertj 00167 * Added common function for GET and HEAD commands. 00168 * Fixed status codes to be the actual status code instead of sequential enum. 00169 * This fixed some problems with proxy pass through of status codes. 00170 * 00171 * Revision 1.14 1996/03/31 08:46:51 robertj 00172 * HTTP 1.1 upgrade. 00173 * 00174 * Revision 1.13 1996/03/17 05:41:57 robertj 00175 * Added hit count to PHTTPResource. 00176 * 00177 * Revision 1.12 1996/03/16 04:39:55 robertj 00178 * Added ParseReponse() for splitting reponse line into code and info. 00179 * Added client side support for HTTP socket. 00180 * Added hooks for proxy support in HTTP socket. 00181 * 00182 * Revision 1.11 1996/03/10 13:15:23 robertj 00183 * Redesign to make resources thread safe. 00184 * 00185 * Revision 1.10 1996/03/02 03:12:55 robertj 00186 * Added radio button and selection boxes to HTTP form resource. 00187 * 00188 * Revision 1.9 1996/02/25 11:14:21 robertj 00189 * Radio button support for forms. 00190 * 00191 * Revision 1.8 1996/02/25 02:57:48 robertj 00192 * Removed pass through HTTP resource. 00193 * 00194 * Revision 1.7 1996/02/19 13:25:43 robertj 00195 * Added overwrite option to AddResource(). 00196 * Added get/set string to PHTTPString resource. 00197 * Moved nested classes from PHTTPForm. 00198 * 00199 * Revision 1.6 1996/02/13 13:09:16 robertj 00200 * Added extra parameters to callback function in PHTTPResources, required 00201 * by descendants to make informed decisions on data being loaded. 00202 * 00203 * Revision 1.5 1996/02/08 12:04:19 robertj 00204 * Redesign of resource object callback virtuals. 00205 * Added HTML form resource type. 00206 * 00207 * Revision 1.4 1996/02/03 11:03:32 robertj 00208 * Added ismodified since and expires time checking. 00209 * Added PHTTPString that defaults to empty string. 00210 * 00211 * Revision 1.3 1996/01/28 14:15:38 robertj 00212 * Changed PCharArray in OnLoadData to PString for convenience in mangling data. 00213 * Beginning of pass through resource type. 00214 * 00215 * Revision 1.2 1996/01/26 02:24:26 robertj 00216 * Further implemetation. 00217 * 00218 * Revision 1.1 1996/01/23 13:04:20 robertj 00219 * Initial revision 00220 * 00221 */ 00222 00223 #ifndef _PHTTP 00224 #define _PHTTP 00225 00226 #ifdef P_USE_PRAGMA 00227 #pragma interface 00228 #endif 00229 00230 #include <ptclib/inetprot.h> 00231 #include <ptclib/mime.h> 00232 #include <ptclib/url.h> 00233 #include <ptclib/html.h> 00234 #include <ptlib/ipsock.h> 00235 00236 00238 // PHTTPSpace 00239 00240 class PHTTPResource; 00241 00246 class PHTTPSpace : public PContainer 00247 { 00248 PCONTAINERINFO(PHTTPSpace, PContainer) 00249 public: 00251 PHTTPSpace(); 00252 00253 00254 // New functions for class. 00255 enum AddOptions { 00257 ErrorOnExist, 00259 Overwrite 00260 }; 00261 00262 00274 BOOL AddResource( 00275 PHTTPResource * resource, 00276 AddOptions overwrite = ErrorOnExist 00278 ); 00279 00287 BOOL DelResource( 00288 const PURL & url 00289 ); 00290 00296 PHTTPResource * FindResource( 00297 const PURL & url 00298 ); 00299 00302 void StartRead() const 00303 { mutex->StartRead(); } 00304 00307 void EndRead() const 00308 { mutex->EndRead(); } 00309 00312 void StartWrite() const 00313 { mutex->StartWrite(); } 00314 00317 void EndWrite() const 00318 { mutex->EndWrite(); } 00319 00320 00321 protected: 00322 PReadWriteMutex * mutex; 00323 00324 class Node; 00325 PSORTED_LIST(ChildList, Node); 00326 class Node : public PString 00327 { 00328 PCLASSINFO(Node, PString) 00329 public: 00330 Node(const PString & name, Node * parentNode); 00331 ~Node(); 00332 00333 Node * parent; 00334 ChildList children; 00335 PHTTPResource * resource; 00336 } * root; 00337 00338 private: 00339 BOOL SetSize(PINDEX) { return FALSE; } 00340 }; 00341 00342 00344 // PHTTP 00345 00349 class PHTTP : public PInternetProtocol 00350 { 00351 PCLASSINFO(PHTTP, PInternetProtocol) 00352 00353 public: 00354 // New functions for class. 00355 enum Commands { 00356 // HTTP/1.0 commands 00357 GET, HEAD, POST, 00358 // HTTP/1.1 commands 00359 PUT, DELETE, TRACE, OPTIONS, 00360 // HTTPS command 00361 CONNECT, 00362 NumCommands 00363 }; 00364 00365 enum StatusCode { 00366 Continue = 100, // 100 - Continue 00367 SwitchingProtocols, // 101 - upgrade allowed 00368 RequestOK = 200, // 200 - request has succeeded 00369 Created, // 201 - new resource created: entity body contains URL 00370 Accepted, // 202 - request accepted, but not yet completed 00371 NonAuthoritativeInformation, // 203 - not definitive entity header 00372 NoContent, // 204 - no new information 00373 ResetContent, // 205 - contents have been reset 00374 PartialContent, // 206 - partial GET succeeded 00375 MultipleChoices = 300, // 300 - requested resource available elsewehere 00376 MovedPermanently, // 301 - resource moved permanently: location field has new URL 00377 MovedTemporarily, // 302 - resource moved temporarily: location field has new URL 00378 SeeOther, // 303 - see other URL 00379 NotModified, // 304 - document has not been modified 00380 UseProxy, // 305 - proxy redirect 00381 BadRequest = 400, // 400 - request malformed or not understood 00382 UnAuthorised, // 401 - request requires authentication 00383 PaymentRequired, // 402 - reserved 00384 Forbidden, // 403 - request is refused due to unsufficient authorisation 00385 NotFound, // 404 - resource cannot be found 00386 MethodNotAllowed, // 405 - not allowed on this resource 00387 NoneAcceptable, // 406 - encoding not acceptable 00388 ProxyAuthenticationRequired, // 407 - must authenticate with proxy first 00389 RequestTimeout, // 408 - server timeout on request 00390 Conflict, // 409 - resource conflict on action 00391 Gone, // 410 - resource gone away 00392 LengthRequired, // 411 - no Content-Length 00393 UnlessTrue, // 412 - no Range header for TRUE Unless 00394 InternalServerError = 500, // 500 - server has encountered an unexpected error 00395 NotImplemented, // 501 - server does not implement request 00396 BadGateway, // 502 - error whilst acting as gateway 00397 ServiceUnavailable, // 503 - server temporarily unable to service request 00398 GatewayTimeout // 504 - timeout whilst talking to gateway 00399 }; 00400 00401 // Common MIME header tags 00402 static const char * const AllowTag; 00403 static const char * const AuthorizationTag; 00404 static const char * const ContentEncodingTag; 00405 static const char * const ContentLengthTag; 00406 static const char * const ContentTypeTag; 00407 static const char * const DateTag; 00408 static const char * const ExpiresTag; 00409 static const char * const FromTag; 00410 static const char * const IfModifiedSinceTag; 00411 static const char * const LastModifiedTag; 00412 static const char * const LocationTag; 00413 static const char * const PragmaTag; 00414 static const char * const PragmaNoCacheTag; 00415 static const char * const RefererTag; 00416 static const char * const ServerTag; 00417 static const char * const UserAgentTag; 00418 static const char * const WWWAuthenticateTag; 00419 static const char * const MIMEVersionTag; 00420 static const char * const ConnectionTag; 00421 static const char * const KeepAliveTag; 00422 static const char * const TransferEncodingTag; 00423 static const char * const ChunkedTag; 00424 static const char * const ProxyConnectionTag; 00425 static const char * const ProxyAuthorizationTag; 00426 static const char * const ProxyAuthenticateTag; 00427 static const char * const ForwardedTag; 00428 static const char * const SetCookieTag; 00429 static const char * const CookieTag; 00430 00431 protected: 00434 PHTTP(); 00435 00447 virtual PINDEX ParseResponse( 00448 const PString & line // Input response line to be parsed 00449 ); 00450 }; 00451 00452 00454 // PHTTPClient 00455 00476 class PHTTPClient : public PHTTP 00477 { 00478 PCLASSINFO(PHTTPClient, PHTTP) 00479 00480 public: 00482 PHTTPClient(); 00483 PHTTPClient( 00484 const PString & userAgentName 00485 ); 00486 00487 00488 // New functions for class. 00496 int ExecuteCommand( 00497 Commands cmd, 00498 const PURL & url, 00499 PMIMEInfo & outMIME, 00500 const PString & dataBody, 00501 PMIMEInfo & replyMime, 00502 BOOL persist = TRUE 00503 ); 00504 int ExecuteCommand( 00505 const PString & cmdName, 00506 const PURL & url, 00507 PMIMEInfo & outMIME, 00508 const PString & dataBody, 00509 PMIMEInfo & replyMime, 00510 BOOL persist = TRUE 00511 ); 00512 00514 BOOL WriteCommand( 00515 Commands cmd, 00516 const PString & url, 00517 PMIMEInfo & outMIME, 00518 const PString & dataBody 00519 ); 00520 BOOL WriteCommand( 00521 const PString & cmdName, 00522 const PString & url, 00523 PMIMEInfo & outMIME, 00524 const PString & dataBody 00525 ); 00526 00528 BOOL ReadResponse( 00529 PMIMEInfo & replyMIME 00530 ); 00531 00533 BOOL ReadContentBody( 00534 PMIMEInfo & replyMIME, 00535 PBYTEArray & body 00536 ); 00537 BOOL ReadContentBody( 00538 PMIMEInfo & replyMIME, 00539 PString & body 00540 ); 00541 00542 00548 BOOL GetTextDocument( 00549 const PURL & url, // Universal Resource Locator for document. 00550 PString & document, // Body read 00551 BOOL persist = TRUE 00552 ); 00553 00559 BOOL GetDocument( 00560 const PURL & url, // Universal Resource Locator for document. 00561 PMIMEInfo & outMIME, // MIME info in request 00562 PMIMEInfo & replyMIME, // MIME info in response 00563 BOOL persist = TRUE 00564 ); 00565 00571 BOOL GetHeader( 00572 const PURL & url, // Universal Resource Locator for document. 00573 PMIMEInfo & outMIME, // MIME info in request 00574 PMIMEInfo & replyMIME, // MIME info in response 00575 BOOL persist = TRUE 00576 ); 00577 00578 00584 BOOL PostData( 00585 const PURL & url, // Universal Resource Locator for document. 00586 PMIMEInfo & outMIME, // MIME info in request 00587 const PString & data, // Information posted to the HTTP server. 00588 PMIMEInfo & replyMIME, // MIME info in response 00589 BOOL persist = TRUE 00590 ); 00591 00597 BOOL PostData( 00598 const PURL & url, // Universal Resource Locator for document. 00599 PMIMEInfo & outMIME, // MIME info in request 00600 const PString & data, // Information posted to the HTTP server. 00601 PMIMEInfo & replyMIME, // MIME info in response 00602 PString & replyBody, // Body of response 00603 BOOL persist = TRUE 00604 ); 00605 00606 protected: 00607 BOOL AssureConnect(const PURL & url, PMIMEInfo & outMIME); 00608 BOOL InternalReadContentBody( 00609 PMIMEInfo & replyMIME, 00610 PAbstractArray & body 00611 ); 00612 00613 PString userAgentName; 00614 }; 00615 00616 00618 // PMultipartFormInfo 00619 00624 class PMultipartFormInfo : public PObject 00625 { 00626 PCLASSINFO(PMultipartFormInfo, PObject); 00627 public: 00628 PMIMEInfo mime; 00629 PString body; 00630 }; 00631 00632 PARRAY(PMultipartFormInfoArray, PMultipartFormInfo); 00633 00635 // PHTTPConnectionInfo 00636 00637 class PHTTPServer; 00638 00643 class PHTTPConnectionInfo : public PObject 00644 { 00645 PCLASSINFO(PHTTPConnectionInfo, PObject) 00646 public: 00647 PHTTPConnectionInfo(); 00648 00649 PHTTP::Commands GetCommandCode() const { return commandCode; } 00650 const PString & GetCommandName() const { return commandName; } 00651 00652 const PURL & GetURL() const { return url; } 00653 00654 const PMIMEInfo & GetMIME() const { return mimeInfo; } 00655 void SetMIME(const PString & tag, const PString & value); 00656 00657 BOOL IsCompatible(int major, int minor) const; 00658 00659 BOOL IsPersistant() const { return isPersistant; } 00660 BOOL WasPersistant() const { return wasPersistant; } 00661 BOOL IsProxyConnection() const { return isProxyConnection; } 00662 int GetMajorVersion() const { return majorVersion; } 00663 int GetMinorVersion() const { return minorVersion; } 00664 00665 long GetEntityBodyLength() const { return entityBodyLength; } 00666 00669 PTimeInterval GetPersistenceTimeout() const { return persistenceTimeout; } 00670 00673 void SetPersistenceTimeout(const PTimeInterval & t) { persistenceTimeout = t; } 00674 00678 unsigned GetPersistenceMaximumTransations() const { return persistenceMaximum; } 00679 00683 void SetPersistenceMaximumTransations(unsigned m) { persistenceMaximum = m; } 00684 00685 const PMultipartFormInfoArray & GetMultipartFormInfo() const 00686 { return multipartFormInfoArray; } 00687 00688 void ResetMultipartFormInfo() 00689 { multipartFormInfoArray.RemoveAll(); } 00690 00691 PString GetEntityBody() const { return entityBody; } 00692 00693 protected: 00694 BOOL Initialise(PHTTPServer & server, PString & args); 00695 void DecodeMultipartFormInfo(const PString & type, const PString & entityBody); 00696 00697 PHTTP::Commands commandCode; 00698 PString commandName; 00699 PURL url; 00700 PMIMEInfo mimeInfo; 00701 BOOL isPersistant; 00702 BOOL wasPersistant; 00703 BOOL isProxyConnection; 00704 int majorVersion; 00705 int minorVersion; 00706 PString entityBody; // original entity body (POST only) 00707 long entityBodyLength; 00708 PTimeInterval persistenceTimeout; 00709 unsigned persistenceMaximum; 00710 PMultipartFormInfoArray multipartFormInfoArray; 00711 00712 friend class PHTTPServer; 00713 }; 00714 00715 00717 // PHTTPServer 00718 00731 class PHTTPServer : public PHTTP 00732 { 00733 PCLASSINFO(PHTTPServer, PHTTP) 00734 00735 public: 00743 PHTTPServer(); 00744 PHTTPServer( 00745 const PHTTPSpace & urlSpace // Name space to use for URLs received. 00746 ); 00747 00748 00749 // New functions for class. 00755 virtual PString GetServerName() const; 00756 00762 PHTTPSpace & GetURLSpace() { return urlSpace; } 00763 00765 void SetURLSpace( 00766 const PHTTPSpace & space // New URL name space to use. 00767 ); 00768 00769 00779 virtual BOOL ProcessCommand(); 00780 00792 virtual BOOL OnGET( 00793 const PURL & url, // Universal Resource Locator for document. 00794 const PMIMEInfo & info, // Extra MIME information in command. 00795 const PHTTPConnectionInfo & conInfo 00796 ); 00797 00798 00799 00811 virtual BOOL OnHEAD( 00812 const PURL & url, // Universal Resource Locator for document. 00813 const PMIMEInfo & info, // Extra MIME information in command. 00814 const PHTTPConnectionInfo & conInfo 00815 ); 00816 00828 virtual BOOL OnPOST( 00829 const PURL & url, // Universal Resource Locator for document. 00830 const PMIMEInfo & info, // Extra MIME information in command. 00831 const PStringToString & data, // Variables provided in the POST data. 00832 const PHTTPConnectionInfo & conInfo 00833 ); 00834 00847 virtual BOOL OnProxy( 00848 const PHTTPConnectionInfo & conInfo 00849 ); 00850 00851 00858 virtual PString ReadEntityBody(); 00859 00865 virtual BOOL OnUnknown( 00866 const PCaselessString & command, // Complete command line received. 00867 const PHTTPConnectionInfo & connectInfo 00868 ); 00869 00888 BOOL StartResponse( 00889 StatusCode code, // Status code for the response. 00890 PMIMEInfo & headers, // MIME variables included in response. 00891 long bodySize // Size of the rest of the response. 00892 ); 00893 00903 virtual BOOL OnError( 00904 StatusCode code, // Status code for the error response. 00905 const PCaselessString & extra, // Extra information included in the response. 00906 const PHTTPConnectionInfo & connectInfo 00907 ); 00908 00911 void SetDefaultMIMEInfo( 00912 PMIMEInfo & info, // Extra MIME information in command. 00913 const PHTTPConnectionInfo & connectInfo 00914 ); 00915 00918 PHTTPConnectionInfo & GetConnectionInfo() { return connectInfo; } 00919 00920 protected: 00921 void Construct(); 00922 00923 PHTTPSpace urlSpace; 00924 PHTTPConnectionInfo connectInfo; 00925 unsigned transactionCount; 00926 PTimeInterval nextTimeout; 00927 }; 00928 00929 00931 // PHTTPRequest 00932 00937 class PHTTPRequest : public PObject 00938 { 00939 PCLASSINFO(PHTTPRequest, PObject) 00940 00941 public: 00942 PHTTPRequest( 00943 const PURL & url, // Universal Resource Locator for document. 00944 const PMIMEInfo & inMIME, // Extra MIME information in command. 00945 const PMultipartFormInfoArray & multipartFormInfo, // multipart form information (if any) 00946 PHTTPServer & server // Server channel that request initiated on 00947 ); 00948 00949 PHTTPServer & server; // Server channel that request initiated on 00950 const PURL & url; // Universal Resource Locator for document. 00951 const PMIMEInfo & inMIME; // Extra MIME information in command. 00952 const PMultipartFormInfoArray & multipartFormInfo; // multipart form information, if any 00953 PHTTP::StatusCode code; // Status code for OnError() reply. 00954 PMIMEInfo outMIME; // MIME information used in reply. 00955 PString entityBody; // original entity body (POST only) 00956 PINDEX contentSize; // Size of the body of the resource data. 00957 PIPSocket::Address origin; // IP address of origin host for request 00958 PIPSocket::Address localAddr; // IP address of local interface for request 00959 WORD localPort; // Port number of local server for request 00960 }; 00961 00962 00964 // PHTTPAuthority 00965 00969 class PHTTPAuthority : public PObject 00970 { 00971 PCLASSINFO(PHTTPAuthority, PObject) 00972 00973 public: 00974 // New functions for class. 00981 virtual PString GetRealm( 00982 const PHTTPRequest & request // Request information. 00983 ) const = 0; 00984 00991 virtual BOOL Validate( 00992 const PHTTPRequest & request, // Request information. 00993 const PString & authInfo // Authority information string. 00994 ) const = 0; 00995 01005 virtual BOOL IsActive() const; 01006 01007 protected: 01008 static void DecodeBasicAuthority( 01009 const PString & authInfo, // Authority information string. 01010 PString & username, // User name decoded from authInfo 01011 PString & password // Password decoded from authInfo 01012 ); 01013 }; 01014 01015 01017 // PHTTPSimpleAuth 01018 01022 class PHTTPSimpleAuth : public PHTTPAuthority 01023 { 01024 PCLASSINFO(PHTTPSimpleAuth, PHTTPAuthority) 01025 01026 public: 01027 PHTTPSimpleAuth( 01028 const PString & realm, // Name space for the username and password. 01029 const PString & username, // Username that this object wiull authorise. 01030 const PString & password // Password for the above username. 01031 ); 01032 // Construct the simple authorisation structure. 01033 01034 01035 // Overrides from class PObject. 01043 virtual PObject * Clone() const; 01044 01045 01046 // Overrides from class PHTTPAuthority. 01053 virtual PString GetRealm( 01054 const PHTTPRequest & request // Request information. 01055 ) const; 01056 01063 virtual BOOL Validate( 01064 const PHTTPRequest & request, // Request information. 01065 const PString & authInfo // Authority information string. 01066 ) const; 01067 01077 virtual BOOL IsActive() const; 01078 01084 const PString & GetUserName() const { return username; } 01085 01091 const PString & GetPassword() const { return password; } 01092 01093 01094 protected: 01095 PString realm; 01096 PString username; 01097 PString password; 01098 }; 01099 01100 01102 // PHTTPMultiSimpAuth 01103 01107 class PHTTPMultiSimpAuth : public PHTTPAuthority 01108 { 01109 PCLASSINFO(PHTTPMultiSimpAuth, PHTTPAuthority) 01110 01111 public: 01112 PHTTPMultiSimpAuth( 01113 const PString & realm // Name space for the username and password. 01114 ); 01115 PHTTPMultiSimpAuth( 01116 const PString & realm, // Name space for the usernames. 01117 const PStringToString & userList // List of usernames and passwords. 01118 ); 01119 // Construct the simple authorisation structure. 01120 01121 01122 // Overrides from class PObject. 01130 virtual PObject * Clone() const; 01131 01132 01133 // Overrides from class PHTTPAuthority. 01140 virtual PString GetRealm( 01141 const PHTTPRequest & request // Request information. 01142 ) const; 01143 01150 virtual BOOL Validate( 01151 const PHTTPRequest & request, // Request information. 01152 const PString & authInfo // Authority information string. 01153 ) const; 01154 01164 virtual BOOL IsActive() const; 01165 01171 void AddUser( 01172 const PString & username, // Username that this object wiull authorise. 01173 const PString & password // Password for the above username. 01174 ); 01175 01176 01177 protected: 01178 PString realm; 01179 PStringToString users; 01180 }; 01181 01182 01184 // PHTTPResource 01185 01189 class PHTTPResource : public PObject 01190 { 01191 PCLASSINFO(PHTTPResource, PObject) 01192 01193 protected: 01194 PHTTPResource( 01195 const PURL & url // Name of the resource in URL space. 01196 ); 01197 PHTTPResource( 01198 const PURL & url, // Name of the resource in URL space. 01199 const PHTTPAuthority & auth // Authorisation for the resource. 01200 ); 01201 PHTTPResource( 01202 const PURL & url, // Name of the resource in URL space. 01203 const PString & contentType // MIME content type for the resource. 01204 ); 01205 PHTTPResource( 01206 const PURL & url, // Name of the resource in URL space. 01207 const PString & contentType, // MIME content type for the resource. 01208 const PHTTPAuthority & auth // Authorisation for the resource. 01209 ); 01210 // Create a new HTTP Resource. 01211 01212 01213 public: 01214 virtual ~PHTTPResource(); 01215 // Destroy the HTTP Resource. 01216 01217 01218 // New functions for class. 01224 const PURL & GetURL() const { return baseURL; } 01225 01231 const PString & GetContentType() const { return contentType; } 01232 01239 PHTTPAuthority * GetAuthority() const { return authority; } 01240 01243 void SetAuthority( 01244 const PHTTPAuthority & auth 01245 ); 01246 01249 void ClearAuthority(); 01250 01257 DWORD GetHitCount() const { return hitCount; } 01258 01259 void ClearHitCount() { hitCount = 0; } 01260 // Clear the hit count for the resource. 01261 01262 01274 virtual BOOL OnGET( 01275 PHTTPServer & server, // HTTP server that received the request 01276 const PURL & url, // Universal Resource Locator for document. 01277 const PMIMEInfo & info, // Extra MIME information in command. 01278 const PHTTPConnectionInfo & conInfo 01279 ); 01280 01290 virtual BOOL OnGETData( 01291 PHTTPServer & server, 01292 const PURL & url, 01293 const PHTTPConnectionInfo & connectInfo, 01294 PHTTPRequest & request 01295 ); 01296 01308 virtual BOOL OnHEAD( 01309 PHTTPServer & server, // HTTP server that received the request 01310 const PURL & url, // Universal Resource Locator for document. 01311 const PMIMEInfo & info, // Extra MIME information in command. 01312 const PHTTPConnectionInfo & conInfo 01313 ); 01314 01326 virtual BOOL OnPOST( 01327 PHTTPServer & server, // HTTP server that received the request 01328 const PURL & url, // Universal Resource Locator for document. 01329 const PMIMEInfo & info, // Extra MIME information in command. 01330 const PStringToString & data, // Variables in the POST data. 01331 const PHTTPConnectionInfo & conInfo 01332 ); 01333 01343 virtual BOOL OnPOSTData( 01344 PHTTPRequest & request, 01345 const PStringToString & data // Variables in the POST data. 01346 ); 01347 01354 virtual BOOL IsModifiedSince( 01355 const PTime & when // Time to see if modified later than 01356 ); 01357 01363 virtual BOOL GetExpirationDate( 01364 PTime & when // Time that the resource expires 01365 ); 01366 01374 virtual PHTTPRequest * CreateRequest( 01375 const PURL & url, // Universal Resource Locator for document. 01376 const PMIMEInfo & inMIME, // Extra MIME information in command. 01377 const PMultipartFormInfoArray & multipartFormInfo, 01378 PHTTPServer & socket 01379 ); 01380 01388 virtual BOOL LoadHeaders( 01389 PHTTPRequest & request // Information on this request. 01390 ) = 0; 01391 01397 virtual void SendData( 01398 PHTTPRequest & request 01399 ); 01400 01409 virtual BOOL LoadData( 01410 PHTTPRequest & request, // Information on this request. 01411 PCharArray & data // Data used in reply. 01412 ); 01413 01422 virtual PString LoadText( 01423 PHTTPRequest & request // Information on this request. 01424 ); 01425 01432 virtual void OnLoadedText( 01433 PHTTPRequest & request, // Information on this request. 01434 PString & text // Data used in reply. 01435 ); 01436 01445 virtual BOOL Post( 01446 PHTTPRequest & request, // Information on this request. 01447 const PStringToString & data, // Variables in the POST data. 01448 PHTML & replyMessage // Reply message for post. 01449 ); 01450 01451 01452 protected: 01455 virtual BOOL CheckAuthority( 01456 PHTTPServer & server, // Server to send response to. 01457 const PHTTPRequest & request, // Information on this request. 01458 const PHTTPConnectionInfo & conInfo // Information on the connection 01459 ); 01460 static BOOL CheckAuthority( 01461 PHTTPAuthority & authority, 01462 PHTTPServer & server, 01463 const PHTTPRequest & request, 01464 const PHTTPConnectionInfo & connectInfo 01465 ); 01466 01467 01469 virtual BOOL OnGETOrHEAD( 01470 PHTTPServer & server, // HTTP server that received the request 01471 const PURL & url, // Universal Resource Locator for document. 01472 const PMIMEInfo & info, // Extra MIME information in command. 01473 const PHTTPConnectionInfo & conInfo, 01474 BOOL IsGet 01475 ); 01476 01478 PURL baseURL; 01480 PString contentType; 01482 PHTTPAuthority * authority; 01484 volatile DWORD hitCount; 01485 }; 01486 01487 01489 // PHTTPString 01490 01495 class PHTTPString : public PHTTPResource 01496 { 01497 PCLASSINFO(PHTTPString, PHTTPResource) 01498 01499 public: 01503 PHTTPString( 01504 const PURL & url // Name of the resource in URL space. 01505 ); 01506 PHTTPString( 01507 const PURL & url, // Name of the resource in URL space. 01508 const PHTTPAuthority & auth // Authorisation for the resource. 01509 ); 01510 PHTTPString( 01511 const PURL & url, // Name of the resource in URL space. 01512 const PString & str // String to return in this resource. 01513 ); 01514 PHTTPString( 01515 const PURL & url, // Name of the resource in URL space. 01516 const PString & str, // String to return in this resource. 01517 const PString & contentType // MIME content type for the file. 01518 ); 01519 PHTTPString( 01520 const PURL & url, // Name of the resource in URL space. 01521 const PString & str, // String to return in this resource. 01522 const PHTTPAuthority & auth // Authorisation for the resource. 01523 ); 01524 PHTTPString( 01525 const PURL & url, // Name of the resource in URL space. 01526 const PString & str, // String to return in this resource. 01527 const PString & contentType, // MIME content type for the file. 01528 const PHTTPAuthority & auth // Authorisation for the resource. 01529 ); 01530 01531 01532 // Overrides from class PHTTPResource 01540 virtual BOOL LoadHeaders( 01541 PHTTPRequest & request // Information on this request. 01542 ); 01543 01552 virtual PString LoadText( 01553 PHTTPRequest & request // Information on this request. 01554 ); 01555 01556 // New functions for class. 01562 const PString & GetString() { return string; } 01563 01566 void SetString( 01567 const PString & str // New string for the resource. 01568 ) { string = str; } 01569 01570 01571 protected: 01572 PString string; 01573 }; 01574 01575 01577 // PHTTPFile 01578 01584 class PHTTPFile : public PHTTPResource 01585 { 01586 PCLASSINFO(PHTTPFile, PHTTPResource) 01587 01588 public: 01595 PHTTPFile( 01596 const PString & filename // file in file system and URL name. 01597 ); 01598 PHTTPFile( 01599 const PString & filename, // file in file system and URL name. 01600 const PHTTPAuthority & auth // Authorisation for the resource. 01601 ); 01602 PHTTPFile( 01603 const PURL & url, // Name of the resource in URL space. 01604 const PFilePath & file // Location of file in file system. 01605 ); 01606 PHTTPFile( 01607 const PURL & url, // Name of the resource in URL space. 01608 const PFilePath & file, // Location of file in file system. 01609 const PString & contentType // MIME content type for the file. 01610 ); 01611 PHTTPFile( 01612 const PURL & url, // Name of the resource in URL space. 01613 const PFilePath & file, // Location of file in file system. 01614 const PHTTPAuthority & auth // Authorisation for the resource. 01615 ); 01616 PHTTPFile( 01617 const PURL & url, // Name of the resource in URL space. 01618 const PFilePath & file, // Location of file in file system. 01619 const PString & contentType, // MIME content type for the file. 01620 const PHTTPAuthority & auth // Authorisation for the resource. 01621 ); 01622 01623 01624 // Overrides from class PHTTPResource 01630 virtual PHTTPRequest * CreateRequest( 01631 const PURL & url, // Universal Resource Locator for document. 01632 const PMIMEInfo & inMIME, // Extra MIME information in command. 01633 const PMultipartFormInfoArray & multipartFormInfo, 01634 PHTTPServer & socket 01635 ); 01636 01644 virtual BOOL LoadHeaders( 01645 PHTTPRequest & request // Information on this request. 01646 ); 01647 01653 virtual BOOL LoadData( 01654 PHTTPRequest & request, // Information on this request. 01655 PCharArray & data // Data used in reply. 01656 ); 01657 01666 virtual PString LoadText( 01667 PHTTPRequest & request // Information on this request. 01668 ); 01669 01670 01671 protected: 01672 PHTTPFile( 01673 const PURL & url, // Name of the resource in URL space. 01674 int dummy 01675 ); 01676 // Constructor used by PHTTPDirectory 01677 01678 01679 PFilePath filePath; 01680 }; 01681 01682 01683 class PHTTPFileRequest : public PHTTPRequest 01684 { 01685 PCLASSINFO(PHTTPFileRequest, PHTTPRequest) 01686 public: 01687 PHTTPFileRequest( 01688 const PURL & url, // Universal Resource Locator for document. 01689 const PMIMEInfo & inMIME, // Extra MIME information in command. 01690 const PMultipartFormInfoArray & multipartFormInfo, 01691 PHTTPServer & server 01692 ); 01693 01694 PFile file; 01695 }; 01696 01697 01699 // PHTTPTailFile 01700 01709 class PHTTPTailFile : public PHTTPFile 01710 { 01711 PCLASSINFO(PHTTPTailFile, PHTTPFile) 01712 01713 public: 01720 PHTTPTailFile( 01721 const PString & filename // file in file system and URL name. 01722 ); 01723 PHTTPTailFile( 01724 const PString & filename, // file in file system and URL name. 01725 const PHTTPAuthority & auth // Authorisation for the resource. 01726 ); 01727 PHTTPTailFile( 01728 const PURL & url, // Name of the resource in URL space. 01729 const PFilePath & file // Location of file in file system. 01730 ); 01731 PHTTPTailFile( 01732 const PURL & url, // Name of the resource in URL space. 01733 const PFilePath & file, // Location of file in file system. 01734 const PString & contentType // MIME content type for the file. 01735 ); 01736 PHTTPTailFile( 01737 const PURL & url, // Name of the resource in URL space. 01738 const PFilePath & file, // Location of file in file system. 01739 const PHTTPAuthority & auth // Authorisation for the resource. 01740 ); 01741 PHTTPTailFile( 01742 const PURL & url, // Name of the resource in URL space. 01743 const PFilePath & file, // Location of file in file system. 01744 const PString & contentType, // MIME content type for the file. 01745 const PHTTPAuthority & auth // Authorisation for the resource. 01746 ); 01747 01748 01749 // Overrides from class PHTTPResource 01757 virtual BOOL LoadHeaders( 01758 PHTTPRequest & request // Information on this request. 01759 ); 01760 01766 virtual BOOL LoadData( 01767 PHTTPRequest & request, // Information on this request. 01768 PCharArray & data // Data used in reply. 01769 ); 01770 }; 01771 01772 01774 // PHTTPDirectory 01775 01788 class PHTTPDirectory : public PHTTPFile 01789 { 01790 PCLASSINFO(PHTTPDirectory, PHTTPFile) 01791 01792 public: 01793 PHTTPDirectory( 01794 const PURL & url, 01795 const PDirectory & dir 01796 ); 01797 PHTTPDirectory( 01798 const PURL & url, 01799 const PDirectory & dir, 01800 const PHTTPAuthority & auth 01801 ); 01802 // Construct a new directory resource for HTTP. 01803 01804 01805 // Overrides from class PHTTPResource 01811 virtual PHTTPRequest * CreateRequest( 01812 const PURL & url, // Universal Resource Locator for document. 01813 const PMIMEInfo & inMIME, // Extra MIME information in command. 01814 const PMultipartFormInfoArray & multipartFormInfo, 01815 PHTTPServer & socket 01816 ); 01817 01825 virtual BOOL LoadHeaders( 01826 PHTTPRequest & request 01827 ); 01828 01837 virtual PString LoadText( 01838 PHTTPRequest & request 01839 ); 01840 01849 void EnableAuthorisation(const PString & realm); 01850 01853 void AllowDirectories(BOOL enable = TRUE); 01854 01855 protected: 01856 BOOL CheckAuthority( 01857 PHTTPServer & server, // Server to send response to. 01858 const PHTTPRequest & request, // Information on this request. 01859 const PHTTPConnectionInfo & conInfo // Information on the connection 01860 ); 01861 01862 BOOL FindAuthorisations(const PDirectory & dir, PString & realm, PStringToString & authorisations); 01863 01864 PDirectory basePath; 01865 PString authorisationRealm; 01866 BOOL allowDirectoryListing; 01867 }; 01868 01869 01870 class PHTTPDirRequest : public PHTTPFileRequest 01871 { 01872 PCLASSINFO(PHTTPDirRequest, PHTTPFileRequest) 01873 public: 01874 PHTTPDirRequest( 01875 const PURL & url, // Universal Resource Locator for document. 01876 const PMIMEInfo & inMIME, // Extra MIME information in command. 01877 const PMultipartFormInfoArray & multipartFormInfo, 01878 PHTTPServer & server 01879 ); 01880 01881 PString fakeIndex; 01882 PFilePath realPath; 01883 }; 01884 01885 01886 #endif 01887 01888 01889 // End Of File ///////////////////////////////////////////////////////////////

Generated on Sat Jul 24 15:35:56 2004 for PWLib by doxygen 1.3.7