GClasses

GClasses::GHttpClient Class Reference

This class allows you to get files using the HTTP protocol. More...

#include <GHttp.h>

List of all members.

Public Types

enum  Status {
  Downloading, Error, NotFound, Done,
  Aborted
}

Public Member Functions

 GHttpClient ()
virtual ~GHttpClient ()
virtual void onReceiveData (const unsigned char *pData, size_t nLen)
bool get (const char *szUrl, bool actuallyDownloadTheData=true)
 Send a request to get a file. Returns immediately (before the file is downloaded).
Status status (float *pfProgress)
 See what the status of the download is. If everything is going okay, it will return "Downloading" while downloading and "Done" when the file is available. pfProgress is an optional parameter. If it is non-NULL, it will return a number between 0 and 1 that indicates the ratio of content (not including header data) already downloaded.
unsigned char * getData (size_t *pnSize)
 Don't call this until the status is "Done". It returns a pointer to the file that was downloaded. The buffer will be deleted when this object is deleted, so if you want to retain the buffer, call releaseData instead.
unsigned char * releaseData (size_t *pnSize)
 Just like getData except it forgets about the buffer so you'll have to delete it yourself.
void onLoseConnection ()
 This is called when the connection is lost.
void setClientName (const char *szClientName)
void abort ()

Protected Member Functions

void processHeader (const unsigned char *szData, size_t nSize)
 called by the consumer, when an abort is desired.
void processBody (const unsigned char *szData, size_t nSize)
void processChunkBody (const unsigned char *szData, size_t nSize)
void gimmeWhatYouGot ()

Protected Attributes

char * m_pReceiveBuf
char m_szHeaderBuf [258]
char m_szServer [256]
char m_szClientName [32]
size_t m_nHeaderPos
size_t m_nContentSize
bool m_bChunked
bool m_aborted
unsigned char * m_pData
size_t m_nDataPos
GHttpClientSocket * m_pSocket
Status m_status
std::ostringstream m_chunkBuf
bool m_bPastHeader
char * m_szRedirect
double m_dLastReceiveTime
bool m_bAmCurrentlyDoingJustHeaders

Detailed Description

This class allows you to get files using the HTTP protocol.


Member Enumeration Documentation

Enumerator:
Downloading 
Error 
NotFound 
Done 
Aborted 

Constructor & Destructor Documentation

GClasses::GHttpClient::GHttpClient ( )
virtual GClasses::GHttpClient::~GHttpClient ( ) [virtual]

Member Function Documentation

void GClasses::GHttpClient::abort ( )
bool GClasses::GHttpClient::get ( const char *  szUrl,
bool  actuallyDownloadTheData = true 
)

Send a request to get a file. Returns immediately (before the file is downloaded).

unsigned char* GClasses::GHttpClient::getData ( size_t *  pnSize)

Don't call this until the status is "Done". It returns a pointer to the file that was downloaded. The buffer will be deleted when this object is deleted, so if you want to retain the buffer, call releaseData instead.

void GClasses::GHttpClient::gimmeWhatYouGot ( ) [protected]
void GClasses::GHttpClient::onLoseConnection ( )

This is called when the connection is lost.

virtual void GClasses::GHttpClient::onReceiveData ( const unsigned char *  pData,
size_t  nLen 
) [inline, virtual]
void GClasses::GHttpClient::processBody ( const unsigned char *  szData,
size_t  nSize 
) [protected]
void GClasses::GHttpClient::processChunkBody ( const unsigned char *  szData,
size_t  nSize 
) [protected]
void GClasses::GHttpClient::processHeader ( const unsigned char *  szData,
size_t  nSize 
) [protected]

called by the consumer, when an abort is desired.

unsigned char* GClasses::GHttpClient::releaseData ( size_t *  pnSize)

Just like getData except it forgets about the buffer so you'll have to delete it yourself.

void GClasses::GHttpClient::setClientName ( const char *  szClientName)
Status GClasses::GHttpClient::status ( float *  pfProgress)

See what the status of the download is. If everything is going okay, it will return "Downloading" while downloading and "Done" when the file is available. pfProgress is an optional parameter. If it is non-NULL, it will return a number between 0 and 1 that indicates the ratio of content (not including header data) already downloaded.


Member Data Documentation

std::ostringstream GClasses::GHttpClient::m_chunkBuf [protected]
unsigned char* GClasses::GHttpClient::m_pData [protected]
GHttpClientSocket* GClasses::GHttpClient::m_pSocket [protected]
char GClasses::GHttpClient::m_szHeaderBuf[258] [protected]
char GClasses::GHttpClient::m_szServer[256] [protected]