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 | Static Private Member Functions | Private Attributes
stor::CurlInterface Class Reference

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

Detailed Description

Helper class to interact with curl

Author:
mommsen
Revision:
1.2.6.1
Date:
2011/03/07 11:33:04

Definition at line 22 of file CurlInterface.h.

Member Typedef Documentation

typedef std::vector<char> stor::CurlInterface::Content

Definition at line 27 of file CurlInterface.h.

Member Function Documentation

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

52 {
53  curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
54  curl_easy_setopt(curl, CURLOPT_TIMEOUT, 4); // seconds
55  curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1); // do not send any signals
56  curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, stor::CurlInterface::writeToString);
57  curl_easy_setopt(curl, CURLOPT_WRITEDATA, &content);
58  curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errorBuffer_);
59  curl_easy_setopt(curl, CURLOPT_FAILONERROR,1);
60 
61  CURLcode returnCode = curl_easy_perform(curl);
62 
63  curl_easy_cleanup(curl);
64 
65  if (returnCode != CURLE_OK)
66  {
67  size_t i = 0;
68  content.clear();
69  while ( errorBuffer_[i] != '\0' )
70  {
71  content.push_back( errorBuffer_[i] );
72  ++i;
73  }
74  content.push_back('\0');
75  }
76 
77  return returnCode;
78 }
int i
Definition: DBlmapReader.cc:9
char errorBuffer_[CURL_ERROR_SIZE]
Definition: CurlInterface.h:52
static size_t writeToString(char *data, size_t size, size_t nmemb, Content *buffer)
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().

15 {
16  CURL* curl = curl_easy_init();
17  if ( ! curl ) return CURLE_FAILED_INIT;
18 
19  curl_easy_setopt(curl, CURLOPT_USERPWD, user.c_str());
20 
21  return do_curl(curl, url, content);
22 }
CURLcode do_curl(CURL *, const std::string &url, Content &content)
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().

32 {
33  CURL* curl = curl_easy_init();
34  if ( ! curl ) return CURLE_FAILED_INIT;
35 
36  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, buf);
37  curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, size);
38 
39  struct curl_slist *headers=NULL;
40  headers = curl_slist_append(headers, "Content-Type: application/octet-stream");
41  headers = curl_slist_append(headers, "Content-Transfer-Encoding: binary");
42  curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
43 
44  CURLcode status = do_curl(curl, url, content);
45  curl_slist_free_all(headers);
46 
47  return status;
48 }
#define NULL
Definition: scimark2.h:8
CURLcode do_curl(CURL *, const std::string &url, Content &content)
tuple status
Definition: ntuplemaker.py:245
tuple size
Write out results.
size_t CurlInterface::writeToString ( char *  data,
size_t  size,
size_t  nmemb,
Content buffer 
)
staticprivate

Definition at line 81 of file CurlInterface.cc.

References runTheMatrix::data, and NULL.

Referenced by do_curl().

82 {
83  if (buffer == NULL) return 0;
84 
85  const size_t length = size * nmemb;
86  buffer->insert(buffer->end(), data, data+length);
87  return length;
88 }
#define NULL
Definition: scimark2.h:8
tuple size
Write out results.

Member Data Documentation

char stor::CurlInterface::errorBuffer_[CURL_ERROR_SIZE]
private

Definition at line 52 of file CurlInterface.h.

Referenced by do_curl().