Logo Search packages:      
Sourcecode: pwlib version File versions  Download package

PHTTPClient Class Reference

#include <http.h>

Inheritance diagram for PHTTPClient:

PHTTP PInternetProtocol PIndirectChannel PChannel PObject

List of all members.


Detailed Description

A TCP/IP socket for the HyperText Transfer Protocol version 1.0.

When acting as a client, the procedure is to make the connection to a remote server, then to retrieve a document using the following procedure:


      PHTTPSocket web("webserver");
      if (web.IsOpen()) {
        PINDEX len;
        if (web.GetDocument("http://www.someone.com/somewhere/url", len)) {
          PString html = web.ReadString(len);
          if (!html.IsEmpty())
            ProcessHTML(html);
        }
        else
           PError << "Could not get page." << endl;
      }
      else
         PError << "HTTP conection failed." << endl;
      

Definition at line 493 of file http.h.


Miscellaneous functions

void AbortCommandString ()
BOOL SendCommandString (const PString &command)
BOOL SetBufferSize (PINDEX newSize)
enum  ShutdownValue { ShutdownRead = 0, ShutdownWrite = 1, ShutdownReadAndWrite = 2 }

Comparison functions

virtual Comparison CompareObjectMemoryDirect (const PObject &obj) const
bool operator!= (const PObject &obj) const
bool operator< (const PObject &obj) const
bool operator<= (const PObject &obj) const
bool operator== (const PObject &obj) const
bool operator> (const PObject &obj) const
bool operator>= (const PObject &obj) const
enum  Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 }

Run Time Type functions

virtual const char * GetClass (unsigned=0) const
virtual BOOL InternalIsDescendant (const char *clsName) const
BOOL IsClass (const char *cls) const
static const char * Class ()

Error functions

Errors GetErrorCode (ErrorGroup group=NumErrorGroups) const
int GetErrorNumber (ErrorGroup group=NumErrorGroups) const
enum  ErrorGroup { LastReadError, LastWriteError, LastGeneralError, NumErrorGroups }
enum  Errors {
  NoError, NotFound, FileExists, DiskFull,
  AccessDenied, DeviceInUse, BadParameter, NoMemory,
  NotOpen, Timeout, Interrupted, BufferTooSmall,
  Miscellaneous, ProtocolFailure, NumNormalisedErrors
}
static PString GetErrorText (Errors lastError, int osError=0)

I/O functions

virtual void PrintOn (ostream &strm) const
virtual void ReadFrom (istream &strm)
ostream & operator<< (ostream &strm, const PObject &obj)
istream & operator>> (istream &strm, PObject &obj)

Scattered read/write functions

virtual BOOL Read (const VectorOfSlice &slices)
virtual BOOL Write (const VectorOfSlice &slices)
typedef std::vector< SliceVectorOfSlice

Public Types

enum  Commands {
  GET, HEAD, POST, PUT,
  DELETE, TRACE, OPTIONS, CONNECT,
  NumCommands
}
enum  PXBlockType { PXReadBlock, PXWriteBlock, PXAcceptBlock, PXConnectBlock }
enum  StatusCode {
  Continue = 100, SwitchingProtocols, RequestOK = 200, Created,
  Accepted, NonAuthoritativeInformation, NoContent, ResetContent,
  PartialContent, MultipleChoices = 300, MovedPermanently, MovedTemporarily,
  SeeOther, NotModified, UseProxy, BadRequest = 400,
  UnAuthorised, PaymentRequired, Forbidden, NotFound,
  MethodNotAllowed, NoneAcceptable, ProxyAuthenticationRequired, RequestTimeout,
  Conflict, Gone, LengthRequired, UnlessTrue,
  InternalServerError = 500, NotImplemented, BadGateway, ServiceUnavailable,
  GatewayTimeout
}

Public Member Functions

virtual BOOL Accept (PSocket &listener)
virtual BOOL Connect (const PString &address, const PString &service)
virtual BOOL Connect (const PString &address, WORD port=0)
virtual int ExecuteCommand (PINDEX cmdNumber, const PString &param)
virtual int ExecuteCommand (PINDEX cmdNumber)
int ExecuteCommand (const PString &cmdName, const PURL &url, PMIMEInfo &outMIME, const PString &dataBody, PMIMEInfo &replyMime, BOOL persist=TRUE)
int ExecuteCommand (Commands cmd, const PURL &url, PMIMEInfo &outMIME, const PString &dataBody, PMIMEInfo &replyMime, BOOL persist=TRUE)
const PStringGetDefaultService () const
BOOL GetDocument (const PURL &url, PMIMEInfo &outMIME, PMIMEInfo &replyMIME, BOOL persist=TRUE)
BOOL GetHeader (const PURL &url, PMIMEInfo &outMIME, PMIMEInfo &replyMIME, BOOL persist=TRUE)
int GetLastResponseCode () const
PString GetLastResponseInfo () const
PIPSocketGetSocket () const
BOOL GetTextDocument (const PURL &url, PString &document, BOOL persist=TRUE)
 PHTTPClient (const PString &userAgentName)
 PHTTPClient ()
 Create a new HTTP client channel.
BOOL PostData (const PURL &url, PMIMEInfo &outMIME, const PString &data, PMIMEInfo &replyMIME, PString &replyBody, BOOL persist=TRUE)
BOOL PostData (const PURL &url, PMIMEInfo &outMIME, const PString &data, PMIMEInfo &replyMIME, BOOL persist=TRUE)
virtual BOOL Read (void *buf, PINDEX len)
virtual BOOL ReadCommand (PINDEX &num, PString &args)
BOOL ReadContentBody (PMIMEInfo &replyMIME, PString &body)
BOOL ReadContentBody (PMIMEInfo &replyMIME, PBYTEArray &body)
 Read the body of the HTTP command.
virtual BOOL ReadLine (PString &line, BOOL allowContinuation=FALSE)
virtual BOOL ReadResponse (int &code, PString &info)
virtual BOOL ReadResponse ()
BOOL ReadResponse (PMIMEInfo &replyMIME)
 Read a response from the server.
void SetReadLineTimeout (const PTimeInterval &t)
virtual void UnRead (const void *buffer, PINDEX len)
virtual void UnRead (const PString &str)
virtual void UnRead (int ch)
virtual BOOL Write (const void *buf, PINDEX len)
virtual BOOL WriteCommand (PINDEX cmdNumber, const PString &param)
virtual BOOL WriteCommand (PINDEX cmdNumber)
BOOL WriteCommand (const PString &cmdName, const PString &url, PMIMEInfo &outMIME, const PString &dataBody)
BOOL WriteCommand (Commands cmd, const PString &url, PMIMEInfo &outMIME, const PString &dataBody)
 Write a HTTP command to server.
virtual BOOL WriteLine (const PString &line)
virtual BOOL WriteResponse (const PString &code, const PString &info)
virtual BOOL WriteResponse (unsigned numericCode, const PString &info)
Miscellaneous functions
virtual PObjectClone () const
Overrides from class PChannel
virtual BOOL Close ()
virtual PChannelGetBaseReadChannel () const
virtual PChannelGetBaseWriteChannel () const
virtual PString GetErrorText (ErrorGroup group=NumErrorGroups) const
virtual PString GetName () const
virtual BOOL IsOpen () const
virtual BOOL Shutdown (ShutdownValue option)
Overrides from class PObject
Comparison Compare (const PObject &obj) const
Information functions
int GetHandle () const
Reading functions
virtual PINDEX GetLastReadCount () const
PTimeInterval GetReadTimeout () const
virtual void OnReadComplete (void *buf, PINDEX len)
virtual BOOL ReadAsync (void *buf, PINDEX len)
BOOL ReadBlock (void *buf, PINDEX len)
virtual int ReadChar ()
PString ReadString (PINDEX len)
void SetReadTimeout (const PTimeInterval &time)
Writing functions
virtual PINDEX GetLastWriteCount () const
PTimeInterval GetWriteTimeout () const
virtual void OnWriteComplete (const void *buf, PINDEX len)
void SetWriteTimeout (const PTimeInterval &time)
virtual BOOL WriteAsync (const void *buf, PINDEX len)
BOOL WriteChar (int c)
BOOL WriteString (const PString &str)
Channel establish functions
PChannelGetReadChannel () const
PChannelGetWriteChannel () const
BOOL Open (PChannel *readChannel, PChannel *writeChannel, BOOL autoDeleteRead=TRUE, BOOL autoDeleteWrite=TRUE)
BOOL Open (PChannel *channel, BOOL autoDelete=TRUE)
BOOL Open (PChannel &channel)
BOOL SetReadChannel (PChannel *channel, BOOL autoDelete=TRUE)
BOOL SetWriteChannel (PChannel *channel, BOOL autoDelete=TRUE)
Overrides from class PObject
virtual PINDEX HashFunction () const

Static Public Member Functions

static BOOL ConvertOSError (int libcReturnValue, Errors &lastError, int &osError)

Static Public Attributes

static const char *const AllowTag = "Allow"
static const char *const AuthorizationTag = "Authorization"
static const char *const ChunkedTag = "chunked"
static const char *const ConnectionTag = "Connection"
static const char *const ContentEncodingTag = "Content-Encoding"
static const char *const ContentLengthTag = "Content-Length"
static const char *const ContentTypeTag = "Content-Type"
static const char *const CookieTag = "Cookie"
static const char *const DateTag = "Date"
static const char *const ExpiresTag = "Expires"
static const char *const ForwardedTag = "Forwarded"
static const char *const FromTag = "From"
static const char *const IfModifiedSinceTag = "If-Modified-Since"
static const char *const KeepAliveTag = "Keep-Alive"
static const char *const LastModifiedTag = "Last-Modified"
static const char *const LocationTag = "Location"
static const char *const MIMEVersionTag = "MIME-Version"
static const char *const PragmaNoCacheTag = "no-cache"
static const char *const PragmaTag = "Pragma"
static const char *const ProxyAuthenticateTag = "Proxy-Authenticate"
static const char *const ProxyAuthorizationTag = "Proxy-Authorization"
static const char *const ProxyConnectionTag = "Proxy-Connection"
static const char *const RefererTag = "Referer"
static const char *const ServerTag = "Server"
static const char *const SetCookieTag = "Set-Cookie"
static const char *const TransferEncodingTag = "Transfer-Encoding"
static const char *const UserAgentTag = "User-Agent"
static const char *const WWWAuthenticateTag = "WWW-Authenticate"

Protected Types

enum  StuffState {
  DontStuff, StuffIdle, StuffCR, StuffCRLF,
  StuffCRLFdot, StuffCRLFdotCR
}

Protected Member Functions

BOOL AssureConnect (const PURL &url, PMIMEInfo &outMIME)
virtual BOOL ConvertOSError (int libcReturnValue, ErrorGroup group=LastGeneralError)
BOOL InternalReadContentBody (PMIMEInfo &replyMIME, PAbstractArray &body)
virtual BOOL OnOpen ()
virtual PINDEX ParseResponse (const PString &line)
int PXClose ()
BOOL PXSetIOBlock (PXBlockType type, const PTimeInterval &timeout)
int ReadCharWithTimeout (PTimeInterval &timeout)
BOOL ReceiveCommandString (int nextChar, const PString &reply, PINDEX &pos, PINDEX start)
BOOL SetErrorValues (Errors errorCode, int osError, ErrorGroup group=LastGeneralError)

Protected Attributes

PString channelName
PReadWriteMutex channelPointerMutex
 Race condition prevention on closing channel.
PStringArray commandNames
PString defaultServiceName
Errors lastErrorCode [NumErrorGroups+1]
 The platform independant error code.
int lastErrorNumber [NumErrorGroups+1]
 The operating system error number (eg as returned by errno).
PINDEX lastReadCount
 Number of byte last read by the Read() function.
int lastResponseCode
PString lastResponseInfo
PINDEX lastWriteCount
 Number of byte last written by the Write() function.
BOOL newLineToCRLF
int os_handle
 The operating system file handle return by standard open() function.
PXBlockType px_lastBlockType
PThreadpx_readThread
PMutex px_selectMutex
PThreadpx_selectThread
PMutex px_threadMutex
PMutex px_writeMutex
PThreadpx_writeThread
BOOL readAutoDelete
 Automatically delete read channel on destruction.
PChannelreadChannel
 Channel for read operations.
PTimeInterval readLineTimeout
PTimeInterval readTimeout
 Timeout for read operations.
enum PInternetProtocol::StuffState stuffingState
PCharArray unReadBuffer
PINDEX unReadCount
PString userAgentName
BOOL writeAutoDelete
 Automatically delete write channel on destruction.
PChannelwriteChannel
 Channel for write operations.
PTimeInterval writeTimeout
 Timeout for write operations.

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

Generated by  Doxygen 1.6.0   Back to index