#include <CurlPoster.h>
Public Types | |
enum | mode { text, stack, leg, bin } |
Public Member Functions | |
bool | check (int) |
CurlPoster (const std::string &url) | |
void | postBinary (const unsigned char *, size_t, unsigned int, const std::string &=standard_post_method_) |
void | postString (const char *, size_t, unsigned int, mode, const std::string &=standard_post_method_) |
virtual | ~CurlPoster () |
Private Member Functions | |
void | post (const unsigned char *, size_t, unsigned int, mode, const std::string &) |
Private Attributes | |
bool | active_ |
struct utsname * | buf_ |
std::string | url_ |
Static Private Attributes | |
static const std::string | standard_post_method_ = "/postEntry" |
Definition at line 10 of file CurlPoster.h.
evf::CurlPoster::CurlPoster | ( | const std::string & | url | ) | [inline] |
virtual evf::CurlPoster::~CurlPoster | ( | ) | [inline, virtual] |
bool evf::CurlPoster::check | ( | int | run | ) |
Definition at line 117 of file CurlPoster.cc.
References active_, gather_cfg::cout, error, summarizeEdmComparisonLogfiles::success, url_, and evf::write_data().
Referenced by evf::Vulture::control().
{ bool retVal = true; char ps[14]; sprintf(ps,"run=%d",run); CURL* han = curl_easy_init(); if(han==0) { active_ = false; } char error[CURL_ERROR_SIZE]; std::string dummy; curl_easy_setopt(han, CURLOPT_URL, url_.c_str() ); curl_easy_setopt(han, CURLOPT_POSTFIELDS,ps ); curl_easy_setopt(han, CURLOPT_WRITEFUNCTION, &write_data ); curl_easy_setopt(han, CURLOPT_WRITEDATA, &dummy ); curl_easy_setopt(han, CURLOPT_ERRORBUFFER, error ); int success = curl_easy_perform(han); curl_easy_cleanup(han); if(success != 0){ std::cout << "curlposter failed check" << std::endl; retVal = false; active_ = false; } return retVal; }
void evf::CurlPoster::post | ( | const unsigned char * | content, |
size_t | len, | ||
unsigned int | run, | ||
mode | m, | ||
const std::string & | post_method | ||
) | [private] |
Definition at line 18 of file CurlPoster.cc.
References bin, buf_, gather_cfg::cout, error, prof2calltree::last, leg, runTheMatrix::msg, NULL, stack, summarizeEdmComparisonLogfiles::success, text, and url_.
Referenced by postBinary(), and postString().
{ std::string urlp = url_+post_method; char srun[12]; sprintf(srun,"%d",run); std::string method; CURL* han = curl_easy_init(); if(han==0) { XCEPT_RAISE(evf::Exception,"could not create handle for curlPoster"); } struct curl_slist *headers=NULL; /* init to NULL is important */ switch(m){ case text: { headers = curl_slist_append(headers, "Content-Type: text/plain"); method = "text"; break; } case stack: { headers = curl_slist_append(headers, "Content-Type: text/plain"); method = "stacktrace"; break; } case leg: { headers = curl_slist_append(headers, "Content-Type: text/plain"); method = "legenda"; break; } case bin: { headers = curl_slist_append(headers, "Content-Type: application/octet-stream"); // headers = curl_slist_append(headers, "Content-Transfer-Encoding: base64"); headers = curl_slist_append(headers, "Expect:"); method = "trp"; break; } default: { headers = curl_slist_append(headers, "Content-Type: application/xml"); } } struct curl_httpspost *post=NULL; struct curl_httpspost *last=NULL; char error[CURL_ERROR_SIZE]; curl_easy_setopt(han, CURLOPT_URL, urlp.c_str()); // curl_easy_setopt(han, CURLOPT_VERBOSE,""); curl_easy_setopt(han, CURLOPT_NOSIGNAL,""); curl_easy_setopt(han, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_0); // curl_easy_setopt(han, CURLOPT_TIMEOUT, 60.0L); curl_formadd(&post, &last, CURLFORM_COPYNAME, "name", CURLFORM_COPYCONTENTS, buf_->nodename, CURLFORM_END); curl_formadd(&post, &last, CURLFORM_COPYNAME, "run", CURLFORM_COPYCONTENTS, srun, CURLFORM_END); int retval = curl_formadd(&post, &last, CURLFORM_COPYNAME, method.c_str(), CURLFORM_COPYCONTENTS, content, CURLFORM_CONTENTSLENGTH, len, CURLFORM_CONTENTHEADER, headers, CURLFORM_END); if(retval != 0) std::cout << "Error in formadd " << retval << std::endl; curl_easy_setopt(han, CURLOPT_HTTPPOST, post); curl_easy_setopt(han, CURLOPT_ERRORBUFFER, error); int success = curl_easy_perform(han); curl_formfree(post); curl_easy_cleanup(han); curl_slist_free_all(headers); /* free the header list */ if(success != 0) { std::ostringstream msg; msg << "could not post data to url " << url_ << " error #" << success << " " << error; XCEPT_RAISE(evf::Exception,msg.str().c_str()); } }
void evf::CurlPoster::postBinary | ( | const unsigned char * | content, |
size_t | len, | ||
unsigned int | run, | ||
const std::string & | post_method = standard_post_method_ |
||
) |
Definition at line 110 of file CurlPoster.cc.
References active_, bin, and post().
Referenced by evf::CPUStat::sendStat(), and evf::RateStat::sendStat().
void evf::CurlPoster::postString | ( | const char * | content, |
size_t | len, | ||
unsigned int | run, | ||
mode | m, | ||
const std::string & | post_method = standard_post_method_ |
||
) |
Definition at line 104 of file CurlPoster.cc.
References active_, and post().
Referenced by evf::Vulture::analyze(), evf::Vulture::prowling(), evf::CPUStat::sendLegenda(), and evf::RateStat::sendLegenda().
bool evf::CurlPoster::active_ [private] |
Definition at line 30 of file CurlPoster.h.
Referenced by check(), postBinary(), and postString().
struct utsname* evf::CurlPoster::buf_ [private] |
Definition at line 31 of file CurlPoster.h.
Referenced by CurlPoster(), post(), and ~CurlPoster().
const std::string evf::CurlPoster::standard_post_method_ = "/postEntry" [static, private] |
Definition at line 32 of file CurlPoster.h.
std::string evf::CurlPoster::url_ [private] |
Definition at line 29 of file CurlPoster.h.