00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
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
00051
00052 class PHTTPResource;
00053
00058 class PHTTPSpace : public PContainer
00059 {
00060 PCONTAINERINFO(PHTTPSpace, PContainer)
00061 public:
00063 PHTTPSpace();
00064
00065
00066
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
00158
00162 class PHTTP : public PInternetProtocol
00163 {
00164 PCLASSINFO(PHTTP, PInternetProtocol)
00165
00166 public:
00167
00168 enum Commands {
00169
00170 GET, HEAD, POST,
00171
00172 PUT, DELETE, TRACE, OPTIONS,
00173
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
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
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
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 bool WriteCommand(
00472 Commands cmd,
00473 const PString & url,
00474 PMIMEInfo & outMIME,
00475 const PString & dataBody
00476 );
00477 bool WriteCommand(
00478 const PString & cmdName,
00479 const PString & url,
00480 PMIMEInfo & outMIME,
00481 const PString & dataBody
00482 );
00483
00485 bool ReadResponse(
00486 PMIMEInfo & replyMIME
00487 );
00488
00490 bool ReadContentBody(
00491 PMIMEInfo & replyMIME
00492 );
00493
00495 bool ReadContentBody(
00496 PMIMEInfo & replyMIME,
00497 PString & body
00498 );
00499
00501 bool ReadContentBody(
00502 PMIMEInfo & replyMIME,
00503 PBYTEArray & body
00504 );
00505
00506
00513 bool GetDocument(
00514 const PURL & url,
00515 PMIMEInfo & outMIME,
00516 PMIMEInfo & replyMIME
00517 );
00518 bool GetDocument(
00519 const PURL & url,
00520 PMIMEInfo & replyMIME
00521 );
00522
00530 bool GetTextDocument(
00531 const PURL & url,
00532 PString & document,
00533 const PString & contentType = PString::Empty()
00534 );
00535
00541 bool GetHeader(
00542 const PURL & url,
00543 PMIMEInfo & outMIME,
00544 PMIMEInfo & replyMIME
00545 );
00546
00547
00553 bool PostData(
00554 const PURL & url,
00555 const PStringToString & data
00556 );
00557
00563 bool PostData(
00564 const PURL & url,
00565 PMIMEInfo & outMIME,
00566 const PString & data
00567 );
00568
00575 bool PostData(
00576 const PURL & url,
00577 PMIMEInfo & outMIME,
00578 const PString & data,
00579 PMIMEInfo & replyMIME
00580 );
00581
00587 bool PostData(
00588 const PURL & url,
00589 PMIMEInfo & outMIME,
00590 const PString & data,
00591 PMIMEInfo & replyMIME,
00592 PString & replyBody
00593 );
00594
00600 bool PutTextDocument(
00601 const PURL & url,
00602 const PString & document,
00603 const PString & contentType = PMIMEInfo::TextPlain()
00604 );
00605
00611 bool PutDocument(
00612 const PURL & url,
00613 PMIMEInfo & outMIME,
00614 PMIMEInfo & replyMIME
00615 );
00616
00622 bool DeleteDocument(
00623 const PURL & url
00624 );
00625
00628 void SetAuthenticationInfo(
00629 const PString & userName,
00630 const PString & password
00631 );
00632
00634 void SetPersistent(
00635 bool persist = true
00636 ) { m_persist = persist; }
00637
00639 bool GetPersistent() const { return m_persist; }
00640
00641 protected:
00642 bool AssureConnect(const PURL & url, PMIMEInfo & outMIME);
00643 bool InternalReadContentBody(
00644 PMIMEInfo & replyMIME,
00645 PAbstractArray * body
00646 );
00647
00648 PString m_userAgentName;
00649 bool m_persist;
00650 PString m_userName;
00651 PString m_password;
00652 PHTTPClientAuthentication * m_authentication;
00653 };
00654
00655
00657
00658
00659 class PHTTPServer;
00660
00665 class PHTTPConnectionInfo : public PObject
00666 {
00667 PCLASSINFO(PHTTPConnectionInfo, PObject)
00668 public:
00669 PHTTPConnectionInfo();
00670
00671 PHTTP::Commands GetCommandCode() const { return commandCode; }
00672 const PString & GetCommandName() const { return commandName; }
00673
00674 const PURL & GetURL() const { return url; }
00675
00676 const PMIMEInfo & GetMIME() const { return mimeInfo; }
00677 void SetMIME(const PString & tag, const PString & value);
00678
00679 PBoolean IsCompatible(int major, int minor) const;
00680
00681 bool IsPersistent() const { return isPersistent; }
00682 bool WasPersistent() const { return wasPersistent; }
00683 bool IsProxyConnection() const { return isProxyConnection; }
00684 int GetMajorVersion() const { return majorVersion; }
00685 int GetMinorVersion() const { return minorVersion; }
00686
00687 long GetEntityBodyLength() const { return entityBodyLength; }
00688
00691 PTimeInterval GetPersistenceTimeout() const { return persistenceTimeout; }
00692
00695 void SetPersistenceTimeout(const PTimeInterval & t) { persistenceTimeout = t; }
00696
00700 unsigned GetPersistenceMaximumTransations() const { return persistenceMaximum; }
00701
00705 void SetPersistenceMaximumTransations(unsigned m) { persistenceMaximum = m; }
00706
00707 const PMultiPartList & GetMultipartFormInfo() const
00708 { return m_multipartFormInfo; }
00709
00710 void ResetMultipartFormInfo()
00711 { m_multipartFormInfo.RemoveAll(); }
00712
00713 PString GetEntityBody() const { return entityBody; }
00714
00715 protected:
00716 PBoolean Initialise(PHTTPServer & server, PString & args);
00717 bool DecodeMultipartFormInfo() { return mimeInfo.DecodeMultiPartList(m_multipartFormInfo, entityBody); }
00718
00719 PHTTP::Commands commandCode;
00720 PString commandName;
00721 PURL url;
00722 PMIMEInfo mimeInfo;
00723 bool isPersistent;
00724 bool wasPersistent;
00725 bool isProxyConnection;
00726 int majorVersion;
00727 int minorVersion;
00728 PString entityBody;
00729 long entityBodyLength;
00730 PTimeInterval persistenceTimeout;
00731 unsigned persistenceMaximum;
00732 PMultiPartList m_multipartFormInfo;
00733
00734 friend class PHTTPServer;
00735 };
00736
00737
00739
00740
00762 class PHTTPServer : public PHTTP
00763 {
00764 PCLASSINFO(PHTTPServer, PHTTP)
00765
00766 public:
00774 PHTTPServer();
00775 PHTTPServer(
00776 const PHTTPSpace & urlSpace
00777 );
00778
00779
00780
00786 virtual PString GetServerName() const;
00787
00793 PHTTPSpace & GetURLSpace() { return urlSpace; }
00794
00796 void SetURLSpace(
00797 const PHTTPSpace & space
00798 );
00799
00800
00810 virtual PBoolean ProcessCommand();
00811
00823 virtual PBoolean OnGET(
00824 const PURL & url,
00825 const PMIMEInfo & info,
00826 const PHTTPConnectionInfo & conInfo
00827 );
00828
00829
00830
00842 virtual PBoolean OnHEAD(
00843 const PURL & url,
00844 const PMIMEInfo & info,
00845 const PHTTPConnectionInfo & conInfo
00846 );
00847
00859 virtual PBoolean OnPOST(
00860 const PURL & url,
00861 const PMIMEInfo & info,
00862 const PStringToString & data,
00863 const PHTTPConnectionInfo & conInfo
00864 );
00865
00878 virtual PBoolean OnProxy(
00879 const PHTTPConnectionInfo & conInfo
00880 );
00881
00882
00889 virtual PString ReadEntityBody();
00890
00896 virtual PBoolean OnUnknown(
00897 const PCaselessString & command,
00898 const PHTTPConnectionInfo & connectInfo
00899 );
00900
00919 PBoolean StartResponse(
00920 StatusCode code,
00921 PMIMEInfo & headers,
00922 long bodySize
00923 );
00924
00934 virtual PBoolean OnError(
00935 StatusCode code,
00936 const PCaselessString & extra,
00937 const PHTTPConnectionInfo & connectInfo
00938 );
00939
00942 void SetDefaultMIMEInfo(
00943 PMIMEInfo & info,
00944 const PHTTPConnectionInfo & connectInfo
00945 );
00946
00949 PHTTPConnectionInfo & GetConnectionInfo() { return connectInfo; }
00950
00951 protected:
00952 void Construct();
00953
00954 PHTTPSpace urlSpace;
00955 PHTTPConnectionInfo connectInfo;
00956 unsigned transactionCount;
00957 PTimeInterval nextTimeout;
00958 };
00959
00960
00962
00963
00968 class PHTTPRequest : public PObject
00969 {
00970 PCLASSINFO(PHTTPRequest, PObject)
00971
00972 public:
00973 PHTTPRequest(
00974 const PURL & url,
00975 const PMIMEInfo & inMIME,
00976 const PMultiPartList & multipartFormInfo,
00977 PHTTPResource * resource,
00978 PHTTPServer & server
00979 );
00980
00981 PHTTPServer & server;
00982 const PURL & url;
00983 const PMIMEInfo & inMIME;
00984 const PMultiPartList & multipartFormInfo;
00985 PHTTP::StatusCode code;
00986 PMIMEInfo outMIME;
00987 PString entityBody;
00988 PINDEX contentSize;
00989 PIPSocket::Address origin;
00990 PIPSocket::Address localAddr;
00991 WORD localPort;
00992 PHTTPResource * m_resource;
00993 };
00994
00995
00997
00998
01002 class PHTTPAuthority : public PObject
01003 {
01004 PCLASSINFO(PHTTPAuthority, PObject)
01005
01006 public:
01007
01014 virtual PString GetRealm(
01015 const PHTTPRequest & request
01016 ) const = 0;
01017
01024 virtual PBoolean Validate(
01025 const PHTTPRequest & request,
01026 const PString & authInfo
01027 ) const = 0;
01028
01038 virtual PBoolean IsActive() const;
01039
01040 protected:
01041 static void DecodeBasicAuthority(
01042 const PString & authInfo,
01043 PString & username,
01044 PString & password
01045 );
01046 };
01047
01048
01050
01051
01055 class PHTTPSimpleAuth : public PHTTPAuthority
01056 {
01057 PCLASSINFO(PHTTPSimpleAuth, PHTTPAuthority)
01058
01059 public:
01060 PHTTPSimpleAuth(
01061 const PString & realm,
01062 const PString & username,
01063 const PString & password
01064 );
01065
01066
01067
01068
01076 virtual PObject * Clone() const;
01077
01078
01079
01086 virtual PString GetRealm(
01087 const PHTTPRequest & request
01088 ) const;
01089
01096 virtual PBoolean Validate(
01097 const PHTTPRequest & request,
01098 const PString & authInfo
01099 ) const;
01100
01110 virtual PBoolean IsActive() const;
01111
01117 const PString & GetUserName() const { return username; }
01118
01124 const PString & GetPassword() const { return password; }
01125
01126
01127 protected:
01128 PString realm;
01129 PString username;
01130 PString password;
01131 };
01132
01133
01135
01136
01140 class PHTTPMultiSimpAuth : public PHTTPAuthority
01141 {
01142 PCLASSINFO(PHTTPMultiSimpAuth, PHTTPAuthority)
01143
01144 public:
01145 PHTTPMultiSimpAuth(
01146 const PString & realm
01147 );
01148 PHTTPMultiSimpAuth(
01149 const PString & realm,
01150 const PStringToString & userList
01151 );
01152
01153
01154
01155
01163 virtual PObject * Clone() const;
01164
01165
01166
01173 virtual PString GetRealm(
01174 const PHTTPRequest & request
01175 ) const;
01176
01183 virtual PBoolean Validate(
01184 const PHTTPRequest & request,
01185 const PString & authInfo
01186 ) const;
01187
01197 virtual PBoolean IsActive() const;
01198
01204 void AddUser(
01205 const PString & username,
01206 const PString & password
01207 );
01208
01209
01210 protected:
01211 PString realm;
01212 PStringToString users;
01213 };
01214
01215
01217
01218
01222 class PHTTPResource : public PObject
01223 {
01224 PCLASSINFO(PHTTPResource, PObject)
01225
01226 protected:
01227 PHTTPResource(
01228 const PURL & url
01229 );
01230 PHTTPResource(
01231 const PURL & url,
01232 const PHTTPAuthority & auth
01233 );
01234 PHTTPResource(
01235 const PURL & url,
01236 const PString & contentType
01237 );
01238 PHTTPResource(
01239 const PURL & url,
01240 const PString & contentType,
01241 const PHTTPAuthority & auth
01242 );
01243
01244
01245
01246 public:
01247 virtual ~PHTTPResource();
01248
01249
01250
01251
01257 const PURL & GetURL() const { return baseURL; }
01258
01264 const PString & GetContentType() const { return contentType; }
01265
01272 PHTTPAuthority * GetAuthority() const { return authority; }
01273
01276 void SetAuthority(
01277 const PHTTPAuthority & auth
01278 );
01279
01282 void ClearAuthority();
01283
01290 DWORD GetHitCount() const { return hitCount; }
01291
01292 void ClearHitCount() { hitCount = 0; }
01293
01294
01295
01307 virtual PBoolean OnGET(
01308 PHTTPServer & server,
01309 const PURL & url,
01310 const PMIMEInfo & info,
01311 const PHTTPConnectionInfo & conInfo
01312 );
01313
01323 virtual PBoolean OnGETData(
01324 PHTTPServer & server,
01325 const PURL & url,
01326 const PHTTPConnectionInfo & connectInfo,
01327 PHTTPRequest & request
01328 );
01329
01341 virtual PBoolean OnHEAD(
01342 PHTTPServer & server,
01343 const PURL & url,
01344 const PMIMEInfo & info,
01345 const PHTTPConnectionInfo & conInfo
01346 );
01347
01359 virtual PBoolean OnPOST(
01360 PHTTPServer & server,
01361 const PURL & url,
01362 const PMIMEInfo & info,
01363 const PStringToString & data,
01364 const PHTTPConnectionInfo & conInfo
01365 );
01366
01376 virtual PBoolean OnPOSTData(
01377 PHTTPRequest & request,
01378 const PStringToString & data
01379 );
01380
01387 virtual PBoolean IsModifiedSince(
01388 const PTime & when
01389 );
01390
01396 virtual PBoolean GetExpirationDate(
01397 PTime & when
01398 );
01399
01407 virtual PHTTPRequest * CreateRequest(
01408 const PURL & url,
01409 const PMIMEInfo & inMIME,
01410 const PMultiPartList & multipartFormInfo,
01411 PHTTPServer & socket
01412 );
01413
01421 virtual PBoolean LoadHeaders(
01422 PHTTPRequest & request
01423 ) = 0;
01424
01430 virtual void SendData(
01431 PHTTPRequest & request
01432 );
01433
01442 virtual PBoolean LoadData(
01443 PHTTPRequest & request,
01444 PCharArray & data
01445 );
01446
01455 virtual PString LoadText(
01456 PHTTPRequest & request
01457 );
01458
01465 virtual void OnLoadedText(
01466 PHTTPRequest & request,
01467 PString & text
01468 );
01469
01478 virtual PBoolean Post(
01479 PHTTPRequest & request,
01480 const PStringToString & data,
01481 PHTML & replyMessage
01482 );
01483
01484
01485 protected:
01488 virtual PBoolean CheckAuthority(
01489 PHTTPServer & server,
01490 const PHTTPRequest & request,
01491 const PHTTPConnectionInfo & conInfo
01492 );
01493 static PBoolean CheckAuthority(
01494 PHTTPAuthority & authority,
01495 PHTTPServer & server,
01496 const PHTTPRequest & request,
01497 const PHTTPConnectionInfo & connectInfo
01498 );
01499
01500
01502 virtual PBoolean OnGETOrHEAD(
01503 PHTTPServer & server,
01504 const PURL & url,
01505 const PMIMEInfo & info,
01506 const PHTTPConnectionInfo & conInfo,
01507 PBoolean isGet
01508 );
01509
01510
01511 PURL baseURL;
01512 PString contentType;
01513 PHTTPAuthority * authority;
01514 volatile DWORD hitCount;
01515 };
01516
01517
01519
01520
01525 class PHTTPString : public PHTTPResource
01526 {
01527 PCLASSINFO(PHTTPString, PHTTPResource)
01528
01529 public:
01533 PHTTPString(
01534 const PURL & url
01535 );
01536 PHTTPString(
01537 const PURL & url,
01538 const PHTTPAuthority & auth
01539 );
01540 PHTTPString(
01541 const PURL & url,
01542 const PString & str
01543 );
01544 PHTTPString(
01545 const PURL & url,
01546 const PString & str,
01547 const PString & contentType
01548 );
01549 PHTTPString(
01550 const PURL & url,
01551 const PString & str,
01552 const PHTTPAuthority & auth
01553 );
01554 PHTTPString(
01555 const PURL & url,
01556 const PString & str,
01557 const PString & contentType,
01558 const PHTTPAuthority & auth
01559 );
01560
01561
01562
01570 virtual PBoolean LoadHeaders(
01571 PHTTPRequest & request
01572 );
01573
01582 virtual PString LoadText(
01583 PHTTPRequest & request
01584 );
01585
01586
01592 const PString & GetString() { return string; }
01593
01596 void SetString(
01597 const PString & str
01598 ) { string = str; }
01599
01600
01601 protected:
01602 PString string;
01603 };
01604
01605
01607
01608
01614 class PHTTPFile : public PHTTPResource
01615 {
01616 PCLASSINFO(PHTTPFile, PHTTPResource)
01617
01618 public:
01625 PHTTPFile(
01626 const PString & filename
01627 );
01628 PHTTPFile(
01629 const PString & filename,
01630 const PHTTPAuthority & auth
01631 );
01632 PHTTPFile(
01633 const PURL & url,
01634 const PFilePath & file
01635 );
01636 PHTTPFile(
01637 const PURL & url,
01638 const PFilePath & file,
01639 const PString & contentType
01640 );
01641 PHTTPFile(
01642 const PURL & url,
01643 const PFilePath & file,
01644 const PHTTPAuthority & auth
01645 );
01646 PHTTPFile(
01647 const PURL & url,
01648 const PFilePath & file,
01649 const PString & contentType,
01650 const PHTTPAuthority & auth
01651 );
01652
01653
01654
01660 virtual PHTTPRequest * CreateRequest(
01661 const PURL & url,
01662 const PMIMEInfo & inMIME,
01663 const PMultiPartList & multipartFormInfo,
01664 PHTTPServer & socket
01665 );
01666
01674 virtual PBoolean LoadHeaders(
01675 PHTTPRequest & request
01676 );
01677
01683 virtual PBoolean LoadData(
01684 PHTTPRequest & request,
01685 PCharArray & data
01686 );
01687
01696 virtual PString LoadText(
01697 PHTTPRequest & request
01698 );
01699
01700
01701 protected:
01702 PHTTPFile(
01703 const PURL & url,
01704 int dummy
01705 );
01706
01707
01708
01709 PFilePath filePath;
01710 };
01711
01712
01713 class PHTTPFileRequest : public PHTTPRequest
01714 {
01715 PCLASSINFO(PHTTPFileRequest, PHTTPRequest)
01716 public:
01717 PHTTPFileRequest(
01718 const PURL & url,
01719 const PMIMEInfo & inMIME,
01720 const PMultiPartList & multipartFormInfo,
01721 PHTTPResource * resource,
01722 PHTTPServer & server
01723 );
01724
01725 PFile file;
01726 };
01727
01728
01730
01731
01740 class PHTTPTailFile : public PHTTPFile
01741 {
01742 PCLASSINFO(PHTTPTailFile, PHTTPFile)
01743
01744 public:
01751 PHTTPTailFile(
01752 const PString & filename
01753 );
01754 PHTTPTailFile(
01755 const PString & filename,
01756 const PHTTPAuthority & auth
01757 );
01758 PHTTPTailFile(
01759 const PURL & url,
01760 const PFilePath & file
01761 );
01762 PHTTPTailFile(
01763 const PURL & url,
01764 const PFilePath & file,
01765 const PString & contentType
01766 );
01767 PHTTPTailFile(
01768 const PURL & url,
01769 const PFilePath & file,
01770 const PHTTPAuthority & auth
01771 );
01772 PHTTPTailFile(
01773 const PURL & url,
01774 const PFilePath & file,
01775 const PString & contentType,
01776 const PHTTPAuthority & auth
01777 );
01778
01779
01780
01788 virtual PBoolean LoadHeaders(
01789 PHTTPRequest & request
01790 );
01791
01797 virtual PBoolean LoadData(
01798 PHTTPRequest & request,
01799 PCharArray & data
01800 );
01801 };
01802
01803
01805
01806
01819 class PHTTPDirectory : public PHTTPFile
01820 {
01821 PCLASSINFO(PHTTPDirectory, PHTTPFile)
01822
01823 public:
01824 PHTTPDirectory(
01825 const PURL & url,
01826 const PDirectory & dir
01827 );
01828 PHTTPDirectory(
01829 const PURL & url,
01830 const PDirectory & dir,
01831 const PHTTPAuthority & auth
01832 );
01833
01834
01835
01836
01842 virtual PHTTPRequest * CreateRequest(
01843 const PURL & url,
01844 const PMIMEInfo & inMIME,
01845 const PMultiPartList & multipartFormInfo,
01846 PHTTPServer & socket
01847 );
01848
01856 virtual PBoolean LoadHeaders(
01857 PHTTPRequest & request
01858 );
01859
01868 virtual PString LoadText(
01869 PHTTPRequest & request
01870 );
01871
01880 void EnableAuthorisation(const PString & realm);
01881
01884 void AllowDirectories(PBoolean enable = true);
01885
01886 protected:
01887 PBoolean CheckAuthority(
01888 PHTTPServer & server,
01889 const PHTTPRequest & request,
01890 const PHTTPConnectionInfo & conInfo
01891 );
01892
01893 PBoolean FindAuthorisations(const PDirectory & dir, PString & realm, PStringToString & authorisations);
01894
01895 PDirectory basePath;
01896 PString authorisationRealm;
01897 PBoolean allowDirectoryListing;
01898 };
01899
01900
01901 class PHTTPDirRequest : public PHTTPFileRequest
01902 {
01903 PCLASSINFO(PHTTPDirRequest, PHTTPFileRequest)
01904 public:
01905 PHTTPDirRequest(
01906 const PURL & url,
01907 const PMIMEInfo & inMIME,
01908 const PMultiPartList & multipartFormInfo,
01909 PHTTPResource * resource,
01910 PHTTPServer & server
01911 );
01912
01913 PString fakeIndex;
01914 PFilePath realPath;
01915 };
01916
01917
01918 PFACTORY_LOAD(PURL_HttpLoader);
01919
01920
01921 #endif // P_HTTP
01922
01923 #endif // PTLIB_HTTP_H
01924
01925
01926