CMS 3D CMS Logo

/data/git/CMSSW_5_3_11_patch5/src/EventFilter/Utilities/src/SquidNet.cc

Go to the documentation of this file.
00001 
00002 #include "EventFilter/Utilities/interface/SquidNet.h"
00003 #include "EventFilter/Utilities/interface/CurlUtils.h"
00004 #include "EventFilter/Utilities/interface/Exception.h"
00005 
00006 #include "curl/curl.h"
00007 #include <netdb.h>
00008 #include <sys/socket.h>        /* for AF_INET */
00009 
00010 #include <fstream>
00011 
00012 
00013 namespace evf{
00014   
00015   SquidNet::SquidNet(unsigned int proxyport, std::string const &url) : port_(proxyport), urlToGet_(url) 
00016   {
00017     std::ostringstream oproxy;
00018     oproxy << "localhost:" << port_;
00019     proxy_ = oproxy.str();
00020   }
00021   bool SquidNet::check(){
00022     bool retVal = true;
00023     
00024     CURL* han = curl_easy_init();
00025     if(han==0)
00026       {
00027         XCEPT_RAISE(evf::Exception,"could not create handle for SquidNet fisher");
00028       }
00029     char error[CURL_ERROR_SIZE];
00030     std::string dummy;
00031 
00032     struct curl_slist *headers=NULL; /* init to NULL is important */
00033 
00034     headers = curl_slist_append(headers, "Pragma:");
00035 
00036     curl_easy_setopt(han, CURLOPT_HTTPHEADER, headers);
00037  
00038     curl_easy_setopt(han, CURLOPT_PROXY, proxy_.c_str());
00039     
00040     curl_easy_setopt(han, CURLOPT_URL, urlToGet_.c_str());
00041     
00042     curl_easy_setopt(han, CURLOPT_WRITEFUNCTION, &write_data);
00043     curl_easy_setopt(han, CURLOPT_WRITEDATA, &dummy);
00044     curl_easy_setopt(han, CURLOPT_ERRORBUFFER, error);
00045     int success = curl_easy_perform(han);
00046 
00047     curl_slist_free_all(headers); /* free the header list */
00048 
00049     curl_easy_cleanup(han);
00050     if(success != 0)
00051       retVal = false;
00052     return retVal;
00053   }
00054 
00055 }