aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmessage/llcurl.h
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llmessage/llcurl.h')
-rw-r--r--linden/indra/llmessage/llcurl.h118
1 files changed, 118 insertions, 0 deletions
diff --git a/linden/indra/llmessage/llcurl.h b/linden/indra/llmessage/llcurl.h
new file mode 100644
index 0000000..4f1b5e6
--- /dev/null
+++ b/linden/indra/llmessage/llcurl.h
@@ -0,0 +1,118 @@
1/*
2 * llcurl.h
3 * MacTester
4 *
5 * Created by Zero Linden on 10/15/06.
6 * Copyright 2006 __MyCompanyName__. All rights reserved.
7 *
8 */
9
10#ifndef LL_LLCURL_H
11#define LL_LLCURL_H
12
13#include "linden_common.h"
14
15#include <sstream>
16#include <string>
17#include <vector>
18
19#include <boost/intrusive_ptr.hpp>
20#include <curl/curl.h>
21
22// #include "llhttpclient.h"
23
24class LLCurl
25{
26public:
27 class Multi;
28
29 class Responder
30 {
31 public:
32 Responder();
33 virtual ~Responder();
34
35 virtual void error(U32 status, const std::stringstream& content); // called with bad status codes
36
37 virtual void result(const std::stringstream& content);
38
39 virtual void completed(U32 status, const std::stringstream& content);
40 /**< The default implemetnation calls
41 either:
42 * result(), or
43 * error()
44 */
45
46 public: /* but not really -- don't touch this */
47 U32 mReferenceCount;
48 };
49 typedef boost::intrusive_ptr<Responder> ResponderPtr;
50
51 class Easy
52 {
53 public:
54 Easy();
55 ~Easy();
56
57 void get(const std::string& url, ResponderPtr);
58 void getByteRange(const std::string& url, S32 offset, S32 length, ResponderPtr);
59
60 void perform();
61
62 private:
63 void prep(const std::string& url, ResponderPtr);
64 void report(CURLcode);
65
66 CURL* mHandle;
67 struct curl_slist* mHeaders;
68
69 std::string mURL;
70 std::string mRange;
71 std::stringstream mRequest;
72
73 std::stringstream mOutput;
74 char mErrorBuffer[CURL_ERROR_SIZE];
75
76 std::stringstream mHeaderOutput; // Debug
77
78 ResponderPtr mResponder;
79
80 friend class Multi;
81 };
82
83
84 class Multi
85 {
86 public:
87 Multi();
88 ~Multi();
89
90 void get(const std::string& url, ResponderPtr);
91 void getByteRange(const std::string& url, S32 offset, S32 length, ResponderPtr);
92
93 void process();
94
95 private:
96 Easy* easyAlloc();
97 void easyFree(Easy*);
98
99 CURLM* mHandle;
100
101 typedef std::vector<Easy*> EasyList;
102 EasyList mFreeEasy;
103 };
104
105
106 static void get(const std::string& url, ResponderPtr);
107 static void getByteRange(const std::string& url, S32 offset, S32 length, ResponderPtr responder);
108
109 static void process();
110};
111
112namespace boost
113{
114 void intrusive_ptr_add_ref(LLCurl::Responder* p);
115 void intrusive_ptr_release(LLCurl::Responder* p);
116};
117
118#endif // LL_LLCURL_H