CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
evf::CurlPoster Class Reference

#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"
 

Detailed Description

Definition at line 10 of file CurlPoster.h.

Member Enumeration Documentation

Enumerator
text 
stack 
leg 
bin 

Definition at line 14 of file CurlPoster.h.

Constructor & Destructor Documentation

evf::CurlPoster::CurlPoster ( const std::string &  url)
inline

Definition at line 16 of file CurlPoster.h.

References buf_.

16  : url_(url), active_(true){
17  buf_=(struct utsname*)new char[sizeof(struct utsname)];
18  uname(buf_);
19  // check();
20  }
struct utsname * buf_
Definition: CurlPoster.h:31
std::string url_
Definition: CurlPoster.h:29
virtual evf::CurlPoster::~CurlPoster ( )
inlinevirtual

Definition at line 21 of file CurlPoster.h.

References buf_.

21 {delete [] buf_;}
struct utsname * buf_
Definition: CurlPoster.h:31

Member Function Documentation

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().

118  {
119  bool retVal = true;
120  char ps[14];
121  sprintf(ps,"run=%d",run);
122  CURL* han = curl_easy_init();
123  if(han==0)
124  {
125  active_ = false;
126  }
127  char error[CURL_ERROR_SIZE];
128  std::string dummy;
129 
130  curl_easy_setopt(han, CURLOPT_URL, url_.c_str() );
131  curl_easy_setopt(han, CURLOPT_POSTFIELDS,ps );
132  curl_easy_setopt(han, CURLOPT_WRITEFUNCTION, &write_data );
133  curl_easy_setopt(han, CURLOPT_WRITEDATA, &dummy );
134  curl_easy_setopt(han, CURLOPT_ERRORBUFFER, error );
135  int success = curl_easy_perform(han);
136 
137  curl_easy_cleanup(han);
138  if(success != 0){
139  std::cout << "curlposter failed check" << std::endl;
140  retVal = false;
141  active_ = false;
142  }
143  return retVal;
144 
145  }
static size_t write_data(void *ptr, size_t size, size_t nmemb, void *pointer)
Definition: CurlUtils.h:12
std::string url_
Definition: CurlPoster.h:29
tuple cout
Definition: gather_cfg.py:41
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().

22  {
23  std::string urlp = url_+post_method;
24  char srun[12];
25  sprintf(srun,"%d",run);
26  std::string method;
27  CURL* han = curl_easy_init();
28  if(han==0)
29  {
30  XCEPT_RAISE(evf::Exception,"could not create handle for curlPoster");
31  }
32  struct curl_slist *headers=NULL; /* init to NULL is important */
33  switch(m){
34  case text:
35  {
36  headers = curl_slist_append(headers, "Content-Type: text/plain");
37  method = "text";
38  break;
39  }
40  case stack:
41  {
42  headers = curl_slist_append(headers, "Content-Type: text/plain");
43  method = "stacktrace";
44  break;
45  }
46  case leg:
47  {
48  headers = curl_slist_append(headers, "Content-Type: text/plain");
49  method = "legenda";
50  break;
51  }
52  case bin:
53  {
54  headers = curl_slist_append(headers, "Content-Type: application/octet-stream");
55  // headers = curl_slist_append(headers, "Content-Transfer-Encoding: base64");
56  headers = curl_slist_append(headers, "Expect:");
57  method = "trp";
58  break;
59  }
60  default:
61  {
62  headers = curl_slist_append(headers, "Content-Type: application/xml");
63  }
64  }
65  struct curl_httppost *post=NULL;
66  struct curl_httppost *last=NULL;
67  char error[CURL_ERROR_SIZE];
68 
69  curl_easy_setopt(han, CURLOPT_URL, urlp.c_str());
70  // curl_easy_setopt(han, CURLOPT_VERBOSE,"");
71  curl_easy_setopt(han, CURLOPT_NOSIGNAL,"");
72  curl_easy_setopt(han, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_0);
73  // curl_easy_setopt(han, CURLOPT_TIMEOUT, 60.0L);
74  curl_formadd(&post, &last,
75  CURLFORM_COPYNAME, "name",
76  CURLFORM_COPYCONTENTS, buf_->nodename, CURLFORM_END);
77  curl_formadd(&post, &last,
78  CURLFORM_COPYNAME, "run",
79  CURLFORM_COPYCONTENTS, srun, CURLFORM_END);
80  int retval = curl_formadd(&post, &last,
81  CURLFORM_COPYNAME, method.c_str(),
82  CURLFORM_COPYCONTENTS, content,
83  CURLFORM_CONTENTSLENGTH, len,
84  CURLFORM_CONTENTHEADER, headers,
85  CURLFORM_END);
86  if(retval != 0) std::cout << "Error in formadd " << retval << std::endl;
87  curl_easy_setopt(han, CURLOPT_HTTPPOST, post);
88  curl_easy_setopt(han, CURLOPT_ERRORBUFFER, error);
89 
90  int success = curl_easy_perform(han);
91  curl_formfree(post);
92  curl_easy_cleanup(han);
93  curl_slist_free_all(headers); /* free the header list */
94 
95  if(success != 0)
96  {
97  std::ostringstream msg;
98  msg << "could not post data to url " << url_ << " error #"
99  << success << " " << error;
100  XCEPT_RAISE(evf::Exception,msg.str().c_str());
101  }
102 
103  }
struct utsname * buf_
Definition: CurlPoster.h:31
#define NULL
Definition: scimark2.h:8
std::string url_
Definition: CurlPoster.h:29
void post(const unsigned char *, size_t, unsigned int, mode, const std::string &)
Definition: CurlPoster.cc:18
tuple cout
Definition: gather_cfg.py:41
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::RateStat::sendStat(), and evf::CPUStat::sendStat().

112  {
113  if(!active_) return;
114  post(content,len,run,bin,post_method);
115  }
void post(const unsigned char *, size_t, unsigned int, mode, const std::string &)
Definition: CurlPoster.cc:18
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::RateStat::sendLegenda(), and evf::CPUStat::sendLegenda().

106  {
107  if(!active_) return;
108  post((unsigned char*)content,(unsigned int)len,run,m,post_method);
109  }
void post(const unsigned char *, size_t, unsigned int, mode, const std::string &)
Definition: CurlPoster.cc:18

Member Data Documentation

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"
staticprivate

Definition at line 32 of file CurlPoster.h.

std::string evf::CurlPoster::url_
private

Definition at line 29 of file CurlPoster.h.

Referenced by check(), and post().