From 31e7c77a411d94bc87f0232588b339149bb29a49 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Sun, 28 Sep 2008 17:21:23 -0500 Subject: Second Life viewer sources 1.21.3-RC --- linden/indra/llmessage/llurlrequest.cpp | 78 +++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 29 deletions(-) (limited to 'linden/indra/llmessage/llurlrequest.cpp') 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( static size_t headerCallback(void* data, size_t size, size_t nmemb, void* user) { - const char* headerLine = (const char*)data; - size_t headerLen = size * nmemb; + const char* header_line = (const char*)data; + size_t header_len = size * nmemb; LLURLRequestComplete* complete = (LLURLRequestComplete*)user; + if (!complete || !header_line) + { + return header_len; + } + // *TODO: This should be a utility in llstring.h: isascii() - for (size_t i = 0; i < headerLen; ++i) + for (size_t i = 0; i < header_len; ++i) { - if (headerLine[i] < 0) + if (header_line[i] < 0) { - return headerLen; + return header_len; } } - size_t sep; - for (sep = 0; sep < headerLen && headerLine[sep] != ':'; ++sep) { } - - if (sep < headerLen && complete) - { - std::string key(headerLine, sep); - std::string value(headerLine + sep + 1, headerLen - sep - 1); - - key = utf8str_tolower(utf8str_trim(key)); - value = utf8str_trim(value); + std::string header(header_line, header_len); - complete->header(key, value); - } - else + // Per HTTP spec the first header line must be the status line. + if (!complete->haveHTTPStatus()) { - std::string s(headerLine, headerLen); - - std::string::iterator end = s.end(); - std::string::iterator pos1 = std::find(s.begin(), end, ' '); + std::string::iterator end = header.end(); + std::string::iterator pos1 = std::find(header.begin(), end, ' '); if (pos1 != end) ++pos1; std::string::iterator pos2 = std::find(pos1, end, ' '); if (pos2 != end) ++pos2; std::string::iterator pos3 = std::find(pos2, end, '\r'); - std::string version(s.begin(), pos1); + std::string version(header.begin(), pos1); std::string status(pos1, pos2); std::string reason(pos2, pos3); int statusCode = atoi(status.c_str()); if (statusCode > 0) { - if (complete) - { - complete->httpStatus((U32)statusCode, reason); - } + complete->httpStatus((U32)statusCode, reason); + } + else + { + llwarns << "Unable to parse http response status line: " + << header << llendl; + complete->httpStatus(499,"Unable to parse status line."); + } + return header_len; + } + + std::string::iterator sep = std::find(header.begin(),header.end(),':'); + + if (sep != header.end()) + { + std::string key(header.begin(), sep); + std::string value(sep + 1, header.end()); + + key = utf8str_tolower(utf8str_trim(key)); + value = utf8str_trim(value); + + complete->header(key, value); + } + else + { + LLStringUtil::trim(header); + if (!header.empty()) + { + llwarns << "Unable to parse header: " << header << llendl; } } - return headerLen; + return header_len; } /** @@ -553,7 +571,8 @@ LLIOPipe::EStatus LLContextURLExtractor::process_impl( * LLURLRequestComplete */ LLURLRequestComplete::LLURLRequestComplete() : - mRequestStatus(LLIOPipe::STATUS_ERROR) + mRequestStatus(LLIOPipe::STATUS_ERROR), + mHaveHTTPStatus(false) { LLMemType m1(LLMemType::MTYPE_IO_URL_REQUEST); } @@ -572,6 +591,7 @@ void LLURLRequestComplete::header(const std::string& header, const std::string& //virtual void LLURLRequestComplete::httpStatus(U32 status, const std::string& reason) { + mHaveHTTPStatus = true; } //virtual -- cgit v1.1 From f6276d08ec2d6a7ce1ac568c77771162bd8cece5 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Wed, 8 Oct 2008 00:59:21 -0500 Subject: Second Life viewer sources 1.21.5-RC --- linden/indra/llmessage/llurlrequest.cpp | 42 +++++++++++++++++---------------- 1 file changed, 22 insertions(+), 20 deletions(-) (limited to 'linden/indra/llmessage/llurlrequest.cpp') diff --git a/linden/indra/llmessage/llurlrequest.cpp b/linden/indra/llmessage/llurlrequest.cpp index fbd002b..ee62798 100644 --- a/linden/indra/llmessage/llurlrequest.cpp +++ b/linden/indra/llmessage/llurlrequest.cpp @@ -484,27 +484,29 @@ static size_t headerCallback(void* data, size_t size, size_t nmemb, void* user) // Per HTTP spec the first header line must be the status line. if (!complete->haveHTTPStatus()) { - std::string::iterator end = header.end(); - std::string::iterator pos1 = std::find(header.begin(), end, ' '); - if (pos1 != end) ++pos1; - std::string::iterator pos2 = std::find(pos1, end, ' '); - if (pos2 != end) ++pos2; - std::string::iterator pos3 = std::find(pos2, end, '\r'); - - std::string version(header.begin(), pos1); - std::string status(pos1, pos2); - std::string reason(pos2, pos3); - - int statusCode = atoi(status.c_str()); - if (statusCode > 0) + if (header.substr(0,5) == "HTTP/") { - complete->httpStatus((U32)statusCode, reason); - } - else - { - llwarns << "Unable to parse http response status line: " - << header << llendl; - complete->httpStatus(499,"Unable to parse status line."); + std::string::iterator end = header.end(); + std::string::iterator pos1 = std::find(header.begin(), end, ' '); + if (pos1 != end) ++pos1; + std::string::iterator pos2 = std::find(pos1, end, ' '); + if (pos2 != end) ++pos2; + std::string::iterator pos3 = std::find(pos2, end, '\r'); + + std::string version(header.begin(), pos1); + std::string status(pos1, pos2); + std::string reason(pos2, pos3); + + int statusCode = atoi(status.c_str()); + if (statusCode >= 300 && statusCode < 400) + { + // This is a redirect, ignore it and all headers + // until we find a normal status code. + } + else if (statusCode > 0) + { + complete->httpStatus((U32)statusCode, reason); + } } return header_len; } -- cgit v1.1