📄 http.h
字号:
@return
String for the authorisation password.
*/
const PString & GetPassword() const { return password; }
protected:
PString realm;
PString username;
PString password;
};
//////////////////////////////////////////////////////////////////////////////
// PHTTPMultiSimpAuth
/** This class describes the simple authorisation mechanism for a Universal
Resource Locator, a fixed realm, multiple usernames and passwords.
*/
class PHTTPMultiSimpAuth : public PHTTPAuthority
{
PCLASSINFO(PHTTPMultiSimpAuth, PHTTPAuthority)
public:
PHTTPMultiSimpAuth(
const PString & realm ///< Name space for the username and password.
);
PHTTPMultiSimpAuth(
const PString & realm, ///< Name space for the usernames.
const PStringToString & userList ///< List of usernames and passwords.
);
// Construct the simple authorisation structure.
// Overrides from class PObject.
/** Create a copy of the class on the heap. This is used by the
#PHTTPResource# classes for maintaining authorisation to
resources.
@return
pointer to new copy of the class instance.
*/
virtual PObject * Clone() const;
// Overrides from class PHTTPAuthority.
/** Get the realm or name space for the user authorisation name and
password as required by the basic authorisation system of HTTP/1.0.
@return
String for the authorisation realm name.
*/
virtual PString GetRealm(
const PHTTPRequest & request ///< Request information.
) const;
/** Validate the user and password provided by the remote HTTP client for
the realm specified by the class instance.
@return
TRUE if the user and password are authorised in the realm.
*/
virtual BOOL Validate(
const PHTTPRequest & request, ///< Request information.
const PString & authInfo ///< Authority information string.
) const;
/** Determine if the authirisation is to be applied. This could be used to
distinguish between net requiring authorisation and requiring autorisation
but having no password.
The default behaviour is to return TRUE.
@return
TRUE if the authorisation in the realm is to be applied.
*/
virtual BOOL IsActive() const;
/** Get the user name allocated to this simple authorisation.
@return
String for the authorisation user name.
*/
void AddUser(
const PString & username, ///< Username that this object wiull authorise.
const PString & password ///< Password for the above username.
);
protected:
PString realm;
PStringToString users;
};
//////////////////////////////////////////////////////////////////////////////
// PHTTPResource
/** This object describes a HyperText Transport Protocol resource. A tree of
these resources are available to the #PHTTPSocket# class.
*/
class PHTTPResource : public PObject
{
PCLASSINFO(PHTTPResource, PObject)
protected:
PHTTPResource(
const PURL & url ///< Name of the resource in URL space.
);
PHTTPResource(
const PURL & url, ///< Name of the resource in URL space.
const PHTTPAuthority & auth ///< Authorisation for the resource.
);
PHTTPResource(
const PURL & url, ///< Name of the resource in URL space.
const PString & contentType ///< MIME content type for the resource.
);
PHTTPResource(
const PURL & url, ///< Name of the resource in URL space.
const PString & contentType, ///< MIME content type for the resource.
const PHTTPAuthority & auth ///< Authorisation for the resource.
);
// Create a new HTTP Resource.
public:
virtual ~PHTTPResource();
// Destroy the HTTP Resource.
// New functions for class.
/** Get the URL for this resource.
@return
The URL for this resource.
*/
const PURL & GetURL() const { return baseURL; }
/** Get the current content type for the resource.
@return
string for the current MIME content type.
*/
const PString & GetContentType() const { return contentType; }
/** Get the current authority for the resource.
@return
Pointer to authority or NULL if unrestricted.
*/
PHTTPAuthority * GetAuthority() const { return authority; }
/** Set the current authority for the resource.
*/
void SetAuthority(
const PHTTPAuthority & auth ///< authority to set
);
/** Set the current authority for the resource to unrestricted.
*/
void ClearAuthority();
/** Get the current hit count for the resource. This is the total number of
times the resource was asked for by a remote client.
@return
Hit count for the resource.
*/
DWORD GetHitCount() const { return hitCount; }
void ClearHitCount() { hitCount = 0; }
// Clear the hit count for the resource.
/** 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.
@return
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.
*/
virtual BOOL OnGET(
PHTTPServer & server, ///< HTTP server that received the request
const PURL & url, ///< Universal Resource Locator for document.
const PMIMEInfo & info, ///< Extra MIME information in command.
const PHTTPConnectionInfo & conInfo ///< HTTP connection information
);
/**Send the data associated with a GET command.
The default action calls #SendData()#.
@return
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.
*/
virtual BOOL OnGETData(
PHTTPServer & server, ///< HTTP server that received the request
const PURL & url, ///< Universal Resource Locator for document
const PHTTPConnectionInfo & connectInfo, ///< HTTP connection information
PHTTPRequest & request ///< request state information
);
/** 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.
@return
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.
*/
virtual BOOL OnHEAD(
PHTTPServer & server, ///< HTTP server that received the request
const PURL & url, ///< Universal Resource Locator for document.
const PMIMEInfo & info, ///< Extra MIME information in command.
const PHTTPConnectionInfo & conInfo ///< HTTP connection information
);
/** 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.
@return
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.
*/
virtual BOOL OnPOST(
PHTTPServer & server, ///< HTTP server that received the request
const PURL & url, ///< Universal Resource Locator for document.
const PMIMEInfo & info, ///< Extra MIME information in command.
const PStringToString & data, ///< Variables in the POST data.
const PHTTPConnectionInfo & conInfo ///< HTTP connection information
);
/**Send the data associated with a POST command.
The default action calls #Post()#.
@return
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.
*/
virtual BOOL OnPOSTData(
PHTTPRequest & request, ///< request information
const PStringToString & data ///< Variables in the POST data.
);
/** Check to see if the resource has been modified since the date
specified.
@return
TRUE if has been modified since.
*/
virtual BOOL IsModifiedSince(
const PTime & when ///< Time to see if modified later than
);
/** Get a block of data (eg HTML) that the resource contains.
@return
Status of load operation.
*/
virtual BOOL GetExpirationDate(
PTime & when ///< Time that the resource expires
);
/** Create a new request block for this type of resource.
The default behaviour is to create a new PHTTPRequest instance.
@return
Pointer to instance of PHTTPRequest descendant class.
*/
virtual PHTTPRequest * CreateRequest(
const PURL & url, ///< Universal Resource Locator for document.
const PMIMEInfo & inMIME, ///< Extra MIME information in command.
const PMultipartFormInfoArray & multipartFormInfo, ///< additional information for multi-part posts
PHTTPServer & socket ///< socket used for request
);
/** Get the headers for block of data (eg HTML) that the resource contains.
This will fill in all the fields of the <CODE>outMIME</CODE> parameter
required by the resource and return the status for the load.
@return
TRUE if all OK, FALSE if an error occurred.
*/
virtual BOOL LoadHeaders(
PHTTPRequest & request ///< Information on this request.
) = 0;
/**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.
*/
virtual void SendData(
PHTTPRequest & request ///< information for this request
);
/** 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.
@return
TRUE if there is still more to load.
*/
virtual BOOL LoadData(
PHTTPRequest & request, ///< Information on this request.
PCharArray & data ///< Data used in reply.
);
/** 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.
@return
String for loaded text.
*/
virtual PString LoadText(
PHTTPRequest & request ///< Information on this request.
);
/** 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.
*/
virtual void OnLoadedText(
PHTTPRequest & request, ///< Information on this request.
PString & text ///< Data used in reply.
);
/** Get a block of data (eg HTML) that the resource contains.
The default action for this function is to do nothing and return
success.
@return
TRUE if the connection may persist, FALSE if the connection must close
*/
virtual BOOL Post(
PHTTPRequest & request, ///< Information on this request.
const PStringToString & data, ///< Variables in the POST data.
PHTML & replyMessage ///< Reply message for post.
);
protected:
/** See if the resource is authorised given the mime info
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -