Loading...
Searching...
No Matches
te::ws::core::CurlWrapper Class Reference

An abstraction to Lib Curl functions. More...

#include <CurlWrapper.h>

Classes

class  CurlGlobalScope
 RAII class to init curl. More...
 

Public Member Functions

 CurlWrapper ()
 
 CurlWrapper (CurlWrapper &&other)
 
virtual void customRequest (const te::core::URI &uri, const std::string &request, const std::string &body=std::string(""), const ::std::string &header=std::string(""))
 Method to make a custom request, useful for performing a HTTP DELETE request.
 
virtual void downloadFile (const std::string &url, const std::string &filePath, te::common::TaskProgress *taskProgress=0)
 Method to download a file retrieved from given URL and save into the specified file path.
 
virtual void downloadFile (const std::string &url, std::FILE *file, te::common::TaskProgress *taskProgress=0)
 Method to download a file retrieved from given URL and save into the specified File.
 
virtual void get (const te::core::URI &uri, std::string &buffer)
 Method to make a GET request.
 
virtual AuthenticationMethod getAuthenticationMethod () const
 Gets current AuthenticationMethod.
 
virtual std::string getTaskMessage () const
 This method gets the message that will be used on Progress Bar when this object is downloading some file.
 
virtual std::string getUsername () const
 Gets the user name that will be used when an athentication method is set.
 
virtual std::vector< std::string > listFiles (const te::core::URI &uri)
 Method to list files in a URI.
 
virtual void post (const te::core::URI &uri, const std::string &postFields, const ::std::string &header)
 Method to request a post in a determined URI.
 
virtual void putFile (const te::core::URI &uri, const std::string &filePath, const ::std::string &header, te::common::TaskProgress *taskProgress=0)
 Method to request a put with a file in a determined URI.
 
virtual void putFile (const te::core::URI &uri, FILE *file, const ::std::string &header, te::common::TaskProgress *taskProgress=0, const long &fileSize=0L)
 Method to request a put a file in a determined URI.
 
virtual const std::string & response () const
 Returns the last operation response if the protocol allows it.
 
virtual const long responseCode () const
 Returns the last operation response code.
 
virtual void setAuthenticationMethod (const AuthenticationMethod &method)
 Sets the authentication method that will be used on the requests.
 
virtual void setPassword (const std::string &password)
 Sets the password that will be used when an athentication method is set.
 
virtual void setTaskMessage (const std::string &taskMessage)
 This method sets the message that will be used on Progress Bar when this object is downloading some file.
 
virtual void setUsername (const std::string &username)
 Sets the user name that will be used when an athentication method is set.
 
virtual void verifyURL (std::string url, uint32_t timeout) const
 Verify if the URI is reacheble.
 
virtual ~CurlWrapper ()
 

Protected Member Functions

virtual void addAuthParameters ()
 Adds HTTP Authentication parameters according to the current AuthenticationMethod.
 
virtual void clean ()
 Reset the curl handle and the class members.
 
virtual void downloadFile_ (const std::string &url, std::FILE *file, te::common::TaskProgress *taskProgress=0)
 Private unsafe method to download a file retrieved from given URL and save into the specified File.
 
std::unique_lock< std::mutex > getLock ()
 
virtual bool handleResponse (int curlStatusCode) const
 Handles the response of a request.
 
virtual std::vector< std::string > listFiles_ (const te::core::URI &uri)
 Private unsafe method to list files in a URI.
 
void setOption (int option, char *value)
 
void setOption (int option, int value)
 
void setOption (int option, std::string value)
 
virtual void setupEnvironment () const
 Sets up the enviroment before any atempt to make a request.
 

Private Attributes

std::unique_ptr< Impl > m_pimpl
 

Static Private Attributes

static CurlGlobalScope curlScope_
 

Detailed Description

An abstraction to Lib Curl functions.

Definition at line 61 of file CurlWrapper.h.

Constructor & Destructor Documentation

◆ CurlWrapper() [1/2]

te::ws::core::CurlWrapper::CurlWrapper ( )

◆ CurlWrapper() [2/2]

te::ws::core::CurlWrapper::CurlWrapper ( CurlWrapper &&  other)

◆ ~CurlWrapper()

virtual te::ws::core::CurlWrapper::~CurlWrapper ( )
virtual

Member Function Documentation

◆ addAuthParameters()

virtual void te::ws::core::CurlWrapper::addAuthParameters ( )
protectedvirtual

Adds HTTP Authentication parameters according to the current AuthenticationMethod.

◆ clean()

virtual void te::ws::core::CurlWrapper::clean ( )
protectedvirtual

Reset the curl handle and the class members.

◆ customRequest()

virtual void te::ws::core::CurlWrapper::customRequest ( const te::core::URI uri,
const std::string &  request,
const std::string &  body = std::string(""),
const ::std::string &  header = std::string("") 
)
virtual

Method to make a custom request, useful for performing a HTTP DELETE request.

Parameters
uriThe URI with the address information
requestThe custom request

◆ downloadFile() [1/2]

virtual void te::ws::core::CurlWrapper::downloadFile ( const std::string &  url,
const std::string &  filePath,
te::common::TaskProgress taskProgress = 0 
)
virtual

Method to download a file retrieved from given URL and save into the specified file path.

Parameters
urlURL that the file will be downloaded.
filePathfile path where downloaded file will be saved.

◆ downloadFile() [2/2]

virtual void te::ws::core::CurlWrapper::downloadFile ( const std::string &  url,
std::FILE *  file,
te::common::TaskProgress taskProgress = 0 
)
virtual

Method to download a file retrieved from given URL and save into the specified File.

Parameters
urlURL that the file will be downloaded.
fileFile where downloaded file will be write.

◆ downloadFile_()

virtual void te::ws::core::CurlWrapper::downloadFile_ ( const std::string &  url,
std::FILE *  file,
te::common::TaskProgress taskProgress = 0 
)
protectedvirtual

Private unsafe method to download a file retrieved from given URL and save into the specified File.

Warning
NOT thread safe, call getLock() to acquire lock before using.
NOT CURL safe, call clean() before using
Parameters
urlURL that the file will be downloaded.
fileFile where downloaded file will be write.

◆ get()

virtual void te::ws::core::CurlWrapper::get ( const te::core::URI uri,
std::string &  buffer 
)
virtual

Method to make a GET request.

Parameters
uriThe URI with the address information
bufferWhere the server answer will be write.

◆ getAuthenticationMethod()

virtual AuthenticationMethod te::ws::core::CurlWrapper::getAuthenticationMethod ( ) const
virtual

Gets current AuthenticationMethod.

Returns
current AuthenticationMethod.

◆ getLock()

std::unique_lock< std::mutex > te::ws::core::CurlWrapper::getLock ( )
protected

◆ getTaskMessage()

virtual std::string te::ws::core::CurlWrapper::getTaskMessage ( ) const
virtual

This method gets the message that will be used on Progress Bar when this object is downloading some file.

◆ getUsername()

virtual std::string te::ws::core::CurlWrapper::getUsername ( ) const
virtual

Gets the user name that will be used when an athentication method is set.

Returns
username

◆ handleResponse()

virtual bool te::ws::core::CurlWrapper::handleResponse ( int  curlStatusCode) const
protectedvirtual

Handles the response of a request.

◆ listFiles()

virtual std::vector< std::string > te::ws::core::CurlWrapper::listFiles ( const te::core::URI uri)
virtual

Method to list files in a URI.

Parameters
urlURL that the files will be listed.

◆ listFiles_()

virtual std::vector< std::string > te::ws::core::CurlWrapper::listFiles_ ( const te::core::URI uri)
protectedvirtual

Private unsafe method to list files in a URI.

Warning
NOT thread safe, call getLock() to acquire lock before using.
NOT CURL safe, call clean() before using
Parameters
urlURL that the files will be listed.

◆ post()

virtual void te::ws::core::CurlWrapper::post ( const te::core::URI uri,
const std::string &  postFields,
const ::std::string &  header 
)
virtual

Method to request a post in a determined URI.

Parameters
uriThe URI with the address information to post
postFieldsThe parameters and values to post
headerA header to the post request

◆ putFile() [1/2]

virtual void te::ws::core::CurlWrapper::putFile ( const te::core::URI uri,
const std::string &  filePath,
const ::std::string &  header,
te::common::TaskProgress taskProgress = 0 
)
virtual

Method to request a put with a file in a determined URI.

Parameters
uriThe URI with the address information
filePath The full path of the file to put
headerA header to the put request

◆ putFile() [2/2]

virtual void te::ws::core::CurlWrapper::putFile ( const te::core::URI uri,
FILE *  file,
const ::std::string &  header,
te::common::TaskProgress taskProgress = 0,
const long &  fileSize = 0L 
)
virtual

Method to request a put a file in a determined URI.

Parameters
uriThe URI with the address information
fileContains the file opened by the fstream
headerA header to the put request

◆ response()

virtual const std::string & te::ws::core::CurlWrapper::response ( ) const
virtual

Returns the last operation response if the protocol allows it.

Returns
The response

◆ responseCode()

virtual const long te::ws::core::CurlWrapper::responseCode ( ) const
virtual

Returns the last operation response code.

Returns
The response code

◆ setAuthenticationMethod()

virtual void te::ws::core::CurlWrapper::setAuthenticationMethod ( const AuthenticationMethod method)
virtual

Sets the authentication method that will be used on the requests.

Parameters
method(e. g.: Basic or Digest)

◆ setOption() [1/3]

void te::ws::core::CurlWrapper::setOption ( int  option,
char *  value 
)
protected

◆ setOption() [2/3]

void te::ws::core::CurlWrapper::setOption ( int  option,
int  value 
)
protected

◆ setOption() [3/3]

void te::ws::core::CurlWrapper::setOption ( int  option,
std::string  value 
)
protected

◆ setPassword()

virtual void te::ws::core::CurlWrapper::setPassword ( const std::string &  password)
virtual

Sets the password that will be used when an athentication method is set.

Parameters
password

◆ setTaskMessage()

virtual void te::ws::core::CurlWrapper::setTaskMessage ( const std::string &  taskMessage)
virtual

This method sets the message that will be used on Progress Bar when this object is downloading some file.

Parameters
taskMessagenew message.

◆ setupEnvironment()

virtual void te::ws::core::CurlWrapper::setupEnvironment ( ) const
protectedvirtual

Sets up the enviroment before any atempt to make a request.

◆ setUsername()

virtual void te::ws::core::CurlWrapper::setUsername ( const std::string &  username)
virtual

Sets the user name that will be used when an athentication method is set.

Parameters
username

◆ verifyURL()

virtual void te::ws::core::CurlWrapper::verifyURL ( std::string  url,
uint32_t  timeout 
) const
virtual

Verify if the URI is reacheble.

Exceptions
te::ws::core::ExceptionRise if the URI cannot be reached.

Member Data Documentation

◆ curlScope_

CurlGlobalScope te::ws::core::CurlWrapper::curlScope_
staticprivate

Definition at line 269 of file CurlWrapper.h.

◆ m_pimpl

std::unique_ptr<Impl> te::ws::core::CurlWrapper::m_pimpl
private

Definition at line 250 of file CurlWrapper.h.


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