summaryrefslogtreecommitdiff
path: root/indra/llmessage
diff options
context:
space:
mode:
authorKelly Washington <kelly@lindenlab.com>2008-08-26 17:15:20 +0000
committerKelly Washington <kelly@lindenlab.com>2008-08-26 17:15:20 +0000
commit2336b76f0da1a745924d4b9f4a08ff75523e8b0d (patch)
tree94892e2a217b322c59eed05c7e5346b0ff475ad9 /indra/llmessage
parent0ae35124549a1fab117fa6631fc8adc54f0501b8 (diff)
merge -r94900 linden/branches/kelly/qar-825 to linden/release
QAR-825 DEV-18489 Event poll is brittle and doesn't parse status correctly
Diffstat (limited to 'indra/llmessage')
-rw-r--r--indra/llmessage/llhttpclient.cpp4
-rw-r--r--indra/llmessage/llurlrequest.cpp78
-rw-r--r--indra/llmessage/llurlrequest.h5
3 files changed, 57 insertions, 30 deletions
diff --git a/indra/llmessage/llhttpclient.cpp b/indra/llmessage/llhttpclient.cpp
index 7a6add6282..2f822aee87 100644
--- a/indra/llmessage/llhttpclient.cpp
+++ b/indra/llmessage/llhttpclient.cpp
@@ -56,7 +56,7 @@ namespace
{
public:
LLHTTPClientURLAdaptor(LLCurl::ResponderPtr responder)
- : mResponder(responder), mStatus(499),
+ : LLURLRequestComplete(), mResponder(responder), mStatus(499),
mReason("LLURLRequest complete w/no status")
{
}
@@ -67,6 +67,8 @@ namespace
virtual void httpStatus(U32 status, const std::string& reason)
{
+ LLURLRequestComplete::httpStatus(status,reason);
+
mStatus = status;
mReason = reason;
}
diff --git a/indra/llmessage/llurlrequest.cpp b/indra/llmessage/llurlrequest.cpp
index 5ac55bc83d..6e5fa6def8 100644
--- a/indra/llmessage/llurlrequest.cpp
+++ b/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
diff --git a/indra/llmessage/llurlrequest.h b/indra/llmessage/llurlrequest.h
index 579706f83b..c0af746116 100644
--- a/indra/llmessage/llurlrequest.h
+++ b/indra/llmessage/llurlrequest.h
@@ -327,6 +327,9 @@ public:
LLURLRequestComplete();
virtual ~LLURLRequestComplete();
+ // The first line of an http response must be the status line
+ // true if we have already parsed this line.
+ bool haveHTTPStatus() const { return mHaveHTTPStatus; }
protected:
/* @name LLIOPipe virtual implementations
*/
@@ -345,6 +348,8 @@ protected:
// value to note if we actually got the response. This value
// depends on correct useage from the LLURLRequest instance.
EStatus mRequestStatus;
+
+ bool mHaveHTTPStatus;
};