⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 http.h

📁 radius协议源码÷The Radius Stack will connect to a Radius Server. This stack implementation is built upo
💻 H
📖 第 1 页 / 共 4 页
字号:
      <PRE><CODE>      PHTTPSocket web("webserver");      if (web.IsOpen()) {        if (web.GetDocument("http://www.someone.com/somewhere/url")) {          while (web.Read(block, sizeof(block)))            ProcessHTML(block);        }        else           PError << "Could not get page." << endl;      }      else         PError << "HTTP conection failed." << endl;      </PRE></CODE> */class PHTTPClient : public PHTTP{  PCLASSINFO(PHTTPClient, PHTTP)  public:    /// Create a new HTTP client channel.    PHTTPClient();  // New functions for class.    /** Send a command and wait for the response header (including MIME fields).       Note that a body may still be on its way even if lasResponseCode is not       200!       @return       TRUE if all of header returned and ready to receive body.     */    int ExecuteCommand(Commands cmd,                       const PString & url,                       const PMIMEInfo & outMIME,                       const PString & dataBody,                       PMIMEInfo & replyMime,                       BOOL persist = TRUE);    int ExecuteCommand(const PString & cmdName,                       const PString & url,                       const PMIMEInfo & outMIME,                       const PString & dataBody,                       PMIMEInfo & replyMime,                       BOOL persist = TRUE);    /// Write a HTTP command to server    BOOL WriteCommand(Commands cmd,                      const PString & url,                      const PMIMEInfo & outMIME,                      const PString & dataBody);    BOOL WriteCommand(const PString & cmdName,                      const PString & url,                      const PMIMEInfo & outMIME,                      const PString & dataBody);    /// Read a response from the server    BOOL ReadResponse(PMIMEInfo & replyMIME);    /** Get the document specified by the URL.       @return       TRUE if document is being transferred.     */    BOOL GetDocument(      const PURL & url,         // Universal Resource Locator for document.      PMIMEInfo & outMIME,      // MIME info in request      PMIMEInfo & replyMIME,    // MIME info in response      BOOL persist = TRUE    );    /** Get the header for the document specified by the URL.       @return       TRUE if document header is being transferred.     */    BOOL GetHeader(      const PURL & url,         // Universal Resource Locator for document.      PMIMEInfo & outMIME,      // MIME info in request      PMIMEInfo & replyMIME,    // MIME info in response      BOOL persist = TRUE    );    /** Post the data specified to the URL.       @return       TRUE if document is being transferred.     */    BOOL PostData(      const PURL & url,       // Universal Resource Locator for document.      PMIMEInfo & outMIME,    // MIME info in request      const PString & data,   // Information posted to the HTTP server.      PMIMEInfo & replyMIME,  // MIME info in response      BOOL persist = TRUE    );  protected:    BOOL AssureConnect(const PURL & url, PMIMEInfo & outMIME);};//////////////////////////////////////////////////////////////////////////////// PHTTPConnectionInfoclass PHTTPServer;/** This object describes the connectiono associated with a HyperText Transport   Protocol request. This information is required by handler functions on   #PHTTPResource# descendant classes to manage the connection correctly.*/class PHTTPConnectionInfo : public PObject{  PCLASSINFO(PHTTPConnectionInfo, PObject)  public:    PHTTPConnectionInfo();    PHTTP::Commands GetCommandCode() const { return commandCode; }    const PString & GetCommandName() const { return commandName; }    const PURL & GetURL() const       { return url; }    const PMIMEInfo & GetMIME() const { return mimeInfo; }    void SetMIME(const PString & tag, const PString & value);    void SetPersistance(BOOL newPersist);    BOOL IsCompatible(int major, int minor) const;    BOOL IsPersistant() const         { return isPersistant; }    BOOL IsProxyConnection() const    { return isProxyConnection; }    int  GetMajorVersion() const      { return majorVersion; }    int  GetMinorVersion() const      { return minorVersion; }    long GetEntityBodyLength() const  { return entityBodyLength; }  protected:    BOOL Initialise(PHTTPServer & server, PString & args);    PHTTP::Commands commandCode;    PString   commandName;    PURL      url;    PMIMEInfo mimeInfo;    BOOL      isPersistant;    BOOL      isProxyConnection;    int       majorVersion;    int       minorVersion;    long      entityBodyLength;  friend class PHTTPServer;};//////////////////////////////////////////////////////////////////////////////// PHTTPServer/** A TCP/IP socket for the HyperText Transfer Protocol version 1.0.    When acting as a server, a descendant class would be created to override    at least the #HandleOpenMailbox()#, #HandleSendMessage()# and    #HandleDeleteMessage()# functions. Other functions may be overridden    for further enhancement to the sockets capabilities, but these will give a    basic POP3 server functionality.    The server socket thread would continuously call the    #ProcessMessage()# function until it returns FALSE. This will then    call the appropriate virtual function on parsing the POP3 protocol. */class PHTTPServer : public PHTTP{  PCLASSINFO(PHTTPServer, PHTTP)  public:    /** Create a TCP/IP HTTP protocol socket channel. The form with the single       <CODE>port</CODE> parameter creates an unopened socket, the form with       the <CODE>address</CODE> parameter makes a connection to a remote       system, opening the socket. The form with the <CODE>socket</CODE>       parameter opens the socket to an incoming call from a "listening"       socket.     */    PHTTPServer();    PHTTPServer(      const PHTTPSpace & urlSpace  // Name space to use for URLs received.    );  // New functions for class.    /** Get the name of the server.       @return       String name of the server.     */    virtual PString GetServerName() const;    /** Get the name space being used by the HTTP server socket.       @return       URL name space tree.     */    PHTTPSpace & GetURLSpace() { return urlSpace; }    /// Use a new URL name space for this HTTP socket.    void SetURLSpace(      const PHTTPSpace & space   // New URL name space to use.    );    /** Process commands, dispatching to the appropriate virtual function. This       is used when the socket is acting as a server.       @return       TRUE if the request specified persistant mode and the request version       allows it, FALSE if the socket closed, timed out, the protocol does not       allow persistant mode, or the client did not request it       timed out     */    BOOL ProcessCommand();    /** Handle a GET command from a client.       The default implementation looks up the URL in the name space declared by       the #PHTTPSpace# class tree and despatches to the       #PHTTPResource# object contained therein.       @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(      const PURL & url,                    // Universal Resource Locator for document.      const PMIMEInfo & info,              // Extra MIME information in command.      const PHTTPConnectionInfo & conInfo    );    /** Handle a HEAD command from a client.       The default implemetation looks up the URL in the name space declared by       the #PHTTPSpace# class tree and despatches to the       #PHTTPResource# object contained therein.       @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(      const PURL & url,                   // Universal Resource Locator for document.      const PMIMEInfo & info,             // Extra MIME information in command.      const PHTTPConnectionInfo & conInfo    );    /** Handle a POST command from a client.       The default implementation looks up the URL in the name space declared by       the #PHTTPSpace# class tree and despatches to the       #PHTTPResource# object contained therein.       @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(      const PURL & url,                   // Universal Resource Locator for document.      const PMIMEInfo & info,             // Extra MIME information in command.      const PStringToString & data,       // Variables provided in the POST data.      const PHTTPConnectionInfo & conInfo    );    /** Handle a proxy command request from a client. This will only get called       if the request was not for this particular server. If it was a proxy       request for this server (host and port number) then the appropriate       #OnGET()#, #OnHEAD()# or #OnPOST()# command is called.       The default implementation returns OnError(BadGateway).       @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 OnProxy(      const PHTTPConnectionInfo & conInfo    );    /** Read the entity body associated with a HTTP request, and close the       socket if not a persistant connection.       @return       The entity body of the command     */    virtual PString ReadEntityBody();    /** Handle an unknown command.       @return       TRUE if the connection may persist, FALSE if the connection must close     */    virtual BOOL OnUnknown(      const PCaselessString & command, // Complete command line received.      const PHTTPConnectionInfo & connectInfo    );    /** Write a command reply back to the client, and construct some of the       outgoing MIME fields. The MIME fields are not sent.       The <CODE>bodySize</CODE> parameter determines the size of the        entity body associated with the response. If <CODE>bodySize</CODE> is       >= 0, then a ContentLength field will be added to the outgoing MIME       headers if one does not already exist.       If <CODE>bodySize</CODE> is < 0, then it is assumed that the size of       the entity body is unknown, or has already been added, and no       ContentLength field will be constructed.        If the version of the request is less than 1.0, then this function does       nothing.     */    void StartResponse(      StatusCode code,      // Status code for the response.      PMIMEInfo & headers,  // MIME variables included in response.      long bodySize         // Size of the rest of the response.    );    /** Write an error response for the specified code.       Depending on the <CODE>code</CODE> parameter this function will also       send a HTML version of the status code for display on the remote client       viewer.       @return       TRUE if the connection may persist, FALSE if the connection must close     */    virtual BOOL OnError(      StatusCode code,                         // Status code for the error response.      const PCaselessString & extra,           // Extra information included in the response.      const PHTTPConnectionInfo & connectInfo    );    /** Set the default mime info     */    void SetDefaultMIMEInfo(      PMIMEInfo & info,      // Extra MIME information in command.      const PHTTPConnectionInfo & connectInfo    );  protected:    void Construct();    PHTTPConnectionInfo connectInfo;    PINDEX transactionCount;    PTimeInterval nextTimeout;    PHTTPSpace urlSpace;};//////////////////////////////////////////////////////////////////////////////// PHTTPRequest/** This object describes a HyperText Transport Protocol request. An individual   request is passed to handler functions on #PHTTPResource# descendant   classes. */class PHTTPRequest : public PObject{  PCLASSINFO(PHTTPRequest, PObject)  public:    PHTTPRequest(      const PURL & url,             // Universal Resource Locator for document.      const PMIMEInfo & inMIME,     // Extra MIME information in command.      PHTTPServer & socket          // socket that request initiated on    );    const PURL & url;               // Universal Resource Locator for document.    const PMIMEInfo & inMIME;       // Extra MIME information in command.    PHTTP::StatusCode code;         // Status code for OnError() reply.    PMIMEInfo outMIME;              // MIME information used in reply.    PINDEX contentSize;             // Size of the body of the resource data.    PIPSocket::Address origin;      // IP address of origin host for request    PIPSocket::Address localAddr;   // IP address of local interface for request    WORD               localPort;   // Port number of local server for request};//////////////////////////////////////////////////////////////////////////////// PHTTPAuthority/** This abstract class describes the authorisation mechanism for a Universal   Resource Locator. */class PHTTPAuthority : public PObject{  PCLASSINFO(PHTTPAuthority, PObject)  public:  // New functions for class.    /** 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.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -