CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SquidNet.cc
Go to the documentation of this file.
1 
5 
6 #include "curl/curl.h"
7 #include <netdb.h>
8 #include <sys/socket.h> /* for AF_INET */
9 
10 #include <fstream>
11 
12 
13 namespace evf{
14 
15  SquidNet::SquidNet(unsigned int proxyport, std::string const &url) : port_(proxyport), urlToGet_(url)
16  {
17  std::ostringstream oproxy;
18  oproxy << "localhost:" << port_;
19  proxy_ = oproxy.str();
20  }
22  bool retVal = true;
23 
24  CURL* han = curl_easy_init();
25  if(han==0)
26  {
27  XCEPT_RAISE(evf::Exception,"could not create handle for SquidNet fisher");
28  }
29  char error[CURL_ERROR_SIZE];
30  std::string dummy;
31 
32  struct curl_slist *headers=NULL; /* init to NULL is important */
33 
34  headers = curl_slist_append(headers, "Pragma:");
35 
36  curl_easy_setopt(han, CURLOPT_HTTPHEADER, headers);
37 
38  curl_easy_setopt(han, CURLOPT_PROXY, proxy_.c_str());
39 
40  curl_easy_setopt(han, CURLOPT_URL, urlToGet_.c_str());
41 
42  curl_easy_setopt(han, CURLOPT_WRITEFUNCTION, &write_data);
43  curl_easy_setopt(han, CURLOPT_WRITEDATA, &dummy);
44  curl_easy_setopt(han, CURLOPT_ERRORBUFFER, error);
45  int success = curl_easy_perform(han);
46 
47  curl_slist_free_all(headers); /* free the header list */
48 
49  curl_easy_cleanup(han);
50  if(success != 0)
51  retVal = false;
52  return retVal;
53  }
54 
55 }
bool check()
Definition: SquidNet.cc:21
#define NULL
Definition: scimark2.h:8
unsigned int port_
Definition: SquidNet.h:15
std::string proxy_
Definition: SquidNet.h:16
static size_t write_data(void *ptr, size_t size, size_t nmemb, void *pointer)
Definition: CurlUtils.h:12
std::string urlToGet_
Definition: SquidNet.h:17
SquidNet(unsigned int, std::string const &)
Definition: SquidNet.cc:15