summaryrefslogtreecommitdiff
path: root/indra/llmessage/llcurl.h
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llmessage/llcurl.h')
-rw-r--r--indra/llmessage/llcurl.h118
1 files changed, 118 insertions, 0 deletions
diff --git a/indra/llmessage/llcurl.h b/indra/llmessage/llcurl.h
new file mode 100644
index 0000000000..4f1b5e6031
--- /dev/null
+++ b/indra/llmessage/llcurl.h
@@ -0,0 +1,118 @@
+/*
+ * llcurl.h
+ * MacTester
+ *
+ * Created by Zero Linden on 10/15/06.
+ * Copyright 2006 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#ifndef LL_LLCURL_H
+#define LL_LLCURL_H
+
+#include "linden_common.h"
+
+#include <sstream>
+#include <string>
+#include <vector>
+
+#include <boost/intrusive_ptr.hpp>
+#include <curl/curl.h>
+
+// #include "llhttpclient.h"
+
+class LLCurl
+{
+public:
+ class Multi;
+
+ class Responder
+ {
+ public:
+ Responder();
+ virtual ~Responder();
+
+ virtual void error(U32 status, const std::stringstream& content); // called with bad status codes
+
+ virtual void result(const std::stringstream& content);
+
+ virtual void completed(U32 status, const std::stringstream& content);
+ /**< The default implemetnation calls
+ either:
+ * result(), or
+ * error()
+ */
+
+ public: /* but not really -- don't touch this */
+ U32 mReferenceCount;
+ };
+ typedef boost::intrusive_ptr<Responder> ResponderPtr;
+
+ class Easy
+ {
+ public:
+ Easy();
+ ~Easy();
+
+ void get(const std::string& url, ResponderPtr);
+ void getByteRange(const std::string& url, S32 offset, S32 length, ResponderPtr);
+
+ void perform();
+
+ private:
+ void prep(const std::string& url, ResponderPtr);
+ void report(CURLcode);
+
+ CURL* mHandle;
+ struct curl_slist* mHeaders;
+
+ std::string mURL;
+ std::string mRange;
+ std::stringstream mRequest;
+
+ std::stringstream mOutput;
+ char mErrorBuffer[CURL_ERROR_SIZE];
+
+ std::stringstream mHeaderOutput; // Debug
+
+ ResponderPtr mResponder;
+
+ friend class Multi;
+ };
+
+
+ class Multi
+ {
+ public:
+ Multi();
+ ~Multi();
+
+ void get(const std::string& url, ResponderPtr);
+ void getByteRange(const std::string& url, S32 offset, S32 length, ResponderPtr);
+
+ void process();
+
+ private:
+ Easy* easyAlloc();
+ void easyFree(Easy*);
+
+ CURLM* mHandle;
+
+ typedef std::vector<Easy*> EasyList;
+ EasyList mFreeEasy;
+ };
+
+
+ static void get(const std::string& url, ResponderPtr);
+ static void getByteRange(const std::string& url, S32 offset, S32 length, ResponderPtr responder);
+
+ static void process();
+};
+
+namespace boost
+{
+ void intrusive_ptr_add_ref(LLCurl::Responder* p);
+ void intrusive_ptr_release(LLCurl::Responder* p);
+};
+
+#endif // LL_LLCURL_H