aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmessage/llhttpclient.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-09-06 18:24:57 -0500
committerJacek Antonelli2008-09-06 18:25:07 -0500
commit798d367d54a6c6379ad355bd8345fa40e31e7fe9 (patch)
tree1921f1708cd0240648c97bc02df2c2ab5f2fc41e /linden/indra/llmessage/llhttpclient.cpp
parentSecond Life viewer sources 1.20.15 (diff)
downloadmeta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.zip
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.gz
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.bz2
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.xz
Second Life viewer sources 1.21.0-RC
Diffstat (limited to 'linden/indra/llmessage/llhttpclient.cpp')
-rw-r--r--linden/indra/llmessage/llhttpclient.cpp111
1 files changed, 66 insertions, 45 deletions
diff --git a/linden/indra/llmessage/llhttpclient.cpp b/linden/indra/llmessage/llhttpclient.cpp
index 22c0c68..caeaee1 100644
--- a/linden/indra/llmessage/llhttpclient.cpp
+++ b/linden/indra/llmessage/llhttpclient.cpp
@@ -122,7 +122,7 @@ namespace
122 { 122 {
123 public: 123 public:
124 RawInjector(const U8* data, S32 size) : mData(data), mSize(size) {} 124 RawInjector(const U8* data, S32 size) : mData(data), mSize(size) {}
125 virtual ~RawInjector() {} 125 virtual ~RawInjector() {delete mData;}
126 126
127 const char* contentType() { return "application/octet-stream"; } 127 const char* contentType() { return "application/octet-stream"; }
128 128
@@ -152,17 +152,22 @@ namespace
152 { 152 {
153 LLBufferStream ostream(channels, buffer.get()); 153 LLBufferStream ostream(channels, buffer.get());
154 154
155 llifstream fstream(mFilename.c_str(), std::iostream::binary | std::iostream::out); 155 llifstream fstream(mFilename, std::iostream::binary | std::iostream::out);
156 fstream.seekg(0, std::ios::end); 156 if(fstream.is_open())
157 U32 fileSize = fstream.tellg(); 157 {
158 fstream.seekg(0, std::ios::beg); 158 fstream.seekg(0, std::ios::end);
159 char* fileBuffer; 159 U32 fileSize = fstream.tellg();
160 fileBuffer = new char [fileSize]; 160 fstream.seekg(0, std::ios::beg);
161 fstream.read(fileBuffer, fileSize); 161 char* fileBuffer;
162 ostream.write(fileBuffer, fileSize); 162 fileBuffer = new char [fileSize];
163 fstream.close(); 163 fstream.read(fileBuffer, fileSize);
164 eos = true; 164 ostream.write(fileBuffer, fileSize);
165 return STATUS_DONE; 165 fstream.close();
166 eos = true;
167 return STATUS_DONE;
168 }
169
170 return STATUS_ERROR;
166 } 171 }
167 172
168 const std::string mFilename; 173 const std::string mFilename;
@@ -199,14 +204,13 @@ namespace
199 LLPumpIO* theClientPump = NULL; 204 LLPumpIO* theClientPump = NULL;
200} 205}
201 206
202static void request(const std::string& url, 207static void request(
203 LLURLRequest::ERequestAction method, 208 const std::string& url,
204 Injector* body_injector, 209 LLURLRequest::ERequestAction method,
205 LLCurl::ResponderPtr responder, 210 Injector* body_injector,
206 const LLSD& headers = LLSD(), 211 LLCurl::ResponderPtr responder,
207 const F32 timeout = HTTP_REQUEST_EXPIRY_SECS, 212 const F32 timeout = HTTP_REQUEST_EXPIRY_SECS,
208 S32 offset = 0, 213 const LLSD& headers = LLSD())
209 S32 bytes = 0)
210{ 214{
211 if (!LLHTTPClient::hasPump()) 215 if (!LLHTTPClient::hasPump())
212 { 216 {
@@ -215,7 +219,7 @@ static void request(const std::string& url,
215 } 219 }
216 LLPumpIO::chain_t chain; 220 LLPumpIO::chain_t chain;
217 221
218 LLURLRequest *req = new LLURLRequest(method, url); 222 LLURLRequest* req = new LLURLRequest(method, url);
219 req->checkRootCertificate(true); 223 req->checkRootCertificate(true);
220 224
221 // Insert custom headers is the caller sent any 225 // Insert custom headers is the caller sent any
@@ -234,10 +238,10 @@ static void request(const std::string& url,
234 //to not use the proxy (read: llurlrequest.cpp) 238 //to not use the proxy (read: llurlrequest.cpp)
235 if ((iter->first == "Pragma") && (iter->second.asString() == "")) 239 if ((iter->first == "Pragma") && (iter->second.asString() == ""))
236 { 240 {
237 req->useProxy(FALSE); 241 req->useProxy(false);
238 } 242 }
239 header << iter->first << ": " << iter->second.asString() ; 243 header << iter->first << ": " << iter->second.asString() ;
240 llinfos << "header = " << header.str() << llendl; 244 lldebugs << "header = " << header.str() << llendl;
241 req->addHeader(header.str().c_str()); 245 req->addHeader(header.str().c_str());
242 } 246 }
243 } 247 }
@@ -257,25 +261,27 @@ static void request(const std::string& url,
257 chain.push_back(LLIOPipe::ptr_t(body_injector)); 261 chain.push_back(LLIOPipe::ptr_t(body_injector));
258 } 262 }
259 263
260 if (method == LLURLRequest::HTTP_GET && (offset > 0 || bytes > 0))
261 {
262 std::string range = llformat("Range: bytes=%d-%d", offset,offset+bytes-1);
263 req->addHeader(range.c_str());
264 }
265
266 chain.push_back(LLIOPipe::ptr_t(req)); 264 chain.push_back(LLIOPipe::ptr_t(req));
267 265
268 theClientPump->addChain(chain, timeout); 266 theClientPump->addChain(chain, timeout);
269} 267}
270 268
271 269
272void LLHTTPClient::getByteRange(const std::string& url, 270void LLHTTPClient::getByteRange(
273 S32 offset, S32 bytes, 271 const std::string& url,
274 ResponderPtr responder, 272 S32 offset,
275 const LLSD& headers, 273 S32 bytes,
276 const F32 timeout) 274 ResponderPtr responder,
275 const LLSD& hdrs,
276 const F32 timeout)
277{ 277{
278 request(url, LLURLRequest::HTTP_GET, NULL, responder, LLSD(), timeout, offset, bytes); 278 LLSD headers = hdrs;
279 if(offset > 0 || bytes > 0)
280 {
281 std::string range = llformat("bytes=%d-%d", offset, offset+bytes-1);
282 headers["Range"] = range;
283 }
284 request(url,LLURLRequest::HTTP_GET, NULL, responder, timeout, headers);
279} 285}
280 286
281void LLHTTPClient::head(const std::string& url, ResponderPtr responder, const F32 timeout) 287void LLHTTPClient::head(const std::string& url, ResponderPtr responder, const F32 timeout)
@@ -285,11 +291,11 @@ void LLHTTPClient::head(const std::string& url, ResponderPtr responder, const F3
285 291
286void LLHTTPClient::get(const std::string& url, ResponderPtr responder, const LLSD& headers, const F32 timeout) 292void LLHTTPClient::get(const std::string& url, ResponderPtr responder, const LLSD& headers, const F32 timeout)
287{ 293{
288 request(url, LLURLRequest::HTTP_GET, NULL, responder, headers, timeout); 294 request(url, LLURLRequest::HTTP_GET, NULL, responder, timeout, headers);
289} 295}
290void LLHTTPClient::getHeaderOnly(const std::string& url, ResponderPtr responder, const LLSD& headers, const F32 timeout) 296void LLHTTPClient::getHeaderOnly(const std::string& url, ResponderPtr responder, const LLSD& headers, const F32 timeout)
291{ 297{
292 request(url, LLURLRequest::HTTP_HEAD, NULL, responder, headers, timeout); 298 request(url, LLURLRequest::HTTP_HEAD, NULL, responder, timeout, headers);
293} 299}
294void LLHTTPClient::getHeaderOnly(const std::string& url, ResponderPtr responder, const F32 timeout) 300void LLHTTPClient::getHeaderOnly(const std::string& url, ResponderPtr responder, const F32 timeout)
295{ 301{
@@ -401,17 +407,11 @@ void LLHTTPClient::post(const std::string& url, const LLSD& body, ResponderPtr r
401 request(url, LLURLRequest::HTTP_POST, new LLSDInjector(body), responder, timeout); 407 request(url, LLURLRequest::HTTP_POST, new LLSDInjector(body), responder, timeout);
402} 408}
403 409
404void LLHTTPClient::post(const std::string& url, const U8* data, S32 size, ResponderPtr responder, const F32 timeout) 410void LLHTTPClient::postRaw(const std::string& url, const U8* data, S32 size, ResponderPtr responder, const F32 timeout)
405{ 411{
406 request(url, LLURLRequest::HTTP_POST, new RawInjector(data, size), responder, timeout); 412 request(url, LLURLRequest::HTTP_POST, new RawInjector(data, size), responder, timeout);
407} 413}
408 414
409void LLHTTPClient::del(const std::string& url, ResponderPtr responder, const F32 timeout)
410{
411 request(url, LLURLRequest::HTTP_DELETE, NULL, responder, timeout);
412}
413
414#if 1
415void LLHTTPClient::postFile(const std::string& url, const std::string& filename, ResponderPtr responder, const F32 timeout) 415void LLHTTPClient::postFile(const std::string& url, const std::string& filename, ResponderPtr responder, const F32 timeout)
416{ 416{
417 request(url, LLURLRequest::HTTP_POST, new FileInjector(filename), responder, timeout); 417 request(url, LLURLRequest::HTTP_POST, new FileInjector(filename), responder, timeout);
@@ -422,7 +422,28 @@ void LLHTTPClient::postFile(const std::string& url, const LLUUID& uuid,
422{ 422{
423 request(url, LLURLRequest::HTTP_POST, new VFileInjector(uuid, asset_type), responder, timeout); 423 request(url, LLURLRequest::HTTP_POST, new VFileInjector(uuid, asset_type), responder, timeout);
424} 424}
425#endif 425
426// static
427void LLHTTPClient::del(
428 const std::string& url,
429 ResponderPtr responder,
430 const F32 timeout)
431{
432 request(url, LLURLRequest::HTTP_DELETE, NULL, responder, timeout);
433}
434
435// static
436void LLHTTPClient::move(
437 const std::string& url,
438 const std::string& destination,
439 ResponderPtr responder,
440 const F32 timeout)
441{
442 LLSD headers;
443 headers["Destination"] = destination;
444 request(url, LLURLRequest::HTTP_MOVE, NULL, responder, timeout, headers);
445}
446
426 447
427void LLHTTPClient::setPump(LLPumpIO& pump) 448void LLHTTPClient::setPump(LLPumpIO& pump)
428{ 449{