4 * HyperText Transport Protocol classes.
6 * Portable Windows Library
8 * Copyright (c) 1993-2002 Equivalence Pty. Ltd.
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/
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
20 * The Original Code is Portable Windows Library.
22 * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
24 * Contributor(s): ______________________________________.
27 * Revision 1.61 2007/04/10 05:08:46 rjongbloed
28 * Fixed issue with use of static C string variables in DLL environment,
29 * must use functional interface for correct initialisation.
31 * Revision 1.60 2005/11/30 12:47:37 csoutheren
32 * Removed tabs, reformatted some code, and changed tags for Doxygen
34 * Revision 1.59 2005/01/03 12:48:41 csoutheren
35 * Added new configure options and ability to disable/enable modules
37 * Revision 1.58 2004/10/23 11:34:59 ykiryanov
38 * Added ifdef _WIN32_WCE for PocketPC 2003 SDK port
40 * Revision 1.57 2002/12/03 22:37:36 robertj
41 * Removed get document that just returns a content length as the chunked
42 * transfer encoding makes this very dangerous.
43 * Added GetTextDocument() to get a URL content into a PString.
44 * Added a version pf PostData() that gets the reponse content into a PString.
45 * Added ReadContentBody() that takes a PString, not just PBYTEArray.
47 * Revision 1.56 2002/11/06 22:47:23 robertj
48 * Fixed header comment (copyright etc)
50 * Revision 1.55 2002/10/10 04:43:43 robertj
51 * VxWorks port, thanks Martijn Roest
53 * Revision 1.54 2002/10/02 08:54:34 craigs
54 * Added support for XMLRPC server
56 * Revision 1.53 2002/09/16 01:08:59 robertj
57 * Added #define so can select if #pragma interface/implementation is used on
58 * platform basis (eg MacOS) rather than compiler, thanks Robert Monaghan.
60 * Revision 1.52 2002/05/08 05:38:53 robertj
61 * Added PHTTPTailFile resource to do a unix 'tail -f' of a file.
63 * Revision 1.51 2001/10/31 01:34:47 robertj
64 * Added extra const for constant HTTP tag name strings.
65 * Changes to support HTTP v1.1 chunked transfer encoding.
67 * Revision 1.50 2001/10/03 00:26:34 robertj
68 * Upgraded client to HTTP/1.1 and for chunked mode entity bodies.
70 * Revision 1.49 2001/09/28 08:55:15 robertj
71 * More changes to support restartable PHTTPClient
73 * Revision 1.48 2001/09/28 00:42:54 robertj
74 * Added automatic setting of some outward MIME fields.
75 * Added "user agent" string field for automatic inclusion.
76 * Added function to read the contents of the HTTP request.
78 * Revision 1.47 2001/08/28 06:44:30 craigs
79 * Added ability to override PHTTPServer creation
81 * Revision 1.46 2001/03/14 01:49:54 craigs
82 * Added ability to handle multi-part form POST commands
84 * Revision 1.45 2001/02/22 05:26:47 robertj
85 * Added "nicer" version of GetDocument in HTTP client class.
87 * Revision 1.44 2001/01/15 06:16:53 robertj
88 * Set HTTP resource members to private to assure are not modified by
89 * dscendents in non-threadsafe manner.
91 * Revision 1.43 2000/09/04 03:57:58 robertj
92 * Added ability to change the persistent connection parameters (timeout etc).
94 * Revision 1.42 2000/05/02 08:28:10 craigs
95 * Removed "memory leaks" caused by brain-dead GNU linker
97 * Revision 1.41 1999/09/17 01:11:14 robertj
98 * Fixed some documentation typos.
100 * Revision 1.40 1999/05/13 04:04:04 robertj
101 * Fixed problem of initialised commandName in ConnectionInfo.
103 * Revision 1.39 1999/05/04 15:26:01 robertj
104 * Improved HTTP/1.1 compatibility (pass through user commands).
105 * Fixed problems with quicktime installer.
107 * Revision 1.38 1999/04/21 01:58:08 robertj
108 * Fixed problem with reading data for request using second form of PHTTPRequestInfo constructor.
110 * Revision 1.37 1999/03/09 08:01:46 robertj
111 * Changed comments for doc++ support (more to come).
113 * Revision 1.36 1999/02/16 08:07:10 robertj
114 * MSVC 6.0 compatibility changes.
116 * Revision 1.35 1998/11/30 02:50:47 robertj
117 * New directory structure
119 * Revision 1.34 1998/10/31 12:49:21 robertj
120 * Added read/write mutex to the HTTP space variable to avoid thread crashes.
122 * Revision 1.33 1998/10/25 01:00:46 craigs
123 * Added ability to specify per-directory authorisation for PHTTPDirectory
125 * Revision 1.32 1998/09/23 06:19:29 robertj
126 * Added open source copyright license.
128 * Revision 1.31 1998/07/24 06:58:42 robertj
129 * Changed PostData function so just has string for data instead of dictionary.
131 * Revision 1.30 1998/06/16 03:33:33 robertj
132 * Changed TCP connection shutdown to be parameterised.
133 * Propagated persistence and proxy flags in new connection info instances.
135 * Revision 1.29 1998/04/14 03:42:59 robertj
136 * Fixed error code propagation in HTTP client.
138 * Revision 1.28 1998/02/03 06:29:38 robertj
139 * Added local address and port to PHTTPRequest.
141 * Revision 1.27 1998/01/26 00:24:24 robertj
142 * Added more information to PHTTPConnectionInfo.
143 * Added function to allow HTTPClient to automatically connect if URL has hostname.
145 * Revision 1.26 1997/10/30 10:22:52 robertj
146 * Added multiple user basic authorisation scheme.
148 * Revision 1.25 1997/10/03 13:30:15 craigs
149 * Added ability to access client socket from within HTTP resources
151 * Revision 1.24 1997/03/28 04:40:22 robertj
152 * Added tags for cookies.
154 * Revision 1.23 1997/01/12 04:15:19 robertj
155 * Globalised MIME tag strings.
157 * Revision 1.22 1996/10/26 03:31:05 robertj
158 * Changed OnError so can pass in full HTML page as parameter.
160 * Revision 1.21 1996/09/14 13:09:10 robertj
162 * rearranged sockets to help support IPX.
163 * added indirect channel class and moved all protocols to descend from it,
164 * separating the protocol from the low level byte transport.
166 * Revision 1.20 1996/08/22 13:20:55 robertj
167 * Fixed bug in authorisation, missing virtual prevented polymorphism.
169 * Revision 1.19 1996/08/19 13:44:06 robertj
170 * Fixed authorisation so if have no user/password on basic authentication, does not require it.
172 * Revision 1.18 1996/06/28 13:15:23 robertj
173 * Modified HTTPAuthority so gets PHTTPReqest (mainly for URL) passed in.
174 * Moved HTTP form resource to another compilation module.
176 * Revision 1.17 1996/06/07 13:52:20 robertj
177 * Added PUT to HTTP proxy FTP. Necessitating redisign of entity body processing.
179 * Revision 1.16 1996/05/23 10:00:52 robertj
180 * Added common function for GET and HEAD commands.
181 * Fixed status codes to be the actual status code instead of sequential enum.
182 * This fixed some problems with proxy pass through of status codes.
184 * Revision 1.14 1996/03/31 08:46:51 robertj
187 * Revision 1.13 1996/03/17 05:41:57 robertj
188 * Added hit count to PHTTPResource.
190 * Revision 1.12 1996/03/16 04:39:55 robertj
191 * Added ParseReponse() for splitting reponse line into code and info.
192 * Added client side support for HTTP socket.
193 * Added hooks for proxy support in HTTP socket.
195 * Revision 1.11 1996/03/10 13:15:23 robertj
196 * Redesign to make resources thread safe.
198 * Revision 1.10 1996/03/02 03:12:55 robertj
199 * Added radio button and selection boxes to HTTP form resource.
201 * Revision 1.9 1996/02/25 11:14:21 robertj
202 * Radio button support for forms.
204 * Revision 1.8 1996/02/25 02:57:48 robertj
205 * Removed pass through HTTP resource.
207 * Revision 1.7 1996/02/19 13:25:43 robertj
208 * Added overwrite option to AddResource().
209 * Added get/set string to PHTTPString resource.
210 * Moved nested classes from PHTTPForm.
212 * Revision 1.6 1996/02/13 13:09:16 robertj
213 * Added extra parameters to callback function in PHTTPResources, required
214 * by descendants to make informed decisions on data being loaded.
216 * Revision 1.5 1996/02/08 12:04:19 robertj
217 * Redesign of resource object callback virtuals.
218 * Added HTML form resource type.
220 * Revision 1.4 1996/02/03 11:03:32 robertj
221 * Added ismodified since and expires time checking.
222 * Added PHTTPString that defaults to empty string.
224 * Revision 1.3 1996/01/28 14:15:38 robertj
225 * Changed PCharArray in OnLoadData to PString for convenience in mangling data.
226 * Beginning of pass through resource type.
228 * Revision 1.2 1996/01/26 02:24:26 robertj
229 * Further implemetation.
231 * Revision 1.1 1996/01/23 13:04:20 robertj
243 #include <ptclib/inetprot.h>
244 #include <ptclib/mime.h>
245 #include <ptclib/url.h>
246 #include <ptlib/ipsock.h>
251 #include <ptclib/html.h>
253 //////////////////////////////////////////////////////////////////////////////
258 /** This class describes a name space that a Universal Resource Locator operates
259 in. Each section of the hierarchy field of the URL points to a leg in the
260 tree specified by this class.
262 class PHTTPSpace
: public PContainer
264 PCONTAINERINFO(PHTTPSpace
, PContainer
)
266 /// Constructor for HTTP URL Name Space
270 // New functions for class.
272 /// Generate error if resource already exists
274 /// Overwrite the existing resource at URL location
279 /** Add a new resource to the URL space. If there is already a resource at
280 the location in the tree, or that location in the tree is already in
281 the path to another resource then the function will fail.
283 The <CODE>overwrite</CODE> flag can be used to replace an existing
284 resource. The function will still fail if the resource is on a partial
285 path to another resource but not if it is a leaf node.
288 TRUE if resource added, FALSE if failed.
291 PHTTPResource
* resource
, ///< Resource to add to the name space.
292 AddOptions overwrite
= ErrorOnExist
293 ///< Flag to overwrite an existing resource if it already exists.
296 /** Delete an existing resource to the URL space. If there is not a resource
297 at the location in the tree, or that location in the tree is in the
298 path to another resource then the function will fail.
301 TRUE if resource deleted, FALSE if failed.
304 const PURL
& url
///< URL to search for in the name space.
307 /** Locate the resource specified by the URL in the URL name space.
310 The resource found or NULL if no resource at that position in hiearchy.
312 PHTTPResource
* FindResource(
313 const PURL
& url
///< URL to search for in the name space.
316 /** This function attempts to acquire the mutex for reading.
318 void StartRead() const
319 { mutex
->StartRead(); }
321 /** This function attempts to release the mutex for reading.
324 { mutex
->EndRead(); }
326 /** This function attempts to acquire the mutex for writing.
328 void StartWrite() const
329 { mutex
->StartWrite(); }
331 /** This function attempts to release the mutex for writing.
333 void EndWrite() const
334 { mutex
->EndWrite(); }
338 PReadWriteMutex
* mutex
;
341 PSORTED_LIST(ChildList
, Node
);
342 class Node
: public PString
344 PCLASSINFO(Node
, PString
)
346 Node(const PString
& name
, Node
* parentNode
);
351 PHTTPResource
* resource
;
355 BOOL
SetSize(PINDEX
) { return FALSE
; }
364 //////////////////////////////////////////////////////////////////////////////
367 /** A common base class for TCP/IP socket for the HyperText Transfer Protocol
368 version 1.0 client and server.
370 class PHTTP
: public PInternetProtocol
372 PCLASSINFO(PHTTP
, PInternetProtocol
)
375 // New functions for class.
380 PUT
, DELETE
, TRACE
, OPTIONS
,
387 Continue
= 100, ///< 100 - Continue
388 SwitchingProtocols
, ///< 101 - upgrade allowed
389 RequestOK
= 200, ///< 200 - request has succeeded
390 Created
, ///< 201 - new resource created: entity body contains URL
391 Accepted
, ///< 202 - request accepted, but not yet completed
392 NonAuthoritativeInformation
, ///< 203 - not definitive entity header
393 NoContent
, ///< 204 - no new information
394 ResetContent
, ///< 205 - contents have been reset
395 PartialContent
, ///< 206 - partial GET succeeded
396 MultipleChoices
= 300, ///< 300 - requested resource available elsewehere
397 MovedPermanently
, ///< 301 - resource moved permanently: location field has new URL
398 MovedTemporarily
, ///< 302 - resource moved temporarily: location field has new URL
399 SeeOther
, ///< 303 - see other URL
400 NotModified
, ///< 304 - document has not been modified
401 UseProxy
, ///< 305 - proxy redirect
402 BadRequest
= 400, ///< 400 - request malformed or not understood
403 UnAuthorised
, ///< 401 - request requires authentication
404 PaymentRequired
, ///< 402 - reserved
405 Forbidden
, ///< 403 - request is refused due to unsufficient authorisation
406 NotFound
, ///< 404 - resource cannot be found
407 MethodNotAllowed
, ///< 405 - not allowed on this resource
408 NoneAcceptable
, ///< 406 - encoding not acceptable
409 ProxyAuthenticationRequired
, ///< 407 - must authenticate with proxy first
410 RequestTimeout
, ///< 408 - server timeout on request
411 Conflict
, ///< 409 - resource conflict on action
412 Gone
, ///< 410 - resource gone away
413 LengthRequired
, ///< 411 - no Content-Length
414 UnlessTrue
, ///< 412 - no Range header for TRUE Unless
415 InternalServerError
= 500, ///< 500 - server has encountered an unexpected error
416 NotImplemented
, ///< 501 - server does not implement request
417 BadGateway
, ///< 502 - error whilst acting as gateway
418 ServiceUnavailable
, ///< 503 - server temporarily unable to service request
419 GatewayTimeout
///< 504 - timeout whilst talking to gateway
422 // Common MIME header tags
423 static const PString
& AllowTag();
424 static const PString
& AuthorizationTag();
425 static const PString
& ContentEncodingTag();
426 static const PString
& ContentLengthTag();
427 static const PString
& ContentTypeTag();
428 static const PString
& DateTag();
429 static const PString
& ExpiresTag();
430 static const PString
& FromTag();
431 static const PString
& IfModifiedSinceTag();
432 static const PString
& LastModifiedTag();
433 static const PString
& LocationTag();
434 static const PString
& PragmaTag();
435 static const PString
& PragmaNoCacheTag();
436 static const PString
& RefererTag();
437 static const PString
& ServerTag();
438 static const PString
& UserAgentTag();
439 static const PString
& WWWAuthenticateTag();
440 static const PString
& MIMEVersionTag();
441 static const PString
& ConnectionTag();
442 static const PString
& KeepAliveTag();
443 static const PString
& TransferEncodingTag();
444 static const PString
& ChunkedTag();
445 static const PString
& ProxyConnectionTag();
446 static const PString
& ProxyAuthorizationTag();
447 static const PString
& ProxyAuthenticateTag();
448 static const PString
& ForwardedTag();
449 static const PString
& SetCookieTag();
450 static const PString
& CookieTag();
453 /** Create a TCP/IP HTTP protocol channel.
457 /** Parse a response line string into a response code and any extra info
458 on the line. Results are placed into the member variables
459 <CODE>lastResponseCode</CODE> and <CODE>lastResponseInfo</CODE>.
461 The default bahaviour looks for a space or a '-' and splits the code
462 and info either side of that character, then returns FALSE.
465 Position of continuation character in response, 0 if no continuation
468 virtual PINDEX
ParseResponse(
469 const PString
& line
///< Input response line to be parsed
474 //////////////////////////////////////////////////////////////////////////////
477 /** A TCP/IP socket for the HyperText Transfer Protocol version 1.0.
479 When acting as a client, the procedure is to make the connection to a
480 remote server, then to retrieve a document using the following procedure:
482 PHTTPSocket web("webserver");
485 if (web.GetDocument("http://www.someone.com/somewhere/url", len)) {
486 PString html = web.ReadString(len);
491 PError << "Could not get page." << endl;
494 PError << "HTTP conection failed." << endl;
497 class PHTTPClient
: public PHTTP
499 PCLASSINFO(PHTTPClient
, PHTTP
)
502 /// Create a new HTTP client channel.
505 const PString
& userAgentName
509 // New functions for class.
510 /** Send a command and wait for the response header (including MIME fields).
511 Note that a body may still be on its way even if lasResponseCode is not
515 TRUE if all of header returned and ready to receive body.
521 const PString
& dataBody
,
522 PMIMEInfo
& replyMime
,
526 const PString
& cmdName
,
529 const PString
& dataBody
,
530 PMIMEInfo
& replyMime
,
534 /// Write a HTTP command to server
539 const PString
& dataBody
542 const PString
& cmdName
,
545 const PString
& dataBody
548 /// Read a response from the server
550 PMIMEInfo
& replyMIME
553 /// Read the body of the HTTP command
554 BOOL
ReadContentBody(
555 PMIMEInfo
& replyMIME
,
558 BOOL
ReadContentBody(
559 PMIMEInfo
& replyMIME
,
564 /** Get the document specified by the URL.
567 TRUE if document is being transferred.
569 BOOL
GetTextDocument(
570 const PURL
& url
, ///< Universal Resource Locator for document.
571 PString
& document
, ///< Body read
572 BOOL persist
= TRUE
///< if TRUE, enable HTTP persistence
575 /** Get the document specified by the URL.
578 TRUE if document is being transferred.
581 const PURL
& url
, ///< Universal Resource Locator for document.
582 PMIMEInfo
& outMIME
, ///< MIME info in request
583 PMIMEInfo
& replyMIME
, ///< MIME info in response
584 BOOL persist
= TRUE
///< if TRUE, enable HTTP persistence
587 /** Get the header for the document specified by the URL.
590 TRUE if document header is being transferred.
593 const PURL
& url
, ///< Universal Resource Locator for document.
594 PMIMEInfo
& outMIME
, ///< MIME info in request
595 PMIMEInfo
& replyMIME
, ///< MIME info in response
596 BOOL persist
= TRUE
///< if TRUE, enable HTTP persistence
600 /** Post the data specified to the URL.
603 TRUE if document is being transferred.
606 const PURL
& url
, ///< Universal Resource Locator for document.
607 PMIMEInfo
& outMIME
, ///< MIME info in request
608 const PString
& data
, ///< Information posted to the HTTP server.
609 PMIMEInfo
& replyMIME
, ///< MIME info in response
610 BOOL persist
= TRUE
///< if TRUE, enable HTTP persistence
613 /** Post the data specified to the URL.
616 TRUE if document is being transferred.
619 const PURL
& url
, ///< Universal Resource Locator for document.
620 PMIMEInfo
& outMIME
, ///< MIME info in request
621 const PString
& data
, ///< Information posted to the HTTP server.
622 PMIMEInfo
& replyMIME
, ///< MIME info in response
623 PString
& replyBody
, ///< Body of response
624 BOOL persist
= TRUE
///< if TRUE, enable HTTP persistence
628 BOOL
AssureConnect(const PURL
& url
, PMIMEInfo
& outMIME
);
629 BOOL
InternalReadContentBody(
630 PMIMEInfo
& replyMIME
,
631 PAbstractArray
& body
634 PString userAgentName
;
639 //////////////////////////////////////////////////////////////////////////////
640 // PMultipartFormInfo
642 /** This object describes the information associated with a multi-part
646 class PMultipartFormInfo
: public PObject
648 PCLASSINFO(PMultipartFormInfo
, PObject
);
654 PARRAY(PMultipartFormInfoArray
, PMultipartFormInfo
);
656 //////////////////////////////////////////////////////////////////////////////
657 // PHTTPConnectionInfo
661 /** This object describes the connectiono associated with a HyperText Transport
662 Protocol request. This information is required by handler functions on
663 #PHTTPResource# descendant classes to manage the connection correctly.
665 class PHTTPConnectionInfo
: public PObject
667 PCLASSINFO(PHTTPConnectionInfo
, PObject
)
669 PHTTPConnectionInfo();
671 PHTTP::Commands
GetCommandCode() const { return commandCode
; }
672 const PString
& GetCommandName() const { return commandName
; }
674 const PURL
& GetURL() const { return url
; }
676 const PMIMEInfo
& GetMIME() const { return mimeInfo
; }
677 void SetMIME(const PString
& tag
, const PString
& value
);
679 BOOL
IsCompatible(int major
, int minor
) const;
681 BOOL
IsPersistant() const { return isPersistant
; }
682 BOOL
WasPersistant() const { return wasPersistant
; }
683 BOOL
IsProxyConnection() const { return isProxyConnection
; }
684 int GetMajorVersion() const { return majorVersion
; }
685 int GetMinorVersion() const { return minorVersion
; }
687 long GetEntityBodyLength() const { return entityBodyLength
; }
689 /**Get the maximum time a persistent connection may persist.
691 PTimeInterval
GetPersistenceTimeout() const { return persistenceTimeout
; }
693 /**Set the maximum time a persistent connection may persist.
695 void SetPersistenceTimeout(const PTimeInterval
& t
) { persistenceTimeout
= t
; }
697 /**Get the maximum number of transations (GET/POST etc) for persistent connection.
698 If this is zero then there is no maximum.
700 unsigned GetPersistenceMaximumTransations() const { return persistenceMaximum
; }
702 /**Set the maximum number of transations (GET/POST etc) for persistent connection.
703 If this is zero then there is no maximum.
705 void SetPersistenceMaximumTransations(unsigned m
) { persistenceMaximum
= m
; }
707 const PMultipartFormInfoArray
& GetMultipartFormInfo() const
708 { return multipartFormInfoArray
; }
710 void ResetMultipartFormInfo()
711 { multipartFormInfoArray
.RemoveAll(); }
713 PString
GetEntityBody() const { return entityBody
; }
716 BOOL
Initialise(PHTTPServer
& server
, PString
& args
);
717 void DecodeMultipartFormInfo(const PString
& type
, const PString
& entityBody
);
719 PHTTP::Commands commandCode
;
725 BOOL isProxyConnection
;
728 PString entityBody
; // original entity body (POST only)
729 long entityBodyLength
;
730 PTimeInterval persistenceTimeout
;
731 unsigned persistenceMaximum
;
732 PMultipartFormInfoArray multipartFormInfoArray
;
734 friend class PHTTPServer
;
738 //////////////////////////////////////////////////////////////////////////////
741 /** A TCP/IP socket for the HyperText Transfer Protocol version 1.0.
743 When acting as a server, a descendant class would be created to override
744 at least the #HandleOpenMailbox()#, #HandleSendMessage()# and
745 #HandleDeleteMessage()# functions. Other functions may be overridden
746 for further enhancement to the sockets capabilities, but these will give a
747 basic POP3 server functionality.
749 The server socket thread would continuously call the
750 #ProcessMessage()# function until it returns FALSE. This will then
751 call the appropriate virtual function on parsing the POP3 protocol.
753 class PHTTPServer
: public PHTTP
755 PCLASSINFO(PHTTPServer
, PHTTP
)
758 /** Create a TCP/IP HTTP protocol socket channel. The form with the single
759 <CODE>port</CODE> parameter creates an unopened socket, the form with
760 the <CODE>address</CODE> parameter makes a connection to a remote
761 system, opening the socket. The form with the <CODE>socket</CODE>
762 parameter opens the socket to an incoming call from a "listening"
767 const PHTTPSpace
& urlSpace
///< Name space to use for URLs received.
771 // New functions for class.
772 /** Get the name of the server.
775 String name of the server.
777 virtual PString
GetServerName() const;
779 /** Get the name space being used by the HTTP server socket.
784 PHTTPSpace
& GetURLSpace() { return urlSpace
; }
786 /// Use a new URL name space for this HTTP socket.
788 const PHTTPSpace
& space
///< New URL name space to use.
792 /** Process commands, dispatching to the appropriate virtual function. This
793 is used when the socket is acting as a server.
796 TRUE if the request specified persistant mode and the request version
797 allows it, FALSE if the socket closed, timed out, the protocol does not
798 allow persistant mode, or the client did not request it
801 virtual BOOL
ProcessCommand();
803 /** Handle a GET command from a client.
805 The default implementation looks up the URL in the name space declared by
806 the #PHTTPSpace# class tree and despatches to the
807 #PHTTPResource# object contained therein.
810 TRUE if the connection may persist, FALSE if the connection must close
811 If there is no ContentLength field in the response, this value must
812 be FALSE for correct operation.
815 const PURL
& url
, ///< Universal Resource Locator for document.
816 const PMIMEInfo
& info
, ///< Extra MIME information in command.
817 const PHTTPConnectionInfo
& conInfo
///< HTTP connection information
822 /** Handle a HEAD command from a client.
824 The default implemetation looks up the URL in the name space declared by
825 the #PHTTPSpace# class tree and despatches to the
826 #PHTTPResource# object contained therein.
829 TRUE if the connection may persist, FALSE if the connection must close
830 If there is no ContentLength field in the response, this value must
831 be FALSE for correct operation.
834 const PURL
& url
, ///< Universal Resource Locator for document.
835 const PMIMEInfo
& info
, ///< Extra MIME information in command.
836 const PHTTPConnectionInfo
& conInfo
///< HTTP connection information
839 /** Handle a POST command from a client.
841 The default implementation looks up the URL in the name space declared by
842 the #PHTTPSpace# class tree and despatches to the
843 #PHTTPResource# object contained therein.
846 TRUE if the connection may persist, FALSE if the connection must close
847 If there is no ContentLength field in the response, this value must
848 be FALSE for correct operation.
851 const PURL
& url
, ///< Universal Resource Locator for document.
852 const PMIMEInfo
& info
, ///< Extra MIME information in command.
853 const PStringToString
& data
, ///< Variables provided in the POST data.
854 const PHTTPConnectionInfo
& conInfo
///< HTTP connection information
857 /** Handle a proxy command request from a client. This will only get called
858 if the request was not for this particular server. If it was a proxy
859 request for this server (host and port number) then the appropriate
860 #OnGET()#, #OnHEAD()# or #OnPOST()# command is called.
862 The default implementation returns OnError(BadGateway).
865 TRUE if the connection may persist, FALSE if the connection must close
866 If there is no ContentLength field in the response, this value must
867 be FALSE for correct operation.
869 virtual BOOL
OnProxy(
870 const PHTTPConnectionInfo
& conInfo
///< HTTP connection information
874 /** Read the entity body associated with a HTTP request, and close the
875 socket if not a persistant connection.
878 The entity body of the command
880 virtual PString
ReadEntityBody();
882 /** Handle an unknown command.
885 TRUE if the connection may persist, FALSE if the connection must close
887 virtual BOOL
OnUnknown(
888 const PCaselessString
& command
, ///< Complete command line received.
889 const PHTTPConnectionInfo
& connectInfo
///< HTTP connection information
892 /** Write a command reply back to the client, and construct some of the
893 outgoing MIME fields. The MIME fields are not sent.
895 The <CODE>bodySize</CODE> parameter determines the size of the
896 entity body associated with the response. If <CODE>bodySize</CODE> is
897 >= 0, then a ContentLength field will be added to the outgoing MIME
898 headers if one does not already exist.
900 If <CODE>bodySize</CODE> is < 0, then it is assumed that the size of
901 the entity body is unknown, or has already been added, and no
902 ContentLength field will be constructed.
904 If the version of the request is less than 1.0, then this function does
908 TRUE if requires v1.1 chunked transfer encoding.
911 StatusCode code
, ///< Status code for the response.
912 PMIMEInfo
& headers
, ///< MIME variables included in response.
913 long bodySize
///< Size of the rest of the response.
916 /** Write an error response for the specified code.
918 Depending on the <CODE>code</CODE> parameter this function will also
919 send a HTML version of the status code for display on the remote client
923 TRUE if the connection may persist, FALSE if the connection must close
925 virtual BOOL
OnError(
926 StatusCode code
, ///< Status code for the error response.
927 const PCaselessString
& extra
, ///< Extra information included in the response.
928 const PHTTPConnectionInfo
& connectInfo
///< HTTP connection information
931 /** Set the default mime info
933 void SetDefaultMIMEInfo(
934 PMIMEInfo
& info
, ///< Extra MIME information in command.
935 const PHTTPConnectionInfo
& connectInfo
938 /**Get the connection info for this connection.
940 PHTTPConnectionInfo
& GetConnectionInfo() { return connectInfo
; }
946 PHTTPConnectionInfo connectInfo
;
947 unsigned transactionCount
;
948 PTimeInterval nextTimeout
;
952 //////////////////////////////////////////////////////////////////////////////
955 /** This object describes a HyperText Transport Protocol request. An individual
956 request is passed to handler functions on #PHTTPResource# descendant
959 class PHTTPRequest
: public PObject
961 PCLASSINFO(PHTTPRequest
, PObject
)
965 const PURL
& url
, ///< Universal Resource Locator for document.
966 const PMIMEInfo
& inMIME
, ///< Extra MIME information in command.
967 const PMultipartFormInfoArray
& multipartFormInfo
, ///< multipart form information (if any)
968 PHTTPServer
& server
///< Server channel that request initiated on
971 PHTTPServer
& server
; ///< Server channel that request initiated on
972 const PURL
& url
; ///< Universal Resource Locator for document.
973 const PMIMEInfo
& inMIME
; ///< Extra MIME information in command.
974 const PMultipartFormInfoArray
& multipartFormInfo
; ///< multipart form information, if any
975 PHTTP::StatusCode code
; ///< Status code for OnError() reply.
976 PMIMEInfo outMIME
; ///< MIME information used in reply.
977 PString entityBody
; ///< original entity body (POST only)
978 PINDEX contentSize
; ///< Size of the body of the resource data.
979 PIPSocket::Address origin
; ///< IP address of origin host for request
980 PIPSocket::Address localAddr
; ///< IP address of local interface for request
981 WORD localPort
; ///< Port number of local server for request
985 //////////////////////////////////////////////////////////////////////////////
988 /** This abstract class describes the authorisation mechanism for a Universal
991 class PHTTPAuthority
: public PObject
993 PCLASSINFO(PHTTPAuthority
, PObject
)
996 // New functions for class.
997 /** Get the realm or name space for the user authorisation name and
998 password as required by the basic authorisation system of HTTP/1.0.
1001 String for the authorisation realm name.
1003 virtual PString
GetRealm(
1004 const PHTTPRequest
& request
///< Request information.
1007 /** Validate the user and password provided by the remote HTTP client for
1008 the realm specified by the class instance.
1011 TRUE if the user and password are authorised in the realm.
1013 virtual BOOL
Validate(
1014 const PHTTPRequest
& request
, ///< Request information.
1015 const PString
& authInfo
///< Authority information string.
1018 /** Determine if the authorisation is to be applied. This could be used to
1019 distinguish between net requiring authorisation and requiring autorisation
1020 but having no password.
1022 The default behaviour is to return TRUE.
1025 TRUE if the authorisation in the realm is to be applied.
1027 virtual BOOL
IsActive() const;
1030 static void DecodeBasicAuthority(
1031 const PString
& authInfo
, ///< Authority information string.
1032 PString
& username
, ///< User name decoded from authInfo
1033 PString
& password
///< Password decoded from authInfo
1038 //////////////////////////////////////////////////////////////////////////////
1041 /** This class describes the simplest authorisation mechanism for a Universal
1042 Resource Locator, a fixed realm, username and password.
1044 class PHTTPSimpleAuth
: public PHTTPAuthority
1046 PCLASSINFO(PHTTPSimpleAuth
, PHTTPAuthority
)
1050 const PString
& realm
, ///< Name space for the username and password.
1051 const PString
& username
, ///< Username that this object wiull authorise.
1052 const PString
& password
///< Password for the above username.
1054 // Construct the simple authorisation structure.
1057 // Overrides from class PObject.
1058 /** Create a copy of the class on the heap. This is used by the
1059 #PHTTPResource# classes for maintaining authorisation to
1063 pointer to new copy of the class instance.
1065 virtual PObject
* Clone() const;
1068 // Overrides from class PHTTPAuthority.
1069 /** Get the realm or name space for the user authorisation name and
1070 password as required by the basic authorisation system of HTTP/1.0.
1073 String for the authorisation realm name.
1075 virtual PString
GetRealm(
1076 const PHTTPRequest
& request
///< Request information.
1079 /** Validate the user and password provided by the remote HTTP client for
1080 the realm specified by the class instance.
1083 TRUE if the user and password are authorised in the realm.
1085 virtual BOOL
Validate(
1086 const PHTTPRequest
& request
, ///< Request information.
1087 const PString
& authInfo
///< Authority information string.
1090 /** Determine if the authorisation is to be applied. This could be used to
1091 distinguish between net requiring authorisation and requiring autorisation
1092 but having no password.
1094 The default behaviour is to return TRUE.
1097 TRUE if the authorisation in the realm is to be applied.
1099 virtual BOOL
IsActive() const;
1101 /** Get the user name allocated to this simple authorisation.
1104 String for the authorisation user name.
1106 const PString
& GetUserName() const { return username
; }
1108 /** Get the password allocated to this simple authorisation.
1111 String for the authorisation password.
1113 const PString
& GetPassword() const { return password
; }
1123 //////////////////////////////////////////////////////////////////////////////
1124 // PHTTPMultiSimpAuth
1126 /** This class describes the simple authorisation mechanism for a Universal
1127 Resource Locator, a fixed realm, multiple usernames and passwords.
1129 class PHTTPMultiSimpAuth
: public PHTTPAuthority
1131 PCLASSINFO(PHTTPMultiSimpAuth
, PHTTPAuthority
)
1135 const PString
& realm
///< Name space for the username and password.
1138 const PString
& realm
, ///< Name space for the usernames.
1139 const PStringToString
& userList
///< List of usernames and passwords.
1141 // Construct the simple authorisation structure.
1144 // Overrides from class PObject.
1145 /** Create a copy of the class on the heap. This is used by the
1146 #PHTTPResource# classes for maintaining authorisation to
1150 pointer to new copy of the class instance.
1152 virtual PObject
* Clone() const;
1155 // Overrides from class PHTTPAuthority.
1156 /** Get the realm or name space for the user authorisation name and
1157 password as required by the basic authorisation system of HTTP/1.0.
1160 String for the authorisation realm name.
1162 virtual PString
GetRealm(
1163 const PHTTPRequest
& request
///< Request information.
1166 /** Validate the user and password provided by the remote HTTP client for
1167 the realm specified by the class instance.
1170 TRUE if the user and password are authorised in the realm.
1172 virtual BOOL
Validate(
1173 const PHTTPRequest
& request
, ///< Request information.
1174 const PString
& authInfo
///< Authority information string.
1177 /** Determine if the authirisation is to be applied. This could be used to
1178 distinguish between net requiring authorisation and requiring autorisation
1179 but having no password.
1181 The default behaviour is to return TRUE.
1184 TRUE if the authorisation in the realm is to be applied.
1186 virtual BOOL
IsActive() const;
1188 /** Get the user name allocated to this simple authorisation.
1191 String for the authorisation user name.
1194 const PString
& username
, ///< Username that this object wiull authorise.
1195 const PString
& password
///< Password for the above username.
1201 PStringToString users
;
1205 //////////////////////////////////////////////////////////////////////////////
1208 /** This object describes a HyperText Transport Protocol resource. A tree of
1209 these resources are available to the #PHTTPSocket# class.
1211 class PHTTPResource
: public PObject
1213 PCLASSINFO(PHTTPResource
, PObject
)
1217 const PURL
& url
///< Name of the resource in URL space.
1220 const PURL
& url
, ///< Name of the resource in URL space.
1221 const PHTTPAuthority
& auth
///< Authorisation for the resource.
1224 const PURL
& url
, ///< Name of the resource in URL space.
1225 const PString
& contentType
///< MIME content type for the resource.
1228 const PURL
& url
, ///< Name of the resource in URL space.
1229 const PString
& contentType
, ///< MIME content type for the resource.
1230 const PHTTPAuthority
& auth
///< Authorisation for the resource.
1232 // Create a new HTTP Resource.
1236 virtual ~PHTTPResource();
1237 // Destroy the HTTP Resource.
1240 // New functions for class.
1241 /** Get the URL for this resource.
1244 The URL for this resource.
1246 const PURL
& GetURL() const { return baseURL
; }
1248 /** Get the current content type for the resource.
1251 string for the current MIME content type.
1253 const PString
& GetContentType() const { return contentType
; }
1255 /** Get the current authority for the resource.
1258 Pointer to authority or NULL if unrestricted.
1261 PHTTPAuthority
* GetAuthority() const { return authority
; }
1263 /** Set the current authority for the resource.
1266 const PHTTPAuthority
& auth
///< authority to set
1269 /** Set the current authority for the resource to unrestricted.
1271 void ClearAuthority();
1273 /** Get the current hit count for the resource. This is the total number of
1274 times the resource was asked for by a remote client.
1277 Hit count for the resource.
1279 DWORD
GetHitCount() const { return hitCount
; }
1281 void ClearHitCount() { hitCount
= 0; }
1282 // Clear the hit count for the resource.
1285 /** Handle the GET command passed from the HTTP socket.
1287 The default action is to check the authorisation for the resource and
1288 call the virtuals #LoadHeaders()# and #OnGETData()# to get
1289 a resource to be sent to the socket.
1292 TRUE if the connection may persist, FALSE if the connection must close.
1293 If there is no ContentLength field in the response, this value must
1294 be FALSE for correct operation.
1297 PHTTPServer
& server
, ///< HTTP server that received the request
1298 const PURL
& url
, ///< Universal Resource Locator for document.
1299 const PMIMEInfo
& info
, ///< Extra MIME information in command.
1300 const PHTTPConnectionInfo
& conInfo
///< HTTP connection information
1303 /**Send the data associated with a GET command.
1305 The default action calls #SendData()#.
1308 TRUE if the connection may persist, FALSE if the connection must close.
1309 If there is no ContentLength field in the response, this value must
1310 be FALSE for correct operation.
1312 virtual BOOL
OnGETData(
1313 PHTTPServer
& server
, ///< HTTP server that received the request
1314 const PURL
& url
, ///< Universal Resource Locator for document
1315 const PHTTPConnectionInfo
& connectInfo
, ///< HTTP connection information
1316 PHTTPRequest
& request
///< request state information
1319 /** Handle the HEAD command passed from the HTTP socket.
1321 The default action is to check the authorisation for the resource and
1322 call the virtual #LoadHeaders()# to get the header information to
1323 be sent to the socket.
1326 TRUE if the connection may persist, FALSE if the connection must close
1327 If there is no ContentLength field in the response, this value must
1328 be FALSE for correct operation.
1330 virtual BOOL
OnHEAD(
1331 PHTTPServer
& server
, ///< HTTP server that received the request
1332 const PURL
& url
, ///< Universal Resource Locator for document.
1333 const PMIMEInfo
& info
, ///< Extra MIME information in command.
1334 const PHTTPConnectionInfo
& conInfo
///< HTTP connection information
1337 /** Handle the POST command passed from the HTTP socket.
1339 The default action is to check the authorisation for the resource and
1340 call the virtual #Post()# function to handle the data being
1344 TRUE if the connection may persist, FALSE if the connection must close
1345 If there is no ContentLength field in the response, this value must
1346 be FALSE for correct operation.
1348 virtual BOOL
OnPOST(
1349 PHTTPServer
& server
, ///< HTTP server that received the request
1350 const PURL
& url
, ///< Universal Resource Locator for document.
1351 const PMIMEInfo
& info
, ///< Extra MIME information in command.
1352 const PStringToString
& data
, ///< Variables in the POST data.
1353 const PHTTPConnectionInfo
& conInfo
///< HTTP connection information
1356 /**Send the data associated with a POST command.
1358 The default action calls #Post()#.
1361 TRUE if the connection may persist, FALSE if the connection must close.
1362 If there is no ContentLength field in the response, this value must
1363 be FALSE for correct operation.
1365 virtual BOOL
OnPOSTData(
1366 PHTTPRequest
& request
, ///< request information
1367 const PStringToString
& data
///< Variables in the POST data.
1370 /** Check to see if the resource has been modified since the date
1374 TRUE if has been modified since.
1376 virtual BOOL
IsModifiedSince(
1377 const PTime
& when
///< Time to see if modified later than
1380 /** Get a block of data (eg HTML) that the resource contains.
1383 Status of load operation.
1385 virtual BOOL
GetExpirationDate(
1386 PTime
& when
///< Time that the resource expires
1389 /** Create a new request block for this type of resource.
1391 The default behaviour is to create a new PHTTPRequest instance.
1394 Pointer to instance of PHTTPRequest descendant class.
1396 virtual PHTTPRequest
* CreateRequest(
1397 const PURL
& url
, ///< Universal Resource Locator for document.
1398 const PMIMEInfo
& inMIME
, ///< Extra MIME information in command.
1399 const PMultipartFormInfoArray
& multipartFormInfo
, ///< additional information for multi-part posts
1400 PHTTPServer
& socket
///< socket used for request
1403 /** Get the headers for block of data (eg HTML) that the resource contains.
1404 This will fill in all the fields of the <CODE>outMIME</CODE> parameter
1405 required by the resource and return the status for the load.
1408 TRUE if all OK, FALSE if an error occurred.
1410 virtual BOOL
LoadHeaders(
1411 PHTTPRequest
& request
///< Information on this request.
1414 /**Send the data associated with a command.
1416 The default action is to call the virtual #LoadData()# to get a
1417 resource to be sent to the socket.
1419 virtual void SendData(
1420 PHTTPRequest
& request
///< information for this request
1423 /** Get a block of data that the resource contains.
1425 The default behaviour is to call the #LoadText()# function and
1426 if successful, call the #OnLoadedText()# function.
1429 TRUE if there is still more to load.
1431 virtual BOOL
LoadData(
1432 PHTTPRequest
& request
, ///< Information on this request.
1433 PCharArray
& data
///< Data used in reply.
1436 /** Get a block of text data (eg HTML) that the resource contains.
1438 The default behaviour is to assert, one of #LoadText()# or
1439 #LoadData()# functions must be overridden for correct operation.
1442 String for loaded text.
1444 virtual PString
LoadText(
1445 PHTTPRequest
& request
///< Information on this request.
1448 /** This is called after the text has been loaded and may be used to
1449 customise or otherwise mangle a loaded piece of text. Typically this is
1450 used with HTML responses.
1452 The default action for this function is to do nothing.
1454 virtual void OnLoadedText(
1455 PHTTPRequest
& request
, ///< Information on this request.
1456 PString
& text
///< Data used in reply.
1459 /** Get a block of data (eg HTML) that the resource contains.
1461 The default action for this function is to do nothing and return
1465 TRUE if the connection may persist, FALSE if the connection must close
1468 PHTTPRequest
& request
, ///< Information on this request.
1469 const PStringToString
& data
, ///< Variables in the POST data.
1470 PHTML
& replyMessage
///< Reply message for post.
1475 /** See if the resource is authorised given the mime info
1477 virtual BOOL
CheckAuthority(
1478 PHTTPServer
& server
, ///< Server to send response to.
1479 const PHTTPRequest
& request
, ///< Information on this request.
1480 const PHTTPConnectionInfo
& conInfo
///< Information on the connection
1482 static BOOL
CheckAuthority(
1483 PHTTPAuthority
& authority
,
1484 PHTTPServer
& server
,
1485 const PHTTPRequest
& request
,
1486 const PHTTPConnectionInfo
& connectInfo
1490 /** common code for GET and HEAD commands */
1491 virtual BOOL
OnGETOrHEAD(
1492 PHTTPServer
& server
, ///< HTTP server that received the request
1493 const PURL
& url
, ///< Universal Resource Locator for document.
1494 const PMIMEInfo
& info
, ///< Extra MIME information in command.
1495 const PHTTPConnectionInfo
& conInfo
,
1499 /// Base URL for the resource, may accept URLS with a longer hierarchy
1501 /// MIME content type for the resource
1502 PString contentType
;
1503 /// Authorisation method for the resource
1504 PHTTPAuthority
* authority
;
1505 /// COunt of number of times resource was accessed.
1506 volatile DWORD hitCount
;
1510 //////////////////////////////////////////////////////////////////////////////
1513 /** This object describes a HyperText Transport Protocol resource which is a
1514 string kept in memory. For instance a pre-calculated HTML string could be
1515 set in this type of resource.
1517 class PHTTPString
: public PHTTPResource
1519 PCLASSINFO(PHTTPString
, PHTTPResource
)
1522 /** Contruct a new simple string resource for the HTTP space. If no MIME
1523 content type is specified then a default type is "text/html".
1526 const PURL
& url
// Name of the resource in URL space.
1529 const PURL
& url
, // Name of the resource in URL space.
1530 const PHTTPAuthority
& auth
// Authorisation for the resource.
1533 const PURL
& url
, // Name of the resource in URL space.
1534 const PString
& str
// String to return in this resource.
1537 const PURL
& url
, // Name of the resource in URL space.
1538 const PString
& str
, // String to return in this resource.
1539 const PString
& contentType
// MIME content type for the file.
1542 const PURL
& url
, // Name of the resource in URL space.
1543 const PString
& str
, // String to return in this resource.
1544 const PHTTPAuthority
& auth
// Authorisation for the resource.
1547 const PURL
& url
, // Name of the resource in URL space.
1548 const PString
& str
, // String to return in this resource.
1549 const PString
& contentType
, // MIME content type for the file.
1550 const PHTTPAuthority
& auth
// Authorisation for the resource.
1554 // Overrides from class PHTTPResource
1555 /** Get the headers for block of data (eg HTML) that the resource contains.
1556 This will fill in all the fields of the <CODE>outMIME</CODE> parameter
1557 required by the resource and return the status for the load.
1560 TRUE if all OK, FALSE if an error occurred.
1562 virtual BOOL
LoadHeaders(
1563 PHTTPRequest
& request
// Information on this request.
1566 /** Get a block of text data (eg HTML) that the resource contains.
1568 The default behaviour is to assert, one of #LoadText()# or
1569 #LoadData()# functions must be overridden for correct operation.
1572 String for loaded text.
1574 virtual PString
LoadText(
1575 PHTTPRequest
& request
// Information on this request.
1578 // New functions for class.
1579 /** Get the string for this resource.
1582 String for resource.
1584 const PString
& GetString() { return string
; }
1586 /** Set the string to be returned by this resource.
1589 const PString
& str
// New string for the resource.
1598 //////////////////////////////////////////////////////////////////////////////
1601 /** This object describes a HyperText Transport Protocol resource which is a
1602 single file. The file can be anywhere in the file system and is mapped to
1603 the specified URL location in the HTTP name space defined by the
1606 class PHTTPFile
: public PHTTPResource
1608 PCLASSINFO(PHTTPFile
, PHTTPResource
)
1611 /** Contruct a new simple file resource for the HTTP space. If no MIME
1612 content type is specified then a default type is used depending on the
1613 file type. For example, "text/html" is used of the file type is
1614 ".html" or ".htm". The default for an unknown type is
1615 "application/octet-stream".
1618 const PString
& filename
// file in file system and URL name.
1621 const PString
& filename
, // file in file system and URL name.
1622 const PHTTPAuthority
& auth
// Authorisation for the resource.
1625 const PURL
& url
, // Name of the resource in URL space.
1626 const PFilePath
& file
// Location of file in file system.
1629 const PURL
& url
, // Name of the resource in URL space.
1630 const PFilePath
& file
, // Location of file in file system.
1631 const PString
& contentType
// MIME content type for the file.
1634 const PURL
& url
, // Name of the resource in URL space.
1635 const PFilePath
& file
, // Location of file in file system.
1636 const PHTTPAuthority
& auth
// Authorisation for the resource.
1639 const PURL
& url
, // Name of the resource in URL space.
1640 const PFilePath
& file
, // Location of file in file system.
1641 const PString
& contentType
, // MIME content type for the file.
1642 const PHTTPAuthority
& auth
// Authorisation for the resource.
1646 // Overrides from class PHTTPResource
1647 /** Create a new request block for this type of resource.
1650 Pointer to instance of PHTTPRequest descendant class.
1652 virtual PHTTPRequest
* CreateRequest(
1653 const PURL
& url
, // Universal Resource Locator for document.
1654 const PMIMEInfo
& inMIME
, // Extra MIME information in command.
1655 const PMultipartFormInfoArray
& multipartFormInfo
,
1656 PHTTPServer
& socket
1659 /** Get the headers for block of data (eg HTML) that the resource contains.
1660 This will fill in all the fields of the <CODE>outMIME</CODE> parameter
1661 required by the resource and return the status for the load.
1664 TRUE if all OK, FALSE if an error occurred.
1666 virtual BOOL
LoadHeaders(
1667 PHTTPRequest
& request
// Information on this request.
1670 /** Get a block of data that the resource contains.
1673 TRUE if more to load.
1675 virtual BOOL
LoadData(
1676 PHTTPRequest
& request
, // Information on this request.
1677 PCharArray
& data
// Data used in reply.
1680 /** Get a block of text data (eg HTML) that the resource contains.
1682 The default behaviour is to assert, one of #LoadText()# or
1683 #LoadData()# functions must be overridden for correct operation.
1686 String for loaded text.
1688 virtual PString
LoadText(
1689 PHTTPRequest
& request
// Information on this request.
1695 const PURL
& url
, // Name of the resource in URL space.
1698 // Constructor used by PHTTPDirectory
1705 class PHTTPFileRequest
: public PHTTPRequest
1707 PCLASSINFO(PHTTPFileRequest
, PHTTPRequest
)
1710 const PURL
& url
, // Universal Resource Locator for document.
1711 const PMIMEInfo
& inMIME
, // Extra MIME information in command.
1712 const PMultipartFormInfoArray
& multipartFormInfo
,
1713 PHTTPServer
& server
1720 //////////////////////////////////////////////////////////////////////////////
1723 /** This object describes a HyperText Transport Protocol resource which is a
1724 single file. The file can be anywhere in the file system and is mapped to
1725 the specified URL location in the HTTP name space defined by the
1728 The difference between this and PHTTPFile is that it continually outputs
1729 the contents of the file, as per the unix "tail -f" command.
1731 class PHTTPTailFile
: public PHTTPFile
1733 PCLASSINFO(PHTTPTailFile
, PHTTPFile
)
1736 /** Contruct a new simple file resource for the HTTP space. If no MIME
1737 content type is specified then a default type is used depending on the
1738 file type. For example, "text/html" is used of the file type is
1739 ".html" or ".htm". The default for an unknown type is
1740 "application/octet-stream".
1743 const PString
& filename
// file in file system and URL name.
1746 const PString
& filename
, // file in file system and URL name.
1747 const PHTTPAuthority
& auth
// Authorisation for the resource.
1750 const PURL
& url
, // Name of the resource in URL space.
1751 const PFilePath
& file
// Location of file in file system.
1754 const PURL
& url
, // Name of the resource in URL space.
1755 const PFilePath
& file
, // Location of file in file system.
1756 const PString
& contentType
// MIME content type for the file.
1759 const PURL
& url
, // Name of the resource in URL space.
1760 const PFilePath
& file
, // Location of file in file system.
1761 const PHTTPAuthority
& auth
// Authorisation for the resource.
1764 const PURL
& url
, // Name of the resource in URL space.
1765 const PFilePath
& file
, // Location of file in file system.
1766 const PString
& contentType
, // MIME content type for the file.
1767 const PHTTPAuthority
& auth
// Authorisation for the resource.
1771 // Overrides from class PHTTPResource
1772 /** Get the headers for block of data (eg HTML) that the resource contains.
1773 This will fill in all the fields of the <CODE>outMIME</CODE> parameter
1774 required by the resource and return the status for the load.
1777 TRUE if all OK, FALSE if an error occurred.
1779 virtual BOOL
LoadHeaders(
1780 PHTTPRequest
& request
// Information on this request.
1783 /** Get a block of data that the resource contains.
1786 TRUE if more to load.
1788 virtual BOOL
LoadData(
1789 PHTTPRequest
& request
, // Information on this request.
1790 PCharArray
& data
// Data used in reply.
1795 //////////////////////////////////////////////////////////////////////////////
1798 /** This object describes a HyperText Transport Protocol resource which is a
1799 set of files in a directory. The directory can be anywhere in the file
1800 system and is mapped to the specified URL location in the HTTP name space
1801 defined by the #PHTTPSpace# class.
1803 All subdirectories and files are available as URL names in the HTTP name
1804 space. This effectively grafts a file system directory tree onto the URL
1807 See the #PMIMEInfo# class for more information on the mappings between
1808 file types and MIME types.
1810 class PHTTPDirectory
: public PHTTPFile
1812 PCLASSINFO(PHTTPDirectory
, PHTTPFile
)
1816 const PURL
& url
, /// Name of the resource in URL space.
1817 const PDirectory
& dir
/// Location of file in file system.
1820 const PURL
& url
, /// Name of the resource in URL space.
1821 const PDirectory
& dir
, /// Location of file in file system.
1822 const PHTTPAuthority
& auth
/// Authorisation for the resource.
1824 // Construct a new directory resource for HTTP.
1827 // Overrides from class PHTTPResource
1828 /** Create a new request block for this type of resource.
1831 Pointer to instance of PHTTPRequest descendant class.
1833 virtual PHTTPRequest
* CreateRequest(
1834 const PURL
& url
, // Universal Resource Locator for document.
1835 const PMIMEInfo
& inMIME
, // Extra MIME information in command.
1836 const PMultipartFormInfoArray
& multipartFormInfo
,
1837 PHTTPServer
& socket
1840 /** Get the headers for block of data (eg HTML) that the resource contains.
1841 This will fill in all the fields of the <CODE>outMIME</CODE> parameter
1842 required by the resource and return the status for the load.
1845 TRUE if all OK, FALSE if an error occurred.
1847 virtual BOOL
LoadHeaders(
1848 PHTTPRequest
& request
/// Information on this request.
1851 /** Get a block of text data (eg HTML) that the resource contains.
1853 The default behaviour is to assert, one of #LoadText()# or
1854 #LoadData()# functions must be overridden for correct operation.
1857 String for loaded text.
1859 virtual PString
LoadText(
1860 PHTTPRequest
& request
/// Information on this request.
1863 /** Enable or disable access control using .access files. A directory tree containing
1864 a _access file will require authorisation to allow access. This file has
1865 contains one or more lines, each containing a username and password seperated
1868 The parameter sets the realm used for authorisation requests. An empty realm disables
1871 void EnableAuthorisation(const PString
& realm
);
1873 /** Enable or disable directory listings when a default directory file does not exist
1875 void AllowDirectories(BOOL enable
= TRUE
);
1878 BOOL
CheckAuthority(
1879 PHTTPServer
& server
, // Server to send response to.
1880 const PHTTPRequest
& request
, // Information on this request.
1881 const PHTTPConnectionInfo
& conInfo
// Information on the connection
1884 BOOL
FindAuthorisations(const PDirectory
& dir
, PString
& realm
, PStringToString
& authorisations
);
1886 PDirectory basePath
;
1887 PString authorisationRealm
;
1888 BOOL allowDirectoryListing
;
1892 class PHTTPDirRequest
: public PHTTPFileRequest
1894 PCLASSINFO(PHTTPDirRequest
, PHTTPFileRequest
)
1897 const PURL
& url
, // Universal Resource Locator for document.
1898 const PMIMEInfo
& inMIME
, // Extra MIME information in command.
1899 const PMultipartFormInfoArray
& multipartFormInfo
,
1900 PHTTPServer
& server
1912 // End Of File ///////////////////////////////////////////////////////////////