PTLib  Version 2.18.8
 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 
27 #ifndef PTLIB_HTTP_H
28 #define PTLIB_HTTP_H
29 
30 #ifdef P_USE_PRAGMA
31 #pragma interface
32 #endif
33 
34 #include <ptlib_config.h>
35 
36 #if P_HTTP
37 
38 #include <ptclib/inetprot.h>
39 #include <ptclib/mime.h>
40 #include <ptclib/url.h>
41 #include <ptlib/ipsock.h>
42 #include <ptlib/pfactory.h>
43 
44 
45 #include <ptclib/html.h>
46 
48 // PHTTPSpace
49 
50 class PHTTPResource;
51 
56 class PHTTPSpace : public PContainer
57 {
59  public:
61  PHTTPSpace();
62 
63 
64  // New functions for class.
65  enum AddOptions {
68  };
69 
70 
83  PHTTPResource * resource,
84  AddOptions overwrite = ErrorOnExist
86  );
87 
96  const PURL & url
97  );
98 
105  const PURL & url
106  );
107 
110  void StartRead() const
111  { mutex->StartRead(); }
112 
115  void EndRead() const
116  { mutex->EndRead(); }
117 
120  void StartWrite() const
121  { mutex->StartWrite(); }
122 
125  void EndWrite() const
126  { mutex->EndWrite(); }
127 
128 
129  protected:
131 
132  class Node;
133  PSORTED_LIST(ChildList, Node);
134  class Node : public PString
135  {
137  public:
138  Node(const PString & name, Node * parentNode);
139  ~Node();
140 
142  ChildList children;
144  } * root;
145 
146  private:
147  PBoolean SetSize(PINDEX) { return false; }
148 };
149 
150 #ifdef TRACE
151 #undef TRACE
152 #endif
153 
155 // PHTTP
156 
160 class PHTTP : public PInternetProtocol
161 {
163 
164  public:
165  // New functions for class.
166  enum Commands {
167  // HTTP/1.0 commands
169  // HTTP/1.1 commands
171  // HTTPS command
174  };
175 
176  enum StatusCode {
183  Continue = 100,
185  RequestOK = 200,
198  BadRequest = 400,
216  };
217 
218  // Common MIME header tags
219  static const PCaselessString & HostTag();
220  static const PCaselessString & AllowTag();
221  static const PCaselessString & AuthorizationTag();
222  static const PCaselessString & ContentEncodingTag();
223  static const PCaselessString & ContentLengthTag();
225  static const PCaselessString & DateTag();
226  static const PCaselessString & ExpiresTag();
227  static const PCaselessString & FromTag();
228  static const PCaselessString & IfModifiedSinceTag();
229  static const PCaselessString & LastModifiedTag();
230  static const PCaselessString & LocationTag();
231  static const PCaselessString & PragmaTag();
232  static const PCaselessString & PragmaNoCacheTag();
233  static const PCaselessString & RefererTag();
234  static const PCaselessString & ServerTag();
235  static const PCaselessString & UserAgentTag();
236  static const PCaselessString & WWWAuthenticateTag();
237  static const PCaselessString & MIMEVersionTag();
238  static const PCaselessString & ConnectionTag();
239  static const PCaselessString & KeepAliveTag();
240  static const PCaselessString & UpgradeTag();
241  static const PCaselessString & WebSocketTag();
242  static const PCaselessString & WebSocketKeyTag();
243  static const PCaselessString & WebSocketAcceptTag();
244  static const PCaselessString & WebSocketProtocolTag();
245  static const PCaselessString & WebSocketVersionTag();
246  static const PCaselessString & TransferEncodingTag();
247  static const PCaselessString & ChunkedTag();
248  static const PCaselessString & ProxyConnectionTag();
249  static const PCaselessString & ProxyAuthorizationTag();
250  static const PCaselessString & ProxyAuthenticateTag();
251  static const PCaselessString & ForwardedTag();
252  static const PCaselessString & SetCookieTag();
253  static const PCaselessString & CookieTag();
254 
255  static const PCaselessString & FormUrlEncoded();
256 
257  protected:
260  PHTTP();
261  PHTTP(
262  const char * defaultServiceName
263  );
264 
276  virtual PINDEX ParseResponse(
277  const PString & line
278  );
279 };
280 
281 
283 {
284 public:
285  PHTTPContentProcessor(bool reader) : m_reader(reader) { }
287  virtual void * GetBuffer(PINDEX & size) = 0;
288  virtual bool Process(const void * /*data*/, PINDEX /*length*/) { return true; }
289  virtual void Reset() { }
290 protected:
291  bool m_reader;
292 };
293 
294 
296 {
297  PCLASSINFO(PHTTPClientAuthentication, PObject);
298  public:
299  class AuthObject {
300  public:
301  virtual ~AuthObject() { }
302  virtual PMIMEInfo & GetMIME() = 0;
303  virtual PString GetURI() = 0;
304  virtual PString GetEntityBody() { return PString::Empty(); }
305  virtual PHTTPContentProcessor * GetContentProcessor() { return NULL; }
306  virtual PString GetMethod() = 0;
307  };
308 
310 
311  virtual Comparison Compare(
312  const PObject & other
313  ) const;
314 
315  virtual PBoolean Parse(
316  const PString & auth,
317  PBoolean proxy
318  ) = 0;
319 
320  virtual PBoolean Authorise(
321  AuthObject & pdu
322  ) const = 0;
323 
324  virtual PBoolean IsProxy() const { return isProxy; }
325 
326  virtual PString GetUsername() const { return username; }
327  virtual PString GetPassword() const { return password; }
328  virtual PString GetAuthRealm() const { return PString::Empty(); }
329 
330  virtual void SetUsername(const PString & user) { username = user; }
331  virtual void SetPassword(const PString & pass) { password = pass; }
332  virtual void SetAuthRealm(const PString &) { }
333 
334  PString GetAuthParam(const PString & auth, const char * name) const;
335  PString AsHex(const PMessageDigest::Result & digest) const { return digest.AsHex(); }
336  PString AsHex(const PBYTEArray & data) const;
337 
338  static PHTTPClientAuthentication * ParseAuthenticationRequired(bool isProxy, const PMIMEInfo & line, PString & errorMsg);
339 
340 
341  protected:
345 };
346 
348 
350 {
351  public:
353  const PString & cmdName,
354  const PString & uri,
355  PMIMEInfo & mime,
356  PHTTPContentProcessor & processor
357  );
358  virtual PMIMEInfo & GetMIME();
359  virtual PString GetURI();
361  virtual PString GetMethod();
362  protected:
367 };
368 
370 
372 {
374  public:
376 
377  virtual Comparison Compare(
378  const PObject & other
379  ) const;
380 
381  virtual PBoolean Parse(
382  const PString & auth,
383  PBoolean proxy
384  );
385 
386  virtual PBoolean Authorise(
387  AuthObject & pdu
388  ) const;
389 };
390 
392 
394 {
396  public:
398 
401  );
402 
403  virtual Comparison Compare(
404  const PObject & other
405  ) const;
406 
407  virtual PBoolean Parse(
408  const PString & auth,
409  PBoolean proxy
410  );
411 
412  virtual PBoolean Authorise(
413  AuthObject & pdu
414  ) const;
415 
416  virtual PString GetAuthRealm() const { return authRealm; }
417  virtual void SetAuthRealm(const PString & r) { authRealm = r; }
418 
419  enum Algorithm {
422  };
423  const PString & GetNonce() const { return nonce; }
424  Algorithm GetAlgorithm() const { return algorithm; }
425  const PString & GetOpaque() const { return opaque; }
426  bool GetStale() const { return stale; }
427 
428  protected:
433 
434  bool qopAuth;
436  bool stale;
439 };
440 
441 
443 // PHTTPClient
444 
465 class PHTTPClient : public PHTTP
466 {
468 
469  public:
471  PHTTPClient(
472  const PString & userAgentName = PString::Empty()
473  );
474  ~PHTTPClient();
475 
476 
477  // New functions for class.
479  bool ConnectURL(
480  const PURL & url
481  );
482 
485 
493  int ExecuteCommand(
494  Commands cmd,
495  const PURL & url,
496  PMIMEInfo & outMIME,
497  const PString & dataBody,
498  PMIMEInfo & replyMime
499  );
500  int ExecuteCommand(
501  Commands cmd,
502  const PURL & url,
503  PMIMEInfo & outMIME,
504  const PBYTEArray & dataBody,
505  PMIMEInfo & replyMime
506  );
507  int ExecuteCommand(
508  Commands cmd,
509  const PURL & url,
510  PMIMEInfo & outMIME,
511  ContentProcessor & processor,
512  PMIMEInfo & replyMime
513  );
514 
516  bool WriteCommand(
517  Commands cmd,
518  const PString & url,
519  PMIMEInfo & outMIME,
520  ContentProcessor & processor
521  );
522 
524  bool ReadResponse(
525  PMIMEInfo & replyMIME
526  );
527 
529  bool ReadContentBody(
530  PMIMEInfo & replyMIME,
531  ContentProcessor & processor
532  );
533 
535  bool ReadContentBody(
536  PMIMEInfo & replyMIME
537  );
538 
540  bool ReadContentBody(
541  PMIMEInfo & replyMIME,
542  PString & body
543  );
544 
546  bool ReadContentBody(
547  PMIMEInfo & replyMIME,
548  PBYTEArray & body
549  );
550 
551 
558  bool GetDocument(
559  const PURL & url,
560  ContentProcessor & processor
561  );
562 
569  bool GetDocument(
570  const PURL & url,
571  PMIMEInfo & outMIME,
572  PMIMEInfo & replyMIME
573  );
574  bool GetDocument(
575  const PURL & url,
576  PMIMEInfo & replyMIME
577  );
578 
579 
587  bool GetTextDocument(
588  const PURL & url,
589  PString & document,
590  const PString & contentType = PString::Empty()
591  );
592 
600  bool GetBinaryDocument(
601  const PURL & url,
602  PBYTEArray & document,
603  const PString & contentType = PString::Empty()
604  );
605 
606 
612  bool GetHeader(
613  const PURL & url,
614  PMIMEInfo & outMIME,
615  PMIMEInfo & replyMIME
616  );
617  bool GetHeader(
618  const PURL & url,
619  PMIMEInfo & replyMIME
620  );
621 
622 
628  bool PostData(
629  const PURL & url,
630  const PStringToString & data
631  );
632 
638  bool PostData(
639  const PURL & url,
640  const PStringToString & data,
641  PMIMEInfo & replyMIME,
642  PString & replyBody
643  );
644 
650  bool PostData(
651  const PURL & url,
652  PMIMEInfo & outMIME,
653  const PString & data
654  );
655 
662  bool PostData(
663  const PURL & url,
664  PMIMEInfo & outMIME,
665  const PString & data,
666  PMIMEInfo & replyMIME
667  );
668 
674  bool PostData(
675  const PURL & url,
676  PMIMEInfo & outMIME,
677  const PString & data,
678  PMIMEInfo & replyMIME,
679  PString & replyBody
680  );
681 
687  bool PutDocument(
688  const PURL & url,
689  const PString & document,
690  const PString & contentType = PMIMEInfo::TextPlain(),
691  const PMIMEInfo & mime = PMIMEInfo()
692  );
693 
699  bool PutDocument(
700  const PURL & url,
701  const PBYTEArray & document,
702  const PString & contentType,
703  const PMIMEInfo & mime = PMIMEInfo()
704  );
705 
711  bool PutDocument(
712  const PURL & url,
713  const PFilePath & document,
714  const PString & contentType = PString::Empty(),
715  const PMIMEInfo & mime = PMIMEInfo()
716  );
717 
718  // For backward compatibility
719  bool PutTextDocument(const PURL & url, const PString & document, const PString & contentType = PMIMEInfo::TextPlain())
720  { return PutDocument(url, document, contentType); }
721 
727  bool DeleteDocument(
728  const PURL & url
729  );
730 
734  const PString & userName,
735  const PString & password
736  );
737 
738 #if P_SSL
739  void SetSSLCredentials(
740  const PString & authority,
741  const PString & certificate,
742  const PString & privateKey
743  );
744 #endif
745 
748  bool persist = true
749  ) { m_persist = persist; }
750 
752  bool GetPersistent() const { return m_persist; }
753 
756  unsigned maxRedirects
757  ) { m_maxRedirects = maxRedirects; }
758 
760  unsigned GetMaxRedirects() const { return m_maxRedirects; }
761 
762 #if PTRACING
763  static PINDEX MaxTraceContentSize;
764 #endif
765 
766  protected:
768  bool m_persist;
769  unsigned m_maxRedirects;
772 #if P_SSL
773  PString m_authority; // Directory, file or data
774  PString m_certificate; // File or data
775  PString m_privateKey; // File or data
776 #endif
778 };
779 
780 
782 // PWebSocket
783 
784 #if P_SSL
785 
792 class PWebSocket : public PIndirectChannel
793 {
794  PCLASSINFO(PWebSocket, PIndirectChannel)
795  public:
797  PWebSocket();
798 
799  // Overrides from PChannel
806  virtual PBoolean Read(
807  void * buf,
808  PINDEX len
809  );
810 
822  virtual PBoolean Write(
823  const void * buf,
824  PINDEX len
825  );
826 
827 
831  virtual bool Connect(
832  const PURL & url,
833  const PStringArray & protocols,
834  PString * selectedProtocol = NULL
835  );
836 
837 
839  virtual bool ReadMessage(
840  PBYTEArray & msg
841  );
842 
843  // Read complete WebSocket text message
844  virtual bool ReadText(
845  PString & msg
846  );
847 
849  bool IsMessageComplete() const;
850 
857  void SetWriteFragmentation(
858  bool frag
859  ) { m_fragmentingWrite = frag; }
860 
862  void SetBinaryMode(
863  bool bin = true
864  ) { m_binaryWrite = bin; }
865 
867  void SetTextMode(
868  bool txt = true
869  ) { m_binaryWrite = !txt; }
870 
871  void SetSSLCredentials(
872  const PString & authority,
873  const PString & certificate,
874  const PString & privateKey
875  );
876 
877 
878  protected:
879  enum OpCodes
880  {
881  Continuation = 0x0,
882  TextFrame = 0x1,
883  BinaryFrame = 0x2,
884  ConnectionClose = 0x8,
885  Ping = 0x9,
886  Pong = 0xA
887  };
888 
889  virtual bool ReadHeader(
890  OpCodes & opCode,
891  bool & fragment,
892  uint64_t & payloadLength,
893  int64_t & masking
894  );
895 
896  virtual bool WriteHeader(
897  OpCodes opCode,
898  bool fragment,
899  uint64_t payloadLength,
900  int64_t masking
901  );
902 
903  bool InternalRead(void * buf, PINDEX len);
904  bool ReadMasked(void * buf, PINDEX len);
905 
906  bool InternalWrite(OpCodes opCode, bool fragmenting, const void * data, PINDEX len);
907  bool WriteMasked(const uint32_t * data, PINDEX len, uint32_t mask);
908 
909  bool m_client;
910  bool m_fragmentingWrite;
911  bool m_binaryWrite;
912  PDECLARE_MUTEX(m_writeMutex);
913 
914  uint64_t m_remainingPayload;
915  int64_t m_currentMask;
916  bool m_fragmentedRead;
917 
918  bool m_recursiveRead;
919 
920  PString m_authority; // Directory, file or data
921  PString m_certificate; // File or data
922  PString m_privateKey; // File or data
923 };
924 
925 #endif // P_SSL
926 
927 
929 // PHTTPConnectionInfo
930 
931 class PHTTPServer;
932 
938 {
940  public:
942 
944  const PString & GetCommandName() const { return commandName; }
945 
946  const PURL & GetURL() const { return url; }
947 
948  const PMIMEInfo & GetMIME() const { return mimeInfo; }
949  void SetMIME(const PString & tag, const PString & value);
950 
951  PBoolean IsCompatible(int major, int minor) const;
952 
953  bool IsPersistent() const { return isPersistent; }
954  bool WasPersistent() const { return wasPersistent; }
955  bool IsProxyConnection() const { return isProxyConnection; }
956  int GetMajorVersion() const { return majorVersion; }
957  int GetMinorVersion() const { return minorVersion; }
958 
959  long GetEntityBodyLength() const { return entityBodyLength; }
960 
963  void DisablePersistence() { isPersistent = false; }
964 
968 
972 
977 
982 
984  { return m_multipartFormInfo; }
985 
988 
989  PString GetEntityBody() const { return entityBody; }
990 
991  bool IsWebSocket() const { return m_isWebSocket; }
992  void ClearWebSocket() { m_isWebSocket = false; }
993 
994  protected:
995  PBoolean Initialise(PHTTPServer & server, PString & args);
997 
1008  PString entityBody; // original entity body (POST only)
1013 
1014  friend class PHTTPServer;
1015 };
1016 
1017 
1019 // PHTTPServer
1020 
1042 class PHTTPServer : public PHTTP
1043 {
1045 
1046  public:
1054  PHTTPServer();
1055  PHTTPServer(
1056  const PHTTPSpace & urlSpace
1057  );
1058 
1059 
1060  // New functions for class.
1066  virtual PString GetServerName() const;
1067 
1074 
1076  void SetURLSpace(
1077  const PHTTPSpace & space
1078  );
1079 
1080 
1090  virtual PBoolean ProcessCommand();
1091 
1103  virtual bool OnGET(
1104  const PHTTPConnectionInfo & conInfo
1105  );
1106 
1118  virtual bool OnHEAD(
1119  const PHTTPConnectionInfo & conInfo
1120  );
1121 
1133  virtual bool OnPOST(
1134  const PHTTPConnectionInfo & conInfo
1135  );
1136 
1149  virtual PBoolean OnProxy(
1150  const PHTTPConnectionInfo & conInfo
1151  );
1152 
1153 
1160  virtual PString ReadEntityBody();
1161 
1167  virtual PBoolean OnUnknown(
1168  const PCaselessString & command,
1169  const PHTTPConnectionInfo & connectInfo
1170  );
1171 
1190  bool StartResponse(
1191  StatusCode code,
1192  PMIMEInfo & headers,
1193  long bodySize
1194  );
1195 
1201  bool SendResponse(
1202  StatusCode code,
1203  const PString & body = PString::Empty()
1204  );
1205  bool SendResponse(
1206  StatusCode code,
1207  PMIMEInfo & headers,
1208  const PString & body = PString::Empty()
1209  );
1210 
1220  virtual PBoolean OnError(
1221  StatusCode code,
1222  const PCaselessString & extra,
1223  const PHTTPConnectionInfo & connectInfo
1224  );
1225 
1228  void SetDefaultMIMEInfo(
1229  PMIMEInfo & info,
1230  const PHTTPConnectionInfo & connectInfo
1231  ) const;
1232 
1236 
1242  virtual bool OnCommand(
1243  PINDEX cmd,
1244  const PURL & url,
1245  const PString & args,
1246  PHTTPConnectionInfo & connectInfo
1247  );
1248 
1267  virtual bool OnWebSocket(
1268  PHTTPConnectionInfo & connectInfo
1269  );
1270 
1272 
1278  void SetWebSocketNotifier(
1279  const PString & protocol,
1280  const WebSocketNotifier & notifier
1281  );
1282 
1285  const PString & protocol
1286  );
1287 
1289  void SetServiceStartTime(const PTime & startTime) { m_serviceStartTime = startTime; }
1290 
1292  const PTime & GetServiceStartTime() const { return m_serviceStartTime; }
1293 
1295  const PTime & GetLastCommandTime() const { return m_lastCommandTime; }
1296 
1297  protected:
1298  void Construct();
1299 #if P_SSL
1300  void SwitchToWebSocket(const PString & protocol, const PString & key);
1301 #endif
1302 
1309 
1310  typedef std::map<std::string, WebSocketNotifier> WebSocketNotifierMap;
1312 
1313  P_REMOVE_VIRTUAL(PBoolean,OnGET(const PURL&,const PMIMEInfo&, const PHTTPConnectionInfo&),false);
1314  P_REMOVE_VIRTUAL(PBoolean,OnHEAD(const PURL&,const PMIMEInfo&,const PHTTPConnectionInfo&),false);
1316 };
1317 
1318 
1320 // PHTTPListener
1321 
1322 class PTCPSocket;
1323 
1328 {
1329 public:
1332  PHTTPListener(
1333  unsigned maxWorkers = 10
1334  );
1335 
1337  ~PHTTPListener();
1338 
1341  bool ListenForHTTP(
1342  WORD port,
1344  unsigned queueSize = 10
1345  );
1346  bool ListenForHTTP(
1347  const PString & interfaces,
1348  WORD port,
1350  unsigned queueSize = 10
1351  );
1352 
1354  void ShutdownListeners();
1355 
1357  bool IsListening() const { return !m_httpListeningSockets.IsEmpty() && m_httpListeningSockets.front().IsOpen(); }
1358 
1360  WORD GetPort() const { return m_httpListeningSockets.IsEmpty() ? 0 : m_httpListeningSockets.front().GetPort(); }
1361 
1364  virtual PChannel * CreateChannelForHTTP(PChannel * channel);
1365  virtual PHTTPServer * CreateServerForHTTP();
1366 
1369  virtual void OnHTTPStarted(PHTTPServer & server);
1370 
1373  virtual void OnHTTPEnded(PHTTPServer & server);
1374 
1375  struct Worker
1376  {
1377  Worker(PHTTPListener & listener, PTCPSocket * socket);
1378  ~Worker();
1379  void Work();
1380 
1385  };
1387 
1389  const ThreadPool & GetThreadPool() const { return m_threadPool; }
1391 
1393  const PHTTPSpace & GetSpace() const { return m_httpNameSpace; }
1395 
1396 protected:
1397  void ListenMain();
1398 
1405  PDECLARE_MUTEX( m_httpServersMutex);
1407 };
1408 
1409 
1411 // PHTTPRequest
1412 
1417 class PHTTPRequest : public PObject
1418 {
1420 
1421  public:
1422  PHTTPRequest(
1423  const PURL & url,
1424  const PMIMEInfo & inMIME,
1426  PHTTPResource * resource,
1427  PHTTPServer & server
1428  );
1429 
1431  const PURL & url;
1432  const PMIMEInfo & inMIME;
1437  PINDEX contentSize;
1440  WORD localPort;
1443 };
1444 
1445 
1447 // PHTTPAuthority
1448 
1452 class PHTTPAuthority : public PObject
1453 {
1455 
1456  public:
1457  // New functions for class.
1464  virtual PString GetRealm(
1465  const PHTTPRequest & request
1466  ) const = 0;
1467 
1474  virtual PBoolean Validate(
1475  const PHTTPRequest & request,
1476  const PString & authInfo
1477  ) const = 0;
1478 
1488  virtual PBoolean IsActive() const;
1489 
1490  protected:
1491  static void DecodeBasicAuthority(
1492  const PString & authInfo,
1493  PString & username,
1494  PString & password
1495  );
1496 };
1497 
1498 
1500 // PHTTPSimpleAuth
1501 
1506 {
1508 
1509  public:
1511  const PString & realm,
1512  const PString & username,
1513  const PString & password
1514  );
1515  // Construct the simple authorisation structure.
1516 
1517 
1518  // Overrides from class PObject.
1526  virtual PObject * Clone() const;
1527 
1528 
1529  // Overrides from class PHTTPAuthority.
1536  virtual PString GetRealm(
1537  const PHTTPRequest & request
1538  ) const;
1539 
1546  virtual PBoolean Validate(
1547  const PHTTPRequest & request,
1548  const PString & authInfo
1549  ) const;
1550 
1560  virtual PBoolean IsActive() const;
1561 
1568  const PString & GetLocalRealm() const { return m_realm; }
1569 
1575  const PString & GetUserName() const { return m_username; }
1576 
1582  const PString & GetPassword() const { return m_password; }
1583 
1584 
1585  protected:
1589 };
1590 
1591 
1593 // PHTTPMultiSimpAuth
1594 
1599 {
1601 
1602  public:
1604  const PString & realm
1605  );
1607  const PString & realm,
1608  const PStringToString & userList
1609  );
1610  // Construct the simple authorisation structure.
1611 
1612 
1613  // Overrides from class PObject.
1621  virtual PObject * Clone() const;
1622 
1623 
1624  // Overrides from class PHTTPAuthority.
1631  virtual PString GetRealm(
1632  const PHTTPRequest & request
1633  ) const;
1634 
1641  virtual PBoolean Validate(
1642  const PHTTPRequest & request,
1643  const PString & authInfo
1644  ) const;
1645 
1655  virtual PBoolean IsActive() const;
1656 
1662  void AddUser(
1663  const PString & username,
1664  const PString & password
1665  );
1666 
1667 
1668  protected:
1671 };
1672 
1673 
1675 // PHTTPResource
1676 
1680 class PHTTPResource : public PObject
1681 {
1683 
1684  protected:
1685  PHTTPResource(
1686  const PURL & url
1687  );
1688  PHTTPResource(
1689  const PURL & url,
1690  const PHTTPAuthority & auth
1691  );
1692  PHTTPResource(
1693  const PURL & url,
1694  const PString & contentType
1695  );
1696  PHTTPResource(
1697  const PURL & url,
1698  const PString & contentType,
1699  const PHTTPAuthority & auth
1700  );
1701  // Create a new HTTP Resource.
1702 
1703 
1704  public:
1705  virtual ~PHTTPResource();
1706  // Destroy the HTTP Resource.
1707 
1708 
1709  // New functions for class.
1715  const PURL & GetURL() const { return m_baseURL; }
1716 
1720 
1726  const PString & GetContentType() const { return m_contentType; }
1727 
1735 
1738  void SetAuthority(
1739  const PHTTPAuthority & auth
1740  );
1741 
1744  void ClearAuthority();
1745 
1752  DWORD GetHitCount() const { return m_hitCount; }
1753 
1755  void ClearHitCount() { m_hitCount = 0; }
1756 
1759  virtual bool SupportsWebSocketProtocol(
1760  const PString & protocol
1761  ) const;
1762 
1779  virtual bool OnWebSocket(
1780  PHTTPServer & server,
1781  PHTTPConnectionInfo & connectInfo
1782  );
1783 
1795  virtual bool OnGET(
1796  PHTTPServer & server,
1797  const PHTTPConnectionInfo & conInfo
1798  );
1799 
1809  virtual PBoolean OnGETData(
1810  PHTTPServer & server,
1811  const PURL & url,
1812  const PHTTPConnectionInfo & connectInfo,
1813  PHTTPRequest & request
1814  );
1815 
1827  virtual bool OnHEAD(
1828  PHTTPServer & server,
1829  const PHTTPConnectionInfo & conInfo
1830  );
1831 
1843  virtual bool OnPOST(
1844  PHTTPServer & server,
1845  const PHTTPConnectionInfo & conInfo
1846  );
1847 
1857  virtual PBoolean OnPOSTData(
1858  PHTTPRequest & request,
1859  const PStringToString & data
1860  );
1861 
1868  virtual PBoolean IsModifiedSince(
1869  const PTime & when
1870  );
1871 
1877  virtual PBoolean GetExpirationDate(
1878  PTime & when
1879  );
1880 
1888  virtual PHTTPRequest * CreateRequest(
1889  const PURL & url,
1890  const PMIMEInfo & inMIME,
1891  const PMultiPartList & multipartFormInfo,
1892  PHTTPServer & socket
1893  );
1894 
1902  virtual PBoolean LoadHeaders(
1903  PHTTPRequest & request
1904  );
1905 
1911  virtual void SendData(
1912  PHTTPRequest & request
1913  );
1914 
1923  virtual PBoolean LoadData(
1924  PHTTPRequest & request,
1925  PCharArray & data
1926  );
1927 
1936  virtual PString LoadText(
1937  PHTTPRequest & request
1938  );
1939 
1946  virtual void OnLoadedText(
1947  PHTTPRequest & request,
1948  PString & text
1949  );
1950 
1959  virtual PBoolean Post(
1960  PHTTPRequest & request,
1961  const PStringToString & data,
1962  PHTML & replyMessage
1963  );
1964 
1965 
1966  protected:
1969  virtual PBoolean CheckAuthority(
1970  PHTTPServer & server,
1971  const PHTTPRequest & request,
1972  const PHTTPConnectionInfo & conInfo
1973  );
1974  static PBoolean CheckAuthority(
1975  PHTTPAuthority & authority,
1976  PHTTPServer & server,
1977  const PHTTPRequest & request,
1978  const PHTTPConnectionInfo & connectInfo
1979  );
1980 
1981 
1983  virtual bool InternalOnCommand(
1984  PHTTPServer & server,
1985  const PHTTPConnectionInfo & conInfo,
1986  PHTTP::Commands cmd
1987  );
1988 
1989 
1994 
1997  P_REMOVE_VIRTUAL(PBoolean,OnGETOrHEAD(PHTTPServer&,const PURL&,const PMIMEInfo&,const PHTTPConnectionInfo&,PBoolean),false);
1999 };
2000 
2001 
2003 // PHTTPString
2004 
2010 {
2012 
2013  public:
2017  PHTTPString(
2018  const PURL & url // Name of the resource in URL space.
2019  );
2020  PHTTPString(
2021  const PURL & url, // Name of the resource in URL space.
2022  const PHTTPAuthority & auth // Authorisation for the resource.
2023  );
2024  PHTTPString(
2025  const PURL & url, // Name of the resource in URL space.
2026  const PString & str // String to return in this resource.
2027  );
2028  PHTTPString(
2029  const PURL & url, // Name of the resource in URL space.
2030  const PString & str, // String to return in this resource.
2031  const PString & contentType // MIME content type for the file.
2032  );
2033  PHTTPString(
2034  const PURL & url, // Name of the resource in URL space.
2035  const PString & str, // String to return in this resource.
2036  const PHTTPAuthority & auth // Authorisation for the resource.
2037  );
2038  PHTTPString(
2039  const PURL & url, // Name of the resource in URL space.
2040  const PString & str, // String to return in this resource.
2041  const PString & contentType, // MIME content type for the file.
2042  const PHTTPAuthority & auth // Authorisation for the resource.
2043  );
2044 
2045 
2046  // Overrides from class PHTTPResource
2054  virtual PBoolean LoadHeaders(
2055  PHTTPRequest & request // Information on this request.
2056  );
2057 
2066  virtual PString LoadText(
2067  PHTTPRequest & request // Information on this request.
2068  );
2069 
2070  // New functions for class.
2076  const PString & GetString() { return m_string; }
2077 
2081  const PString & str // New string for the resource.
2082  ) { m_string = str; }
2083 
2084 
2085  protected:
2087 };
2088 
2089 
2091 // PHTTPFile
2092 
2098 class PHTTPFile : public PHTTPResource
2099 {
2101 
2102  public:
2109  PHTTPFile(
2110  const PString & filename // file in file system and URL name.
2111  );
2112  PHTTPFile(
2113  const PString & filename, // file in file system and URL name.
2114  const PHTTPAuthority & auth // Authorisation for the resource.
2115  );
2116  PHTTPFile(
2117  const PURL & url, // Name of the resource in URL space.
2118  const PFilePath & file // Location of file in file system.
2119  );
2120  PHTTPFile(
2121  const PURL & url, // Name of the resource in URL space.
2122  const PFilePath & file, // Location of file in file system.
2123  const PString & contentType // MIME content type for the file.
2124  );
2125  PHTTPFile(
2126  const PURL & url, // Name of the resource in URL space.
2127  const PFilePath & file, // Location of file in file system.
2128  const PHTTPAuthority & auth // Authorisation for the resource.
2129  );
2130  PHTTPFile(
2131  const PURL & url, // Name of the resource in URL space.
2132  const PFilePath & file, // Location of file in file system.
2133  const PString & contentType, // MIME content type for the file.
2134  const PHTTPAuthority & auth // Authorisation for the resource.
2135  );
2136 
2137 
2138  // Overrides from class PHTTPResource
2144  virtual PHTTPRequest * CreateRequest(
2145  const PURL & url, // Universal Resource Locator for document.
2146  const PMIMEInfo & inMIME, // Extra MIME information in command.
2147  const PMultiPartList & multipartFormInfo,
2148  PHTTPServer & socket
2149  );
2150 
2158  virtual PBoolean LoadHeaders(
2159  PHTTPRequest & request // Information on this request.
2160  );
2161 
2167  virtual PBoolean LoadData(
2168  PHTTPRequest & request, // Information on this request.
2169  PCharArray & data // Data used in reply.
2170  );
2171 
2180  virtual PString LoadText(
2181  PHTTPRequest & request // Information on this request.
2182  );
2183 
2184 
2185  protected:
2186  PHTTPFile(
2187  const PURL & url, // Name of the resource in URL space.
2188  int dummy
2189  );
2190  // Constructor used by PHTTPDirectory
2191 
2192 
2194 };
2195 
2196 
2198 {
2200  public:
2202  const PURL & url, // Universal Resource Locator for document.
2203  const PMIMEInfo & inMIME, // Extra MIME information in command.
2205  PHTTPResource * resource,
2207  );
2208 
2210 };
2211 
2212 
2214 // PHTTPTailFile
2215 
2224 class PHTTPTailFile : public PHTTPFile
2225 {
2227 
2228  public:
2235  PHTTPTailFile(
2236  const PString & filename // file in file system and URL name.
2237  );
2238  PHTTPTailFile(
2239  const PString & filename, // file in file system and URL name.
2240  const PHTTPAuthority & auth // Authorisation for the resource.
2241  );
2242  PHTTPTailFile(
2243  const PURL & url, // Name of the resource in URL space.
2244  const PFilePath & file // Location of file in file system.
2245  );
2246  PHTTPTailFile(
2247  const PURL & url, // Name of the resource in URL space.
2248  const PFilePath & file, // Location of file in file system.
2249  const PString & contentType // MIME content type for the file.
2250  );
2251  PHTTPTailFile(
2252  const PURL & url, // Name of the resource in URL space.
2253  const PFilePath & file, // Location of file in file system.
2254  const PHTTPAuthority & auth // Authorisation for the resource.
2255  );
2256  PHTTPTailFile(
2257  const PURL & url, // Name of the resource in URL space.
2258  const PFilePath & file, // Location of file in file system.
2259  const PString & contentType, // MIME content type for the file.
2260  const PHTTPAuthority & auth // Authorisation for the resource.
2261  );
2262 
2263 
2264  // Overrides from class PHTTPResource
2272  virtual PBoolean LoadHeaders(
2273  PHTTPRequest & request // Information on this request.
2274  );
2275 
2281  virtual PBoolean LoadData(
2282  PHTTPRequest & request, // Information on this request.
2283  PCharArray & data // Data used in reply.
2284  );
2285 };
2286 
2287 
2289 // PHTTPDirectory
2290 
2304 {
2306 
2307  public:
2309  const PURL & url,
2310  const PDirectory & dir
2311  );
2313  const PURL & url,
2314  const PDirectory & dir,
2315  const PHTTPAuthority & auth
2316  );
2317  // Construct a new directory resource for HTTP.
2318 
2319 
2320  // Overrides from class PHTTPResource
2326  virtual PHTTPRequest * CreateRequest(
2327  const PURL & url, // Universal Resource Locator for document.
2328  const PMIMEInfo & inMIME, // Extra MIME information in command.
2329  const PMultiPartList & multipartFormInfo,
2330  PHTTPServer & socket
2331  );
2332 
2340  virtual PBoolean LoadHeaders(
2341  PHTTPRequest & request
2342  );
2343 
2352  virtual PString LoadText(
2353  PHTTPRequest & request
2354  );
2355 
2364  void EnableAuthorisation(const PString & realm);
2365 
2368  void AllowDirectories(PBoolean enable = true);
2369 
2370  protected:
2372  PHTTPServer & server, // Server to send response to.
2373  const PHTTPRequest & request, // Information on this request.
2374  const PHTTPConnectionInfo & conInfo // Information on the connection
2375  );
2376 
2377  PBoolean FindAuthorisations(const PDirectory & dir, PString & realm, PStringToString & authorisations);
2378 
2382 };
2383 
2384 
2386 {
2388  public:
2390  const PURL & url, // Universal Resource Locator for document.
2391  const PMIMEInfo & inMIME, // Extra MIME information in command.
2393  PHTTPResource * resource,
2395  );
2396 
2399 };
2400 
2401 
2402 #endif // P_HTTP
2403 
2404 #endif // PTLIB_HTTP_H
2405 
2406 
2407 // End Of File ///////////////////////////////////////////////////////////////
static const PCaselessString & TransferEncodingTag()
void SetPersistenceMaximumTransations(unsigned m)
Set the maximum number of transations (GET/POST etc) for persistent connection.
Definition: http.h:981
PString commandName
Definition: http.h:999
void SetMIME(const PString &tag, const PString &value)
void SetString(const PString &str)
Set the string to be returned by this resource.
Definition: http.h:2080
Definition: http.h:393
PHTTPListener(unsigned maxWorkers=10)
Construct new HTTP listsner with specified maximum number of threads in pool.
virtual PBoolean Post(PHTTPRequest &request, const PStringToString &data, PHTML &replyMessage)
Get a block of data (eg HTML) that the resource contains.
virtual PString GetPassword() const
Definition: http.h:327
virtual PBoolean Parse(const PString &auth, PBoolean proxy)
virtual void SetPassword(const PString &pass)
Definition: http.h:331
void ClearWebSocketNotifier(const PString &protocol)
Remove a WebSocket notifier.
virtual PMIMEInfo & GetMIME()=0
PString AsHex(const PMessageDigest::Result &digest) const
Definition: http.h:335
const PString & GetPassword() const
Get the password allocated to this simple authorisation.
Definition: http.h:1582
PHTTPSpace::Node * root
static const PCaselessString & ContentTypeTag()
bool DecodeMultiPartList(PMultiPartList &parts, const PString &body, const PCaselessString &key) const
Decode parts from a multipart body using the field value.
PBoolean Initialise(PHTTPServer &server, PString &args)
bool GetPersistent() const
Get persistent connection mode.
Definition: http.h:752
This class contains the Multipurpose Internet Mail Extensions parameters and variables.
Definition: mime.h:48
virtual bool SupportsWebSocketProtocol(const PString &protocol) const
Indicate that the web socket protocol is supported by this resource.
static const PCaselessString & FormUrlEncoded()
static const PCaselessString & ExpiresTag()
WORD m_listenerPort
Definition: http.h:1401
virtual bool OnHEAD(PHTTPServer &server, const PHTTPConnectionInfo &conInfo)
Handle the HEAD command passed from the HTTP socket.
This object describes the information associated with multi-part bodies.
Definition: mime.h:327
PString entityBody
Definition: http.h:1008
const PString & GetNonce() const
Definition: http.h:423
PFile m_file
Definition: http.h:2209
PString m_password
Definition: http.h:1588
virtual PBoolean IsActive() const
Determine if the authorisation is to be applied.
301 - resource moved permanently: location field has new URL
Definition: http.h:193
This class represents a disk file.
Definition: file.h:57
bool StartResponse(StatusCode code, PMIMEInfo &headers, long bodySize)
Write a command reply back to the client, and construct some of the outgoing MIME fields...
virtual PBoolean IsProxy() const
Definition: http.h:324
bool DeleteDocument(const PURL &url)
Delete the document specified by the URL.
PHTTPClientAuthenticator(const PString &cmdName, const PString &uri, PMIMEInfo &mime, PHTTPContentProcessor &processor)
PDECLARE_MUTEX(px_threadMutex)
Definition: http.h:134
static const PCaselessString & CookieTag()
PHTTPClientDigestAuthentication & operator=(const PHTTPClientDigestAuthentication &auth)
This class defines an arbitrary time interval to millisecond accuracy.
Definition: timeint.h:51
virtual void * GetBuffer(PINDEX &size)=0
1 = response is malformed
Definition: http.h:177
bool WasPersistent() const
Definition: http.h:954
static const PCaselessString & AuthorizationTag()
void EndRead() const
This function attempts to release the mutex for reading.
Definition: http.h:115
Array of characters.
Definition: array.h:552
412 - no Range header for true Unless
Definition: http.h:210
virtual PString GetRealm(const PHTTPRequest &request) const
Get the realm or name space for the user authorisation name and password as required by the basic aut...
PHTTPServer()
Create a TCP/IP HTTP protocol socket channel.
virtual PString GetRealm(const PHTTPRequest &request) const
Get the realm or name space for the user authorisation name and password as required by the basic aut...
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:2164
void EnableAuthorisation(const PString &realm)
Enable or disable access control using .access files.
virtual PBoolean Authorise(AuthObject &pdu) const
PString m_uri
Definition: http.h:364
~PHTTPListener()
Shut down all listeners on destruction.
500 - server has encountered an unexpected error
Definition: http.h:211
static const PCaselessString & LocationTag()
void DisablePersistence()
Do not persist.
Definition: http.h:963
PBoolean CheckAuthority(PHTTPServer &server, const PHTTPRequest &request, const PHTTPConnectionInfo &conInfo)
See if the resource is authorised given the mime info.
virtual PBoolean LoadData(PHTTPRequest &request, PCharArray &data)
Get a block of data that the resource contains.
void ListenMain()
PSORTED_LIST(ChildList, Node)
PHTTPAuthority * GetAuthority() const
Get the current authority for the resource.
Definition: http.h:1734
Definition: http.h:173
This class describes the simplest authorisation mechanism for a Universal Resource Locator...
Definition: http.h:1505
PHTTPResource * resource
Definition: http.h:143
PHTTPContentProcessor & m_contentProcessor
Definition: http.h:366
void ClearHitCount()
Clear the hit count for the resource.
Definition: http.h:1755
static const PCaselessString & RefererTag()
bool IsProxyConnection() const
Definition: http.h:955
PFilePath m_realPath
Definition: http.h:2398
PTCPSocket * m_socket
Definition: http.h:1382
const PTime & GetLastCommandTime() const
Get time last command was read.
Definition: http.h:1295
This abstract class describes the authorisation mechanism for a Universal Resource Locator...
Definition: http.h:1452
This class defines an absolute time and date.
Definition: ptime.h:49
virtual PObject * Clone() const
Create a copy of the class on the heap.
bool PutDocument(const PURL &url, const PString &document, const PString &contentType=PMIMEInfo::TextPlain(), const PMIMEInfo &mime=PMIMEInfo())
Put the document specified by the URL.
static const PCaselessString & PragmaNoCacheTag()
static const PCaselessString & WWWAuthenticateTag()
PHTTPContentProcessor(bool reader)
Definition: http.h:285
PString m_realm
Definition: http.h:1669
virtual void SetUsername(const PString &user)
Definition: http.h:330
503 - server temporarily unable to service request
Definition: http.h:214
PTimeInterval m_nextTimeout
Definition: http.h:1308
P_REMOVE_VIRTUAL(PBoolean, OnGET(const PURL &, const PMIMEInfo &, const PHTTPConnectionInfo &), false)
unsigned GetMaxRedirects() const
Get max redirects on operation.
Definition: http.h:760
int ExecuteCommand(Commands cmd, const PURL &url, PMIMEInfo &outMIME, const PString &dataBody, PMIMEInfo &replyMime)
Send a command and wait for the response header (including MIME fields).
virtual PString LoadText(PHTTPRequest &request)
Get a block of text data (eg HTML) that the resource contains.
const PString & GetContentType() const
Get the current content type for the resource.
Definition: http.h:1726
Algorithm
Definition: http.h:419
void SetAuthority(const PHTTPAuthority &auth)
Set the current authority for the resource.
const PMultiPartList & multipartFormInfo
multipart form information, if any
Definition: http.h:1433
static const PCaselessString & ContentLengthTag()
Definition: http.h:170
static const PCaselessString & ProxyConnectionTag()
virtual Comparison Compare(const PObject &other) const
Compare the two objects and return their relative rank.
203 - not definitive entity header
Definition: http.h:188
205 - contents have been reset
Definition: http.h:190
PHTTP::Commands commandCode
Definition: http.h:998
virtual PString GetURI()
bool GetHeader(const PURL &url, PMIMEInfo &outMIME, PMIMEInfo &replyMIME)
Get the header for the document specified by the URL.
Definition: http.h:295
virtual PBoolean CheckAuthority(PHTTPServer &server, const PHTTPRequest &request, const PHTTPConnectionInfo &conInfo)
See if the resource is authorised given the mime info.
Generate error if resource already exists.
Definition: http.h:66
virtual PString GetServerName() const
Get the name of the server.
303 - see other URL
Definition: http.h:195
PHTTPFileRequest(const PURL &url, const PMIMEInfo &inMIME, const PMultiPartList &multipartFormInfo, PHTTPResource *resource, PHTTPServer &server)
This is a dictionary collection class of PString objects, keyed by another string.
Definition: pstring.h:3151
This class describes a full description for a file on the particular platform.
Definition: filepath.h:61
void SetServiceStartTime(const PTime &startTime)
Set start of service time.
Definition: http.h:1289
static const PCaselessString & SetCookieTag()
PBoolean isProxy
Definition: http.h:342
PString m_password
Definition: http.h:771
virtual Comparison Compare(const PObject &other) const
Compare the two objects and return their relative rank.
Comparison
Result of the comparison operation performed by the Compare() function.
Definition: object.h:2251
void SetMaxRedirects(unsigned maxRedirects)
Set max redirects on operation.
Definition: http.h:755
void AddUser(const PString &username, const PString &password)
Get the user name allocated to this simple authorisation.
PHTTPResource * FindResource(const PURL &url)
Locate the resource specified by the URL in the URL name space.
static const PCaselessString & ContentEncodingTag()
virtual PBoolean Validate(const PHTTPRequest &request, const PString &authInfo) const
Validate the user and password provided by the remote HTTP client for the realm specified by the clas...
virtual bool OnGET(PHTTPServer &server, const PHTTPConnectionInfo &conInfo)
Handle the GET command passed from the HTTP socket.
This is a channel that operates indirectly through another channel(s).
Definition: indchan.h:45
This class is a variation of a string that ignores case.
Definition: pstring.h:2012
virtual PBoolean LoadHeaders(PHTTPRequest &request)
Get the headers for block of data (eg HTML) that the resource contains.
std::map< std::string, WebSocketNotifier > WebSocketNotifierMap
Definition: http.h:1310
PMIMEInfo & m_mime
Definition: http.h:365
PTime m_lastCommandTime
Definition: http.h:1304
PString m_userAgentName
Definition: http.h:767
virtual bool OnWebSocket(PHTTPConnectionInfo &connectInfo)
Called when a request indicates a swtch to WebSocket protocol.
PHTTPSpace & GetURLSpace()
Get the name space being used by the HTTP server socket.
Definition: http.h:1073
Definition: http.h:2385
static const PCaselessString & WebSocketProtocolTag()
void EndWrite() const
This function attempts to release the mutex for writing.
Definition: http.h:125
virtual void SetAuthRealm(const PString &r)
Definition: http.h:417
static const PCaselessString & ServerTag()
void ShutdownListeners()
Shut down the listener socket, it&#39;s thread, and all threads in the pool.
ThreadPool & GetThreadPool()
Definition: http.h:1390
PBoolean AddResource(PHTTPResource *resource, AddOptions overwrite=ErrorOnExist)
Add a new resource to the URL space.
bool wasPersistent
Definition: http.h:1003
unsigned m_transactionCount
Definition: http.h:1307
virtual PObject * Clone() const
Create a copy of the class on the heap.
Definition: http.h:168
bool stale
Definition: http.h:436
Overwrite the existing resource at URL location.
Definition: http.h:67
void StartRead() const
This function attempts to acquire the mutex for reading.
Definition: http.h:110
static const PCaselessString & ProxyAuthorizationTag()
PHTTPConnectionInfo m_connectInfo
Definition: http.h:1306
virtual PBoolean LoadHeaders(PHTTPRequest &request)
Get the headers for block of data (eg HTML) that the resource contains.
501 - server does not implement request
Definition: http.h:212
Definition: http.h:2197
virtual bool Process(const void *, PINDEX)
Definition: http.h:288
virtual PBoolean IsActive() const
Determine if the authorisation is to be applied.
__inline void StartWrite()
This function attempts to acquire the mutex for writing.
Definition: syncthrd.h:299
PString entityBody
original entity body (POST only)
Definition: http.h:1436
This object describes a HyperText Transport Protocol resource which is a single file.
Definition: http.h:2098
virtual PString GetAuthRealm() const
Definition: http.h:328
virtual PChannel * CreateChannelForHTTP(PChannel *channel)
Call back to create transport socket, or TLS, channel.
bool WriteCommand(Commands cmd, const PString &url, PMIMEInfo &outMIME, ContentProcessor &processor)
Write a HTTP command to server.
PString m_username
Definition: http.h:1587
Node * parent
Definition: http.h:141
200 - request has succeeded
Definition: http.h:185
This is an array collection class of PString objects.
Definition: pstring.h:2365
101 - upgrade allowed
Definition: http.h:184
int GetMajorVersion() const
Definition: http.h:956
PHTTPString(const PURL &url)
Contruct a new simple string resource for the HTTP space.
This object describes a HyperText Transport Protocol resource which is a string kept in memory...
Definition: http.h:2009
unsigned persistenceMaximum
Definition: http.h:1011
Definition: http.h:168
PString m_contentType
MIME content type for the resource.
Definition: http.h:1991
PHTTPClientAuthentication * m_authentication
Definition: http.h:777
const PMIMEInfo & GetMIME() const
Definition: http.h:948
virtual bool OnWebSocket(PHTTPServer &server, PHTTPConnectionInfo &connectInfo)
Called when a request indicates a swtch to WebSocket protocol.
void StartWrite() const
This function attempts to acquire the mutex for writing.
Definition: http.h:120
PThread * m_listenerThread
Definition: http.h:1402
virtual PBoolean GetExpirationDate(PTime &when)
Get a block of data (eg HTML) that the resource contains.
long GetEntityBodyLength() const
Definition: http.h:959
virtual PHTTPContentProcessor * GetContentProcessor()
Definition: http.h:305
static const PCaselessString & WebSocketKeyTag()
PHTTPServer * m_httpServer
Definition: http.h:1383
unsigned persistenceSeconds
Definition: http.h:1010
401 - request requires authentication
Definition: http.h:199
PHTTPDirRequest(const PURL &url, const PMIMEInfo &inMIME, const PMultiPartList &multipartFormInfo, PHTTPResource *resource, PHTTPServer &server)
WebSocketNotifierMap m_webSocketNotifiers
Definition: http.h:1311
This object describes a HyperText Transport Protocol resource.
Definition: http.h:1680
PHTTPSimpleAuth(const PString &realm, const PString &username, const PString &password)
PHTTPSpace m_httpNameSpace
Definition: http.h:1399
404 - resource cannot be found
Definition: http.h:202
PString defaultServiceName
Definition: inetprot.h:377
void SetURLSpace(const PHTTPSpace &space)
Use a new URL name space for this HTTP socket.
virtual Comparison Compare(const PObject &other) const
Compare the two objects and return their relative rank.
PHTTPMultiSimpAuth(const PString &realm)
virtual bool OnPOST(const PHTTPConnectionInfo &conInfo)
Handle a POST command from a client.
virtual void RemoveAll()
Remove all of the elements in the collection.
virtual void OnHTTPEnded(PHTTPServer &server)
Callback when an existing HTTP connection has ended.
static const PCaselessString & ForwardedTag()
const PString & GetOpaque() const
Definition: http.h:425
virtual PBoolean LoadHeaders(PHTTPRequest &request)
Get the headers for block of data (eg HTML) that the resource contains.
Could not connect transport.
Definition: http.h:180
This object describes a HyperText Transport Protocol resource which is a set of files in a directory...
Definition: http.h:2303
A TCP/IP socket for process/application layer high level protocols.
Definition: inetprot.h:61
Definition: http.h:170
PString GetAuthParam(const PString &auth, const char *name) const
virtual PHTTPContentProcessor * GetContentProcessor()
302 - resource moved temporarily: location field has new URL
Definition: http.h:194
bool GetDocument(const PURL &url, ContentProcessor &processor)
Start getting the document specified by the URL.
ChildList children
Definition: http.h:142
virtual PHTTPRequest * CreateRequest(const PURL &url, const PMIMEInfo &inMIME, const PMultiPartList &multipartFormInfo, PHTTPServer &socket)
Create a new request block for this type of resource.
long entityBodyLength
Definition: http.h:1009
bool PutTextDocument(const PURL &url, const PString &document, const PString &contentType=PMIMEInfo::TextPlain())
Definition: http.h:719
virtual PBoolean LoadHeaders(PHTTPRequest &request)
Get the headers for block of data (eg HTML) that the resource contains.
Class to represent a directory in the operating system file system.
Definition: pdirect.h:173
const PString & GetCommandName() const
Definition: http.h:944
402 - reserved
Definition: http.h:200
bool PostData(const PURL &url, const PStringToString &data)
Post the &quot;application/x-www-form-urlencoded&quot; data specified to the URL.
PHTTPConnectionInfo & GetConnectionInfo()
Get the connection info for this connection.
Definition: http.h:1235
PTime m_serviceStartTime
Definition: http.h:1303
PHTTPAuthority * m_authority
Authorisation method for the resource.
Definition: http.h:1992
static void DecodeBasicAuthority(const PString &authInfo, PString &username, PString &password)
Definition: http.h:349
Array of unsigned characters.
Definition: array.h:605
Node(const PString &name, Node *parentNode)
virtual PBoolean OnProxy(const PHTTPConnectionInfo &conInfo)
Handle a proxy command request from a client.
PString password
Definition: http.h:344
const ThreadPool & GetThreadPool() const
Get the thread pool in use for this HTTP listener.
Definition: http.h:1389
405 - not allowed on this resource
Definition: http.h:203
__inline void StartRead()
This function attempts to acquire the mutex for reading.
Definition: syncthrd.h:276
410 - resource gone away
Definition: http.h:208
const PURL & url
Universal Resource Locator for document.
Definition: http.h:1431
PTimeInterval GetPersistenceTimeout() const
Get the maximum time a persistent connection may persist.
Definition: http.h:967
static const PCaselessString & WebSocketTag()
Worker(PHTTPListener &listener, PTCPSocket *socket)
Definition: socket.h:86
virtual void OnHTTPStarted(PHTTPServer &server)
Callback when a new HTTP connection has begun.
bool DecodeMultipartFormInfo()
Definition: http.h:996
virtual PBoolean OnUnknown(const PCaselessString &command, const PHTTPConnectionInfo &connectInfo)
Handle an unknown command.
virtual PBoolean Parse(const PString &auth, PBoolean proxy)=0
The PNotifier and PNotifierFunction classes build a completely type safe mechanism for calling arbitr...
Definition: notifier.h:109
bool ListenForHTTP(WORD port, PSocket::Reusability reuse=PSocket::CanReuseAddress, unsigned queueSize=10)
Start listening for HTTP connections.
PINDEX contentSize
Size of the body of the resource data.
Definition: http.h:1437
virtual void Reset()
Definition: http.h:289
int minorVersion
Definition: http.h:1007
PHTTPClient(const PString &userAgentName=PString::Empty())
Create a new HTTP client channel.
PIPSocket::Address localAddr
IP address of local interface for request.
Definition: http.h:1439
virtual ~PHTTPResource()
const PString & GetString()
Get the string for this resource.
Definition: http.h:2076
PDirectory m_basePath
Definition: http.h:2379
PFilePath m_filePath
Definition: http.h:2193
A TCP/IP socket for the HyperText Transfer Protocol version 1.0.
Definition: http.h:465
const PURL & GetURL() const
Get the URL for this resource.
Definition: http.h:1715
bool m_isWebSocket
Definition: http.h:1005
Translate to a string as only path.
Definition: url.h:135
PHTTPFile(const PString &filename)
Contruct a new simple file resource for the HTTP space.
static const PCaselessString & UserAgentTag()
const PHTTPSpace & GetSpace() const
Get the resource space for HTTP listener.
Definition: http.h:1393
Unknown &quot;Transfer-Encoding&quot; extension.
Definition: http.h:179
static const PCaselessString & FromTag()
PDECLARE_MUTEX(m_httpServersMutex)
virtual bool OnPOST(PHTTPServer &server, const PHTTPConnectionInfo &conInfo)
Handle the POST command passed from the HTTP socket.
204 - no new information
Definition: http.h:189
Abstract class defining I/O channel semantics.
Definition: channel.h:103
virtual PString LoadText(PHTTPRequest &request)
Get a block of text data (eg HTML) that the resource contains.
static const PCaselessString & MIMEVersionTag()
bool IsListening() const
Indicate is currently listening and processing requests.
Definition: http.h:1357
virtual PHTTPServer * CreateServerForHTTP()
virtual PBoolean Parse(const PString &auth, PBoolean proxy)
virtual PBoolean ProcessCommand()
Process commands, dispatching to the appropriate virtual function.
PBoolean IsCompatible(int major, int minor) const
void AllowDirectories(PBoolean enable=true)
Enable or disable directory listings when a default directory file does not exist.
void ResetMultipartFormInfo()
Definition: http.h:986
PHTTP()
Create a TCP/IP HTTP protocol channel.
bool PBoolean
Definition: object.h:174
bool m_persist
Definition: http.h:768
static const PCaselessString & ChunkedTag()
virtual PString GetEntityBody()
Definition: http.h:304
Could not write transport.
Definition: http.h:181
PURL m_baseURL
Base URL for the resource, may accept URLS with a longer hierarchy.
Definition: http.h:1990
void SetDefaultMIMEInfo(PMIMEInfo &info, const PHTTPConnectionInfo &connectInfo) const
Set the default mime info.
PString cnonce
Definition: http.h:437
const PString & GetLocalRealm() const
Get the realm or name space for the user authorisation name and password as required by the basic aut...
Definition: http.h:1568
bool m_allowDirectoryListing
Definition: http.h:2381
static const PCaselessString & WebSocketAcceptTag()
virtual PINDEX ParseResponse(const PString &line)
Parse a response line string into a response code and any extra info on the line. ...
virtual bool OnCommand(PINDEX cmd, const PURL &url, const PString &args, PHTTPConnectionInfo &connectInfo)
Called when a request is received.
virtual ~AuthObject()
Definition: http.h:301
PIPSocket::Address origin
IP address of origin host for request.
Definition: http.h:1438
PReadWriteMutex * mutex
Definition: http.h:130
void SetPersistenceTimeout(const PTimeInterval &t)
Set the maximum time a persistent connection may persist.
Definition: http.h:971
virtual PBoolean Validate(const PHTTPRequest &request, const PString &authInfo) const =0
Validate the user and password provided by the remote HTTP client for the realm specified by the clas...
void ClearAuthority()
Set the current authority for the resource to unrestricted.
305 - proxy redirect
Definition: http.h:197
PHTTPSpace m_urlSpace
Definition: http.h:1305
PString opaque
Definition: http.h:432
PString m_method
Definition: http.h:363
The character string class.
Definition: pstring.h:108
void SetWebSocketNotifier(const PString &protocol, const WebSocketNotifier &notifier)
Set the handler for WebSocket sub-protocol.
static const PCaselessString & PragmaTag()
A socket that uses the TCP transport on the Internet Protocol.
Definition: tcpsock.h:40
409 - resource conflict on action
Definition: http.h:207
static const PCaselessString & LastModifiedTag()
virtual bool OnGET(const PHTTPConnectionInfo &conInfo)
Handle a GET command from a client.
PString m_realm
Definition: http.h:1586
WORD localPort
Port number of local server for request.
Definition: http.h:1440
bool m_reader
Definition: http.h:291
300 - requested resource available elsewehere
Definition: http.h:192
#define PCONTAINERINFO(cls, par)
Macro to declare funtions required in a container.
Definition: contain.h:340
411 - no Content-Length
Definition: http.h:209
bool ConnectURL(const PURL &url)
Connect at transport level to remote, based on URL.
virtual PString GetAuthRealm() const
Definition: http.h:416
PHTTPResource(const PURL &url)
bool IsWebSocket() const
Definition: http.h:991
304 - document has not been modified
Definition: http.h:196
PString m_fakeIndex
Definition: http.h:2397
Content Processer returned error.
Definition: http.h:178
PString nonce
Definition: http.h:430
atomic< uint32_t > nonceCount
Definition: http.h:438
virtual PBoolean Write(const void *buf, PINDEX len)
Low level write to the channel.
PBoolean FindAuthorisations(const PDirectory &dir, PString &realm, PStringToString &authorisations)
PHTTP::StatusCode code
Status code for OnError() reply.
Definition: http.h:1434
virtual PString LoadText(PHTTPRequest &request)
Get a block of text data (eg HTML) that the resource contains.
Definition: http.h:282
This class defines a thread of execution in the system.
Definition: thread.h:66
Abstract class to embody the base functionality of a container.
Definition: contain.h:99
virtual PBoolean IsModifiedSince(const PTime &when)
Check to see if the resource has been modified since the date specified.
This class describes the simple authorisation mechanism for a Universal Resource Locator, a fixed realm, multiple usernames and passwords.
Definition: http.h:1598
bool isPersistent
Definition: http.h:1002
static const PCaselessString & ContentTypeTag()
Definition: http.h:224
AddOptions
Definition: http.h:65
This class describes a name space that a Universal Resource Locator operates in.
Definition: http.h:56
virtual PBoolean LoadHeaders(PHTTPRequest &request)
Get the headers for block of data (eg HTML) that the resource contains.
void SetPersistent(bool persist=true)
Set persistent connection mode.
Definition: http.h:747
PHTTPTailFile(const PString &filename)
Contruct a new simple file resource for the HTTP space.
bool IsPersistent() const
Definition: http.h:953
This class describes a HyperText markup Language string as used by the World Wide Web and the PURL an...
Definition: html.h:45
static const PString & Empty()
Return an empty string.
Definition: http.h:172
PString m_listenerInterfaces
Definition: http.h:1400
PMIMEInfo mimeInfo
Definition: http.h:1001
Listener for incoming HTTP request with thread pool to handle those requests.
Definition: http.h:1327
virtual PBoolean OnPOSTData(PHTTPRequest &request, const PStringToString &data)
Send the data associated with a POST command.
PTime m_arrivalTime
Time of arrival of the HTTP request.
Definition: http.h:1442
PHTTPSpace()
Constructor for HTTP URL Name Space.
Class for a factory to create concrete class instances without parameters during construction.
Definition: pfactory.h:396
ThreadPool m_threadPool
Definition: http.h:1406
Definition: http.h:170
PHTTPListener & m_listener
Definition: http.h:1381
A class describing an IP address.
Definition: ipsock.h:59
PStringToString m_users
Definition: http.h:1670
PFactory< PHTTPClientAuthentication > PHTTPClientAuthenticationFactory
Definition: http.h:347
Definition: http.h:170
void Construct()
bool GetBinaryDocument(const PURL &url, PBYTEArray &document, const PString &contentType=PString::Empty())
Get the document specified by the URL.
PMultiPartList m_multipartFormInfo
Definition: http.h:1012
WORD GetPort() const
Get the port we are lkstening on.
Definition: http.h:1360
virtual PHTTPRequest * CreateRequest(const PURL &url, const PMIMEInfo &inMIME, const PMultiPartList &multipartFormInfo, PHTTPServer &socket)
Create a new request block for this type of resource.
bool qopAuthInt
Definition: http.h:435
static const PCaselessString & KeepAliveTag()
void EndWrite()
This function attempts to release the mutex for writing.
Definition: syncthrd.h:313
bool SendResponse(StatusCode code, const PString &body=PString::Empty())
Send a response to client.
int GetMinorVersion() const
Definition: http.h:957
Could not read transport.
Definition: http.h:182
bool GetTextDocument(const PURL &url, PString &document, const PString &contentType=PString::Empty())
Get the document specified by the URL.
PString GetHotLink() const
Get relative hot link for this resouce.
Definition: http.h:1719
virtual PBoolean IsActive() const
Determine if the authirisation is to be applied.
virtual PBoolean Read(void *buf, PINDEX len)
Low level read from the channel.
PHTTPServer & server
Server channel that request initiated on.
Definition: http.h:1430
virtual PBoolean OnError(StatusCode code, const PCaselessString &extra, const PHTTPConnectionInfo &connectInfo)
Write an error response for the specified code.
DWORD GetHitCount() const
Get the current hit count for the resource.
Definition: http.h:1752
403 - request is refused due to unsufficient authorisation
Definition: http.h:201
virtual PHTTPRequest * CreateRequest(const PURL &url, const PMIMEInfo &inMIME, const PMultiPartList &multipartFormInfo, PHTTPServer &socket)
Create a new request block for this type of resource.
const PString & GetUserName() const
Get the user name allocated to this simple authorisation.
Definition: http.h:1575
unsigned m_maxRedirects
Definition: http.h:769
StatusCode
Definition: http.h:176
PString m_string
Definition: http.h:2086
long GetSeconds() const
Get the number of whole seconds for the time interval.
virtual PBoolean OnGETData(PHTTPServer &server, const PURL &url, const PHTTPConnectionInfo &connectInfo, PHTTPRequest &request)
Send the data associated with a GET command.
static const PCaselessString & ConnectionTag()
bool ReadContentBody(PMIMEInfo &replyMIME, ContentProcessor &processor)
Read the body of the HTTP command.
PNotifierTemplate< PHTTPConnectionInfo > WebSocketNotifier
Definition: http.h:1271
Definition: http.h:1375
PString m_userName
Definition: http.h:770
static const PCaselessString & ProxyAuthenticateTag()
408 - server timeout on request
Definition: http.h:206
static const PCaselessString & UpgradeTag()
406 - encoding not acceptable
Definition: http.h:204
virtual PBoolean LoadData(PHTTPRequest &request, PCharArray &data)
Get a block of data that the resource contains.
PHTTPRequest(const PURL &url, const PMIMEInfo &inMIME, const PMultiPartList &multipartFormInfo, PHTTPResource *resource, PHTTPServer &server)
PSocketList m_httpListeningSockets
Definition: http.h:1403
PQueuedThreadPool< Worker > ThreadPool
Definition: http.h:1386
This class defines a thread synchronisation object.
Definition: syncthrd.h:256
virtual PBoolean LoadData(PHTTPRequest &request, PCharArray &data)
Get a block of data that the resource contains.
PHTTPSpace & GetSpace()
Definition: http.h:1394
PBoolean DelResource(const PURL &url)
Delete an existing resource to the URL space.
static const PCaselessString & IfModifiedSinceTag()
const PMultiPartList & GetMultipartFormInfo() const
Definition: http.h:983
virtual PBoolean ReadResponse()
Read a response code followed by a text string describing the response to a command.
virtual bool InternalOnCommand(PHTTPServer &server, const PHTTPConnectionInfo &conInfo, PHTTP::Commands cmd)
common code for GET and HEAD commands
202 - request accepted, but not yet completed
Definition: http.h:187
const PURL & GetURL() const
Definition: http.h:946
__inline void EndRead()
This function attempts to release the mutex for reading.
Definition: syncthrd.h:281
Definition: http.h:371
bool isProxyConnection
Definition: http.h:1004
static PHTTPClientAuthentication * ParseAuthenticationRequired(bool isProxy, const PMIMEInfo &line, PString &errorMsg)
static const PCaselessString & WebSocketVersionTag()
virtual void SendData(PHTTPRequest &request)
Send the data associated with a command.
PURL url
Definition: http.h:1000
bool qopAuth
Definition: http.h:434
502 - error whilst acting as gateway
Definition: http.h:213
unsigned GetPersistenceMaximumTransations() const
Get the maximum number of transations (GET/POST etc) for persistent connection.
Definition: http.h:976
PString GetEntityBody() const
Definition: http.h:989
virtual PBoolean Authorise(AuthObject &pdu) const
virtual PBoolean Authorise(AuthObject &pdu) const =0
static const PCaselessString & DateTag()
PString authRealm
Definition: http.h:429
Definition: http.h:168
407 - must authenticate with proxy first
Definition: http.h:205
virtual void OnLoadedText(PHTTPRequest &request, PString &text)
This is called after the text has been loaded and may be used to customise or otherwise mangle a load...
PString username
Definition: http.h:343
PMIMEInfo outMIME
MIME information used in reply.
Definition: http.h:1435
static const PCaselessString & TextPlain()
PTime m_queuedTime
Definition: http.h:1384
atomic< unsigned > m_hitCount
Count of number of times resource was accessed.
Definition: http.h:1993
A TCP/IP socket for the HyperText Transfer Protocol version 1.0.
Definition: http.h:1042
A common base class for TCP/IP socket for the HyperText Transfer Protocol version 1...
Definition: http.h:160
This object describes a HyperText Transport Protocol request.
Definition: http.h:1417
static const PCaselessString & HostTag()
PString AsString(UrlFormat fmt=FullURL) const
Convert the URL object into its string representation.
P_REMOVE_VIRTUAL(PBoolean, OnGET(PHTTPServer &, const PURL &, const PMIMEInfo &, const PHTTPConnectionInfo &), false)
Reusability
Flags to reuse of port numbers in Listen() function.
Definition: socket.h:85
Ultimate parent class for all objects in the class library.
Definition: object.h:2204
This object describes the connectiono associated with a HyperText Transport Protocol request...
Definition: http.h:937
206 - partial GET succeeded
Definition: http.h:191
Commands
Definition: http.h:166
void ClearWebSocket()
Definition: http.h:992
This class describes a Universal Resource Locator.
Definition: url.h:56
100 - Continue
Definition: http.h:183
static const PCaselessString & AllowTag()
PHTTPContentProcessor ContentProcessor
Call back to process the body of the HTTP command.
Definition: http.h:484
virtual PString GetUsername() const
Definition: http.h:326
int majorVersion
Definition: http.h:1006
virtual PString GetRealm(const PHTTPRequest &request) const =0
Get the realm or name space for the user authorisation name and password as required by the basic aut...
400 - request malformed or not understood
Definition: http.h:198
PList< PHTTPServer > m_httpServers
Definition: http.h:1404
PHTTPResource * m_resource
HTTP resource found for the request.
Definition: http.h:1441
Algorithm GetAlgorithm() const
Definition: http.h:424
virtual bool OnHEAD(const PHTTPConnectionInfo &conInfo)
Handle a HEAD command from a client.
virtual PString LoadText(PHTTPRequest &request)
Get a block of text data (eg HTML) that the resource contains.
PHTTP::Commands GetCommandCode() const
Definition: http.h:943
bool GetStale() const
Definition: http.h:426
Algorithm algorithm
Definition: http.h:431
PHTTPDirectory(const PURL &url, const PDirectory &dir)
virtual PMIMEInfo & GetMIME()
virtual ~PHTTPContentProcessor()
Definition: http.h:286
PString m_authorisationRealm
Definition: http.h:2380
virtual PString ReadEntityBody()
Read the entity body associated with a HTTP request, and close the socket if not a persistent connect...
This object describes a HyperText Transport Protocol resource which is a single file.
Definition: http.h:2224
const PTime & GetServiceStartTime() const
Get start of service time.
Definition: http.h:1292
void SetAuthenticationInfo(const PString &userName, const PString &password)
Set authentication paramaters to be use for retreiving documents.
201 - new resource created: entity body contains URL
Definition: http.h:186
const PMIMEInfo & inMIME
Extra MIME information in command.
Definition: http.h:1432
virtual void SetAuthRealm(const PString &)
Definition: http.h:332
virtual PBoolean Validate(const PHTTPRequest &request, const PString &authInfo) const
Validate the user and password provided by the remote HTTP client for the realm specified by the clas...
virtual PString GetMethod()
504 - timeout whilst talking to gateway
Definition: http.h:215