aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmessage/llurlrequest.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-09-28 17:21:23 -0500
committerJacek Antonelli2008-09-28 17:21:46 -0500
commit31e7c77a411d94bc87f0232588b339149bb29a49 (patch)
tree49e487700e91713e620e4d33f20b7f7afb5a2fa9 /linden/indra/llmessage/llurlrequest.cpp
parentSecond Life viewer sources 1.21.2-RC (diff)
downloadmeta-impy-31e7c77a411d94bc87f0232588b339149bb29a49.zip
meta-impy-31e7c77a411d94bc87f0232588b339149bb29a49.tar.gz
meta-impy-31e7c77a411d94bc87f0232588b339149bb29a49.tar.bz2
meta-impy-31e7c77a411d94bc87f0232588b339149bb29a49.tar.xz
Second Life viewer sources 1.21.3-RC
Diffstat (limited to 'linden/indra/llmessage/llurlrequest.cpp')
-rw-r--r--linden/indra/llmessage/llurlrequest.cpp78
1 files changed, 49 insertions, 29 deletions
diff --git a/linden/indra/llmessage/llurlrequest.cpp b/linden/indra/llmessage/llurlrequest.cpp
index 42f3f04..fbd002b 100644
--- a/linden/indra/llmessage/llurlrequest.cpp
+++ b/linden/indra/llmessage/llurlrequest.cpp
@@ -461,58 +461,76 @@ size_t LLURLRequest::upCallback(
461 461
462static size_t headerCallback(void* data, size_t size, size_t nmemb, void* user) 462static size_t headerCallback(void* data, size_t size, size_t nmemb, void* user)
463{ 463{
464 const char* headerLine = (const char*)data; 464 const char* header_line = (const char*)data;
465 size_t headerLen = size * nmemb; 465 size_t header_len = size * nmemb;
466 LLURLRequestComplete* complete = (LLURLRequestComplete*)user; 466 LLURLRequestComplete* complete = (LLURLRequestComplete*)user;
467 467
468 if (!complete || !header_line)
469 {
470 return header_len;
471 }
472
468 // *TODO: This should be a utility in llstring.h: isascii() 473 // *TODO: This should be a utility in llstring.h: isascii()
469 for (size_t i = 0; i < headerLen; ++i) 474 for (size_t i = 0; i < header_len; ++i)
470 { 475 {
471 if (headerLine[i] < 0) 476 if (header_line[i] < 0)
472 { 477 {
473 return headerLen; 478 return header_len;
474 } 479 }
475 } 480 }
476 481
477 size_t sep; 482 std::string header(header_line, header_len);
478 for (sep = 0; sep < headerLen && headerLine[sep] != ':'; ++sep) { }
479
480 if (sep < headerLen && complete)
481 {
482 std::string key(headerLine, sep);
483 std::string value(headerLine + sep + 1, headerLen - sep - 1);
484
485 key = utf8str_tolower(utf8str_trim(key));
486 value = utf8str_trim(value);
487 483
488 complete->header(key, value); 484 // Per HTTP spec the first header line must be the status line.
489 } 485 if (!complete->haveHTTPStatus())
490 else
491 { 486 {
492 std::string s(headerLine, headerLen); 487 std::string::iterator end = header.end();
493 488 std::string::iterator pos1 = std::find(header.begin(), end, ' ');
494 std::string::iterator end = s.end();
495 std::string::iterator pos1 = std::find(s.begin(), end, ' ');
496 if (pos1 != end) ++pos1; 489 if (pos1 != end) ++pos1;
497 std::string::iterator pos2 = std::find(pos1, end, ' '); 490 std::string::iterator pos2 = std::find(pos1, end, ' ');
498 if (pos2 != end) ++pos2; 491 if (pos2 != end) ++pos2;
499 std::string::iterator pos3 = std::find(pos2, end, '\r'); 492 std::string::iterator pos3 = std::find(pos2, end, '\r');
500 493
501 std::string version(s.begin(), pos1); 494 std::string version(header.begin(), pos1);
502 std::string status(pos1, pos2); 495 std::string status(pos1, pos2);
503 std::string reason(pos2, pos3); 496 std::string reason(pos2, pos3);
504 497
505 int statusCode = atoi(status.c_str()); 498 int statusCode = atoi(status.c_str());
506 if (statusCode > 0) 499 if (statusCode > 0)
507 { 500 {
508 if (complete) 501 complete->httpStatus((U32)statusCode, reason);
509 { 502 }
510 complete->httpStatus((U32)statusCode, reason); 503 else
511 } 504 {
505 llwarns << "Unable to parse http response status line: "
506 << header << llendl;
507 complete->httpStatus(499,"Unable to parse status line.");
508 }
509 return header_len;
510 }
511
512 std::string::iterator sep = std::find(header.begin(),header.end(),':');
513
514 if (sep != header.end())
515 {
516 std::string key(header.begin(), sep);
517 std::string value(sep + 1, header.end());
518
519 key = utf8str_tolower(utf8str_trim(key));
520 value = utf8str_trim(value);
521
522 complete->header(key, value);
523 }
524 else
525 {
526 LLStringUtil::trim(header);
527 if (!header.empty())
528 {
529 llwarns << "Unable to parse header: " << header << llendl;
512 } 530 }
513 } 531 }
514 532
515 return headerLen; 533 return header_len;
516} 534}
517 535
518/** 536/**
@@ -553,7 +571,8 @@ LLIOPipe::EStatus LLContextURLExtractor::process_impl(
553 * LLURLRequestComplete 571 * LLURLRequestComplete
554 */ 572 */
555LLURLRequestComplete::LLURLRequestComplete() : 573LLURLRequestComplete::LLURLRequestComplete() :
556 mRequestStatus(LLIOPipe::STATUS_ERROR) 574 mRequestStatus(LLIOPipe::STATUS_ERROR),
575 mHaveHTTPStatus(false)
557{ 576{
558 LLMemType m1(LLMemType::MTYPE_IO_URL_REQUEST); 577 LLMemType m1(LLMemType::MTYPE_IO_URL_REQUEST);
559} 578}
@@ -572,6 +591,7 @@ void LLURLRequestComplete::header(const std::string& header, const std::string&
572//virtual 591//virtual
573void LLURLRequestComplete::httpStatus(U32 status, const std::string& reason) 592void LLURLRequestComplete::httpStatus(U32 status, const std::string& reason)
574{ 593{
594 mHaveHTTPStatus = true;
575} 595}
576 596
577//virtual 597//virtual