PTLib  Version 2.10.11
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: 29065 $
27  * $Author: rjongbloed $
28  * $Date: 2013-02-11 18:26:26 -0600 (Mon, 11 Feb 2013) $
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
170  GET, HEAD, POST,
171  // HTTP/1.1 commands
172  PUT, DELETE, TRACE, OPTIONS,
173  // HTTPS command
175  NumCommands
176  };
177 
178  enum StatusCode {
179  Continue = 100,
181  RequestOK = 200,
188  MultipleChoices = 300,
194  BadRequest = 400,
207  InternalServerError = 500,
211  GatewayTimeout
212  };
213 
214  // Common MIME header tags
215  static const PCaselessString & AllowTag();
216  static const PCaselessString & AuthorizationTag();
217  static const PCaselessString & ContentEncodingTag();
218  static const PCaselessString & ContentLengthTag();
220  static const PCaselessString & DateTag();
221  static const PCaselessString & ExpiresTag();
222  static const PCaselessString & FromTag();
223  static const PCaselessString & IfModifiedSinceTag();
224  static const PCaselessString & LastModifiedTag();
225  static const PCaselessString & LocationTag();
226  static const PCaselessString & PragmaTag();
227  static const PCaselessString & PragmaNoCacheTag();
228  static const PCaselessString & RefererTag();
229  static const PCaselessString & ServerTag();
230  static const PCaselessString & UserAgentTag();
231  static const PCaselessString & WWWAuthenticateTag();
232  static const PCaselessString & MIMEVersionTag();
233  static const PCaselessString & ConnectionTag();
234  static const PCaselessString & KeepAliveTag();
235  static const PCaselessString & TransferEncodingTag();
236  static const PCaselessString & ChunkedTag();
237  static const PCaselessString & ProxyConnectionTag();
238  static const PCaselessString & ProxyAuthorizationTag();
239  static const PCaselessString & ProxyAuthenticateTag();
240  static const PCaselessString & ForwardedTag();
241  static const PCaselessString & SetCookieTag();
242  static const PCaselessString & CookieTag();
243 
244  protected:
247  PHTTP();
248 
260  virtual PINDEX ParseResponse(
261  const PString & line
262  );
263 };
264 
265 
266 
268 {
270  public:
271  class AuthObject {
272  public:
273  virtual ~AuthObject() { }
274  virtual PMIMEInfo & GetMIME() = 0;
275  virtual PString GetURI() = 0;
276  virtual PString GetEntityBody() = 0;
277  virtual PString GetMethod() = 0;
278  };
279 
281 
282  virtual Comparison Compare(
283  const PObject & other
284  ) const;
285 
286  virtual PBoolean Parse(
287  const PString & auth,
288  PBoolean proxy
289  ) = 0;
290 
291  virtual PBoolean Authorise(
292  AuthObject & pdu
293  ) const = 0;
294 
295  virtual PBoolean IsProxy() const { return isProxy; }
296 
297  virtual PString GetUsername() const { return username; }
298  virtual PString GetPassword() const { return password; }
299  virtual PString GetAuthRealm() const { return PString::Empty(); }
300 
301  virtual void SetUsername(const PString & user) { username = user; }
302  virtual void SetPassword(const PString & pass) { password = pass; }
303  virtual void SetAuthRealm(const PString &) { }
304 
305  PString GetAuthParam(const PString & auth, const char * name) const;
306  PString AsHex(PMessageDigest5::Code & digest) const;
307  PString AsHex(const PBYTEArray & data) const;
308 
309  static PHTTPClientAuthentication * ParseAuthenticationRequired(bool isProxy, const PMIMEInfo & line, PString & errorMsg);
310 
311 
312  protected:
316 };
317 
319 
321 {
322  public:
324  const PString & cmdName,
325  const PString & uri,
326  PMIMEInfo & mime,
327  const PString & body
328  );
329  virtual PMIMEInfo & GetMIME();
330  virtual PString GetURI();
331  virtual PString GetEntityBody();
332  virtual PString GetMethod();
333  protected:
338 };
339 
341 
343 {
345  public:
347 
348  virtual Comparison Compare(
349  const PObject & other
350  ) const;
351 
352  virtual PBoolean Parse(
353  const PString & auth,
354  PBoolean proxy
355  );
356 
357  virtual PBoolean Authorise(
358  AuthObject & pdu
359  ) const;
360 };
361 
363 
365 {
367  public:
369 
372  );
373 
374  virtual Comparison Compare(
375  const PObject & other
376  ) const;
377 
378  virtual PBoolean Parse(
379  const PString & auth,
380  PBoolean proxy
381  );
382 
383  virtual PBoolean Authorise(
384  AuthObject & pdu
385  ) const;
386 
387  virtual PString GetAuthRealm() const { return authRealm; }
388  virtual void SetAuthRealm(const PString & r) { authRealm = r; }
389 
390  enum Algorithm {
392  NumAlgorithms
393  };
394  const PString & GetNonce() const { return nonce; }
395  Algorithm GetAlgorithm() const { return algorithm; }
396  const PString & GetOpaque() const { return opaque; }
397  bool GetStale() const { return stale; }
398 
399  protected:
404 
405  bool qopAuth;
407  bool stale;
410 };
411 
412 
414 // PHTTPClient
415 
436 class PHTTPClient : public PHTTP
437 {
439 
440  public:
442  PHTTPClient(
443  const PString & userAgentName = PString::Empty()
444  );
445 
446 
447  // New functions for class.
455  int ExecuteCommand(
456  Commands cmd,
457  const PURL & url,
458  PMIMEInfo & outMIME,
459  const PString & dataBody,
460  PMIMEInfo & replyMime
461  );
462  int ExecuteCommand(
463  const PString & cmdName,
464  const PURL & url,
465  PMIMEInfo & outMIME,
466  const PString & dataBody,
467  PMIMEInfo & replyMime
468  );
469 
471  bool WriteCommand(
472  Commands cmd,
473  const PString & url,
474  PMIMEInfo & outMIME,
475  const PString & dataBody
476  );
477  bool WriteCommand(
478  const PString & cmdName,
479  const PString & url,
480  PMIMEInfo & outMIME,
481  const PString & dataBody
482  );
483 
485  bool ReadResponse(
486  PMIMEInfo & replyMIME
487  );
488 
490  bool ReadContentBody(
491  PMIMEInfo & replyMIME
492  );
493 
495  bool ReadContentBody(
496  PMIMEInfo & replyMIME,
497  PString & body
498  );
499 
501  bool ReadContentBody(
502  PMIMEInfo & replyMIME,
503  PBYTEArray & body
504  );
505 
506 
513  bool GetDocument(
514  const PURL & url,
515  PMIMEInfo & outMIME,
516  PMIMEInfo & replyMIME
517  );
518  bool GetDocument(
519  const PURL & url,
520  PMIMEInfo & replyMIME
521  );
522 
530  bool GetTextDocument(
531  const PURL & url,
532  PString & document,
533  const PString & contentType = PString::Empty()
534  );
535 
541  bool GetHeader(
542  const PURL & url,
543  PMIMEInfo & outMIME,
544  PMIMEInfo & replyMIME
545  );
546 
547 
553  bool PostData(
554  const PURL & url,
555  const PStringToString & data
556  );
557 
563  bool PostData(
564  const PURL & url,
565  PMIMEInfo & outMIME,
566  const PString & data
567  );
568 
575  bool PostData(
576  const PURL & url,
577  PMIMEInfo & outMIME,
578  const PString & data,
579  PMIMEInfo & replyMIME
580  );
581 
587  bool PostData(
588  const PURL & url,
589  PMIMEInfo & outMIME,
590  const PString & data,
591  PMIMEInfo & replyMIME,
592  PString & replyBody
593  );
594 
600  bool PutTextDocument(
601  const PURL & url,
602  const PString & document,
603  const PString & contentType = PMIMEInfo::TextPlain()
604  );
605 
611  bool PutDocument(
612  const PURL & url,
613  PMIMEInfo & outMIME,
614  PMIMEInfo & replyMIME
615  );
616 
622  bool DeleteDocument(
623  const PURL & url
624  );
625 
628  void SetAuthenticationInfo(
629  const PString & userName,
630  const PString & password
631  );
632 
635  bool persist = true
636  ) { m_persist = persist; }
637 
639  bool GetPersistent() const { return m_persist; }
640 
641  protected:
642  bool AssureConnect(const PURL & url, PMIMEInfo & outMIME);
643  bool InternalReadContentBody(
644  PMIMEInfo & replyMIME,
645  PAbstractArray * body
646  );
647 
649  bool m_persist;
653 };
654 
655 
657 // PHTTPConnectionInfo
658 
659 class PHTTPServer;
660 
666 {
668  public:
670 
671  PHTTP::Commands GetCommandCode() const { return commandCode; }
672  const PString & GetCommandName() const { return commandName; }
673 
674  const PURL & GetURL() const { return url; }
675 
676  const PMIMEInfo & GetMIME() const { return mimeInfo; }
677  void SetMIME(const PString & tag, const PString & value);
678 
679  PBoolean IsCompatible(int major, int minor) const;
680 
681  bool IsPersistent() const { return isPersistent; }
682  bool WasPersistent() const { return wasPersistent; }
683  bool IsProxyConnection() const { return isProxyConnection; }
684  int GetMajorVersion() const { return majorVersion; }
685  int GetMinorVersion() const { return minorVersion; }
686 
687  long GetEntityBodyLength() const { return entityBodyLength; }
688 
691  PTimeInterval GetPersistenceTimeout() const { return persistenceTimeout; }
692 
695  void SetPersistenceTimeout(const PTimeInterval & t) { persistenceTimeout = t; }
696 
700  unsigned GetPersistenceMaximumTransations() const { return persistenceMaximum; }
701 
705  void SetPersistenceMaximumTransations(unsigned m) { persistenceMaximum = m; }
706 
708  { return m_multipartFormInfo; }
709 
711  { m_multipartFormInfo.RemoveAll(); }
712 
713  PString GetEntityBody() const { return entityBody; }
714 
715  protected:
716  PBoolean Initialise(PHTTPServer & server, PString & args);
717  bool DecodeMultipartFormInfo() { return mimeInfo.DecodeMultiPartList(m_multipartFormInfo, entityBody); }
718 
728  PString entityBody; // original entity body (POST only)
733 
734  friend class PHTTPServer;
735 };
736 
737 
739 // PHTTPServer
740 
762 class PHTTPServer : public PHTTP
763 {
765 
766  public:
774  PHTTPServer();
775  PHTTPServer(
776  const PHTTPSpace & urlSpace
777  );
778 
779 
780  // New functions for class.
786  virtual PString GetServerName() const;
787 
793  PHTTPSpace & GetURLSpace() { return urlSpace; }
794 
796  void SetURLSpace(
797  const PHTTPSpace & space
798  );
799 
800 
810  virtual PBoolean ProcessCommand();
811 
823  virtual PBoolean OnGET(
824  const PURL & url,
825  const PMIMEInfo & info,
826  const PHTTPConnectionInfo & conInfo
827  );
828 
829 
830 
842  virtual PBoolean OnHEAD(
843  const PURL & url,
844  const PMIMEInfo & info,
845  const PHTTPConnectionInfo & conInfo
846  );
847 
859  virtual PBoolean OnPOST(
860  const PURL & url,
861  const PMIMEInfo & info,
862  const PStringToString & data,
863  const PHTTPConnectionInfo & conInfo
864  );
865 
878  virtual PBoolean OnProxy(
879  const PHTTPConnectionInfo & conInfo
880  );
881 
882 
889  virtual PString ReadEntityBody();
890 
896  virtual PBoolean OnUnknown(
897  const PCaselessString & command,
898  const PHTTPConnectionInfo & connectInfo
899  );
900 
919  PBoolean StartResponse(
920  StatusCode code,
921  PMIMEInfo & headers,
922  long bodySize
923  );
924 
934  virtual PBoolean OnError(
935  StatusCode code,
936  const PCaselessString & extra,
937  const PHTTPConnectionInfo & connectInfo
938  );
939 
942  void SetDefaultMIMEInfo(
943  PMIMEInfo & info,
944  const PHTTPConnectionInfo & connectInfo
945  );
946 
949  PHTTPConnectionInfo & GetConnectionInfo() { return connectInfo; }
950 
951  protected:
952  void Construct();
953 
958 };
959 
960 
962 // PHTTPRequest
963 
968 class PHTTPRequest : public PObject
969 {
971 
972  public:
973  PHTTPRequest(
974  const PURL & url,
975  const PMIMEInfo & inMIME,
976  const PMultiPartList & multipartFormInfo,
978  PHTTPServer & server
979  );
980 
982  const PURL & url;
983  const PMIMEInfo & inMIME;
988  PINDEX contentSize;
991  WORD localPort;
993 };
994 
995 
997 // PHTTPAuthority
998 
1002 class PHTTPAuthority : public PObject
1003 {
1005 
1006  public:
1007  // New functions for class.
1014  virtual PString GetRealm(
1015  const PHTTPRequest & request
1016  ) const = 0;
1017 
1024  virtual PBoolean Validate(
1025  const PHTTPRequest & request,
1026  const PString & authInfo
1027  ) const = 0;
1028 
1038  virtual PBoolean IsActive() const;
1039 
1040  protected:
1041  static void DecodeBasicAuthority(
1042  const PString & authInfo,
1043  PString & username,
1044  PString & password
1045  );
1046 };
1047 
1048 
1050 // PHTTPSimpleAuth
1051 
1056 {
1058 
1059  public:
1061  const PString & realm,
1062  const PString & username,
1063  const PString & password
1064  );
1065  // Construct the simple authorisation structure.
1066 
1067 
1068  // Overrides from class PObject.
1076  virtual PObject * Clone() const;
1077 
1078 
1079  // Overrides from class PHTTPAuthority.
1086  virtual PString GetRealm(
1087  const PHTTPRequest & request
1088  ) const;
1089 
1096  virtual PBoolean Validate(
1097  const PHTTPRequest & request,
1098  const PString & authInfo
1099  ) const;
1100 
1110  virtual PBoolean IsActive() const;
1111 
1117  const PString & GetUserName() const { return username; }
1118 
1124  const PString & GetPassword() const { return password; }
1125 
1126 
1127  protected:
1131 };
1132 
1133 
1135 // PHTTPMultiSimpAuth
1136 
1141 {
1143 
1144  public:
1146  const PString & realm
1147  );
1149  const PString & realm,
1150  const PStringToString & userList
1151  );
1152  // Construct the simple authorisation structure.
1153 
1154 
1155  // Overrides from class PObject.
1163  virtual PObject * Clone() const;
1164 
1165 
1166  // Overrides from class PHTTPAuthority.
1173  virtual PString GetRealm(
1174  const PHTTPRequest & request
1175  ) const;
1176 
1183  virtual PBoolean Validate(
1184  const PHTTPRequest & request,
1185  const PString & authInfo
1186  ) const;
1187 
1197  virtual PBoolean IsActive() const;
1198 
1204  void AddUser(
1205  const PString & username,
1206  const PString & password
1207  );
1208 
1209 
1210  protected:
1213 };
1214 
1215 
1217 // PHTTPResource
1218 
1222 class PHTTPResource : public PObject
1223 {
1225 
1226  protected:
1227  PHTTPResource(
1228  const PURL & url
1229  );
1230  PHTTPResource(
1231  const PURL & url,
1232  const PHTTPAuthority & auth
1233  );
1234  PHTTPResource(
1235  const PURL & url,
1236  const PString & contentType
1237  );
1238  PHTTPResource(
1239  const PURL & url,
1240  const PString & contentType,
1241  const PHTTPAuthority & auth
1242  );
1243  // Create a new HTTP Resource.
1244 
1245 
1246  public:
1247  virtual ~PHTTPResource();
1248  // Destroy the HTTP Resource.
1249 
1250 
1251  // New functions for class.
1257  const PURL & GetURL() const { return baseURL; }
1258 
1264  const PString & GetContentType() const { return contentType; }
1265 
1272  PHTTPAuthority * GetAuthority() const { return authority; }
1273 
1276  void SetAuthority(
1277  const PHTTPAuthority & auth
1278  );
1279 
1282  void ClearAuthority();
1283 
1290  DWORD GetHitCount() const { return hitCount; }
1291 
1292  void ClearHitCount() { hitCount = 0; }
1293  // Clear the hit count for the resource.
1294 
1295 
1307  virtual PBoolean OnGET(
1308  PHTTPServer & server,
1309  const PURL & url,
1310  const PMIMEInfo & info,
1311  const PHTTPConnectionInfo & conInfo
1312  );
1313 
1323  virtual PBoolean OnGETData(
1324  PHTTPServer & server,
1325  const PURL & url,
1326  const PHTTPConnectionInfo & connectInfo,
1327  PHTTPRequest & request
1328  );
1329 
1341  virtual PBoolean OnHEAD(
1342  PHTTPServer & server,
1343  const PURL & url,
1344  const PMIMEInfo & info,
1345  const PHTTPConnectionInfo & conInfo
1346  );
1347 
1359  virtual PBoolean OnPOST(
1360  PHTTPServer & server,
1361  const PURL & url,
1362  const PMIMEInfo & info,
1363  const PStringToString & data,
1364  const PHTTPConnectionInfo & conInfo
1365  );
1366 
1376  virtual PBoolean OnPOSTData(
1377  PHTTPRequest & request,
1378  const PStringToString & data
1379  );
1380 
1387  virtual PBoolean IsModifiedSince(
1388  const PTime & when
1389  );
1390 
1396  virtual PBoolean GetExpirationDate(
1397  PTime & when
1398  );
1399 
1407  virtual PHTTPRequest * CreateRequest(
1408  const PURL & url,
1409  const PMIMEInfo & inMIME,
1410  const PMultiPartList & multipartFormInfo,
1411  PHTTPServer & socket
1412  );
1413 
1421  virtual PBoolean LoadHeaders(
1422  PHTTPRequest & request
1423  ) = 0;
1424 
1430  virtual void SendData(
1431  PHTTPRequest & request
1432  );
1433 
1442  virtual PBoolean LoadData(
1443  PHTTPRequest & request,
1444  PCharArray & data
1445  );
1446 
1455  virtual PString LoadText(
1456  PHTTPRequest & request
1457  );
1458 
1465  virtual void OnLoadedText(
1466  PHTTPRequest & request,
1467  PString & text
1468  );
1469 
1478  virtual PBoolean Post(
1479  PHTTPRequest & request,
1480  const PStringToString & data,
1481  PHTML & replyMessage
1482  );
1483 
1484 
1485  protected:
1488  virtual PBoolean CheckAuthority(
1489  PHTTPServer & server,
1490  const PHTTPRequest & request,
1491  const PHTTPConnectionInfo & conInfo
1492  );
1493  static PBoolean CheckAuthority(
1494  PHTTPAuthority & authority,
1495  PHTTPServer & server,
1496  const PHTTPRequest & request,
1497  const PHTTPConnectionInfo & connectInfo
1498  );
1499 
1500 
1502  virtual PBoolean OnGETOrHEAD(
1503  PHTTPServer & server,
1504  const PURL & url,
1505  const PMIMEInfo & info,
1506  const PHTTPConnectionInfo & conInfo,
1507  PBoolean isGet
1508  );
1509 
1510 
1514  volatile DWORD hitCount;
1515 };
1516 
1517 
1519 // PHTTPString
1520 
1526 {
1528 
1529  public:
1533  PHTTPString(
1534  const PURL & url // Name of the resource in URL space.
1535  );
1536  PHTTPString(
1537  const PURL & url, // Name of the resource in URL space.
1538  const PHTTPAuthority & auth // Authorisation for the resource.
1539  );
1540  PHTTPString(
1541  const PURL & url, // Name of the resource in URL space.
1542  const PString & str // String to return in this resource.
1543  );
1544  PHTTPString(
1545  const PURL & url, // Name of the resource in URL space.
1546  const PString & str, // String to return in this resource.
1547  const PString & contentType // MIME content type for the file.
1548  );
1549  PHTTPString(
1550  const PURL & url, // Name of the resource in URL space.
1551  const PString & str, // String to return in this resource.
1552  const PHTTPAuthority & auth // Authorisation for the resource.
1553  );
1554  PHTTPString(
1555  const PURL & url, // Name of the resource in URL space.
1556  const PString & str, // String to return in this resource.
1557  const PString & contentType, // MIME content type for the file.
1558  const PHTTPAuthority & auth // Authorisation for the resource.
1559  );
1560 
1561 
1562  // Overrides from class PHTTPResource
1570  virtual PBoolean LoadHeaders(
1571  PHTTPRequest & request // Information on this request.
1572  );
1573 
1582  virtual PString LoadText(
1583  PHTTPRequest & request // Information on this request.
1584  );
1585 
1586  // New functions for class.
1592  const PString & GetString() { return string; }
1593 
1597  const PString & str // New string for the resource.
1598  ) { string = str; }
1599 
1600 
1601  protected:
1603 };
1604 
1605 
1607 // PHTTPFile
1608 
1614 class PHTTPFile : public PHTTPResource
1615 {
1617 
1618  public:
1625  PHTTPFile(
1626  const PString & filename // file in file system and URL name.
1627  );
1628  PHTTPFile(
1629  const PString & filename, // file in file system and URL name.
1630  const PHTTPAuthority & auth // Authorisation for the resource.
1631  );
1632  PHTTPFile(
1633  const PURL & url, // Name of the resource in URL space.
1634  const PFilePath & file // Location of file in file system.
1635  );
1636  PHTTPFile(
1637  const PURL & url, // Name of the resource in URL space.
1638  const PFilePath & file, // Location of file in file system.
1639  const PString & contentType // MIME content type for the file.
1640  );
1641  PHTTPFile(
1642  const PURL & url, // Name of the resource in URL space.
1643  const PFilePath & file, // Location of file in file system.
1644  const PHTTPAuthority & auth // Authorisation for the resource.
1645  );
1646  PHTTPFile(
1647  const PURL & url, // Name of the resource in URL space.
1648  const PFilePath & file, // Location of file in file system.
1649  const PString & contentType, // MIME content type for the file.
1650  const PHTTPAuthority & auth // Authorisation for the resource.
1651  );
1652 
1653 
1654  // Overrides from class PHTTPResource
1660  virtual PHTTPRequest * CreateRequest(
1661  const PURL & url, // Universal Resource Locator for document.
1662  const PMIMEInfo & inMIME, // Extra MIME information in command.
1663  const PMultiPartList & multipartFormInfo,
1664  PHTTPServer & socket
1665  );
1666 
1674  virtual PBoolean LoadHeaders(
1675  PHTTPRequest & request // Information on this request.
1676  );
1677 
1683  virtual PBoolean LoadData(
1684  PHTTPRequest & request, // Information on this request.
1685  PCharArray & data // Data used in reply.
1686  );
1687 
1696  virtual PString LoadText(
1697  PHTTPRequest & request // Information on this request.
1698  );
1699 
1700 
1701  protected:
1702  PHTTPFile(
1703  const PURL & url, // Name of the resource in URL space.
1704  int dummy
1705  );
1706  // Constructor used by PHTTPDirectory
1707 
1708 
1710 };
1711 
1712 
1714 {
1716  public:
1718  const PURL & url, // Universal Resource Locator for document.
1719  const PMIMEInfo & inMIME, // Extra MIME information in command.
1720  const PMultiPartList & multipartFormInfo,
1722  PHTTPServer & server
1723  );
1724 
1726 };
1727 
1728 
1730 // PHTTPTailFile
1731 
1740 class PHTTPTailFile : public PHTTPFile
1741 {
1743 
1744  public:
1751  PHTTPTailFile(
1752  const PString & filename // file in file system and URL name.
1753  );
1754  PHTTPTailFile(
1755  const PString & filename, // file in file system and URL name.
1756  const PHTTPAuthority & auth // Authorisation for the resource.
1757  );
1758  PHTTPTailFile(
1759  const PURL & url, // Name of the resource in URL space.
1760  const PFilePath & file // Location of file in file system.
1761  );
1762  PHTTPTailFile(
1763  const PURL & url, // Name of the resource in URL space.
1764  const PFilePath & file, // Location of file in file system.
1765  const PString & contentType // MIME content type for the file.
1766  );
1767  PHTTPTailFile(
1768  const PURL & url, // Name of the resource in URL space.
1769  const PFilePath & file, // Location of file in file system.
1770  const PHTTPAuthority & auth // Authorisation for the resource.
1771  );
1772  PHTTPTailFile(
1773  const PURL & url, // Name of the resource in URL space.
1774  const PFilePath & file, // Location of file in file system.
1775  const PString & contentType, // MIME content type for the file.
1776  const PHTTPAuthority & auth // Authorisation for the resource.
1777  );
1778 
1779 
1780  // Overrides from class PHTTPResource
1788  virtual PBoolean LoadHeaders(
1789  PHTTPRequest & request // Information on this request.
1790  );
1791 
1797  virtual PBoolean LoadData(
1798  PHTTPRequest & request, // Information on this request.
1799  PCharArray & data // Data used in reply.
1800  );
1801 };
1802 
1803 
1805 // PHTTPDirectory
1806 
1820 {
1822 
1823  public:
1825  const PURL & url,
1826  const PDirectory & dir
1827  );
1829  const PURL & url,
1830  const PDirectory & dir,
1831  const PHTTPAuthority & auth
1832  );
1833  // Construct a new directory resource for HTTP.
1834 
1835 
1836  // Overrides from class PHTTPResource
1842  virtual PHTTPRequest * CreateRequest(
1843  const PURL & url, // Universal Resource Locator for document.
1844  const PMIMEInfo & inMIME, // Extra MIME information in command.
1845  const PMultiPartList & multipartFormInfo,
1846  PHTTPServer & socket
1847  );
1848 
1856  virtual PBoolean LoadHeaders(
1857  PHTTPRequest & request
1858  );
1859 
1868  virtual PString LoadText(
1869  PHTTPRequest & request
1870  );
1871 
1880  void EnableAuthorisation(const PString & realm);
1881 
1884  void AllowDirectories(PBoolean enable = true);
1885 
1886  protected:
1887  PBoolean CheckAuthority(
1888  PHTTPServer & server, // Server to send response to.
1889  const PHTTPRequest & request, // Information on this request.
1890  const PHTTPConnectionInfo & conInfo // Information on the connection
1891  );
1892 
1893  PBoolean FindAuthorisations(const PDirectory & dir, PString & realm, PStringToString & authorisations);
1894 
1898 };
1899 
1900 
1902 {
1904  public:
1906  const PURL & url, // Universal Resource Locator for document.
1907  const PMIMEInfo & inMIME, // Extra MIME information in command.
1908  const PMultiPartList & multipartFormInfo,
1910  PHTTPServer & server
1911  );
1912 
1915 };
1916 
1917 
1918 PFACTORY_LOAD(PURL_HttpLoader);
1919 
1920 
1921 #endif // P_HTTP
1922 
1923 #endif // PTLIB_HTTP_H
1924 
1925 
1926 // End Of File ///////////////////////////////////////////////////////////////
void SetPersistenceMaximumTransations(unsigned m)
Set the maximum number of transations (GET/POST etc) for persistent connection.
Definition: http.h:705
PString commandName
Definition: http.h:720
void SetString(const PString &str)
Set the string to be returned by this resource.
Definition: http.h:1596
void EndRead()
This function attempts to release the mutex for reading.
Definition: http.h:364
virtual void SetPassword(const PString &pass)
Definition: http.h:302
const PURL & GetURL() const
Definition: http.h:674
PHTTPSpace::Node * root
static const PCaselessString & ContentTypeTag()
This class contains the Multipurpose Internet Mail Extensions parameters and variables.
Definition: mime.h:52
Definition: mime.h:295
PString entityBody
Definition: http.h:728
volatile DWORD hitCount
COunt of number of times resource was accessed.
Definition: http.h:1514
PString & operator=(const PString &str)
Assign the string to the current object.
301 - resource moved permanently: location field has new URL
Definition: http.h:189
This class represents a disk file.
Definition: file.h:60
PString username
Definition: http.h:1129
Definition: http.h:136
This class defines an arbitrary time interval to millisecond accuracy.
Definition: timeint.h:55
unsigned GetPersistenceMaximumTransations() const
Get the maximum number of transations (GET/POST etc) for persistent connection.
Definition: http.h:700
Array of characters.
Definition: array.h:551
412 - no Range header for true Unless
Definition: http.h:206
#define PCLASSINFO(cls, par)
Declare all the standard PTLib class information.
Definition: object.h:1049
virtual PString GetPassword() const
Definition: http.h:298
PString m_uri
Definition: http.h:335
PSORTED_LIST(ChildList, Node)
This class describes the simplest authorisation mechanism for a Universal Resource Locator...
Definition: http.h:1055
PHTTPResource * resource
Definition: http.h:145
void ClearHitCount()
Definition: http.h:1292
PString password
Definition: http.h:1130
This abstract class describes the authorisation mechanism for a Universal Resource Locator...
Definition: http.h:1002
This class defines an absolute time and date.
Definition: ptime.h:53
void StartWrite() const
This function attempts to acquire the mutex for writing.
Definition: http.h:122
virtual void SetUsername(const PString &user)
Definition: http.h:301
PFilePath realPath
Definition: http.h:1914
503 - server temporarily unable to service request
Definition: http.h:210
void StartWrite()
This function attempts to acquire the mutex for writing.
Algorithm
Definition: http.h:390
void StartRead()
This function attempts to acquire the mutex for reading.
const PMultiPartList & multipartFormInfo
multipart form information, if any
Definition: http.h:984
203 - not definitive entity header
Definition: http.h:184
205 - contents have been reset
Definition: http.h:186
PHTTP::Commands commandCode
Definition: http.h:719
Definition: http.h:267
Generate error if resource already exists.
Definition: http.h:68
303 - see other URL
Definition: http.h:191
This is a dictionary collection class of PString objects, keyed by another string.
Definition: pstring.h:2784
This class describes a full description for a file on the particular platform.
Definition: filepath.h:65
PBoolean allowDirectoryListing
Definition: http.h:1897
PBoolean isProxy
Definition: http.h:313
PString m_password
Definition: http.h:651
Comparison
Result of the comparison operation performed by the Compare() function.
Definition: object.h:1184
PHTTPAuthority * authority
Authorisation method for the resource.
Definition: http.h:1513
PHTTPResource * FindResource(const PURL &url)
Locate the resource specified by the URL in the URL name space.
This class is a variation of a string that ignores case.
Definition: pstring.h:1708
PString string
Definition: http.h:1602
void EndWrite() const
This function attempts to release the mutex for writing.
Definition: http.h:127
PFile file
Definition: http.h:1725
PMIMEInfo & m_mime
Definition: http.h:336
PString m_userAgentName
Definition: http.h:648
PHTTPSpace & GetURLSpace()
Get the name space being used by the HTTP server socket.
Definition: http.h:793
Definition: http.h:1901
virtual void SetAuthRealm(const PString &r)
Definition: http.h:388
PBoolean AddResource(PHTTPResource *resource, AddOptions overwrite=ErrorOnExist)
Add a new resource to the URL space.
bool wasPersistent
Definition: http.h:724
Definition: http.h:170
bool stale
Definition: http.h:407
Overwrite the existing resource at URL location.
Definition: http.h:69
501 - server does not implement request
Definition: http.h:208
Definition: http.h:1713
PString entityBody
original entity body (POST only)
Definition: http.h:987
This object describes a HyperText Transport Protocol resource which is a single file.
Definition: http.h:1614
virtual PString GetAuthRealm() const
Definition: http.h:299
Node * parent
Definition: http.h:143
101 - upgrade allowed
Definition: http.h:180
This object describes a HyperText Transport Protocol resource which is a string kept in memory...
Definition: http.h:1525
unsigned persistenceMaximum
Definition: http.h:731
PString fakeIndex
Definition: http.h:1913
PHTTPClientAuthentication * m_authentication
Definition: http.h:652
PString realm
Definition: http.h:1128
401 - request requires authentication
Definition: http.h:195
bool GetPersistent() const
Get persistent connection mode.
Definition: http.h:639
This object describes a HyperText Transport Protocol resource.
Definition: http.h:1222
bool IsPersistent() const
Definition: http.h:681
404 - resource cannot be found
Definition: http.h:198
const PURL & GetURL() const
Get the URL for this resource.
Definition: http.h:1257
This object describes a HyperText Transport Protocol resource which is a set of files in a directory...
Definition: http.h:1819
A TCP/IP socket for process/application layer high level protocols.
Definition: inetprot.h:62
This class contains a variable length array of arbitrary memory blocks.
Definition: array.h:67
302 - resource moved temporarily: location field has new URL
Definition: http.h:190
ChildList children
Definition: http.h:144
long entityBodyLength
Definition: http.h:729
void EndRead() const
This function attempts to release the mutex for reading.
Definition: http.h:117
PHTTP::Commands GetCommandCode() const
Definition: http.h:671
BOOL PBoolean
Definition: object.h:102
Class to represent a directory in the operating system file system.
Definition: pdirect.h:182
402 - reserved
Definition: http.h:196
PHTTPConnectionInfo & GetConnectionInfo()
Get the connection info for this connection.
Definition: http.h:949
PTimeInterval GetPersistenceTimeout() const
Get the maximum time a persistent connection may persist.
Definition: http.h:691
Definition: http.h:320
const PString & GetPassword() const
Get the password allocated to this simple authorisation.
Definition: http.h:1124
Array of unsigned characters.
Definition: array.h:670
Node(const PString &name, Node *parentNode)
PString password
Definition: http.h:315
bool GetStale() const
Definition: http.h:397
This class implements an integer that can be atomically incremented and decremented in a thread-safe ...
Definition: critsec.h:171
405 - not allowed on this resource
Definition: http.h:199
410 - resource gone away
Definition: http.h:204
const PURL & url
Universal Resource Locator for document.
Definition: http.h:982
bool DecodeMultipartFormInfo()
Definition: http.h:717
PINDEX contentSize
Size of the body of the resource data.
Definition: http.h:988
int minorVersion
Definition: http.h:727
PIPSocket::Address localAddr
IP address of local interface for request.
Definition: http.h:990
const PString & GetString()
Get the string for this resource.
Definition: http.h:1592
A TCP/IP socket for the HyperText Transfer Protocol version 1.0.
Definition: http.h:436
PFACTORY_LOAD(PURL_HttpLoader)
PURL baseURL
Base URL for the resource, may accept URLS with a longer hierarchy.
Definition: http.h:1511
204 - no new information
Definition: http.h:185
int GetMinorVersion() const
Definition: http.h:685
DWORD GetHitCount() const
Get the current hit count for the resource.
Definition: http.h:1290
PString GetEntityBody() const
Definition: http.h:713
virtual PBoolean IsProxy() const
Definition: http.h:295
void ResetMultipartFormInfo()
Definition: http.h:710
bool m_persist
Definition: http.h:649
PHTTPAuthority * GetAuthority() const
Get the current authority for the resource.
Definition: http.h:1272
PHTTPSpace urlSpace
Definition: http.h:954
PString cnonce
Definition: http.h:408
PString authorisationRealm
Definition: http.h:1896
virtual ~AuthObject()
Definition: http.h:273
PIPSocket::Address origin
IP address of origin host for request.
Definition: http.h:989
PReadWriteMutex * mutex
Definition: http.h:132
void SetPersistenceTimeout(const PTimeInterval &t)
Set the maximum time a persistent connection may persist.
Definition: http.h:695
305 - proxy redirect
Definition: http.h:193
PDirectory basePath
Definition: http.h:1895
PString opaque
Definition: http.h:403
PString m_method
Definition: http.h:334
The character string class.
Definition: pstring.h:108
PHTTPConnectionInfo connectInfo
Definition: http.h:955
PAtomicInteger nonceCount
Definition: http.h:409
409 - resource conflict on action
Definition: http.h:203
int GetMajorVersion() const
Definition: http.h:684
virtual Comparison Compare(const PObject &obj) const
Get the relative rank of the two strings.
static PString Empty()
Return an empty string.
PFilePath filePath
Definition: http.h:1709
WORD localPort
Port number of local server for request.
Definition: http.h:991
PTimeInterval persistenceTimeout
Definition: http.h:730
#define PCONTAINERINFO(cls, par)
Macro to declare funtions required in a container.
Definition: contain.h:343
411 - no Content-Length
Definition: http.h:205
304 - document has not been modified
Definition: http.h:192
const PString & GetCommandName() const
Definition: http.h:672
void StartRead() const
This function attempts to acquire the mutex for reading.
Definition: http.h:112
PString nonce
Definition: http.h:401
const PMIMEInfo & GetMIME() const
Definition: http.h:676
PHTTP::StatusCode code
Status code for OnError() reply.
Definition: http.h:985
const PMultiPartList & GetMultipartFormInfo() const
Definition: http.h:707
Abstract class to embody the base functionality of a container.
Definition: contain.h:104
This class describes the simple authorisation mechanism for a Universal Resource Locator, a fixed realm, multiple usernames and passwords.
Definition: http.h:1140
bool isPersistent
Definition: http.h:723
static const PCaselessString & ContentTypeTag()
Definition: http.h:219
AddOptions
Definition: http.h:67
This class describes a name space that a Universal Resource Locator operates in.
Definition: http.h:58
void SetPersistent(bool persist=true)
Set persistent connection mode.
Definition: http.h:634
This class describes a HyperText markup Language string as used by the World Wide Web and the PURL an...
Definition: html.h:49
Definition: http.h:174
PMIMEInfo mimeInfo
Definition: http.h:722
PHTTPSpace()
Constructor for HTTP URL Name Space.
const PString & GetContentType() const
Get the current content type for the resource.
Definition: http.h:1264
Template class for generic factories of an abstract class.
Definition: pfactory.h:144
Definition: http.h:172
A class describing an IP address.
Definition: ipsock.h:75
virtual PString GetUsername() const
Definition: http.h:297
PFactory< PHTTPClientAuthentication > PHTTPClientAuthenticationFactory
Definition: http.h:318
PMultiPartList m_multipartFormInfo
Definition: http.h:732
const PString & GetOpaque() const
Definition: http.h:396
bool qopAuthInt
Definition: http.h:406
void EndWrite()
This function attempts to release the mutex for writing.
PString m_body
Definition: http.h:337
PHTTPServer & server
Server channel that request initiated on.
Definition: http.h:981
403 - request is refused due to unsufficient authorisation
Definition: http.h:197
StatusCode
Definition: http.h:178
PString m_userName
Definition: http.h:650
408 - server timeout on request
Definition: http.h:202
406 - encoding not acceptable
Definition: http.h:200
This class defines a thread synchronisation object.
Definition: syncthrd.h:251
PString contentType
MIME content type for the resource.
Definition: http.h:1512
PBoolean DelResource(const PURL &url)
Delete an existing resource to the URL space.
202 - request accepted, but not yet completed
Definition: http.h:183
bool WasPersistent() const
Definition: http.h:682
virtual PBoolean SetSize(PINDEX newSize)
Set the size of the string.
Definition: http.h:342
bool isProxyConnection
Definition: http.h:725
PURL url
Definition: http.h:721
bool qopAuth
Definition: http.h:405
502 - error whilst acting as gateway
Definition: http.h:209
unsigned transactionCount
Definition: http.h:956
PTimeInterval nextTimeout
Definition: http.h:957
PString authRealm
Definition: http.h:400
407 - must authenticate with proxy first
Definition: http.h:201
PString username
Definition: http.h:314
PMIMEInfo outMIME
MIME information used in reply.
Definition: http.h:986
static const PCaselessString & TextPlain()
A TCP/IP socket for the HyperText Transfer Protocol version 1.0.
Definition: http.h:762
bool IsProxyConnection() const
Definition: http.h:683
A common base class for TCP/IP socket for the HyperText Transfer Protocol version 1...
Definition: http.h:162
This object describes a HyperText Transport Protocol request.
Definition: http.h:968
Ultimate parent class for all objects in the class library.
Definition: object.h:1118
This object describes the connectiono associated with a HyperText Transport Protocol request...
Definition: http.h:665
206 - partial GET succeeded
Definition: http.h:187
PString realm
Definition: http.h:1211
Commands
Definition: http.h:168
This class describes a Universal Resource Locator.
Definition: url.h:54
long GetEntityBodyLength() const
Definition: http.h:687
virtual PString GetAuthRealm() const
Definition: http.h:387
int majorVersion
Definition: http.h:726
virtual PObject * Clone() const
Make a complete duplicate of the string.
Algorithm GetAlgorithm() const
Definition: http.h:395
PHTTPResource * m_resource
HTTP resource found for the request.
Definition: http.h:992
Definition: cypher.h:341
Algorithm algorithm
Definition: http.h:402
This object describes a HyperText Transport Protocol resource which is a single file.
Definition: http.h:1740
const PString & GetUserName() const
Get the user name allocated to this simple authorisation.
Definition: http.h:1117
PStringToString users
Definition: http.h:1212
201 - new resource created: entity body contains URL
Definition: http.h:182
const PMIMEInfo & inMIME
Extra MIME information in command.
Definition: http.h:983
const PString & GetNonce() const
Definition: http.h:394
virtual void SetAuthRealm(const PString &)
Definition: http.h:303