|
KiCad PCB EDA Suite
|
#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) |
| bool | SetConnectTimeout (long aTimeoutSecs) |
| Set the connection timeout in seconds. | |
| bool | SetTimeout (long aTimeoutSecs) |
| Set the total operation timeout in seconds. | |
| bool | SetStallTimeout (long aMinBytesPerSec, long aDurationSecs) |
| Detect stalled transfers without limiting overall transfer time. | |
| CURL * | GetCurl () |
| 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 | |
| CURL * | m_CURL |
| curl_slist * | m_headers |
| std::string | m_buffer |
| std::unique_ptr< CURL_PROGRESS > | progress |
| std::shared_lock< std::shared_mutex > | m_curlSharedLock |
Definition at line 69 of file kicad_curl_easy.h.
| KICAD_CURL_EASY::KICAD_CURL_EASY | ( | ) |
Definition at line 123 of file kicad_curl_easy.cpp.
References BEST_EFFORT, GetBuildDate(), GetBuildVersion(), GetPlatformGetBitnessName(), KIPLATFORM::POLICY::GetPolicyEnum(), m_buffer, m_CURL, m_curlSharedLock, m_headers, NONE, POLICY_KEY_REQUESTS_CURL_REVOKE, setOption(), THROW_IO_ERROR, and write_callback().
| KICAD_CURL_EASY::~KICAD_CURL_EASY | ( | ) |
Definition at line 202 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 323 of file kicad_curl_easy.cpp.
References m_CURL.
Referenced by COMMON_CONTROL::ReportBug(), and SetPostFields().
|
inline |
Return a reference to the received data buffer.
Definition at line 143 of file kicad_curl_easy.h.
References m_buffer.
|
inline |
Definition at line 192 of file kicad_curl_easy.h.
References m_CURL.
| const std::string KICAD_CURL_EASY::GetErrorText | ( | int | aCode | ) |
Fetch CURL's "friendly" error string for a given error code.
| aCode | is CURL error code. |
Definition at line 237 of file kicad_curl_easy.cpp.
Referenced by PCM_TASK_MANAGER::downloadFile(), PLUGIN_CONTENT_MANAGER::DownloadToStream(), and UPDATE_MANAGER::PostRequest().
| int KICAD_CURL_EASY::GetResponseStatusCode | ( | ) |
Definition at line 395 of file kicad_curl_easy.cpp.
References m_CURL.
Referenced by UPDATE_MANAGER::PostRequest().
| int KICAD_CURL_EASY::GetTransferTotal | ( | uint64_t & | aDownloadedBytes | ) | const |
Definition at line 379 of file kicad_curl_easy.cpp.
References m_CURL, and result.
Referenced by PCM_TASK_MANAGER::downloadFile().
| int KICAD_CURL_EASY::Perform | ( | ) |
Equivalent to curl_easy_perform.
Executes the request that was previously setup.
Definition at line 211 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().
| bool KICAD_CURL_EASY::SetConnectTimeout | ( | long | aTimeoutSecs | ) |
Set the connection timeout in seconds.
This controls how long CURL will wait for a connection to be established. The default is 30 seconds.
| aTimeoutSecs | timeout in seconds, or 0 to disable |
Definition at line 359 of file kicad_curl_easy.cpp.
References setOption().
| bool KICAD_CURL_EASY::SetFollowRedirects | ( | bool | aFollow | ) |
Enable 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 314 of file kicad_curl_easy.cpp.
References setOption().
Referenced by PCM_TASK_MANAGER::downloadFile(), PLUGIN_CONTENT_MANAGER::DownloadToStream(), and UPDATE_MANAGER::PostRequest().
| void KICAD_CURL_EASY::SetHeader | ( | const std::string & | aName, |
| const std::string & | aValue ) |
Set 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 223 of file kicad_curl_easy.cpp.
References header, and m_headers.
Referenced by PLUGIN_CONTENT_MANAGER::DownloadToStream(), and UPDATE_MANAGER::PostRequest().
Set 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 231 of file kicad_curl_easy.cpp.
Referenced by KICAD_CURL_EASY(), SetConnectTimeout(), SetFollowRedirects(), SetPostFields(), SetPostFields(), SetStallTimeout(), SetTimeout(), SetTransferCallback(), SetURL(), and SetUserAgent().
| bool KICAD_CURL_EASY::SetOutputStream | ( | const std::ostream * | aOutput | ) |
Definition at line 351 of file kicad_curl_easy.cpp.
References m_CURL, and stream_write_callback().
Referenced by PCM_TASK_MANAGER::downloadFile(), PLUGIN_CONTENT_MANAGER::DownloadToStream(), and UPDATE_MANAGER::PostRequest().
| 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.
| aField | is the string body to send |
Definition at line 273 of file kicad_curl_easy.cpp.
References setOption().
| 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.
| aFields | is the vector of fields (key-value pairs). |
Definition at line 252 of file kicad_curl_easy.cpp.
References Escape(), and setOption().
Referenced by UPDATE_MANAGER::PostRequest().
| bool KICAD_CURL_EASY::SetStallTimeout | ( | long | aMinBytesPerSec, |
| long | aDurationSecs ) |
Detect stalled transfers without limiting overall transfer time.
If the average transfer rate falls below aMinBytesPerSec for at least aDurationSecs seconds, libcurl aborts the transfer. Use this for downloads of unbounded or large size (packages, resources) so that a progressing-but-slow link is not aborted while still bounding hangs from servers that accept the connection then stop sending data.
| aMinBytesPerSec | lower threshold for the average transfer rate |
| aDurationSecs | how long the rate may stay below the threshold |
Definition at line 371 of file kicad_curl_easy.cpp.
References setOption().
Referenced by PLUGIN_CONTENT_MANAGER::DownloadToStream().
| bool KICAD_CURL_EASY::SetTimeout | ( | long | aTimeoutSecs | ) |
Set the total operation timeout in seconds.
Limits the maximum time a transfer may take, including both connection and data transfer phases. Appropriate for small fixed-size payloads (e.g. JSON metadata) where any transfer exceeding the limit is almost certainly stalled. Do not use for large or unbounded downloads, since a slow but progressing transfer would be aborted; prefer SetStallTimeout() instead.
| aTimeoutSecs | total timeout in seconds, or 0 to disable |
Definition at line 365 of file kicad_curl_easy.cpp.
References setOption().
Referenced by UPDATE_MANAGER::PostRequest().
| bool KICAD_CURL_EASY::SetTransferCallback | ( | const TRANSFER_CALLBACK & | aCallback, |
| size_t | aInterval ) |
Definition at line 334 of file kicad_curl_easy.cpp.
References L, progress, progressinfo(), and setOption().
Referenced by PCM_TASK_MANAGER::downloadFile(), PLUGIN_CONTENT_MANAGER::DownloadToStream(), and UPDATE_MANAGER::PostRequest().
| bool KICAD_CURL_EASY::SetURL | ( | const std::string & | aURL | ) |
Set the request URL.
| aURL | is the URL. |
Definition at line 282 of file kicad_curl_easy.cpp.
References KIPLATFORM::ENV::GetSystemProxyConfig(), KIPLATFORM::ENV::PROXY_CONFIG::host, m_CURL, KIPLATFORM::ENV::PROXY_CONFIG::password, setOption(), and KIPLATFORM::ENV::PROXY_CONFIG::username.
Referenced by PCM_TASK_MANAGER::downloadFile(), PLUGIN_CONTENT_MANAGER::DownloadToStream(), and UPDATE_MANAGER::PostRequest().
| bool KICAD_CURL_EASY::SetUserAgent | ( | const std::string & | aAgent | ) |
Set the request user agent.
| aAgent | is the string to set for the user agent. |
Definition at line 243 of file kicad_curl_easy.cpp.
References setOption().
|
private |
Definition at line 209 of file kicad_curl_easy.h.
Referenced by GetBuffer(), KICAD_CURL_EASY(), and Perform().
|
private |
Definition at line 207 of file kicad_curl_easy.h.
Referenced by Escape(), GetCurl(), GetResponseStatusCode(), GetTransferTotal(), KICAD_CURL_EASY(), Perform(), setOption(), SetOutputStream(), SetURL(), and ~KICAD_CURL_EASY().
|
private |
Definition at line 211 of file kicad_curl_easy.h.
Referenced by KICAD_CURL_EASY().
|
private |
Definition at line 208 of file kicad_curl_easy.h.
Referenced by KICAD_CURL_EASY(), Perform(), SetHeader(), and ~KICAD_CURL_EASY().
|
private |
Definition at line 210 of file kicad_curl_easy.h.
Referenced by SetTransferCallback().