KiCad PCB EDA Suite
Loading...
Searching...
No Matches
KICAD_CURL_EASY Class Reference

#include <kicad_curl_easy.h>

Public Member Functions

 KICAD_CURL_EASY ()
 
 ~KICAD_CURL_EASY ()
 
int Perform ()
 Equivalent to curl_easy_perform.
 
void SetHeader (const std::string &aName, const std::string &aValue)
 Set an arbitrary header for the HTTP(s) request.
 
bool SetUserAgent (const std::string &aAgent)
 Set the request user agent.
 
bool SetPostFields (const std::vector< std::pair< std::string, std::string > > &aFields)
 Set fields for application/x-www-form-urlencoded POST request.
 
bool SetPostFields (const std::string &aField)
 Set the post content body to the string, usually used for json rather than the typical key/value pair.
 
bool SetURL (const std::string &aURL)
 Set the request URL.
 
bool SetFollowRedirects (bool aFollow)
 Enable the following of HTTP(s) and other redirects, by default curl does not follow redirects.
 
const std::string GetErrorText (int aCode)
 Fetch CURL's "friendly" error string for a given error code.
 
int GetTransferTotal (uint64_t &aDownloadedBytes) const
 
const std::string & GetBuffer ()
 Return a reference to the received data buffer.
 
std::string Escape (const std::string &aUrl)
 Escapes a string for use as a URL.
 
bool SetTransferCallback (const TRANSFER_CALLBACK &aCallback, size_t aInterval)
 
bool SetOutputStream (const std::ostream *aOutput)
 
CURLGetCurl ()
 
int GetResponseStatusCode ()
 

Private Member Functions

template<typename T >
int setOption (int aOption, T aArg)
 Set a curl option, only supports single parameter curl options.
 

Private Attributes

CURLm_CURL
 
curl_slist * m_headers
 
std::string m_buffer
 
std::unique_ptr< CURL_PROGRESSprogress
 
std::shared_lock< std::shared_mutex > m_curlSharedLock
 

Detailed Description

Definition at line 69 of file kicad_curl_easy.h.

Constructor & Destructor Documentation

◆ KICAD_CURL_EASY()

◆ ~KICAD_CURL_EASY()

KICAD_CURL_EASY::~KICAD_CURL_EASY ( )

Definition at line 193 of file kicad_curl_easy.cpp.

References m_CURL, and m_headers.

Member Function Documentation

◆ Escape()

std::string KICAD_CURL_EASY::Escape ( const std::string &  aUrl)

Escapes a string for use as a URL.

Definition at line 315 of file kicad_curl_easy.cpp.

References m_CURL.

Referenced by COMMON_CONTROL::ReportBug(), and SetPostFields().

◆ GetBuffer()

const std::string & KICAD_CURL_EASY::GetBuffer ( )
inline

Return a reference to the received data buffer.

Definition at line 143 of file kicad_curl_easy.h.

◆ GetCurl()

CURL * KICAD_CURL_EASY::GetCurl ( )
inline

Definition at line 152 of file kicad_curl_easy.h.

◆ GetErrorText()

const std::string KICAD_CURL_EASY::GetErrorText ( int  aCode)

Fetch CURL's "friendly" error string for a given error code.

Parameters
aCodeis CURL error code.
Returns
The corresponding error string for the given code.

Definition at line 228 of file kicad_curl_easy.cpp.

Referenced by PCM_TASK_MANAGER::downloadFile(), PLUGIN_CONTENT_MANAGER::DownloadToStream(), and UPDATE_MANAGER::PostRequest().

◆ GetResponseStatusCode()

int KICAD_CURL_EASY::GetResponseStatusCode ( )

Definition at line 367 of file kicad_curl_easy.cpp.

References m_CURL.

Referenced by UPDATE_MANAGER::PostRequest().

◆ GetTransferTotal()

int KICAD_CURL_EASY::GetTransferTotal ( uint64_t &  aDownloadedBytes) const

Definition at line 351 of file kicad_curl_easy.cpp.

References m_CURL.

Referenced by PCM_TASK_MANAGER::downloadFile().

◆ Perform()

int KICAD_CURL_EASY::Perform ( )

Equivalent to curl_easy_perform.

Executes the request that was previously setup.

Definition at line 202 of file kicad_curl_easy.cpp.

References m_buffer, m_CURL, and m_headers.

Referenced by PCM_TASK_MANAGER::downloadFile(), PLUGIN_CONTENT_MANAGER::DownloadToStream(), and UPDATE_MANAGER::PostRequest().

◆ SetFollowRedirects()

bool KICAD_CURL_EASY::SetFollowRedirects ( bool  aFollow)

Enable the following of HTTP(s) and other redirects, by default curl does not follow redirects.

Parameters
aFollowis a boolean where true will enable following redirects.
Returns
True if successful, false if not.

Definition at line 306 of file kicad_curl_easy.cpp.

Referenced by PCM_TASK_MANAGER::downloadFile(), PLUGIN_CONTENT_MANAGER::DownloadToStream(), and UPDATE_MANAGER::PostRequest().

◆ SetHeader()

void KICAD_CURL_EASY::SetHeader ( const std::string &  aName,
const std::string &  aValue 
)

Set an arbitrary header for the HTTP(s) request.

Parameters
aNameis the left hand side of the header, i.e. Accept without the colon.
aValueis the right hand side of the header, i.e. application/json.

Definition at line 214 of file kicad_curl_easy.cpp.

References m_headers.

Referenced by UPDATE_MANAGER::PostRequest().

◆ setOption()

template<typename T >
int KICAD_CURL_EASY::setOption ( int  aOption,
aArg 
)
private

Set a curl option, only supports single parameter curl options.

Parameters
aOptionis CURL option, see CURL manual for options.
aArgis the argument being passed to CURL, ensure it is the right type per manual.
Returns
A CURL error code, will return CURLE_OK unless a problem was encountered.

Definition at line 222 of file kicad_curl_easy.cpp.

References m_CURL.

Referenced by KICAD_CURL_EASY(), and SetTransferCallback().

◆ SetOutputStream()

bool KICAD_CURL_EASY::SetOutputStream ( const std::ostream *  aOutput)

◆ SetPostFields() [1/2]

bool KICAD_CURL_EASY::SetPostFields ( const std::string &  aField)

Set the post content body to the string, usually used for json rather than the typical key/value pair.

Parameters
aFieldis the string body to send
Returns
True if successful, false if not.

Definition at line 265 of file kicad_curl_easy.cpp.

◆ SetPostFields() [2/2]

bool KICAD_CURL_EASY::SetPostFields ( const std::vector< std::pair< std::string, std::string > > &  aFields)

Set fields for application/x-www-form-urlencoded POST request.

Parameters
aFieldsis the vector of fields (key-value pairs).
Returns
True if successful, false if not.

Definition at line 243 of file kicad_curl_easy.cpp.

References Escape().

Referenced by UPDATE_MANAGER::PostRequest().

◆ SetTransferCallback()

bool KICAD_CURL_EASY::SetTransferCallback ( const TRANSFER_CALLBACK aCallback,
size_t  aInterval 
)

◆ SetURL()

bool KICAD_CURL_EASY::SetURL ( const std::string &  aURL)

◆ SetUserAgent()

bool KICAD_CURL_EASY::SetUserAgent ( const std::string &  aAgent)

Set the request user agent.

Parameters
aAgentis the string to set for the user agent.
Returns
True if successful, false if not.

Definition at line 234 of file kicad_curl_easy.cpp.

Member Data Documentation

◆ m_buffer

std::string KICAD_CURL_EASY::m_buffer
private

Definition at line 169 of file kicad_curl_easy.h.

Referenced by KICAD_CURL_EASY(), and Perform().

◆ m_CURL

◆ m_curlSharedLock

std::shared_lock<std::shared_mutex> KICAD_CURL_EASY::m_curlSharedLock
private

Definition at line 171 of file kicad_curl_easy.h.

◆ m_headers

curl_slist* KICAD_CURL_EASY::m_headers
private

Definition at line 168 of file kicad_curl_easy.h.

Referenced by Perform(), SetHeader(), and ~KICAD_CURL_EASY().

◆ progress

std::unique_ptr<CURL_PROGRESS> KICAD_CURL_EASY::progress
private

Definition at line 170 of file kicad_curl_easy.h.

Referenced by SetTransferCallback().


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