|
SSS - S3 Toolkit 0.9.6
S3 client library and applications
|
Send web requests through libcurl. More...
#include <webclient.h>
Public Types | |
| using | WriteFunction = size_t(*)(char *data, size_t size, size_t nmemb, void *writerData) |
| using | ReadFunction = size_t(*)(void *ptr, size_t size, size_t nmemb, void *readerData) |
Public Member Functions | |
| WebClient (const WebClient &)=delete | |
| Disable copy constructor: only one libcurl handle per thread allwed. | |
| WebClient (WebClient &&other) | |
| Move constructor. | |
| WebClient () | |
| Default constructor. First instance initializes libcurl. | |
| WebClient (const std::string &url) | |
| Constructor initializing only URL. | |
| WebClient (const std::string &endPoint, const std::string &path, const std::string &method="GET", const Map ¶ms=Map(), const Map headers=Map()) | |
| ~WebClient () | |
| Destructor. Last instance cleans up libcurl. | |
| bool | Send () |
| bool | SSLVerify (bool verifyPeer, bool verifyHost=true) |
| bool | SetUrl (const std::string &url) |
| void | SetEndpoint (const std::string &ep) |
Set endpoint: <proto>://<server>:<port> | |
| void | SetPath (const std::string &path) |
| void | SetHeaders (const Map &headers) |
| void | SetReqParameters (const Map ¶ms) |
| void | SetMethod (const std::string &method, size_t size=0) |
| void | SetUrlEncodedPostData (const Map &postData) |
| void | SetUrlEncodedPostData (const std::string &postData) |
| void | SetPostData (const std::string &data) |
| long | StatusCode () const |
| const std::string & | GetUrl () const |
| const std::vector< char > & | GetResponseBody () const |
| const std::vector< char > & | GetResponseHeader () const |
| std::string | GetContentText () const |
| Get response body as text. | |
| std::string | GetHeaderText () const |
| bool | SetWriteFunction (WriteFunction f, void *userData) |
| bool | SetReadFunction (ReadFunction f, void *userData) |
| bool | UploadFile (const std::string &fname, size_t fsize=0) |
| Upload file. | |
| bool | UploadFile (const std::string &fname, size_t offset, size_t size) |
| Upload file starting from offset. | |
| bool | UploadFileUnbuffered (const std::string &fname, size_t offset, size_t size) |
| Upload file starting from offset using unbuffered I/O read. | |
| bool | UploadFileMM (const std::string &fname, size_t offset, size_t size) |
| Upload file starting from offset using unbuffered memory mapping of file. | |
| bool | UploadDataFromBuffer (const char *data, size_t offset, size_t size) |
| Upload data from memory buffer. | |
| std::string | ErrorMsg () const |
| CURLcode | SetOpt (CURLoption option, va_list argp) |
Passthrough to curl_easy_setopt. | |
| CURLcode | GetInfo (CURLINFO info, va_list argp) |
Passthrough method to curl_easy_getinfo. | |
| void | SetVerbose (bool verbose) |
Send verbose output to stderr or the stream mapped to CURLOPT_STDERR. | |
| bool | RedirectSTDErr (FILE *f) |
Redirect stderr to file. Returns false when it fails. | |
| void | ClearBuffers () |
| Clear internal buffers. | |
| void | ResetRWFunctions () |
| Reset read/write functions to default. | |
Send web requests through libcurl.
Configure state then invoke WebClient::Send to send request.
Retrieve data through:
Error handling is managed by having libcurl log errors into a char buffer. When a method fails returning false, you can extract the error message by invoking the WebClient::ErrorMsg() method.
| using sss::WebClient::ReadFunction = size_t (*)(void *ptr, size_t size, size_t nmemb, void *readerData) |
Function type invoked by libcurl to read data to send
| [in] | nmemb | number of blocks of size size |
| [in] | readerData | user data passed to reade function |
| using sss::WebClient::WriteFunction = size_t (*)(char *data, size_t size, size_t nmemb, void *writerData) |
Function type invoked by libcurl to write received data
| [in] | nmemb | number of blocks of size size |
| [in] | writerData | user data passed to write function |
|
inline |
Constructor
| [in] | endPoint | endpoint in the format <proto>://<server>:port |
| [in] | path | path to be added to endPoint to compete URL: /.../... |
| [in] | method | HTTP method |
| [in] | params | key,value map of parameters k1=value1&k2=value2&... |
| sss::WebClient::~WebClient | ( | ) |
Destructor. Last instance cleans up libcurl.
Cleanup and invoke cleanup on libcurl in case of last instance.
| std::string sss::WebClient::ErrorMsg | ( | ) | const |
Return curl error.
curl_easy_strerror or curl_multi_strerror.
Here is the caller graph for this function:| std::string sss::WebClient::GetHeaderText | ( | ) | const |
Get headers as text.
References sss::begin(), sss::end(), and GetResponseHeader().
Here is the call graph for this function:
Here is the caller graph for this function:| CURLcode sss::WebClient::GetInfo | ( | CURLINFO | info, |
| va_list | argp | ||
| ) |
Passthrough method to curl_easy_getinfo.
| const std::vector< char > & sss::WebClient::GetResponseBody | ( | ) | const |
Get response content.
char used because it's the type used within libcurl)
Here is the caller graph for this function:| const std::vector< char > & sss::WebClient::GetResponseHeader | ( | ) | const |
Get reponse header.
Here is the caller graph for this function:| const std::string & sss::WebClient::GetUrl | ( | ) | const |
Return full URL.
| bool sss::WebClient::Send | ( | ) |
Send request.
false if error, retrieve error message through WebClient::ErroMsg
Here is the caller graph for this function:| void sss::WebClient::SetHeaders | ( | const Map & | headers | ) |
Store headers into internal buffer.
| [in] | headers | HTTP headers |
Here is the caller graph for this function:| void sss::WebClient::SetMethod | ( | const std::string & | method, |
| size_t | size = 0 |
||
| ) |
Set HTTP method.
| [in] | method | "GET", "POST", "PUT", "DELETE", "HEAD" |
References sss::ToUpper().
Here is the call graph for this function:
Here is the caller graph for this function:| CURLcode sss::WebClient::SetOpt | ( | CURLoption | option, |
| va_list | argp | ||
| ) |
Passthrough to curl_easy_setopt.
| void sss::WebClient::SetPath | ( | const std::string & | path | ) |
| void sss::WebClient::SetPostData | ( | const std::string & | data | ) |
Store data to be posted.
| [in] | data | text to be posted. |
Here is the caller graph for this function:| bool sss::WebClient::SetReadFunction | ( | ReadFunction | f, |
| void * | userData | ||
| ) |
Set function libcurl uses to read data to send.
| [in] | f | pointer to function called by libcurl to read data to send; set to NULL to read from file. |
| [in] | userData | pointer to user data. |
Here is the caller graph for this function:| void sss::WebClient::SetReqParameters | ( | const Map & | params | ) |
Store request parameters into internal buffer.
| [in] | params | URL parameters: key=value&... |
Here is the caller graph for this function:| bool sss::WebClient::SetUrl | ( | const std::string & | url | ) |
| void sss::WebClient::SetUrlEncodedPostData | ( | const Map & | postData | ) |
Url-encode and store data to be posted from {key,value} map.
| [in] | postData | {key, value} map of URL paramters. |
References sss::UrlEncode().
Here is the call graph for this function:
Here is the caller graph for this function:| void sss::WebClient::SetUrlEncodedPostData | ( | const std::string & | postData | ) |
Url-encode and store data to be posted from string in the standard key=value&key2=value2... format.
| [in] | postData | "key1=value1&key2=value2..." |
References sss::UrlEncode().
Here is the call graph for this function:| bool sss::WebClient::SetWriteFunction | ( | WriteFunction | f, |
| void * | userData | ||
| ) |
Set function libcurl uses to store response data.
| [in] | f | pointer to function called by libcurl to consume returned data. |
| [in] | userData | pointer to user data. |
Here is the caller graph for this function:| bool sss::WebClient::SSLVerify | ( | bool | verifyPeer, |
| bool | verifyHost = true |
||
| ) |
Set SSL verification options: peer and/or host Verification should be disabled when sending https requests through SSH tunnels.
| [in] | verifyPeer | verify the authenticity of the peer's certificate |
| [in] | verifyHost | verify the identity of the server |
Here is the caller graph for this function:| long sss::WebClient::StatusCode | ( | ) | const |
Return status code from last executed request.
| bool sss::WebClient::UploadDataFromBuffer | ( | const char * | data, |
| size_t | offset, | ||
| size_t | size | ||
| ) |
Upload data from memory buffer.
| [in] | data | pointer to data |
| [in] | offset | offset |
| [in] | size | data size |
true if successful, false otherwise References Send(), and SetMethod().
Here is the call graph for this function:
Here is the caller graph for this function:| bool sss::WebClient::UploadFile | ( | const std::string & | fname, |
| size_t | fsize = 0 |
||
| ) |
Upload file.
| [in] | fname | file name |
| [in] | fsize | file size, if zero file size will be computed |
true if successful, false otherwise References ErrorMsg(), sss::FileSize(), Send(), SetMethod(), and SetReadFunction().
Here is the call graph for this function:
Here is the caller graph for this function:| bool sss::WebClient::UploadFile | ( | const std::string & | fname, |
| size_t | offset, | ||
| size_t | size | ||
| ) |
Upload file starting from offset.
| [in] | fname | file name |
| [in] | offset | offset |
| [in] | size | file size, if zero size is computed from file. |
true if successful, false otherwise References ErrorMsg(), sss::FileSize(), sss::ReadFile(), Send(), SetMethod(), and SetReadFunction().
Here is the call graph for this function:| bool sss::WebClient::UploadFileMM | ( | const std::string & | fname, |
| size_t | offset, | ||
| size_t | size | ||
| ) |
Upload file starting from offset using unbuffered memory mapping of file.
| [in] | fname | file name |
| [in] | offset | offset |
| [in] | size | file size, if zero it will compute file size on its ow |
true if successful, false otherwise References UploadDataFromBuffer().
Here is the call graph for this function:| bool sss::WebClient::UploadFileUnbuffered | ( | const std::string & | fname, |
| size_t | offset, | ||
| size_t | size | ||
| ) |
Upload file starting from offset using unbuffered I/O read.
| [in] | fname | file name |
| [in] | offset | offset |
| [in] | size | file size, if zero size will be computer as (file size) - offset. |
true if successful, false otherwise References ErrorMsg(), Send(), SetMethod(), and SetReadFunction().
Here is the call graph for this function: