PTLib
Version 2.10.4
|
00001 /* 00002 * http.h 00003 * 00004 * HyperText Transport Protocol classes. 00005 * 00006 * Portable Windows Library 00007 * 00008 * Copyright (c) 1993-2002 Equivalence Pty. Ltd. 00009 * 00010 * The contents of this file are subject to the Mozilla Public License 00011 * Version 1.0 (the "License"); you may not use this file except in 00012 * compliance with the License. You may obtain a copy of the License at 00013 * http://www.mozilla.org/MPL/ 00014 * 00015 * Software distributed under the License is distributed on an "AS IS" 00016 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00017 * the License for the specific language governing rights and limitations 00018 * under the License. 00019 * 00020 * The Original Code is Portable Windows Library. 00021 * 00022 * The Initial Developer of the Original Code is Equivalence Pty. Ltd. 00023 * 00024 * Contributor(s): ______________________________________. 00025 * 00026 * $Revision: 26045 $ 00027 * $Author: rjongbloed $ 00028 * $Date: 2011-06-19 20:28:39 -0500 (Sun, 19 Jun 2011) $ 00029 */ 00030 00031 #ifndef PTLIB_HTTP_H 00032 #define PTLIB_HTTP_H 00033 00034 #ifdef P_USE_PRAGMA 00035 #pragma interface 00036 #endif 00037 00038 #if P_HTTP 00039 00040 #include <ptclib/inetprot.h> 00041 #include <ptclib/mime.h> 00042 #include <ptclib/url.h> 00043 #include <ptlib/ipsock.h> 00044 #include <ptlib/pfactory.h> 00045 00046 00047 #include <ptclib/html.h> 00048 00050 // PHTTPSpace 00051 00052 class PHTTPResource; 00053 00058 class PHTTPSpace : public PContainer 00059 { 00060 PCONTAINERINFO(PHTTPSpace, PContainer) 00061 public: 00063 PHTTPSpace(); 00064 00065 00066 // New functions for class. 00067 enum AddOptions { 00068 ErrorOnExist, 00069 Overwrite 00070 }; 00071 00072 00084 PBoolean AddResource( 00085 PHTTPResource * resource, 00086 AddOptions overwrite = ErrorOnExist 00088 ); 00089 00097 PBoolean DelResource( 00098 const PURL & url 00099 ); 00100 00106 PHTTPResource * FindResource( 00107 const PURL & url 00108 ); 00109 00112 void StartRead() const 00113 { mutex->StartRead(); } 00114 00117 void EndRead() const 00118 { mutex->EndRead(); } 00119 00122 void StartWrite() const 00123 { mutex->StartWrite(); } 00124 00127 void EndWrite() const 00128 { mutex->EndWrite(); } 00129 00130 00131 protected: 00132 PReadWriteMutex * mutex; 00133 00134 class Node; 00135 PSORTED_LIST(ChildList, Node); 00136 class Node : public PString 00137 { 00138 PCLASSINFO(Node, PString) 00139 public: 00140 Node(const PString & name, Node * parentNode); 00141 ~Node(); 00142 00143 Node * parent; 00144 ChildList children; 00145 PHTTPResource * resource; 00146 } * root; 00147 00148 private: 00149 PBoolean SetSize(PINDEX) { return false; } 00150 }; 00151 00152 #ifdef TRACE 00153 #undef TRACE 00154 #endif 00155 00157 // PHTTP 00158 00162 class PHTTP : public PInternetProtocol 00163 { 00164 PCLASSINFO(PHTTP, PInternetProtocol) 00165 00166 public: 00167 // New functions for class. 00168 enum Commands { 00169 // HTTP/1.0 commands 00170 GET, HEAD, POST, 00171 // HTTP/1.1 commands 00172 PUT, DELETE, TRACE, OPTIONS, 00173 // HTTPS command 00174 CONNECT, 00175 NumCommands 00176 }; 00177 00178 enum StatusCode { 00179 Continue = 100, 00180 SwitchingProtocols, 00181 RequestOK = 200, 00182 Created, 00183 Accepted, 00184 NonAuthoritativeInformation, 00185 NoContent, 00186 ResetContent, 00187 PartialContent, 00188 MultipleChoices = 300, 00189 MovedPermanently, 00190 MovedTemporarily, 00191 SeeOther, 00192 NotModified, 00193 UseProxy, 00194 BadRequest = 400, 00195 UnAuthorised, 00196 PaymentRequired, 00197 Forbidden, 00198 NotFound, 00199 MethodNotAllowed, 00200 NoneAcceptable, 00201 ProxyAuthenticationRequired, 00202 RequestTimeout, 00203 Conflict, 00204 Gone, 00205 LengthRequired, 00206 UnlessTrue, 00207 InternalServerError = 500, 00208 NotImplemented, 00209 BadGateway, 00210 ServiceUnavailable, 00211 GatewayTimeout 00212 }; 00213 00214 // Common MIME header tags 00215 static const PCaselessString & AllowTag(); 00216 static const PCaselessString & AuthorizationTag(); 00217 static const PCaselessString & ContentEncodingTag(); 00218 static const PCaselessString & ContentLengthTag(); 00219 static const PCaselessString & ContentTypeTag() { return PMIMEInfo::ContentTypeTag(); } 00220 static const PCaselessString & DateTag(); 00221 static const PCaselessString & ExpiresTag(); 00222 static const PCaselessString & FromTag(); 00223 static const PCaselessString & IfModifiedSinceTag(); 00224 static const PCaselessString & LastModifiedTag(); 00225 static const PCaselessString & LocationTag(); 00226 static const PCaselessString & PragmaTag(); 00227 static const PCaselessString & PragmaNoCacheTag(); 00228 static const PCaselessString & RefererTag(); 00229 static const PCaselessString & ServerTag(); 00230 static const PCaselessString & UserAgentTag(); 00231 static const PCaselessString & WWWAuthenticateTag(); 00232 static const PCaselessString & MIMEVersionTag(); 00233 static const PCaselessString & ConnectionTag(); 00234 static const PCaselessString & KeepAliveTag(); 00235 static const PCaselessString & TransferEncodingTag(); 00236 static const PCaselessString & ChunkedTag(); 00237 static const PCaselessString & ProxyConnectionTag(); 00238 static const PCaselessString & ProxyAuthorizationTag(); 00239 static const PCaselessString & ProxyAuthenticateTag(); 00240 static const PCaselessString & ForwardedTag(); 00241 static const PCaselessString & SetCookieTag(); 00242 static const PCaselessString & CookieTag(); 00243 00244 protected: 00247 PHTTP(); 00248 00260 virtual PINDEX ParseResponse( 00261 const PString & line 00262 ); 00263 }; 00264 00265 00266 00267 class PHTTPClientAuthentication : public PObject 00268 { 00269 PCLASSINFO(PHTTPClientAuthentication, PObject); 00270 public: 00271 class AuthObject { 00272 public: 00273 virtual ~AuthObject() { } 00274 virtual PMIMEInfo & GetMIME() = 0; 00275 virtual PString GetURI() = 0; 00276 virtual PString GetEntityBody() = 0; 00277 virtual PString GetMethod() = 0; 00278 }; 00279 00280 PHTTPClientAuthentication(); 00281 00282 virtual Comparison Compare( 00283 const PObject & other 00284 ) const; 00285 00286 virtual PBoolean Parse( 00287 const PString & auth, 00288 PBoolean proxy 00289 ) = 0; 00290 00291 virtual PBoolean Authorise( 00292 AuthObject & pdu 00293 ) const = 0; 00294 00295 virtual PBoolean IsProxy() const { return isProxy; } 00296 00297 virtual PString GetUsername() const { return username; } 00298 virtual PString GetPassword() const { return password; } 00299 virtual PString GetAuthRealm() const { return PString::Empty(); } 00300 00301 virtual void SetUsername(const PString & user) { username = user; } 00302 virtual void SetPassword(const PString & pass) { password = pass; } 00303 virtual void SetAuthRealm(const PString &) { } 00304 00305 PString GetAuthParam(const PString & auth, const char * name) const; 00306 PString AsHex(PMessageDigest5::Code & digest) const; 00307 PString AsHex(const PBYTEArray & data) const; 00308 00309 static PHTTPClientAuthentication * ParseAuthenticationRequired(bool isProxy, const PMIMEInfo & line, PString & errorMsg); 00310 00311 00312 protected: 00313 PBoolean isProxy; 00314 PString username; 00315 PString password; 00316 }; 00317 00318 typedef PFactory<PHTTPClientAuthentication> PHTTPClientAuthenticationFactory; 00319 00320 class PHTTPClientAuthenticator : public PHTTPClientAuthentication::AuthObject 00321 { 00322 public: 00323 PHTTPClientAuthenticator( 00324 const PString & cmdName, 00325 const PString & uri, 00326 PMIMEInfo & mime, 00327 const PString & body 00328 ); 00329 virtual PMIMEInfo & GetMIME(); 00330 virtual PString GetURI(); 00331 virtual PString GetEntityBody(); 00332 virtual PString GetMethod(); 00333 protected: 00334 PString m_method; 00335 PString m_uri; 00336 PMIMEInfo & m_mime; 00337 PString m_body; 00338 }; 00339 00341 00342 class PHTTPClientBasicAuthentication : public PHTTPClientAuthentication 00343 { 00344 PCLASSINFO(PHTTPClientBasicAuthentication, PHTTPClientAuthentication); 00345 public: 00346 PHTTPClientBasicAuthentication(); 00347 00348 virtual Comparison Compare( 00349 const PObject & other 00350 ) const; 00351 00352 virtual PBoolean Parse( 00353 const PString & auth, 00354 PBoolean proxy 00355 ); 00356 00357 virtual PBoolean Authorise( 00358 AuthObject & pdu 00359 ) const; 00360 }; 00361 00363 00364 class PHTTPClientDigestAuthentication : public PHTTPClientAuthentication 00365 { 00366 PCLASSINFO(PHTTPClientDigestAuthentication, PHTTPClientAuthentication); 00367 public: 00368 PHTTPClientDigestAuthentication(); 00369 00370 PHTTPClientDigestAuthentication & operator =( 00371 const PHTTPClientDigestAuthentication & auth 00372 ); 00373 00374 virtual Comparison Compare( 00375 const PObject & other 00376 ) const; 00377 00378 virtual PBoolean Parse( 00379 const PString & auth, 00380 PBoolean proxy 00381 ); 00382 00383 virtual PBoolean Authorise( 00384 AuthObject & pdu 00385 ) const; 00386 00387 virtual PString GetAuthRealm() const { return authRealm; } 00388 virtual void SetAuthRealm(const PString & r) { authRealm = r; } 00389 00390 enum Algorithm { 00391 Algorithm_MD5, 00392 NumAlgorithms 00393 }; 00394 const PString & GetNonce() const { return nonce; } 00395 Algorithm GetAlgorithm() const { return algorithm; } 00396 const PString & GetOpaque() const { return opaque; } 00397 bool GetStale() const { return stale; } 00398 00399 protected: 00400 PString authRealm; 00401 PString nonce; 00402 Algorithm algorithm; 00403 PString opaque; 00404 00405 bool qopAuth; 00406 bool qopAuthInt; 00407 bool stale; 00408 PString cnonce; 00409 mutable PAtomicInteger nonceCount; 00410 }; 00411 00412 00414 // PHTTPClient 00415 00436 class PHTTPClient : public PHTTP 00437 { 00438 PCLASSINFO(PHTTPClient, PHTTP) 00439 00440 public: 00442 PHTTPClient( 00443 const PString & userAgentName = PString::Empty() 00444 ); 00445 00446 00447 // New functions for class. 00455 int ExecuteCommand( 00456 Commands cmd, 00457 const PURL & url, 00458 PMIMEInfo & outMIME, 00459 const PString & dataBody, 00460 PMIMEInfo & replyMime 00461 ); 00462 int ExecuteCommand( 00463 const PString & cmdName, 00464 const PURL & url, 00465 PMIMEInfo & outMIME, 00466 const PString & dataBody, 00467 PMIMEInfo & replyMime 00468 ); 00469 00471 PBoolean WriteCommand( 00472 Commands cmd, 00473 const PString & url, 00474 PMIMEInfo & outMIME, 00475 const PString & dataBody 00476 ); 00477 PBoolean WriteCommand( 00478 const PString & cmdName, 00479 const PString & url, 00480 PMIMEInfo & outMIME, 00481 const PString & dataBody 00482 ); 00483 00485 PBoolean ReadResponse( 00486 PMIMEInfo & replyMIME 00487 ); 00488 00490 PBoolean ReadContentBody( 00491 PMIMEInfo & replyMIME, 00492 PBYTEArray & body 00493 ); 00494 PBoolean ReadContentBody( 00495 PMIMEInfo & replyMIME, 00496 PString & body 00497 ); 00498 00499 00508 PBoolean GetTextDocument( 00509 const PURL & url, 00510 PString & document, 00511 const PString & contentType = PString::Empty() 00512 ); 00513 00519 PBoolean GetDocument( 00520 const PURL & url, 00521 PMIMEInfo & outMIME, 00522 PMIMEInfo & replyMIME 00523 ); 00524 00530 PBoolean GetHeader( 00531 const PURL & url, 00532 PMIMEInfo & outMIME, 00533 PMIMEInfo & replyMIME 00534 ); 00535 00536 00542 PBoolean PostData( 00543 const PURL & url, 00544 PMIMEInfo & outMIME, 00545 const PString & data, 00546 PMIMEInfo & replyMIME 00547 ); 00548 00554 PBoolean PostData( 00555 const PURL & url, 00556 PMIMEInfo & outMIME, 00557 const PString & data, 00558 PMIMEInfo & replyMIME, 00559 PString & replyBody 00560 ); 00561 00567 bool PutTextDocument( 00568 const PURL & url, 00569 const PString & document, 00570 const PString & contentType = PMIMEInfo::TextPlain() 00571 ); 00572 00578 bool PutDocument( 00579 const PURL & url, 00580 PMIMEInfo & outMIME, 00581 PMIMEInfo & replyMIME 00582 ); 00583 00589 bool DeleteDocument( 00590 const PURL & url 00591 ); 00592 00595 void SetAuthenticationInfo( 00596 const PString & userName, 00597 const PString & password 00598 ); 00599 00601 void SetPersistent( 00602 bool persist = true 00603 ) { m_persist = persist; } 00604 00606 bool GetPersistent() const { return m_persist; } 00607 00608 protected: 00609 PBoolean AssureConnect(const PURL & url, PMIMEInfo & outMIME); 00610 bool InternalReadContentBody( 00611 PMIMEInfo & replyMIME, 00612 PAbstractArray * body 00613 ); 00614 00615 PString m_userAgentName; 00616 bool m_persist; 00617 PString m_userName; 00618 PString m_password; 00619 PHTTPClientAuthentication * m_authentication; 00620 }; 00621 00622 00624 // PHTTPConnectionInfo 00625 00626 class PHTTPServer; 00627 00632 class PHTTPConnectionInfo : public PObject 00633 { 00634 PCLASSINFO(PHTTPConnectionInfo, PObject) 00635 public: 00636 PHTTPConnectionInfo(); 00637 00638 PHTTP::Commands GetCommandCode() const { return commandCode; } 00639 const PString & GetCommandName() const { return commandName; } 00640 00641 const PURL & GetURL() const { return url; } 00642 00643 const PMIMEInfo & GetMIME() const { return mimeInfo; } 00644 void SetMIME(const PString & tag, const PString & value); 00645 00646 PBoolean IsCompatible(int major, int minor) const; 00647 00648 bool IsPersistent() const { return isPersistent; } 00649 bool WasPersistent() const { return wasPersistent; } 00650 bool IsProxyConnection() const { return isProxyConnection; } 00651 int GetMajorVersion() const { return majorVersion; } 00652 int GetMinorVersion() const { return minorVersion; } 00653 00654 long GetEntityBodyLength() const { return entityBodyLength; } 00655 00658 PTimeInterval GetPersistenceTimeout() const { return persistenceTimeout; } 00659 00662 void SetPersistenceTimeout(const PTimeInterval & t) { persistenceTimeout = t; } 00663 00667 unsigned GetPersistenceMaximumTransations() const { return persistenceMaximum; } 00668 00672 void SetPersistenceMaximumTransations(unsigned m) { persistenceMaximum = m; } 00673 00674 const PMultiPartList & GetMultipartFormInfo() const 00675 { return m_multipartFormInfo; } 00676 00677 void ResetMultipartFormInfo() 00678 { m_multipartFormInfo.RemoveAll(); } 00679 00680 PString GetEntityBody() const { return entityBody; } 00681 00682 protected: 00683 PBoolean Initialise(PHTTPServer & server, PString & args); 00684 bool DecodeMultipartFormInfo() { return mimeInfo.DecodeMultiPartList(m_multipartFormInfo, entityBody); } 00685 00686 PHTTP::Commands commandCode; 00687 PString commandName; 00688 PURL url; 00689 PMIMEInfo mimeInfo; 00690 bool isPersistent; 00691 bool wasPersistent; 00692 bool isProxyConnection; 00693 int majorVersion; 00694 int minorVersion; 00695 PString entityBody; // original entity body (POST only) 00696 long entityBodyLength; 00697 PTimeInterval persistenceTimeout; 00698 unsigned persistenceMaximum; 00699 PMultiPartList m_multipartFormInfo; 00700 00701 friend class PHTTPServer; 00702 }; 00703 00704 00706 // PHTTPServer 00707 00729 class PHTTPServer : public PHTTP 00730 { 00731 PCLASSINFO(PHTTPServer, PHTTP) 00732 00733 public: 00741 PHTTPServer(); 00742 PHTTPServer( 00743 const PHTTPSpace & urlSpace 00744 ); 00745 00746 00747 // New functions for class. 00753 virtual PString GetServerName() const; 00754 00760 PHTTPSpace & GetURLSpace() { return urlSpace; } 00761 00763 void SetURLSpace( 00764 const PHTTPSpace & space 00765 ); 00766 00767 00777 virtual PBoolean ProcessCommand(); 00778 00790 virtual PBoolean OnGET( 00791 const PURL & url, 00792 const PMIMEInfo & info, 00793 const PHTTPConnectionInfo & conInfo 00794 ); 00795 00796 00797 00809 virtual PBoolean OnHEAD( 00810 const PURL & url, 00811 const PMIMEInfo & info, 00812 const PHTTPConnectionInfo & conInfo 00813 ); 00814 00826 virtual PBoolean OnPOST( 00827 const PURL & url, 00828 const PMIMEInfo & info, 00829 const PStringToString & data, 00830 const PHTTPConnectionInfo & conInfo 00831 ); 00832 00845 virtual PBoolean OnProxy( 00846 const PHTTPConnectionInfo & conInfo 00847 ); 00848 00849 00856 virtual PString ReadEntityBody(); 00857 00863 virtual PBoolean OnUnknown( 00864 const PCaselessString & command, 00865 const PHTTPConnectionInfo & connectInfo 00866 ); 00867 00886 PBoolean StartResponse( 00887 StatusCode code, 00888 PMIMEInfo & headers, 00889 long bodySize 00890 ); 00891 00901 virtual PBoolean OnError( 00902 StatusCode code, 00903 const PCaselessString & extra, 00904 const PHTTPConnectionInfo & connectInfo 00905 ); 00906 00909 void SetDefaultMIMEInfo( 00910 PMIMEInfo & info, 00911 const PHTTPConnectionInfo & connectInfo 00912 ); 00913 00916 PHTTPConnectionInfo & GetConnectionInfo() { return connectInfo; } 00917 00918 protected: 00919 void Construct(); 00920 00921 PHTTPSpace urlSpace; 00922 PHTTPConnectionInfo connectInfo; 00923 unsigned transactionCount; 00924 PTimeInterval nextTimeout; 00925 }; 00926 00927 00929 // PHTTPRequest 00930 00935 class PHTTPRequest : public PObject 00936 { 00937 PCLASSINFO(PHTTPRequest, PObject) 00938 00939 public: 00940 PHTTPRequest( 00941 const PURL & url, 00942 const PMIMEInfo & inMIME, 00943 const PMultiPartList & multipartFormInfo, 00944 PHTTPResource * resource, 00945 PHTTPServer & server 00946 ); 00947 00948 PHTTPServer & server; 00949 const PURL & url; 00950 const PMIMEInfo & inMIME; 00951 const PMultiPartList & multipartFormInfo; 00952 PHTTP::StatusCode code; 00953 PMIMEInfo outMIME; 00954 PString entityBody; 00955 PINDEX contentSize; 00956 PIPSocket::Address origin; 00957 PIPSocket::Address localAddr; 00958 WORD localPort; 00959 PHTTPResource * m_resource; 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 00983 ) const = 0; 00984 00991 virtual PBoolean Validate( 00992 const PHTTPRequest & request, 00993 const PString & authInfo 00994 ) const = 0; 00995 01005 virtual PBoolean IsActive() const; 01006 01007 protected: 01008 static void DecodeBasicAuthority( 01009 const PString & authInfo, 01010 PString & username, 01011 PString & password 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, 01029 const PString & username, 01030 const PString & password 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 01055 ) const; 01056 01063 virtual PBoolean Validate( 01064 const PHTTPRequest & request, 01065 const PString & authInfo 01066 ) const; 01067 01077 virtual PBoolean 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 01114 ); 01115 PHTTPMultiSimpAuth( 01116 const PString & realm, 01117 const PStringToString & userList 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 01142 ) const; 01143 01150 virtual PBoolean Validate( 01151 const PHTTPRequest & request, 01152 const PString & authInfo 01153 ) const; 01154 01164 virtual PBoolean IsActive() const; 01165 01171 void AddUser( 01172 const PString & username, 01173 const PString & password 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 01196 ); 01197 PHTTPResource( 01198 const PURL & url, 01199 const PHTTPAuthority & auth 01200 ); 01201 PHTTPResource( 01202 const PURL & url, 01203 const PString & contentType 01204 ); 01205 PHTTPResource( 01206 const PURL & url, 01207 const PString & contentType, 01208 const PHTTPAuthority & auth 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 PBoolean OnGET( 01275 PHTTPServer & server, 01276 const PURL & url, 01277 const PMIMEInfo & info, 01278 const PHTTPConnectionInfo & conInfo 01279 ); 01280 01290 virtual PBoolean OnGETData( 01291 PHTTPServer & server, 01292 const PURL & url, 01293 const PHTTPConnectionInfo & connectInfo, 01294 PHTTPRequest & request 01295 ); 01296 01308 virtual PBoolean OnHEAD( 01309 PHTTPServer & server, 01310 const PURL & url, 01311 const PMIMEInfo & info, 01312 const PHTTPConnectionInfo & conInfo 01313 ); 01314 01326 virtual PBoolean OnPOST( 01327 PHTTPServer & server, 01328 const PURL & url, 01329 const PMIMEInfo & info, 01330 const PStringToString & data, 01331 const PHTTPConnectionInfo & conInfo 01332 ); 01333 01343 virtual PBoolean OnPOSTData( 01344 PHTTPRequest & request, 01345 const PStringToString & data 01346 ); 01347 01354 virtual PBoolean IsModifiedSince( 01355 const PTime & when 01356 ); 01357 01363 virtual PBoolean GetExpirationDate( 01364 PTime & when 01365 ); 01366 01374 virtual PHTTPRequest * CreateRequest( 01375 const PURL & url, 01376 const PMIMEInfo & inMIME, 01377 const PMultiPartList & multipartFormInfo, 01378 PHTTPServer & socket 01379 ); 01380 01388 virtual PBoolean LoadHeaders( 01389 PHTTPRequest & request 01390 ) = 0; 01391 01397 virtual void SendData( 01398 PHTTPRequest & request 01399 ); 01400 01409 virtual PBoolean LoadData( 01410 PHTTPRequest & request, 01411 PCharArray & data 01412 ); 01413 01422 virtual PString LoadText( 01423 PHTTPRequest & request 01424 ); 01425 01432 virtual void OnLoadedText( 01433 PHTTPRequest & request, 01434 PString & text 01435 ); 01436 01445 virtual PBoolean Post( 01446 PHTTPRequest & request, 01447 const PStringToString & data, 01448 PHTML & replyMessage 01449 ); 01450 01451 01452 protected: 01455 virtual PBoolean CheckAuthority( 01456 PHTTPServer & server, 01457 const PHTTPRequest & request, 01458 const PHTTPConnectionInfo & conInfo 01459 ); 01460 static PBoolean CheckAuthority( 01461 PHTTPAuthority & authority, 01462 PHTTPServer & server, 01463 const PHTTPRequest & request, 01464 const PHTTPConnectionInfo & connectInfo 01465 ); 01466 01467 01469 virtual PBoolean OnGETOrHEAD( 01470 PHTTPServer & server, 01471 const PURL & url, 01472 const PMIMEInfo & info, 01473 const PHTTPConnectionInfo & conInfo, 01474 PBoolean isGet 01475 ); 01476 01477 01478 PURL baseURL; 01479 PString contentType; 01480 PHTTPAuthority * authority; 01481 volatile DWORD hitCount; 01482 }; 01483 01484 01486 // PHTTPString 01487 01492 class PHTTPString : public PHTTPResource 01493 { 01494 PCLASSINFO(PHTTPString, PHTTPResource) 01495 01496 public: 01500 PHTTPString( 01501 const PURL & url // Name of the resource in URL space. 01502 ); 01503 PHTTPString( 01504 const PURL & url, // Name of the resource in URL space. 01505 const PHTTPAuthority & auth // Authorisation for the resource. 01506 ); 01507 PHTTPString( 01508 const PURL & url, // Name of the resource in URL space. 01509 const PString & str // String to return in this resource. 01510 ); 01511 PHTTPString( 01512 const PURL & url, // Name of the resource in URL space. 01513 const PString & str, // String to return in this resource. 01514 const PString & contentType // MIME content type for the file. 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 const PHTTPAuthority & auth // Authorisation for the resource. 01520 ); 01521 PHTTPString( 01522 const PURL & url, // Name of the resource in URL space. 01523 const PString & str, // String to return in this resource. 01524 const PString & contentType, // MIME content type for the file. 01525 const PHTTPAuthority & auth // Authorisation for the resource. 01526 ); 01527 01528 01529 // Overrides from class PHTTPResource 01537 virtual PBoolean LoadHeaders( 01538 PHTTPRequest & request // Information on this request. 01539 ); 01540 01549 virtual PString LoadText( 01550 PHTTPRequest & request // Information on this request. 01551 ); 01552 01553 // New functions for class. 01559 const PString & GetString() { return string; } 01560 01563 void SetString( 01564 const PString & str // New string for the resource. 01565 ) { string = str; } 01566 01567 01568 protected: 01569 PString string; 01570 }; 01571 01572 01574 // PHTTPFile 01575 01581 class PHTTPFile : public PHTTPResource 01582 { 01583 PCLASSINFO(PHTTPFile, PHTTPResource) 01584 01585 public: 01592 PHTTPFile( 01593 const PString & filename // file in file system and URL name. 01594 ); 01595 PHTTPFile( 01596 const PString & filename, // file in file system and URL name. 01597 const PHTTPAuthority & auth // Authorisation for the resource. 01598 ); 01599 PHTTPFile( 01600 const PURL & url, // Name of the resource in URL space. 01601 const PFilePath & file // Location of file in file system. 01602 ); 01603 PHTTPFile( 01604 const PURL & url, // Name of the resource in URL space. 01605 const PFilePath & file, // Location of file in file system. 01606 const PString & contentType // MIME content type for the file. 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 const PHTTPAuthority & auth // Authorisation for the resource. 01612 ); 01613 PHTTPFile( 01614 const PURL & url, // Name of the resource in URL space. 01615 const PFilePath & file, // Location of file in file system. 01616 const PString & contentType, // MIME content type for the file. 01617 const PHTTPAuthority & auth // Authorisation for the resource. 01618 ); 01619 01620 01621 // Overrides from class PHTTPResource 01627 virtual PHTTPRequest * CreateRequest( 01628 const PURL & url, // Universal Resource Locator for document. 01629 const PMIMEInfo & inMIME, // Extra MIME information in command. 01630 const PMultiPartList & multipartFormInfo, 01631 PHTTPServer & socket 01632 ); 01633 01641 virtual PBoolean LoadHeaders( 01642 PHTTPRequest & request // Information on this request. 01643 ); 01644 01650 virtual PBoolean LoadData( 01651 PHTTPRequest & request, // Information on this request. 01652 PCharArray & data // Data used in reply. 01653 ); 01654 01663 virtual PString LoadText( 01664 PHTTPRequest & request // Information on this request. 01665 ); 01666 01667 01668 protected: 01669 PHTTPFile( 01670 const PURL & url, // Name of the resource in URL space. 01671 int dummy 01672 ); 01673 // Constructor used by PHTTPDirectory 01674 01675 01676 PFilePath filePath; 01677 }; 01678 01679 01680 class PHTTPFileRequest : public PHTTPRequest 01681 { 01682 PCLASSINFO(PHTTPFileRequest, PHTTPRequest) 01683 public: 01684 PHTTPFileRequest( 01685 const PURL & url, // Universal Resource Locator for document. 01686 const PMIMEInfo & inMIME, // Extra MIME information in command. 01687 const PMultiPartList & multipartFormInfo, 01688 PHTTPResource * resource, 01689 PHTTPServer & server 01690 ); 01691 01692 PFile file; 01693 }; 01694 01695 01697 // PHTTPTailFile 01698 01707 class PHTTPTailFile : public PHTTPFile 01708 { 01709 PCLASSINFO(PHTTPTailFile, PHTTPFile) 01710 01711 public: 01718 PHTTPTailFile( 01719 const PString & filename // file in file system and URL name. 01720 ); 01721 PHTTPTailFile( 01722 const PString & filename, // file in file system and URL name. 01723 const PHTTPAuthority & auth // Authorisation for the resource. 01724 ); 01725 PHTTPTailFile( 01726 const PURL & url, // Name of the resource in URL space. 01727 const PFilePath & file // Location of file in file system. 01728 ); 01729 PHTTPTailFile( 01730 const PURL & url, // Name of the resource in URL space. 01731 const PFilePath & file, // Location of file in file system. 01732 const PString & contentType // MIME content type for the file. 01733 ); 01734 PHTTPTailFile( 01735 const PURL & url, // Name of the resource in URL space. 01736 const PFilePath & file, // Location of file in file system. 01737 const PHTTPAuthority & auth // Authorisation for the resource. 01738 ); 01739 PHTTPTailFile( 01740 const PURL & url, // Name of the resource in URL space. 01741 const PFilePath & file, // Location of file in file system. 01742 const PString & contentType, // MIME content type for the file. 01743 const PHTTPAuthority & auth // Authorisation for the resource. 01744 ); 01745 01746 01747 // Overrides from class PHTTPResource 01755 virtual PBoolean LoadHeaders( 01756 PHTTPRequest & request // Information on this request. 01757 ); 01758 01764 virtual PBoolean LoadData( 01765 PHTTPRequest & request, // Information on this request. 01766 PCharArray & data // Data used in reply. 01767 ); 01768 }; 01769 01770 01772 // PHTTPDirectory 01773 01786 class PHTTPDirectory : public PHTTPFile 01787 { 01788 PCLASSINFO(PHTTPDirectory, PHTTPFile) 01789 01790 public: 01791 PHTTPDirectory( 01792 const PURL & url, 01793 const PDirectory & dir 01794 ); 01795 PHTTPDirectory( 01796 const PURL & url, 01797 const PDirectory & dir, 01798 const PHTTPAuthority & auth 01799 ); 01800 // Construct a new directory resource for HTTP. 01801 01802 01803 // Overrides from class PHTTPResource 01809 virtual PHTTPRequest * CreateRequest( 01810 const PURL & url, // Universal Resource Locator for document. 01811 const PMIMEInfo & inMIME, // Extra MIME information in command. 01812 const PMultiPartList & multipartFormInfo, 01813 PHTTPServer & socket 01814 ); 01815 01823 virtual PBoolean LoadHeaders( 01824 PHTTPRequest & request 01825 ); 01826 01835 virtual PString LoadText( 01836 PHTTPRequest & request 01837 ); 01838 01847 void EnableAuthorisation(const PString & realm); 01848 01851 void AllowDirectories(PBoolean enable = true); 01852 01853 protected: 01854 PBoolean CheckAuthority( 01855 PHTTPServer & server, // Server to send response to. 01856 const PHTTPRequest & request, // Information on this request. 01857 const PHTTPConnectionInfo & conInfo // Information on the connection 01858 ); 01859 01860 PBoolean FindAuthorisations(const PDirectory & dir, PString & realm, PStringToString & authorisations); 01861 01862 PDirectory basePath; 01863 PString authorisationRealm; 01864 PBoolean allowDirectoryListing; 01865 }; 01866 01867 01868 class PHTTPDirRequest : public PHTTPFileRequest 01869 { 01870 PCLASSINFO(PHTTPDirRequest, PHTTPFileRequest) 01871 public: 01872 PHTTPDirRequest( 01873 const PURL & url, // Universal Resource Locator for document. 01874 const PMIMEInfo & inMIME, // Extra MIME information in command. 01875 const PMultiPartList & multipartFormInfo, 01876 PHTTPResource * resource, 01877 PHTTPServer & server 01878 ); 01879 01880 PString fakeIndex; 01881 PFilePath realPath; 01882 }; 01883 01884 01885 PFACTORY_LOAD(PURL_HttpLoader); 01886 01887 01888 #endif // P_HTTP 01889 01890 #endif // PTLIB_HTTP_H 01891 01892 01893 // End Of File ///////////////////////////////////////////////////////////////