CARMA C++
CurlUtils.h
Go to the documentation of this file.
1 // $Id: CurlUtils.h,v 1.1 2010/12/13 21:06:29 eml Exp $
2 
3 #ifndef SZA_UTIL_CURLUTILS_H
4 #define SZA_UTIL_CURLUTILS_H
5 
15 #include <sstream>
16 #include <curl/curl.h>
17 
18 namespace sza {
19  namespace util {
20 
21  class CurlUtils {
22  public:
23 
27  CurlUtils();
28 
32  virtual ~CurlUtils();
33 
34  std::string getUrl(std::string url, bool printStats=false);
35 
36  std::string postUserPass(std::string url, std::string user, std::string pass, std::string challenge);
37 
38  protected:
39 
40  enum {
41  OPTION_FALSE = 0,
42  OPTION_TRUE = 1
43  };
44 
45  // A stream containing the last read information returned from
46  // the URL fetch
47 
48  std::ostringstream lastRead_;
49 
50  // A function that will be called to handle data from a call to
51  // 'perform'
52 
53  static size_t handleData(void* buffer, size_t size, size_t nmemb, void* userp);
54 
55 
56  // Initialize the CURL interface
57 
58  CURL* initCurl();
59 
60  // Cleanup the CURL interface
61 
62  void cleanUp(CURL* ctx);
63 
64  // Perform the request specified, and return stats about it, if
65  // printStats=true
66 
67  const CURLcode performRequest(CURL* ctx, bool printStats);
68 
69  // Set up a URL to fetch
70 
71  void setUrl(CURL* ctx, std::string url);
72 
73  }; // End class CurlUtils
74 
75  } // End namespace util
76 } // End namespace sza
77 
78 
79 
80 #endif // End #ifndef SZA_UTIL_CURLUTILS_H