PTLib  Version 2.18.8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PHTTPDirectory Class Reference

This object describes a HyperText Transport Protocol resource which is a set of files in a directory. More...

#include <http.h>

Inheritance diagram for PHTTPDirectory:
Collaboration diagram for PHTTPDirectory:

Public Member Functions

 PHTTPDirectory (const PURL &url, const PDirectory &dir)
 
 PHTTPDirectory (const PURL &url, const PDirectory &dir, const PHTTPAuthority &auth)
 
virtual PHTTPRequestCreateRequest (const PURL &url, const PMIMEInfo &inMIME, const PMultiPartList &multipartFormInfo, PHTTPServer &socket)
 Create a new request block for this type of resource. More...
 
virtual PBoolean LoadHeaders (PHTTPRequest &request)
 Get the headers for block of data (eg HTML) that the resource contains. More...
 
virtual PString LoadText (PHTTPRequest &request)
 Get a block of text data (eg HTML) that the resource contains. More...
 
void EnableAuthorisation (const PString &realm)
 Enable or disable access control using .access files. More...
 
void AllowDirectories (PBoolean enable=true)
 Enable or disable directory listings when a default directory file does not exist. More...
 
- Public Member Functions inherited from PHTTPFile
 PHTTPFile (const PString &filename)
 Contruct a new simple file resource for the HTTP space. More...
 
 PHTTPFile (const PString &filename, const PHTTPAuthority &auth)
 
 PHTTPFile (const PURL &url, const PFilePath &file)
 
 PHTTPFile (const PURL &url, const PFilePath &file, const PString &contentType)
 
 PHTTPFile (const PURL &url, const PFilePath &file, const PHTTPAuthority &auth)
 
 PHTTPFile (const PURL &url, const PFilePath &file, const PString &contentType, const PHTTPAuthority &auth)
 
virtual PBoolean LoadData (PHTTPRequest &request, PCharArray &data)
 Get a block of data that the resource contains. More...
 
- Public Member Functions inherited from PHTTPResource
virtual ~PHTTPResource ()
 
const PURLGetURL () const
 Get the URL for this resource. More...
 
PString GetHotLink () const
 Get relative hot link for this resouce. More...
 
const PStringGetContentType () const
 Get the current content type for the resource. More...
 
PHTTPAuthorityGetAuthority () const
 Get the current authority for the resource. More...
 
void SetAuthority (const PHTTPAuthority &auth)
 Set the current authority for the resource. More...
 
void ClearAuthority ()
 Set the current authority for the resource to unrestricted. More...
 
DWORD GetHitCount () const
 Get the current hit count for the resource. More...
 
void ClearHitCount ()
 Clear the hit count for the resource. More...
 
virtual bool SupportsWebSocketProtocol (const PString &protocol) const
 Indicate that the web socket protocol is supported by this resource. More...
 
virtual bool OnWebSocket (PHTTPServer &server, PHTTPConnectionInfo &connectInfo)
 Called when a request indicates a swtch to WebSocket protocol. More...
 
virtual bool OnGET (PHTTPServer &server, const PHTTPConnectionInfo &conInfo)
 Handle the GET command passed from the HTTP socket. More...
 
virtual PBoolean OnGETData (PHTTPServer &server, const PURL &url, const PHTTPConnectionInfo &connectInfo, PHTTPRequest &request)
 Send the data associated with a GET command. More...
 
virtual bool OnHEAD (PHTTPServer &server, const PHTTPConnectionInfo &conInfo)
 Handle the HEAD command passed from the HTTP socket. More...
 
virtual bool OnPOST (PHTTPServer &server, const PHTTPConnectionInfo &conInfo)
 Handle the POST command passed from the HTTP socket. More...
 
virtual PBoolean OnPOSTData (PHTTPRequest &request, const PStringToString &data)
 Send the data associated with a POST command. More...
 
virtual PBoolean IsModifiedSince (const PTime &when)
 Check to see if the resource has been modified since the date specified. More...
 
virtual PBoolean GetExpirationDate (PTime &when)
 Get a block of data (eg HTML) that the resource contains. More...
 
virtual void SendData (PHTTPRequest &request)
 Send the data associated with a command. More...
 
virtual void OnLoadedText (PHTTPRequest &request, PString &text)
 This is called after the text has been loaded and may be used to customise or otherwise mangle a loaded piece of text. More...
 
virtual PBoolean Post (PHTTPRequest &request, const PStringToString &data, PHTML &replyMessage)
 Get a block of data (eg HTML) that the resource contains. More...
 
- Public Member Functions inherited from PObject
__inline unsigned GetTraceContextIdentifier () const
 Get PTRACE context identifier. More...
 
__inline void SetTraceContextIdentifier (unsigned id)
 
__inline void SetTraceContextIdentifier (const PObject &obj)
 
__inline void SetTraceContextIdentifier (const PObject *obj)
 
__inline void CopyTraceContextIdentifier (PObject &obj) const
 
__inline void CopyTraceContextIdentifier (PObject *obj) const
 
virtual ~PObject ()
 
__inline const char * GetClass () const
 
__inline bool IsClass (const char *name) const
 
__inline const PObjectPTraceObjectInstance () const
 
virtual PObjectClone () const
 Create a copy of the class on the heap. More...
 
template<class CLS >
CLS * CloneAs () const
 As for Clone() but converts to specified type. More...
 
virtual PINDEX HashFunction () const
 This function yields a hash value required by the PDictionary class. More...
 
virtual Comparison Compare (const PObject &obj) const
 Compare the two objects and return their relative rank. More...
 
virtual Comparison CompareObjectMemoryDirect (const PObject &obj) const
 Determine the byte wise comparison of two objects. More...
 
bool operator== (const PObject &obj) const
 Compare the two objects. More...
 
bool operator!= (const PObject &obj) const
 Compare the two objects. More...
 
bool operator< (const PObject &obj) const
 Compare the two objects. More...
 
bool operator> (const PObject &obj) const
 Compare the two objects. More...
 
bool operator<= (const PObject &obj) const
 Compare the two objects. More...
 
bool operator>= (const PObject &obj) const
 Compare the two objects. More...
 
virtual void PrintOn (ostream &strm) const
 Output the contents of the object to the stream. More...
 
virtual void ReadFrom (istream &strm)
 Input the contents of the object from the stream. More...
 

Protected Member Functions

PBoolean CheckAuthority (PHTTPServer &server, const PHTTPRequest &request, const PHTTPConnectionInfo &conInfo)
 See if the resource is authorised given the mime info. More...
 
PBoolean FindAuthorisations (const PDirectory &dir, PString &realm, PStringToString &authorisations)
 
- Protected Member Functions inherited from PHTTPFile
 PHTTPFile (const PURL &url, int dummy)
 
- Protected Member Functions inherited from PHTTPResource
 PHTTPResource (const PURL &url)
 
 PHTTPResource (const PURL &url, const PHTTPAuthority &auth)
 
 PHTTPResource (const PURL &url, const PString &contentType)
 
 PHTTPResource (const PURL &url, const PString &contentType, const PHTTPAuthority &auth)
 
virtual bool InternalOnCommand (PHTTPServer &server, const PHTTPConnectionInfo &conInfo, PHTTP::Commands cmd)
 common code for GET and HEAD commands More...
 
 P_REMOVE_VIRTUAL (PBoolean, OnGET(PHTTPServer &, const PURL &, const PMIMEInfo &, const PHTTPConnectionInfo &), false)
 
 P_REMOVE_VIRTUAL (PBoolean, OnHEAD(PHTTPServer &, const PURL &, const PMIMEInfo &, const PHTTPConnectionInfo &), false)
 
 P_REMOVE_VIRTUAL (PBoolean, OnGETOrHEAD(PHTTPServer &, const PURL &, const PMIMEInfo &, const PHTTPConnectionInfo &, PBoolean), false)
 
 P_REMOVE_VIRTUAL (PBoolean, OnPOST(PHTTPServer &, const PURL &, const PMIMEInfo &, const PStringToString &, const PHTTPConnectionInfo &), false)
 
- Protected Member Functions inherited from PObject
 PObject ()
 Constructor for PObject, made protected so cannot ever create one on its own. More...
 

Protected Attributes

PDirectory m_basePath
 
PString m_authorisationRealm
 
bool m_allowDirectoryListing
 
- Protected Attributes inherited from PHTTPFile
PFilePath m_filePath
 
- Protected Attributes inherited from PHTTPResource
PURL m_baseURL
 Base URL for the resource, may accept URLS with a longer hierarchy. More...
 
PString m_contentType
 MIME content type for the resource. More...
 
PHTTPAuthoritym_authority
 Authorisation method for the resource. More...
 
atomic< unsigned > m_hitCount
 Count of number of times resource was accessed. More...
 
- Protected Attributes inherited from PObject
unsigned m_traceContextIdentifier
 

Additional Inherited Members

- Public Types inherited from PObject
enum  Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 }
 Result of the comparison operation performed by the Compare() function. More...
 
- Static Public Member Functions inherited from PObject
static __inline void CopyTraceContextIdentifier (PObject &to, const PObject &from)
 
static __inline void CopyTraceContextIdentifier (PObject &to, const PObject *from)
 
static __inline void CopyTraceContextIdentifier (PObject *to, const PObject &from)
 
static __inline void CopyTraceContextIdentifier (PObject *to, const PObject *from)
 
static __inline const char * Class ()
 
static __inline const PObjectPTraceObjectInstance (const char *)
 
static __inline const PObjectPTraceObjectInstance (const PObject *obj)
 
template<typename T >
static Comparison Compare2 (T v1, T v2)
 Compare two types, returning Comparison type. More...
 
static Comparison InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size)
 Internal function caled from CompareObjectMemoryDirect() More...
 
- Static Protected Member Functions inherited from PHTTPResource
static PBoolean CheckAuthority (PHTTPAuthority &authority, PHTTPServer &server, const PHTTPRequest &request, const PHTTPConnectionInfo &connectInfo)
 

Detailed Description

This object describes a HyperText Transport Protocol resource which is a set of files in a directory.

The directory can be anywhere in the file system and is mapped to the specified URL location in the HTTP name space defined by the PHTTPSpace class.

All subdirectories and files are available as URL names in the HTTP name space. This effectively grafts a file system directory tree onto the URL name space tree.

See the PMIMEInfo class for more information on the mappings between file types and MIME types.

Constructor & Destructor Documentation

PHTTPDirectory::PHTTPDirectory ( const PURL url,
const PDirectory dir 
)
Parameters
urlName of the resource in URL space.
dirLocation of file in file system.
PHTTPDirectory::PHTTPDirectory ( const PURL url,
const PDirectory dir,
const PHTTPAuthority auth 
)
Parameters
urlName of the resource in URL space.
dirLocation of file in file system.
authAuthorisation for the resource.

Member Function Documentation

void PHTTPDirectory::AllowDirectories ( PBoolean  enable = true)

Enable or disable directory listings when a default directory file does not exist.

PBoolean PHTTPDirectory::CheckAuthority ( PHTTPServer server,
const PHTTPRequest request,
const PHTTPConnectionInfo conInfo 
)
protectedvirtual

See if the resource is authorised given the mime info.

Reimplemented from PHTTPResource.

virtual PHTTPRequest* PHTTPDirectory::CreateRequest ( const PURL url,
const PMIMEInfo inMIME,
const PMultiPartList multipartFormInfo,
PHTTPServer socket 
)
virtual

Create a new request block for this type of resource.

Returns
Pointer to instance of PHTTPRequest descendant class.

Reimplemented from PHTTPFile.

void PHTTPDirectory::EnableAuthorisation ( const PString realm)

Enable or disable access control using .access files.

A directory tree containing a _access file will require authorisation to allow access. This file has contains one or more lines, each containing a username and password seperated by a ":" character.

The parameter sets the realm used for authorisation requests. An empty realm disables auhtorisation.

PBoolean PHTTPDirectory::FindAuthorisations ( const PDirectory dir,
PString realm,
PStringToString authorisations 
)
protected
virtual PBoolean PHTTPDirectory::LoadHeaders ( PHTTPRequest request)
virtual

Get the headers for block of data (eg HTML) that the resource contains.

This will fill in all the fields of the outMIME parameter required by the resource and return the status for the load.

Returns
true if all OK, false if an error occurred.
Parameters
requestInformation on this request.

Reimplemented from PHTTPFile.

virtual PString PHTTPDirectory::LoadText ( PHTTPRequest request)
virtual

Get a block of text data (eg HTML) that the resource contains.

The default behaviour is to assert, one of LoadText() or LoadData() functions must be overridden for correct operation.

Returns
String for loaded text.
Parameters
requestInformation on this request.

Reimplemented from PHTTPFile.

Member Data Documentation

bool PHTTPDirectory::m_allowDirectoryListing
protected
PString PHTTPDirectory::m_authorisationRealm
protected
PDirectory PHTTPDirectory::m_basePath
protected

The documentation for this class was generated from the following file: