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

This object describes a HyperText Transport Protocol resource. More...

#include <http.h>

Inheritance diagram for PHTTPResource:
Collaboration diagram for PHTTPResource:

Public Member Functions

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 OnWebSocket (PHTTPServer &server, PHTTPConnectionInfo &connectInfo)
 Called when a request indicates a swtch to WebSocket protocol. More...
 
virtual PBoolean OnGET (PHTTPServer &server, const PURL &url, const PMIMEInfo &info, 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 PBoolean OnHEAD (PHTTPServer &server, const PURL &url, const PMIMEInfo &info, const PHTTPConnectionInfo &conInfo)
 Handle the HEAD command passed from the HTTP socket. More...
 
virtual PBoolean OnPOST (PHTTPServer &server, const PURL &url, const PMIMEInfo &info, const PStringToString &data, 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 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 void SendData (PHTTPRequest &request)
 Send the data associated with a command. More...
 
virtual PBoolean LoadData (PHTTPRequest &request, PCharArray &data)
 Get a block of data that the resource contains. More...
 
virtual PString LoadText (PHTTPRequest &request)
 Get a block of text data (eg HTML) that the resource contains. 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
unsigned GetTraceContextIdentifier () const
 Get PTRACE context identifier. More...
 
void SetTraceContextIdentifier (unsigned id)
 
void GetTraceContextIdentifier (PObject &obj)
 
void GetTraceContextIdentifier (PObject *obj)
 
void SetTraceContextIdentifier (const PObject &obj)
 
void SetTraceContextIdentifier (const PObject *obj)
 
virtual ~PObject ()
 
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 const char * GetClass (unsigned ancestor=0) const
 Get the current dynamic type of the object instance. More...
 
PBoolean IsClass (const char *cls) const
 
virtual PBoolean InternalIsDescendant (const char *clsName) const
 Determine if the dynamic type of the current instance is a descendent of the specified class. More...
 
__inline const PObjectPTraceObjectInstance () const
 
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

 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 PBoolean CheckAuthority (PHTTPServer &server, const PHTTPRequest &request, const PHTTPConnectionInfo &conInfo)
 See if the resource is authorised given the mime info. More...
 
virtual PBoolean OnGETOrHEAD (PHTTPServer &server, const PURL &url, const PMIMEInfo &info, const PHTTPConnectionInfo &conInfo, PBoolean isGet)
 common code for GET and HEAD commands More...
 
- Protected Member Functions inherited from PObject
 PObject ()
 Constructor for PObject, made protected so cannot ever create one on its own. More...
 

Static Protected Member Functions

static PBoolean CheckAuthority (PHTTPAuthority &authority, PHTTPServer &server, const PHTTPRequest &request, const PHTTPConnectionInfo &connectInfo)
 

Protected Attributes

PURL baseURL
 Base URL for the resource, may accept URLS with a longer hierarchy. More...
 
PString contentType
 MIME content type for the resource. More...
 
PHTTPAuthorityauthority
 Authorisation method for the resource. More...
 
volatile DWORD 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 Comparison InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size)
 Internal function caled from CompareObjectMemoryDirect() More...
 
static const char * Class ()
 Get the name of the class as a C string. More...
 
static __inline const PObjectPTraceObjectInstance (const char *)
 
static __inline const PObjectPTraceObjectInstance (const PObject *obj)
 
- Friends inherited from PObject

Detailed Description

This object describes a HyperText Transport Protocol resource.

A tree of these resources are available to the PHTTPServer class.

Constructor & Destructor Documentation

PHTTPResource::PHTTPResource ( const PURL url)
protected
Parameters
urlName of the resource in URL space.
PHTTPResource::PHTTPResource ( const PURL url,
const PHTTPAuthority auth 
)
protected
Parameters
urlName of the resource in URL space.
authAuthorisation for the resource.
PHTTPResource::PHTTPResource ( const PURL url,
const PString contentType 
)
protected
Parameters
urlName of the resource in URL space.
contentTypeMIME content type for the resource.
PHTTPResource::PHTTPResource ( const PURL url,
const PString contentType,
const PHTTPAuthority auth 
)
protected
Parameters
urlName of the resource in URL space.
contentTypeMIME content type for the resource.
authAuthorisation for the resource.
virtual PHTTPResource::~PHTTPResource ( )
virtual

Member Function Documentation

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

See if the resource is authorised given the mime info.

Parameters
serverServer to send response to.
requestInformation on this request.
conInfoInformation on the connection

Reimplemented in PHTTPDirectory.

static PBoolean PHTTPResource::CheckAuthority ( PHTTPAuthority authority,
PHTTPServer server,
const PHTTPRequest request,
const PHTTPConnectionInfo connectInfo 
)
staticprotected
void PHTTPResource::ClearAuthority ( )

Set the current authority for the resource to unrestricted.

void PHTTPResource::ClearHitCount ( )
inline

Clear the hit count for the resource.

References hitCount.

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

Create a new request block for this type of resource.

The default behaviour is to create a new PHTTPRequest instance.

Returns
Pointer to instance of PHTTPRequest descendant class.
Parameters
urlUniversal Resource Locator for document.
inMIMEExtra MIME information in command.
multipartFormInfoadditional information for multi-part posts
socketsocket used for request

Reimplemented in PHTTPDirectory, and PHTTPFile.

PHTTPAuthority* PHTTPResource::GetAuthority ( ) const
inline

Get the current authority for the resource.

Returns
Pointer to authority or NULL if unrestricted.

References authority.

const PString& PHTTPResource::GetContentType ( ) const
inline

Get the current content type for the resource.

Returns
string for the current MIME content type.

References contentType.

virtual PBoolean PHTTPResource::GetExpirationDate ( PTime when)
virtual

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

Returns
Status of load operation.
Parameters
whenTime that the resource expires

Reimplemented in PServiceHTTPDirectory, PServiceHTTPFile, PServiceHTTPString, PConfigSectionsPage, and PConfigPage.

DWORD PHTTPResource::GetHitCount ( ) const
inline

Get the current hit count for the resource.

This is the total number of times the resource was asked for by a remote client.

Returns
Hit count for the resource.

References hitCount.

PString PHTTPResource::GetHotLink ( ) const
inline

Get relative hot link for this resouce.

References PURL::AsString(), baseURL, and PURL::PathOnly.

const PURL& PHTTPResource::GetURL ( ) const
inline

Get the URL for this resource.

Returns
The URL for this resource.

References baseURL.

virtual PBoolean PHTTPResource::IsModifiedSince ( const PTime when)
virtual

Check to see if the resource has been modified since the date specified.

Returns
true if has been modified since.
Parameters
whenTime to see if modified later than
virtual PBoolean PHTTPResource::LoadData ( PHTTPRequest request,
PCharArray data 
)
virtual

Get a block of data that the resource contains.

The default behaviour is to call the LoadText() function and if successful, call the OnLoadedText() function.

Returns
true if there is still more to load.
Parameters
requestInformation on this request.
dataData used in reply.

Reimplemented in PHTTPTailFile, and PHTTPFile.

virtual PBoolean PHTTPResource::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 in PHTTPDirectory, PHTTPTailFile, PHTTPFile, PHTTPString, PSOAPServerResource, and PXMLRPCServerResource.

virtual PString PHTTPResource::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 in PHTTPDirectory, PHTTPFile, PHTTPString, PServiceHTTPString, and PRegisterPage.

virtual PBoolean PHTTPResource::OnGET ( PHTTPServer server,
const PURL url,
const PMIMEInfo info,
const PHTTPConnectionInfo conInfo 
)
virtual

Handle the GET command passed from the HTTP socket.

The default action is to check the authorisation for the resource and call the virtuals LoadHeaders() and OnGETData() to get a resource to be sent to the socket.

Returns
true if the connection may persist, false if the connection must close. If there is no ContentLength field in the response, this value must be false for correct operation.
Parameters
serverHTTP server that received the request
urlUniversal Resource Locator for document.
infoExtra MIME information in command.
conInfoHTTP connection information
virtual PBoolean PHTTPResource::OnGETData ( PHTTPServer server,
const PURL url,
const PHTTPConnectionInfo connectInfo,
PHTTPRequest request 
)
virtual

Send the data associated with a GET command.

The default action calls SendData().

Returns
true if the connection may persist, false if the connection must close. If there is no ContentLength field in the response, this value must be false for correct operation.
Parameters
serverHTTP server that received the request
urlUniversal Resource Locator for document
connectInfoHTTP connection information
requestrequest state information
virtual PBoolean PHTTPResource::OnGETOrHEAD ( PHTTPServer server,
const PURL url,
const PMIMEInfo info,
const PHTTPConnectionInfo conInfo,
PBoolean  isGet 
)
protectedvirtual

common code for GET and HEAD commands

Parameters
serverHTTP server that received the request
urlUniversal Resource Locator for document.
infoExtra MIME information in command.
conInfoConnection information
isGetFlag indicating is GET or HEAD
virtual PBoolean PHTTPResource::OnHEAD ( PHTTPServer server,
const PURL url,
const PMIMEInfo info,
const PHTTPConnectionInfo conInfo 
)
virtual

Handle the HEAD command passed from the HTTP socket.

The default action is to check the authorisation for the resource and call the virtual LoadHeaders() to get the header information to be sent to the socket.

Returns
true if the connection may persist, false if the connection must close If there is no ContentLength field in the response, this value must be false for correct operation.
Parameters
serverHTTP server that received the request
urlUniversal Resource Locator for document.
infoExtra MIME information in command.
conInfoHTTP connection information
virtual void PHTTPResource::OnLoadedText ( PHTTPRequest request,
PString text 
)
virtual

This is called after the text has been loaded and may be used to customise or otherwise mangle a loaded piece of text.

Typically this is used with HTML responses.

The default action for this function is to do nothing.

Parameters
requestInformation on this request.
textData used in reply.

Reimplemented in PHTTPConfigSectionList, PHTTPConfig, PHTTPForm, PServiceHTTPDirectory, PServiceHTTPFile, PRegisterPage, PConfigSectionsPage, and PConfigPage.

virtual PBoolean PHTTPResource::OnPOST ( PHTTPServer server,
const PURL url,
const PMIMEInfo info,
const PStringToString data,
const PHTTPConnectionInfo conInfo 
)
virtual

Handle the POST command passed from the HTTP socket.

The default action is to check the authorisation for the resource and call the virtual Post() function to handle the data being received.

Returns
true if the connection may persist, false if the connection must close If there is no ContentLength field in the response, this value must be false for correct operation.
Parameters
serverHTTP server that received the request
urlUniversal Resource Locator for document.
infoExtra MIME information in command.
dataVariables in the POST data.
conInfoHTTP connection information

Reimplemented in PConfigSectionsPage, and PConfigPage.

virtual PBoolean PHTTPResource::OnPOSTData ( PHTTPRequest request,
const PStringToString data 
)
virtual

Send the data associated with a POST command.

The default action calls Post().

Returns
true if the connection may persist, false if the connection must close. If there is no ContentLength field in the response, this value must be false for correct operation.
Parameters
requestrequest information
dataVariables in the POST data.

Reimplemented in PSOAPServerResource, and PXMLRPCServerResource.

virtual bool PHTTPResource::OnWebSocket ( PHTTPServer server,
PHTTPConnectionInfo connectInfo 
)
virtual

Called when a request indicates a swtch to WebSocket protocol.

This will handle a WebScoket protocol change.

After the start up handshake has completed, if there is a notifier and it is non-null, then the notifier is called. The notifier, may then call connectInfo.ClearWebSocket() if it wishes to return to HTTP mode. That is, ProcessCommand() will return true and the normal persistence rules apply. If ClearWebSocket() is not called then ProcessCommand() will return false.

Note, that the latter case does not mean that the underlying socket is necessarily closed, it could subsequently be disconnected from the PHTTPServer objects and passed to PWebSocket for processing.

Returns
true if want to persist with HTTP connection.
Parameters
serverHTTP server that received the request
connectInfoHTTP connection information
virtual PBoolean PHTTPResource::Post ( PHTTPRequest request,
const PStringToString data,
PHTML replyMessage 
)
virtual

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

The default action for this function is to do nothing and return success.

Returns
true if the connection may persist, false if the connection must close
Parameters
requestInformation on this request.
dataVariables in the POST data.
replyMessageReply message for post.

Reimplemented in PHTTPConfigSectionList, PHTTPConfig, PHTTPForm, PRegisterPage, PConfigSectionsPage, and PConfigPage.

virtual void PHTTPResource::SendData ( PHTTPRequest request)
virtual

Send the data associated with a command.

The default action is to call the virtual LoadData() to get a resource to be sent to the socket.

Parameters
requestinformation for this request
void PHTTPResource::SetAuthority ( const PHTTPAuthority auth)

Set the current authority for the resource.

Parameters
authauthority to set

Member Data Documentation

PHTTPAuthority* PHTTPResource::authority
protected

Authorisation method for the resource.

Referenced by GetAuthority().

PURL PHTTPResource::baseURL
protected

Base URL for the resource, may accept URLS with a longer hierarchy.

Referenced by GetHotLink(), and GetURL().

PString PHTTPResource::contentType
protected

MIME content type for the resource.

Referenced by GetContentType().

volatile DWORD PHTTPResource::hitCount
protected

COunt of number of times resource was accessed.

Referenced by ClearHitCount(), and GetHitCount().


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