PTLib  Version 2.14.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
http.h
Go to the documentation of this file.
1 /*
2  * http.h
3  *
4  * HyperText Transport Protocol classes.
5  *
6  * Portable Windows Library
7  *
8  * Copyright (c) 1993-2002 Equivalence Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Portable Windows Library.
21  *
22  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
23  *
24  * Contributor(s): ______________________________________.
25  *
26  * $Revision: 32013 $
27  * $Author: rjongbloed $
28  * $Date: 2014-05-31 16:14:55 +1000 (Sat, 31 May 2014) $
29  */
30 
31 #ifndef PTLIB_HTTP_H
32 #define PTLIB_HTTP_H
33 
34 #ifdef P_USE_PRAGMA
35 #pragma interface
36 #endif
37 
38 #if P_HTTP
39 
40 #include <ptclib/inetprot.h>
41 #include <ptclib/mime.h>
42 #include <ptclib/url.h>
43 #include <ptlib/ipsock.h>
44 #include <ptlib/pfactory.h>
45 
46 
47 #include <ptclib/html.h>
48 
50 // PHTTPSpace
51 
52 class PHTTPResource;
53 
58 class PHTTPSpace : public PContainer
59 {
61  public:
63  PHTTPSpace();
64 
65 
66  // New functions for class.
67  enum AddOptions {
70  };
71 
72 
85  PHTTPResource * resource,
86  AddOptions overwrite = ErrorOnExist
88  );
89 
98  const PURL & url
99  );
100 
107  const PURL & url
108  );
109 
112  void StartRead() const
113  { mutex->StartRead(); }
114 
117  void EndRead() const
118  { mutex->EndRead(); }
119 
122  void StartWrite() const
123  { mutex->StartWrite(); }
124 
127  void EndWrite() const
128  { mutex->EndWrite(); }
129 
130 
131  protected:
133 
134  class Node;
135  PSORTED_LIST(ChildList, Node);
136  class Node : public PString
137  {
139  public:
140  Node(const PString & name, Node * parentNode);
141  ~Node();
142 
144  ChildList children;
146  } * root;
147 
148  private:
149  PBoolean SetSize(PINDEX) { return false; }
150 };
151 
152 #ifdef TRACE
153 #undef TRACE
154 #endif
155 
157 // PHTTP
158 
162 class PHTTP : public PInternetProtocol
163 {
165 
166  public:
167  // New functions for class.
168  enum Commands {
169  // HTTP/1.0 commands
171  // HTTP/1.1 commands
173  // HTTPS command
176  };
177 
178  enum StatusCode {
182  Continue = 100,
184  RequestOK = 200,
197  BadRequest = 400,
215  };
216 
217  // Common MIME header tags
218  static const PCaselessString & HostTag();
219  static const PCaselessString & AllowTag();
220  static const PCaselessString & AuthorizationTag();
221  static const PCaselessString & ContentEncodingTag();
222  static const PCaselessString & ContentLengthTag();
224  static const PCaselessString & DateTag();
225  static const PCaselessString & ExpiresTag();
226  static const PCaselessString & FromTag();
227  static const PCaselessString & IfModifiedSinceTag();
228  static const PCaselessString & LastModifiedTag();
229  static const PCaselessString & LocationTag();
230  static const PCaselessString & PragmaTag();
231  static const PCaselessString & PragmaNoCacheTag();
232  static const PCaselessString & RefererTag();
233  static const PCaselessString & ServerTag();
234  static const PCaselessString & UserAgentTag();
235  static const PCaselessString & WWWAuthenticateTag();
236  static const PCaselessString & MIMEVersionTag();
237  static const PCaselessString & ConnectionTag();
238  static const PCaselessString & KeepAliveTag();
239  static const PCaselessString & UpgradeTag();
240  static const PCaselessString & WebSocketTag();
241  static const PCaselessString & WebSocketKeyTag();
242  static const PCaselessString & WebSocketAcceptTag();
243  static const PCaselessString & WebSocketProtocolTag();
244  static const PCaselessString & WebSocketVersionTag();
245  static const PCaselessString & TransferEncodingTag();
246  static const PCaselessString & ChunkedTag();
247  static const PCaselessString & ProxyConnectionTag();
248  static const PCaselessString & ProxyAuthorizationTag();
249  static const PCaselessString & ProxyAuthenticateTag();
250  static const PCaselessString & ForwardedTag();
251  static const PCaselessString & SetCookieTag();
252  static const PCaselessString & CookieTag();
253 
254  protected:
257  PHTTP();
258  PHTTP(
259  const char * defaultServiceName
260  );
261 
273  virtual PINDEX ParseResponse(
274  const PString & line
275  );
276 };
277 
278 
279 
281 {
282  PCLASSINFO(PHTTPClientAuthentication, PObject);
283  public:
284  class AuthObject {
285  public:
286  virtual ~AuthObject() { }
287  virtual PMIMEInfo & GetMIME() = 0;
288  virtual PString GetURI() = 0;
289  virtual PString GetEntityBody() = 0;
290  virtual PString GetMethod() = 0;
291  };
292 
294 
295  virtual Comparison Compare(
296  const PObject & other
297  ) const;
298 
299  virtual PBoolean Parse(
300  const PString & auth,
301  PBoolean proxy
302  ) = 0;
303 
304  virtual PBoolean Authorise(
305  AuthObject & pdu
306  ) const = 0;
307 
308  virtual PBoolean IsProxy() const { return isProxy; }
309 
310  virtual PString GetUsername() const { return username; }
311  virtual PString GetPassword() const { return password; }
312  virtual PString GetAuthRealm() const { return PString::Empty(); }
313 
314  virtual void SetUsername(const PString & user) { username = user; }
315  virtual void SetPassword(const PString & pass) { password = pass; }
316  virtual void SetAuthRealm(const PString &) { }
317 
318  PString GetAuthParam(const PString & auth, const char * name) const;
319  PString AsHex(PMessageDigest5::Code & digest) const;
320  PString AsHex(const PBYTEArray & data) const;
321 
322  static PHTTPClientAuthentication * ParseAuthenticationRequired(bool isProxy, const PMIMEInfo & line, PString & errorMsg);
323 
324 
325  protected:
329 };
330 
332 
334 {
335  public:
337  const PString & cmdName,
338  const PString & uri,
339  PMIMEInfo & mime,
340  const PString & body
341  );
342  virtual PMIMEInfo & GetMIME();
343  virtual PString GetURI();
344  virtual PString GetEntityBody();
345  virtual PString GetMethod();
346  protected:
351 };
352 
354 
356 {
358  public:
360 
361  virtual Comparison Compare(
362  const PObject & other
363  ) const;
364 
365  virtual PBoolean Parse(
366  const PString & auth,
367  PBoolean proxy
368  );
369 
370  virtual PBoolean Authorise(
371  AuthObject & pdu
372  ) const;
373 };
374 
376 
378 {
380  public:
382 
385  );
386 
387  virtual Comparison Compare(
388  const PObject & other
389  ) const;
390 
391  virtual PBoolean Parse(
392  const PString & auth,
393  PBoolean proxy
394  );
395 
396  virtual PBoolean Authorise(
397  AuthObject & pdu
398  ) const;
399 
400  virtual PString GetAuthRealm() const { return authRealm; }
401  virtual void SetAuthRealm(const PString & r) { authRealm = r; }
402 
403  enum Algorithm {
406  };
407  const PString & GetNonce() const { return nonce; }
408  Algorithm GetAlgorithm() const { return algorithm; }
409  const PString & GetOpaque() const { return opaque; }
410  bool GetStale() const { return stale; }
411 
412  protected:
417 
418  bool qopAuth;
420  bool stale;
423 };
424 
425 
427 // PHTTPClient
428 
449 class PHTTPClient : public PHTTP
450 {
452 
453  public:
455  PHTTPClient(
456  const PString & userAgentName = PString::Empty()
457  );
458 
459 
460  // New functions for class.
468  int ExecuteCommand(
469  Commands cmd,
470  const PURL & url,
471  PMIMEInfo & outMIME,
472  const PString & dataBody,
473  PMIMEInfo & replyMime
474  );
475  int ExecuteCommand(
476  const PString & cmdName,
477  const PURL & url,
478  PMIMEInfo & outMIME,
479  const PString & dataBody,
480  PMIMEInfo & replyMime
481  );
482 
484  bool WriteCommand(
485  Commands cmd,
486  const PString & url,
487  PMIMEInfo & outMIME,
488  const PString & dataBody
489  );
490  bool WriteCommand(
491  const PString & cmdName,
492  const PString & url,
493  PMIMEInfo & outMIME,
494  const PString & dataBody
495  );
496 
498  bool ReadResponse(
499  PMIMEInfo & replyMIME
500  );
501 
504  {
505  virtual ~ContentProcessor() { }
506  virtual void * GetBuffer(PINDEX & size) = 0;
507  virtual bool Process(const void * data, PINDEX length) = 0;
508  };
509 
511  bool ReadContentBody(
512  PMIMEInfo & replyMIME,
513  ContentProcessor & processor
514  );
515 
517  bool ReadContentBody(
518  PMIMEInfo & replyMIME
519  );
520 
522  bool ReadContentBody(
523  PMIMEInfo & replyMIME,
524  PString & body
525  );
526 
528  bool ReadContentBody(
529  PMIMEInfo & replyMIME,
530  PBYTEArray & body
531  );
532 
533 
540  bool GetDocument(
541  const PURL & url,
542  ContentProcessor & processor
543  );
544 
551  bool GetDocument(
552  const PURL & url,
553  PMIMEInfo & outMIME,
554  PMIMEInfo & replyMIME
555  );
556  bool GetDocument(
557  const PURL & url,
558  PMIMEInfo & replyMIME
559  );
560 
561 
569  bool GetTextDocument(
570  const PURL & url,
571  PString & document,
572  const PString & contentType = PString::Empty()
573  );
574 
582  bool GetBinaryDocument(
583  const PURL & url,
584  PBYTEArray & document,
585  const PString & contentType = PString::Empty()
586  );
587 
588 
594  bool GetHeader(
595  const PURL & url,
596  PMIMEInfo & outMIME,
597  PMIMEInfo & replyMIME
598  );
599  bool GetHeader(
600  const PURL & url,
601  PMIMEInfo & replyMIME
602  );
603 
604 
610  bool PostData(
611  const PURL & url,
612  const PStringToString & data
613  );
614 
620  bool PostData(
621  const PURL & url,
622  PMIMEInfo & outMIME,
623  const PString & data
624  );
625 
632  bool PostData(
633  const PURL & url,
634  PMIMEInfo & outMIME,
635  const PString & data,
636  PMIMEInfo & replyMIME
637  );
638 
644  bool PostData(
645  const PURL & url,
646  PMIMEInfo & outMIME,
647  const PString & data,
648  PMIMEInfo & replyMIME,
649  PString & replyBody
650  );
651 
657  bool PutTextDocument(
658  const PURL & url,
659  const PString & document,
660  const PString & contentType = PMIMEInfo::TextPlain()
661  );
662 
668  bool PutDocument(
669  const PURL & url,
670  PMIMEInfo & outMIME,
671  PMIMEInfo & replyMIME
672  );
673 
679  bool DeleteDocument(
680  const PURL & url
681  );
682 
686  const PString & userName,
687  const PString & password
688  );
689 
690 #if P_SSL
691  void SetSSLCredentials(
692  const PString & authority,
693  const PString & certificate,
694  const PString & privateKey
695  );
696 #endif
697 
700  bool persist = true
701  ) { m_persist = persist; }
702 
704  bool GetPersistent() const { return m_persist; }
705 
706  protected:
707  bool AssureConnect(const PURL & url, PMIMEInfo & outMIME);
708 
710  bool m_persist;
713 #if P_SSL
714  PString m_authority; // Directory, file or data
715  PString m_certificate; // File or data
716  PString m_privateKey; // File or data
717 #endif
719 };
720 
721 
723 // PWebSocket
724 
725 #if P_SSL
726 
733 class PWebSocket : public PIndirectChannel
734 {
735  PCLASSINFO(PWebSocket, PIndirectChannel)
736  public:
738  PWebSocket();
739 
740  // Overrides from PChannel
747  virtual PBoolean Read(
748  void * buf,
749  PINDEX len
750  );
751 
763  virtual PBoolean Write(
764  const void * buf,
765  PINDEX len
766  );
767 
768 
772  bool Connect(
773  const PStringArray & protocols,
774  PString * selectedProtocol = NULL
775  );
776 
777 
779  virtual bool ReadMessage(
780  PBYTEArray & msg
781  );
782 
784  bool IsMessageComplete() const { return m_fragmentedRead && m_remainingPayload == 0; }
785 
792  void SetWriteFragmentation(
793  bool frag
794  ) { m_fragmentingWrite = frag; }
795 
797  void SetBinaryMode(
798  bool bin = true
799  ) { m_binaryWrite = bin; }
800 
802  void SetTextMode(
803  bool txt = true
804  ) { m_binaryWrite = !txt; }
805 
806 
807  protected:
808  enum OpCodes
809  {
810  Continuation = 0x0,
811  TextFrame = 0x1,
812  BinaryFrame = 0x2,
813  ConnectionClose = 0x8,
814  Ping = 0x9,
815  Pong = 0xA
816  };
817 
818  virtual bool ReadHeader(
819  OpCodes & opCode,
820  bool & fragment,
821  uint64_t & payloadLength,
822  int64_t & masking
823  );
824 
825  virtual bool WriteHeader(
826  OpCodes opCode,
827  bool fragment,
828  uint64_t payloadLength,
829  int64_t masking
830  );
831 
832  bool WriteMasked(
833  const uint32_t * data,
834  PINDEX len,
835  uint32_t mask
836  );
837 
838  bool m_client;
839  bool m_fragmentingWrite;
840  bool m_binaryWrite;
841 
842  uint64_t m_remainingPayload;
843  int64_t m_currentMask;
844  bool m_fragmentedRead;
845 
846  bool m_recursiveRead;
847 };
848 
849 #endif // P_SSL
850 
851 
853 // PHTTPConnectionInfo
854 
855 class PHTTPServer;
856 
862 {
864  public:
866 
868  const PString & GetCommandName() const { return commandName; }
869 
870  const PURL & GetURL() const { return url; }
871 
872  const PMIMEInfo & GetMIME() const { return mimeInfo; }
873  void SetMIME(const PString & tag, const PString & value);
874 
875  PBoolean IsCompatible(int major, int minor) const;
876 
877  bool IsPersistent() const { return isPersistent; }
878  bool WasPersistent() const { return wasPersistent; }
879  bool IsProxyConnection() const { return isProxyConnection; }
880  int GetMajorVersion() const { return majorVersion; }
881  int GetMinorVersion() const { return minorVersion; }
882 
883  long GetEntityBodyLength() const { return entityBodyLength; }
884 
888 
892 
897 
902 
904  { return m_multipartFormInfo; }
905 
908 
909  PString GetEntityBody() const { return entityBody; }
910 
911  bool IsWebSocket() const { return m_isWebSocket; }
912  void ClearWebSocket() { m_isWebSocket = false; }
913 
914  protected:
915  PBoolean Initialise(PHTTPServer & server, PString & args);
917 
928  PString entityBody; // original entity body (POST only)
933 
934  friend class PHTTPServer;
935 };
936 
937 
939 // PHTTPServer
940 
962 class PHTTPServer : public PHTTP
963 {
965 
966  public:
974  PHTTPServer();
975  PHTTPServer(
976  const PHTTPSpace & urlSpace
977  );
978 
979 
980  // New functions for class.
986  virtual PString GetServerName() const;
987 
994 
996  void SetURLSpace(
997  const PHTTPSpace & space
998  );
999 
1000 
1010  virtual PBoolean ProcessCommand();
1011 
1023  virtual PBoolean OnGET(
1024  const PURL & url,
1025  const PMIMEInfo & info,
1026  const PHTTPConnectionInfo & conInfo
1027  );
1028 
1029 
1030 
1042  virtual PBoolean OnHEAD(
1043  const PURL & url,
1044  const PMIMEInfo & info,
1045  const PHTTPConnectionInfo & conInfo
1046  );
1047 
1059  virtual PBoolean OnPOST(
1060  const PURL & url,
1061  const PMIMEInfo & info,
1062  const PStringToString & data,
1063  const PHTTPConnectionInfo & conInfo
1064  );
1065 
1078  virtual PBoolean OnProxy(
1079  const PHTTPConnectionInfo & conInfo
1080  );
1081 
1082 
1089  virtual PString ReadEntityBody();
1090 
1096  virtual PBoolean OnUnknown(
1097  const PCaselessString & command,
1099  );
1100 
1120  StatusCode code,
1121  PMIMEInfo & headers,
1122  long bodySize
1123  );
1124 
1134  virtual PBoolean OnError(
1135  StatusCode code,
1136  const PCaselessString & extra,
1138  );
1139 
1142  void SetDefaultMIMEInfo(
1143  PMIMEInfo & info,
1145  );
1146 
1150 
1156  virtual bool OnCommand(
1157  PINDEX cmd,
1158  const PURL & url,
1159  const PString & args,
1161  );
1162 
1181  virtual bool OnWebSocket(
1183  );
1184 
1186 
1192  void SetWebSocketNotifier(
1193  const PString & protocol,
1194  const WebSocketNotifier & notifier
1195  );
1196 
1199  const PString & protocol
1200  );
1201 
1202  protected:
1203  void Construct();
1204 
1209 
1210  std::map<PString, WebSocketNotifier> m_webSocketNotifiers;
1211 };
1212 
1213 
1215 // PHTTPRequest
1216 
1221 class PHTTPRequest : public PObject
1222 {
1224 
1225  public:
1226  PHTTPRequest(
1227  const PURL & url,
1228  const PMIMEInfo & inMIME,
1230  PHTTPResource * resource,
1231  PHTTPServer & server
1232  );
1233 
1235  const PURL & url;
1236  const PMIMEInfo & inMIME;
1241  PINDEX contentSize;
1244  WORD localPort;
1246 };
1247 
1248 
1250 // PHTTPAuthority
1251 
1255 class PHTTPAuthority : public PObject
1256 {
1258 
1259  public:
1260  // New functions for class.
1267  virtual PString GetRealm(
1268  const PHTTPRequest & request
1269  ) const = 0;
1270 
1277  virtual PBoolean Validate(
1278  const PHTTPRequest & request,
1279  const PString & authInfo
1280  ) const = 0;
1281 
1291  virtual PBoolean IsActive() const;
1292 
1293  protected:
1294  static void DecodeBasicAuthority(
1295  const PString & authInfo,
1296  PString & username,
1297  PString & password
1298  );
1299 };
1300 
1301 
1303 // PHTTPSimpleAuth
1304 
1309 {
1311 
1312  public:
1314  const PString & realm,
1315  const PString & username,
1316  const PString & password
1317  );
1318  // Construct the simple authorisation structure.
1319 
1320 
1321  // Overrides from class PObject.
1329  virtual PObject * Clone() const;
1330 
1331 
1332  // Overrides from class PHTTPAuthority.
1339  virtual PString GetRealm(
1340  const PHTTPRequest & request
1341  ) const;
1342 
1349  virtual PBoolean Validate(
1350  const PHTTPRequest & request,
1351  const PString & authInfo
1352  ) const;
1353 
1363  virtual PBoolean IsActive() const;
1364 
1370  const PString & GetUserName() const { return username; }
1371 
1377  const PString & GetPassword() const { return password; }
1378 
1379 
1380  protected:
1384 };
1385 
1386 
1388 // PHTTPMultiSimpAuth
1389 
1394 {
1396 
1397  public:
1399  const PString & realm
1400  );
1402  const PString & realm,
1403  const PStringToString & userList
1404  );
1405  // Construct the simple authorisation structure.
1406 
1407 
1408  // Overrides from class PObject.
1416  virtual PObject * Clone() const;
1417 
1418 
1419  // Overrides from class PHTTPAuthority.
1426  virtual PString GetRealm(
1427  const PHTTPRequest & request
1428  ) const;
1429 
1436  virtual PBoolean Validate(
1437  const PHTTPRequest & request,
1438  const PString & authInfo
1439  ) const;
1440 
1450  virtual PBoolean IsActive() const;
1451 
1457  void AddUser(
1458  const PString & username,
1459  const PString & password
1460  );
1461 
1462 
1463  protected:
1466 };
1467 
1468 
1470 // PHTTPResource
1471 
1475 class PHTTPResource : public PObject
1476 {
1478 
1479  protected:
1480  PHTTPResource(
1481  const PURL & url
1482  );
1483  PHTTPResource(
1484  const PURL & url,
1485  const PHTTPAuthority & auth
1486  );
1487  PHTTPResource(
1488  const PURL & url,
1489  const PString & contentType
1490  );
1491  PHTTPResource(
1492  const PURL & url,
1493  const PString & contentType,
1494  const PHTTPAuthority & auth
1495  );
1496  // Create a new HTTP Resource.
1497 
1498 
1499  public:
1500  virtual ~PHTTPResource();
1501  // Destroy the HTTP Resource.
1502 
1503 
1504  // New functions for class.
1510  const PURL & GetURL() const { return baseURL; }
1511 
1515 
1521  const PString & GetContentType() const { return contentType; }
1522 
1529  PHTTPAuthority * GetAuthority() const { return authority; }
1530 
1533  void SetAuthority(
1534  const PHTTPAuthority & auth
1535  );
1536 
1539  void ClearAuthority();
1540 
1547  DWORD GetHitCount() const { return hitCount; }
1548 
1550  void ClearHitCount() { hitCount = 0; }
1551 
1568  virtual bool OnWebSocket(
1569  PHTTPServer & server,
1570  PHTTPConnectionInfo & connectInfo
1571  );
1572 
1584  virtual PBoolean OnGET(
1585  PHTTPServer & server,
1586  const PURL & url,
1587  const PMIMEInfo & info,
1588  const PHTTPConnectionInfo & conInfo
1589  );
1590 
1600  virtual PBoolean OnGETData(
1601  PHTTPServer & server,
1602  const PURL & url,
1603  const PHTTPConnectionInfo & connectInfo,
1604  PHTTPRequest & request
1605  );
1606 
1618  virtual PBoolean OnHEAD(
1619  PHTTPServer & server,
1620  const PURL & url,
1621  const PMIMEInfo & info,
1622  const PHTTPConnectionInfo & conInfo
1623  );
1624 
1636  virtual PBoolean OnPOST(
1637  PHTTPServer & server,
1638  const PURL & url,
1639  const PMIMEInfo & info,
1640  const PStringToString & data,
1641  const PHTTPConnectionInfo & conInfo
1642  );
1643 
1653  virtual PBoolean OnPOSTData(
1654  PHTTPRequest & request,
1655  const PStringToString & data
1656  );
1657 
1664  virtual PBoolean IsModifiedSince(
1665  const PTime & when
1666  );
1667 
1673  virtual PBoolean GetExpirationDate(
1674  PTime & when
1675  );
1676 
1684  virtual PHTTPRequest * CreateRequest(
1685  const PURL & url,
1686  const PMIMEInfo & inMIME,
1687  const PMultiPartList & multipartFormInfo,
1688  PHTTPServer & socket
1689  );
1690 
1698  virtual PBoolean LoadHeaders(
1699  PHTTPRequest & request
1700  );
1701 
1707  virtual void SendData(
1708  PHTTPRequest & request
1709  );
1710 
1719  virtual PBoolean LoadData(
1720  PHTTPRequest & request,
1721  PCharArray & data
1722  );
1723 
1732  virtual PString LoadText(
1733  PHTTPRequest & request
1734  );
1735 
1742  virtual void OnLoadedText(
1743  PHTTPRequest & request,
1744  PString & text
1745  );
1746 
1755  virtual PBoolean Post(
1756  PHTTPRequest & request,
1757  const PStringToString & data,
1758  PHTML & replyMessage
1759  );
1760 
1761 
1762  protected:
1765  virtual PBoolean CheckAuthority(
1766  PHTTPServer & server,
1767  const PHTTPRequest & request,
1768  const PHTTPConnectionInfo & conInfo
1769  );
1770  static PBoolean CheckAuthority(
1772  PHTTPServer & server,
1773  const PHTTPRequest & request,
1774  const PHTTPConnectionInfo & connectInfo
1775  );
1776 
1777 
1779  virtual PBoolean OnGETOrHEAD(
1780  PHTTPServer & server,
1781  const PURL & url,
1782  const PMIMEInfo & info,
1783  const PHTTPConnectionInfo & conInfo,
1784  PBoolean isGet
1785  );
1786 
1787 
1791  volatile DWORD hitCount;
1792 };
1793 
1794 
1796 // PHTTPString
1797 
1803 {
1805 
1806  public:
1810  PHTTPString(
1811  const PURL & url // Name of the resource in URL space.
1812  );
1813  PHTTPString(
1814  const PURL & url, // Name of the resource in URL space.
1815  const PHTTPAuthority & auth // Authorisation for the resource.
1816  );
1817  PHTTPString(
1818  const PURL & url, // Name of the resource in URL space.
1819  const PString & str // String to return in this resource.
1820  );
1821  PHTTPString(
1822  const PURL & url, // Name of the resource in URL space.
1823  const PString & str, // String to return in this resource.
1824  const PString & contentType // MIME content type for the file.
1825  );
1826  PHTTPString(
1827  const PURL & url, // Name of the resource in URL space.
1828  const PString & str, // String to return in this resource.
1829  const PHTTPAuthority & auth // Authorisation for the resource.
1830  );
1831  PHTTPString(
1832  const PURL & url, // Name of the resource in URL space.
1833  const PString & str, // String to return in this resource.
1834  const PString & contentType, // MIME content type for the file.
1835  const PHTTPAuthority & auth // Authorisation for the resource.
1836  );
1837 
1838 
1839  // Overrides from class PHTTPResource
1847  virtual PBoolean LoadHeaders(
1848  PHTTPRequest & request // Information on this request.
1849  );
1850 
1859  virtual PString LoadText(
1860  PHTTPRequest & request // Information on this request.
1861  );
1862 
1863  // New functions for class.
1869  const PString & GetString() { return string; }
1870 
1874  const PString & str // New string for the resource.
1875  ) { string = str; }
1876 
1877 
1878  protected:
1880 };
1881 
1882 
1884 // PHTTPFile
1885 
1891 class PHTTPFile : public PHTTPResource
1892 {
1894 
1895  public:
1902  PHTTPFile(
1903  const PString & filename // file in file system and URL name.
1904  );
1905  PHTTPFile(
1906  const PString & filename, // file in file system and URL name.
1907  const PHTTPAuthority & auth // Authorisation for the resource.
1908  );
1909  PHTTPFile(
1910  const PURL & url, // Name of the resource in URL space.
1911  const PFilePath & file // Location of file in file system.
1912  );
1913  PHTTPFile(
1914  const PURL & url, // Name of the resource in URL space.
1915  const PFilePath & file, // Location of file in file system.
1916  const PString & contentType // MIME content type for the file.
1917  );
1918  PHTTPFile(
1919  const PURL & url, // Name of the resource in URL space.
1920  const PFilePath & file, // Location of file in file system.
1921  const PHTTPAuthority & auth // Authorisation for the resource.
1922  );
1923  PHTTPFile(
1924  const PURL & url, // Name of the resource in URL space.
1925  const PFilePath & file, // Location of file in file system.
1926  const PString & contentType, // MIME content type for the file.
1927  const PHTTPAuthority & auth // Authorisation for the resource.
1928  );
1929 
1930 
1931  // Overrides from class PHTTPResource
1937  virtual PHTTPRequest * CreateRequest(
1938  const PURL & url, // Universal Resource Locator for document.
1939  const PMIMEInfo & inMIME, // Extra MIME information in command.
1940  const PMultiPartList & multipartFormInfo,
1941  PHTTPServer & socket
1942  );
1943 
1951  virtual PBoolean LoadHeaders(
1952  PHTTPRequest & request // Information on this request.
1953  );
1954 
1960  virtual PBoolean LoadData(
1961  PHTTPRequest & request, // Information on this request.
1962  PCharArray & data // Data used in reply.
1963  );
1964 
1973  virtual PString LoadText(
1974  PHTTPRequest & request // Information on this request.
1975  );
1976 
1977 
1978  protected:
1979  PHTTPFile(
1980  const PURL & url, // Name of the resource in URL space.
1981  int dummy
1982  );
1983  // Constructor used by PHTTPDirectory
1984 
1985 
1987 };
1988 
1989 
1991 {
1993  public:
1995  const PURL & url, // Universal Resource Locator for document.
1996  const PMIMEInfo & inMIME, // Extra MIME information in command.
1998  PHTTPResource * resource,
2000  );
2001 
2003 };
2004 
2005 
2007 // PHTTPTailFile
2008 
2017 class PHTTPTailFile : public PHTTPFile
2018 {
2020 
2021  public:
2028  PHTTPTailFile(
2029  const PString & filename // file in file system and URL name.
2030  );
2031  PHTTPTailFile(
2032  const PString & filename, // file in file system and URL name.
2033  const PHTTPAuthority & auth // Authorisation for the resource.
2034  );
2035  PHTTPTailFile(
2036  const PURL & url, // Name of the resource in URL space.
2037  const PFilePath & file // Location of file in file system.
2038  );
2039  PHTTPTailFile(
2040  const PURL & url, // Name of the resource in URL space.
2041  const PFilePath & file, // Location of file in file system.
2042  const PString & contentType // MIME content type for the file.
2043  );
2044  PHTTPTailFile(
2045  const PURL & url, // Name of the resource in URL space.
2046  const PFilePath & file, // Location of file in file system.
2047  const PHTTPAuthority & auth // Authorisation for the resource.
2048  );
2049  PHTTPTailFile(
2050  const PURL & url, // Name of the resource in URL space.
2051  const PFilePath & file, // Location of file in file system.
2052  const PString & contentType, // MIME content type for the file.
2053  const PHTTPAuthority & auth // Authorisation for the resource.
2054  );
2055 
2056 
2057  // Overrides from class PHTTPResource
2065  virtual PBoolean LoadHeaders(
2066  PHTTPRequest & request // Information on this request.
2067  );
2068 
2074  virtual PBoolean LoadData(
2075  PHTTPRequest & request, // Information on this request.
2076  PCharArray & data // Data used in reply.
2077  );
2078 };
2079 
2080 
2082 // PHTTPDirectory
2083 
2097 {
2099 
2100  public:
2102  const PURL & url,
2103  const PDirectory & dir
2104  );
2106  const PURL & url,
2107  const PDirectory & dir,
2108  const PHTTPAuthority & auth
2109  );
2110  // Construct a new directory resource for HTTP.
2111 
2112 
2113  // Overrides from class PHTTPResource
2119  virtual PHTTPRequest * CreateRequest(
2120  const PURL & url, // Universal Resource Locator for document.
2121  const PMIMEInfo & inMIME, // Extra MIME information in command.
2122  const PMultiPartList & multipartFormInfo,
2123  PHTTPServer & socket
2124  );
2125 
2133  virtual PBoolean LoadHeaders(
2134  PHTTPRequest & request
2135  );
2136 
2145  virtual PString LoadText(
2146  PHTTPRequest & request
2147  );
2148 
2157  void EnableAuthorisation(const PString & realm);
2158 
2161  void AllowDirectories(PBoolean enable = true);
2162 
2163  protected:
2165  PHTTPServer & server, // Server to send response to.
2166  const PHTTPRequest & request, // Information on this request.
2167  const PHTTPConnectionInfo & conInfo // Information on the connection
2168  );
2169 
2170  PBoolean FindAuthorisations(const PDirectory & dir, PString & realm, PStringToString & authorisations);
2171 
2175 };
2176 
2177 
2179 {
2181  public:
2183  const PURL & url, // Universal Resource Locator for document.
2184  const PMIMEInfo & inMIME, // Extra MIME information in command.
2186  PHTTPResource * resource,
2188  );
2189 
2192 };
2193 
2194 
2195 #endif // P_HTTP
2196 
2197 #endif // PTLIB_HTTP_H
2198 
2199 
2200 // End Of File ///////////////////////////////////////////////////////////////