#include <CurlInterface.h>
Public Types | |
typedef std::vector< char > | Content |
Public Member Functions | |
CURLcode | getContent (const std::string &url, const std::string &user, Content &content) |
CURLcode | postBinaryMessage (const std::string &url, void *buf, size_t size, Content &content) |
Private Member Functions | |
CURLcode | do_curl (CURL *, const std::string &url, Content &content) |
Static Private Member Functions | |
static size_t | writeToString (char *data, size_t size, size_t nmemb, Content *buffer) |
Private Attributes | |
char | errorBuffer_ [CURL_ERROR_SIZE] |
Helper class to interact with curl
Definition at line 22 of file CurlInterface.h.
typedef std::vector<char> stor::CurlInterface::Content |
Definition at line 27 of file CurlInterface.h.
CURLcode CurlInterface::do_curl | ( | CURL * | curl, |
const std::string & | url, | ||
Content & | content | ||
) | [private] |
Definition at line 51 of file CurlInterface.cc.
References errorBuffer_, i, runEdmFileComparison::returnCode, and writeToString().
{ curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); curl_easy_setopt(curl, CURLOPT_TIMEOUT, 4); // seconds curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); // do not send any signals curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, stor::CurlInterface::writeToString); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &content); curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer_); curl_easy_setopt(curl, CURLOPT_FAILONERROR,1); CURLcode returnCode = curl_easy_perform(curl); curl_easy_cleanup(curl); if (returnCode != CURLE_OK) { size_t i = 0; content.clear(); while ( errorBuffer_[i] != '\0' ) { content.push_back( errorBuffer_[i] ); ++i; } content.push_back('\0'); } return returnCode; }
CURLcode CurlInterface::getContent | ( | const std::string & | url, |
const std::string & | user, | ||
Content & | content | ||
) |
Get webpage content from specified URL using the user/password specified. If the return value is CURLE_OK, the webpage could be fetched and the content is in the content string. Otherwise, the content string contains the error message.
Definition at line 10 of file CurlInterface.cc.
Referenced by stor::ResourceMonitorCollection::checkSataDisks().
CURLcode CurlInterface::postBinaryMessage | ( | const std::string & | url, |
void * | buf, | ||
size_t | size, | ||
Content & | content | ||
) |
Post message a message at the given location. If the return value is CURLE_OK, the post succeeded and the reply is in the content string. Otherwise, the content string contains the error message.
Definition at line 26 of file CurlInterface.cc.
References NULL, and ntuplemaker::status.
Referenced by stor::EventServerProxy< RegInfo >::getInitMsgFromEventServer().
{ CURL* curl = curl_easy_init(); if ( ! curl ) return CURLE_FAILED_INIT; curl_easy_setopt(curl, CURLOPT_POSTFIELDS, buf); curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, size); struct curl_slist *headers=NULL; headers = curl_slist_append(headers, "Content-Type: application/octet-stream"); headers = curl_slist_append(headers, "Content-Transfer-Encoding: binary"); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); CURLcode status = do_curl(curl, url, content); curl_slist_free_all(headers); return status; }
size_t CurlInterface::writeToString | ( | char * | data, |
size_t | size, | ||
size_t | nmemb, | ||
Content * | buffer | ||
) | [static, private] |
Definition at line 81 of file CurlInterface.cc.
References runTheMatrix::data, and NULL.
Referenced by do_curl().
char stor::CurlInterface::errorBuffer_[CURL_ERROR_SIZE] [private] |
Definition at line 52 of file CurlInterface.h.
Referenced by do_curl().