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, legaux,
  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 
legaux 
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 125 of file CurlPoster.cc.

References active_, gather_cfg::cout, error, AlCaHLTBitMon_QueryRunRegistry::string, summarizeEdmComparisonLogfiles::success, url_, and evf::write_data().

Referenced by evf::Vulture::control().

126  {
127  bool retVal = true;
128  char ps[14];
129  sprintf(ps,"run=%d",run);
130  CURL* han = curl_easy_init();
131  if(han==0)
132  {
133  active_ = false;
134  }
135  char error[CURL_ERROR_SIZE];
136  std::string dummy;
137 
138  curl_easy_setopt(han, CURLOPT_URL, url_.c_str() );
139  curl_easy_setopt(han, CURLOPT_POSTFIELDS,ps );
140  curl_easy_setopt(han, CURLOPT_WRITEFUNCTION, &write_data );
141  curl_easy_setopt(han, CURLOPT_WRITEDATA, &dummy );
142  curl_easy_setopt(han, CURLOPT_ERRORBUFFER, error );
143  curl_easy_setopt(han, CURLOPT_TIMEOUT, 5 );
144  curl_easy_setopt(han, CURLOPT_CONNECTTIMEOUT, 5 );
145  int success = curl_easy_perform(han);
146 
147  curl_easy_cleanup(han);
148  if(success != 0){
149  std::cout << "curlposter failed check" << std::endl;
150  retVal = false;
151  active_ = false;
152  }
153  return retVal;
154 
155  }
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:121
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_, ws_sso_content_reader::content, gather_cfg::cout, error, prof2calltree::last, leg, legaux, PFRecoTauDiscriminationAgainstElectronMVA2_cfi::method, lumiQueryAPI::msg, NULL, stack, AlCaHLTBitMon_QueryRunRegistry::string, 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);
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 legaux:
53  {
54  headers = curl_slist_append(headers, "Content-Type: text/plain");
55  method = "legendaAux";
56  break;
57  }
58  case bin:
59  {
60  headers = curl_slist_append(headers, "Content-Type: application/octet-stream");
61  // headers = curl_slist_append(headers, "Content-Transfer-Encoding: base64");
62  headers = curl_slist_append(headers, "Expect:");
63  method = "trp";
64  break;
65  }
66  default:
67  {
68  headers = curl_slist_append(headers, "Content-Type: application/xml");
69  }
70  }
71  struct curl_httppost *post=NULL;
72  struct curl_httppost *last=NULL;
73  char error[CURL_ERROR_SIZE];
74 
75  curl_easy_setopt(han, CURLOPT_URL, urlp.c_str());
76  // curl_easy_setopt(han, CURLOPT_VERBOSE,"");
77  curl_easy_setopt(han, CURLOPT_NOSIGNAL,"");
78  curl_easy_setopt(han, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_0);
79  // curl_easy_setopt(han, CURLOPT_TIMEOUT, 60.0L);
80  curl_formadd(&post, &last,
81  CURLFORM_COPYNAME, "name",
82  CURLFORM_COPYCONTENTS, buf_->nodename, CURLFORM_END);
83  curl_formadd(&post, &last,
84  CURLFORM_COPYNAME, "run",
85  CURLFORM_COPYCONTENTS, srun, CURLFORM_END);
86  int retval = curl_formadd(&post, &last,
87  CURLFORM_COPYNAME, method.c_str(),
88  CURLFORM_COPYCONTENTS, content,
89  CURLFORM_CONTENTSLENGTH, len,
90  CURLFORM_CONTENTHEADER, headers,
91  CURLFORM_END);
92  if(retval != 0) std::cout << "Error in formadd " << retval << std::endl;
93  curl_easy_setopt(han, CURLOPT_HTTPPOST, post);
94  curl_easy_setopt(han, CURLOPT_ERRORBUFFER, error);
95  curl_easy_setopt(han, CURLOPT_TIMEOUT, 5);
96  curl_easy_setopt(han, CURLOPT_CONNECTTIMEOUT, 5);
97 
98  int success = curl_easy_perform(han);
99  curl_formfree(post);
100  curl_easy_cleanup(han);
101  curl_slist_free_all(headers); /* free the header list */
102 
103  if(success != 0)
104  {
105  std::ostringstream msg;
106  msg << "could not post data to url " << url_ << " error #"
107  << success << " " << error;
108  XCEPT_RAISE(evf::Exception,msg.str().c_str());
109  }
110 
111  }
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:121
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 118 of file CurlPoster.cc.

References active_, bin, and post().

Referenced by evf::RateStat::sendStat(), and evf::CPUStat::sendStat().

120  {
121  if(!active_) return;
122  post(content,len,run,bin,post_method);
123  }
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 112 of file CurlPoster.cc.

References active_, and post().

Referenced by evf::Vulture::analyze(), evf::Vulture::prowling(), evf::RateStat::sendAuxLegenda(), evf::RateStat::sendLegenda(), and evf::CPUStat::sendLegenda().

114  {
115  if(!active_) return;
116  post((unsigned char*)content,(unsigned int)len,run,m,post_method);
117  }
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().