![]() |
KiCad PCB EDA Suite
|
KICAD_CURL_EASY wrapper interface around the curl_easy API. More...
#include <kicad_curl_easy.h>
Public Member Functions | |
KICAD_CURL_EASY () | |
~KICAD_CURL_EASY () | |
void | Perform () |
Function perform equivalent to curl_easy_perform. More... | |
void | SetHeader (const std::string &aName, const std::string &aValue) |
Function SetHeader sets an arbitrary header for the HTTP(s) request. More... | |
bool | SetUserAgent (const std::string &aAgent) |
Function SetUserAgent sets the request user agent. More... | |
bool | SetURL (const std::string &aURL) |
Function SetURL sets the request URL. More... | |
bool | SetFollowRedirects (bool aFollow) |
Function SetFollowRedirects enables the following of HTTP(s) and other redirects, by default curl does not follow redirects. More... | |
const std::string | GetErrorText (int aCode) |
Function GetErrorText fetches CURL's "friendly" error string for a given error code. More... | |
const std::string & | GetBuffer () |
Function GetBuffer returns a const reference to the recevied data buffer. More... | |
std::string | Escape (const std::string &aUrl) |
Escapes a string for use as a URL. More... | |
Private Member Functions | |
template<typename T > | |
int | setOption (int aOption, T aArg) |
Function setOption sets a curl option, only supports single parameter curl options. More... | |
Private Attributes | |
CURL * | m_CURL |
curl_slist * | m_headers |
std::string | m_buffer |
KICAD_CURL_EASY wrapper interface around the curl_easy API.
Handling of using the curl_easy API to make a request and save the response to a memory buffer
Here is a small example usage:
Definition at line 59 of file kicad_curl_easy.h.
KICAD_CURL_EASY::KICAD_CURL_EASY | ( | ) |
Definition at line 47 of file kicad_curl_easy.cpp.
References KICAD_CURL::Init(), m_buffer, m_CURL, THROW_IO_ERROR, and write_callback().
KICAD_CURL_EASY::~KICAD_CURL_EASY | ( | ) |
Definition at line 68 of file kicad_curl_easy.cpp.
std::string KICAD_CURL_EASY::Escape | ( | const std::string & | aUrl | ) |
Escapes a string for use as a URL.
Definition at line 147 of file kicad_curl_easy.cpp.
References m_CURL.
Referenced by COMMON_CONTROL::ReportBug().
|
inline |
Function GetBuffer returns a const reference to the recevied data buffer.
Definition at line 124 of file kicad_curl_easy.h.
References m_buffer.
const std::string KICAD_CURL_EASY::GetErrorText | ( | int | aCode | ) |
Function GetErrorText fetches CURL's "friendly" error string for a given error code.
aCode | is CURL error code |
Definition at line 111 of file kicad_curl_easy.cpp.
Referenced by Perform().
void KICAD_CURL_EASY::Perform | ( | ) |
Function perform equivalent to curl_easy_perform.
Executes the request that was previously setup.
IO_ERROR,if | there is a CURL request error |
Definition at line 77 of file kicad_curl_easy.cpp.
References GetErrorText(), m_buffer, m_CURL, m_headers, and THROW_IO_ERROR.
bool KICAD_CURL_EASY::SetFollowRedirects | ( | bool | aFollow | ) |
Function SetFollowRedirects enables the following of HTTP(s) and other redirects, by default curl does not follow redirects.
aFollow | is a boolean where true will enable following redirects |
Definition at line 137 of file kicad_curl_easy.cpp.
void KICAD_CURL_EASY::SetHeader | ( | const std::string & | aName, |
const std::string & | aValue | ||
) |
Function SetHeader sets an arbitrary header for the HTTP(s) request.
aName | is the left hand side of the header, i.e. Accept without the colon |
aValue | is the right hand side of the header, i.e. application/json |
Definition at line 98 of file kicad_curl_easy.cpp.
References m_headers.
|
private |
Function setOption sets a curl option, only supports single parameter curl options.
aOption | is CURL option, see CURL manual for options |
aArg | is the argument being passed to CURL, ensure it is the right type per manual |
Definition at line 105 of file kicad_curl_easy.cpp.
References m_CURL.
bool KICAD_CURL_EASY::SetURL | ( | const std::string & | aURL | ) |
Function SetURL sets the request URL.
aURL | is the URL |
Definition at line 127 of file kicad_curl_easy.cpp.
bool KICAD_CURL_EASY::SetUserAgent | ( | const std::string & | aAgent | ) |
Function SetUserAgent sets the request user agent.
aAgent | is the string to set for the user agent |
Definition at line 117 of file kicad_curl_easy.cpp.
|
private |
Definition at line 146 of file kicad_curl_easy.h.
Referenced by GetBuffer(), KICAD_CURL_EASY(), and Perform().
|
private |
Definition at line 144 of file kicad_curl_easy.h.
Referenced by Escape(), KICAD_CURL_EASY(), Perform(), setOption(), and ~KICAD_CURL_EASY().
|
private |
Definition at line 145 of file kicad_curl_easy.h.
Referenced by Perform(), SetHeader(), and ~KICAD_CURL_EASY().