The "easy" unspecialized interface to libCURL. More...
#include <base.h>
Public Member Functions | |
wxCurlBase (const wxString &szURL=wxEmptyString, const wxString &szUserName=wxEmptyString, const wxString &szPassword=wxEmptyString, wxEvtHandler *pEvtHandler=NULL, int id=wxID_ANY, long flags=wxCURL_DEFAULT_FLAGS) | |
bool | SetOpt (CURLoption option,...) |
Sets a transfer option for this libCURL session instance. | |
bool | GetInfo (CURLINFO info,...) const |
Gets an info from this libCURL session instance. | |
bool | Perform () |
Start the operation as described by the options set previously with SetOpt. | |
bool | InitHandle () |
Initializes the internal libCURL handle. | |
bool | CleanupHandle () |
Closes this libCURL session. | |
bool | ReInitHandle () |
Reinit the handle of this libCURL session. Equivalent to call CleanupHandle and then InitHandle. | |
bool | ResetHandle () |
Re-initializes all options previously set on this libCURL session to the default values. | |
bool | IsOk () const |
Is the underlying libCURL handle valid? | |
bool | SetEvtHandler (wxEvtHandler *pParent, int id=wxID_ANY) |
Sets the event handler to which the wxCurlDownloadEvent, wxCurlBeginPerformEvent and wxCurlEndPerformEvent will be sent if they are enabled (see SetFlags). | |
wxEvtHandler * | GetEvtHandler () const |
int | GetId () const |
void | SetFlags (long flags) |
Sets the "event policy" of wxCURL: if you pass zero, then no events will ever be sent. | |
long | GetFlags () const |
void | SetBaseURL (const wxString &szBaseURL) |
Sets the base URL. | |
wxString | GetBaseURL () const |
void | SetURL (const wxString &szRelativeURL) |
Sets the current URL. The 'base url' will be prepended to the given string. | |
wxString | GetURL () const |
Returns the current 'full' URL. I.e. the real URL being used for the transfer. | |
void | SetPort (const long &iPort) |
Sets the host Port. | |
long | GetPort () const |
void | SetUsername (const wxString &szUsername) |
Sets the Username. | |
wxString | GetUsername () const |
void | SetPassword (const wxString &szPassword) |
Sets the Password. | |
wxString | GetPassword () const |
wxString | GetResponseHeader () const |
Returns the header of the response. | |
wxString | GetResponseBody () const |
long | GetResponseCode () const |
void | UseProxy (const bool &bUseProxy) |
Should the proxy be used? | |
bool | UseProxy () const |
void | SetProxyHost (const wxString &szProxyHost) |
Sets proxy host. | |
wxString | GetProxyHost () const |
void | SetProxyUsername (const wxString &szProxyUsername) |
Sets the username for proxy access (if needed). | |
wxString | GetProxyUsername () const |
void | SetProxyPassword (const wxString &szProxyPassword) |
Sets the password for proxy access (if needed). | |
wxString | GetProxyPassword () const |
void | SetProxyPort (const long &iProxyPort) |
Sets the port for proxy access. | |
long | GetProxyPort () const |
void | SetVerbose (const bool &bVerbose) |
Sets verbose mode on/off. | |
bool | IsVerbose () const |
bool | GetVerboseStream (wxOutputStream &destStream) const |
Writes into the given stream the verbose messages collected so far. | |
bool | GetVerboseString (wxString &szStream) const |
Appends to the given stream the verbose messages collected so far. | |
wxString | GetErrorString () const |
Returns a generic, short string describing the last occurred error. | |
wxString | GetDetailedErrorString () const |
Returns a short string with a detailed description of last occurred error. | |
Static Public Member Functions | |
static void | Init () |
Initializes the libCURL. Call this only once at the beginning of your program. | |
static void | Shutdown () |
Clean up libCURL. Call this only once at the end of your program. | |
static wxDateTime | GetDateFromString (const wxString &szDate) |
static wxString | GetURLEncodedString (const wxString &szData) |
static wxString | GetStringFromURLEncoded (const wxString &szData) |
static wxString | GetCURLVersion () |
Protected Member Functions | |
void | OverrideProgressCallback (curl_progress_callback newcallback, void *data) |
Sets a custom callback as the progress callback. | |
wxDateTime | GetBeginTransferSpan () const |
Returns the time at which started the last transfer "span". | |
wxTimeSpan | GetElapsedTimeOffset () const |
Returns the current time offset, i.e. | |
void | EndTransferSpan () |
A transfer span has been completed (i.e. the user paused the transfer). | |
void | BeginTransferSpan () |
A new transfer span has begun (i.e. the user resumed the transfer). | |
virtual void | SetCurlHandleToDefaults (const wxString &relativeURL) |
virtual void | SetHeaders () |
virtual void | ResetHeaders () |
virtual void | ResetResponseVars () |
void | DumpErrorIfNeed (CURLcode error) const |
bool | SetStringOpt (CURLoption option, const wxCharBuffer &str) |
bool | SetStringWriteFunction (const wxCharBuffer &str) |
bool | SetStreamWriteFunction (const wxOutputStream &buf) |
bool | SetStringReadFunction (const wxCharBuffer &str) |
bool | SetStreamReadFunction (const wxInputStream &buf) |
Protected Attributes | |
CURL * | m_pCURL |
wxCharBuffer | m_szBaseURL |
wxCharBuffer | m_szCurrFullURL |
wxCharBuffer | m_szUsername |
wxCharBuffer | m_szPassword |
wxCharBuffer | m_szUserPass |
long | m_iHostPort |
wxCharBuffer | m_szResponseHeader |
wxCharBuffer | m_szResponseBody |
long | m_iResponseCode |
wxArrayString | m_arrHeaders |
struct curl_slist * | m_pHeaders |
bool | m_bUseProxy |
wxCharBuffer | m_szProxyHost |
wxCharBuffer | m_szProxyUsername |
wxCharBuffer | m_szProxyPassword |
wxCharBuffer | m_szProxyUserPass |
long | m_iProxyPort |
bool | m_bVerbose |
wxStringOutputStream | m_mosVerbose |
char | m_szDetailedErrorBuffer [CURL_ERROR_SIZE] |
wxCharBuffer | m_szLastError |
wxEvtHandler * | m_pEvtHandler |
int | m_nId |
long | m_nFlags |
curl_progress_callback | m_progressCallback |
void * | m_progressData |
wxDateTime | m_dtBeginTransferSpan |
wxTimeSpan | m_tsElapsedOffset |
Friends | |
class | wxCurlBaseThread |
class | wxCurlSizeQueryThread |
class | wxCurlProgressBaseEvent |
The "easy" unspecialized interface to libCURL.
You may want to look at wxCurlFTP, wxCurlHTTP, wxCurlDAV if you want to have a specialized interface for respectively the FTP, HTTP and WebDAV protocols.
wxCurlBase represents a libCURL handle to a "session". To use this interface you should:
bool wxCurlBase::CleanupHandle | ( | ) |
Closes this libCURL session.
This will effectively close all connections this handle has used and possibly has kept open until now. This function is automatically called by the destructor.
wxString wxCurlBase::GetDetailedErrorString | ( | ) | const |
Returns a short string with a detailed description of last occurred error.
This is typically something technical which you may want to hide from the end users of your application (and e.g. show only in log files).
wxTimeSpan wxCurlBase::GetElapsedTimeOffset | ( | ) | const [inline, protected] |
Returns the current time offset, i.e.
the time elapsed in all previous transfer spans.
bool wxCurlBase::GetInfo | ( | CURLINFO | info, | |
... | ||||
) | const |
Gets an info from this libCURL session instance.
See the curl_easy_getinfo() function call for more info.
bool wxCurlBase::InitHandle | ( | ) |
Initializes the internal libCURL handle.
This function is automatically called by the constructor.
void wxCurlBase::OverrideProgressCallback | ( | curl_progress_callback | newcallback, | |
void * | data | |||
) | [inline, protected] |
Sets a custom callback as the progress callback.
Note that using this function you'll break the dispatching of wxCurlDownloadEvent and wxCurlUploadEvent unless your own callback does dispatch the events itself. wxCURL users should never need to use this function.
bool wxCurlBase::Perform | ( | ) |
Start the operation as described by the options set previously with SetOpt.
If you set CURLOPT_UPLOAD to zero and the CURLOPT_WRITEFUNCTION and CURLOPT_WRITEDATA options to suitable values, a download will be performed. If you set CURLOPT_UPLOAD to nonzero and the CURLOPT_READFUNCTION and CURLOPT_READDATA options to suitable values, an upload will be performed. See the curl_easy_perform() function call for more info.
void wxCurlBase::SetBaseURL | ( | const wxString & | szBaseURL | ) |
Sets the base URL.
This allows you to specify a 'base' URL if you are performing multiple actions.
bool wxCurlBase::SetEvtHandler | ( | wxEvtHandler * | pParent, | |
int | id = wxID_ANY | |||
) |
Sets the event handler to which the wxCurlDownloadEvent, wxCurlBeginPerformEvent and wxCurlEndPerformEvent will be sent if they are enabled (see SetFlags).
void wxCurlBase::SetFlags | ( | long | flags | ) |
Sets the "event policy" of wxCURL: if you pass zero, then no events will ever be sent.
The wxCURL_SEND_PROGRESS_EVENTS and wxCURL_SEND_BEGINEND_EVENTS flags instead tell wxCURL to send respectively the wxCurlDownloadEvent and wxCurlBeginPerformEvent, wxCurlEndPerformEvent events.
bool wxCurlBase::SetOpt | ( | CURLoption | option, | |
... | ||||
) |
Sets a transfer option for this libCURL session instance.
See the curl_easy_setopt() function call for more info.
void wxCurlBase::SetPassword | ( | const wxString & | szPassword | ) |
Sets the Password.
If no password is needed, simply assign an empty string (which is the default).
void wxCurlBase::SetPort | ( | const long & | iPort | ) |
Sets the host Port.
This allows you to specify a specific (non- default port) if you like. The value -1 means that the default port will be used.
void wxCurlBase::SetUsername | ( | const wxString & | szUsername | ) |
Sets the Username.
If no username is needed, simply assign an empty string (which is the default).
void wxCurlBase::SetVerbose | ( | const bool & | bVerbose | ) |
Sets verbose mode on/off.
Note that in verbose mode a lot of info will be printed into an internal memory stream which can be queried using GetVerboseStream and GetVerboseString.