Downloader. More...

#include <rdownload.h>

Inheritance diagram for RDownload:
[legend]
Collaboration diagram for RDownload:
[legend]

Public Member Functions

 RDownload (void)
 
void Download (const RURI &uri)
 
RString GetMIMEType (void)
 
virtual ~RDownload (void)
 

Private Member Functions

virtual bool IsValidContent (const R::RString &MIME)
 
virtual bool StartDownload (void)
 
virtual size_t GetData (void *buffer, size_t size, size_t nmemb)
 
virtual void EndDownload (void)
 

Static Private Member Functions

static size_t WriteTmpFile (void *buffer, size_t size, size_t nmemb, void *param)
 
static size_t TreatHeader (void *buffer, size_t size, size_t nmemb, void *param)
 

Private Attributes

void * Lib
 
bool ValidContent
 
RString MIME
 
bool First
 
RURI URI
 

Static Private Attributes

static bool MustInitCURL
 

Detailed Description

Downloader.

The RDownload class provides a session that will download content retrieved from URLs. To store the content in a file, use the RDownloadFile class.

This class is a encapsulation of libCURL.

Constructor & Destructor Documentation

RDownload ( void  )

Construct the downloader.

virtual ~RDownload ( void  )
virtual

Destruct the downloader.

Member Function Documentation

static size_t WriteTmpFile ( void *  buffer,
size_t  size,
size_t  nmemb,
void *  param 
)
staticprivate

Parameter function given to CURLOPT_WRITEFUNCTION and called by CURL when data are downloaded.

The total size downloaded is given by size multiplied with nmemb.

Parameters
bufferPointer to the delivered data
sizeSize of an element downloaded.
nmembNumber of elements downloaded.
static size_t TreatHeader ( void *  buffer,
size_t  size,
size_t  nmemb,
void *  param 
)
staticprivate

Parameter function given to CURLOPT_HEADERFUNCTION and called by CURL when a part of the header is downloaded.

The total size downloaded is given by size multiplied with nmemb.

Parameters
bufferPointer to the delivered data
sizeSize of an element downloaded.
nmembNumber of elements downloaded.
virtual bool IsValidContent ( const R::RString MIME)
privatevirtual

If the protocol is HTTP and the server returns a content type for the downloaded file, this function is called to verify if the file should be really downloaded.

Parameters
MIMEMIME type send by the server.
Returns
true if the file should be downloaded (default).
virtual bool StartDownload ( void  )
privatevirtual

Method called when the download of file starts.

Returns
true if the file should really be downloaded (default).
virtual size_t GetData ( void *  buffer,
size_t  size,
size_t  nmemb 
)
privatevirtual

Call each time a given amount of data is downloaded. By default, it does nothing.

Parameters
bufferPointer to the delivered data
sizeSize of an element downloaded.
nmembNumber of elements downloaded.
Returns
the number of bytes actually taken care of. If it differs from the number of bytes downloaded, the download is stopped.

Reimplemented in RDownloadFile.

virtual void EndDownload ( void  )
privatevirtual

Method called when the dowload finishes. By default, it does nothing

void Download ( const RURI uri)

Download a document given by an URI.

Parameters
uriURI of the document.
RString GetMIMEType ( void  )

Get the current MIME type.

Field Documentation

void* Lib
private

Pointer to an instance of the library.

bool ValidContent
private

Valid Content?

RString MIME
private

Current MIME Type;

bool First
private

Is it the first bloc of data downloaded?

RURI URI
private

URI to download.

bool MustInitCURL
staticprivate

Was CURL Initialize ?