summaryrefslogtreecommitdiff
path: root/indra/llmessage/lliohttpserver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llmessage/lliohttpserver.cpp')
-rwxr-xr-xindra/llmessage/lliohttpserver.cpp165
1 files changed, 93 insertions, 72 deletions
diff --git a/indra/llmessage/lliohttpserver.cpp b/indra/llmessage/lliohttpserver.cpp
index 1236fc8b71..d9042fa8b0 100755
--- a/indra/llmessage/lliohttpserver.cpp
+++ b/indra/llmessage/lliohttpserver.cpp
@@ -33,6 +33,8 @@
#include "llapr.h"
#include "llbuffer.h"
#include "llbufferstream.h"
+#include "llhttpconstants.h"
+#include "llfasttimer.h"
#include "llhttpnode.h"
#include "lliopipe.h"
#include "lliosocket.h"
@@ -49,15 +51,6 @@
#include <boost/tokenizer.hpp>
static const char HTTP_VERSION_STR[] = "HTTP/1.0";
-const std::string CONTEXT_REQUEST("request");
-const std::string CONTEXT_RESPONSE("response");
-const std::string CONTEXT_VERB("verb");
-const std::string CONTEXT_HEADERS("headers");
-const std::string HTTP_VERB_GET("GET");
-const std::string HTTP_VERB_PUT("PUT");
-const std::string HTTP_VERB_POST("POST");
-const std::string HTTP_VERB_DELETE("DELETE");
-const std::string HTTP_VERB_OPTIONS("OPTIONS");
static LLIOHTTPServer::timing_callback_t sTimingCallback = NULL;
static void* sTimingCallbackData = NULL;
@@ -102,7 +95,7 @@ private:
// from LLHTTPNode::Response
virtual void result(const LLSD&);
virtual void extendedResult(S32 code, const std::string& body, const LLSD& headers);
-
+ virtual void extendedResult(S32 code, const LLSD& body, const LLSD& headers);
virtual void status(S32 code, const std::string& message);
void nullPipe();
@@ -122,7 +115,8 @@ private:
STATE_LOCKED,
STATE_GOOD_RESULT,
STATE_STATUS_RESULT,
- STATE_EXTENDED_RESULT
+ STATE_EXTENDED_RESULT,
+ STATE_EXTENDED_LLSD_RESULT
};
State mState;
@@ -132,17 +126,17 @@ private:
void lockChain(LLPumpIO*);
void unlockChain();
- LLSD mGoodResult;
+ LLSD mResult;
S32 mStatusCode;
std::string mStatusMessage;
LLSD mHeaders;
};
-static LLFastTimer::DeclareTimer FTM_PROCESS_HTTP_PIPE("HTTP Pipe");
-static LLFastTimer::DeclareTimer FTM_PROCESS_HTTP_GET("HTTP Get");
-static LLFastTimer::DeclareTimer FTM_PROCESS_HTTP_PUT("HTTP Put");
-static LLFastTimer::DeclareTimer FTM_PROCESS_HTTP_POST("HTTP Post");
-static LLFastTimer::DeclareTimer FTM_PROCESS_HTTP_DELETE("HTTP Delete");
+static LLTrace::BlockTimerStatHandle FTM_PROCESS_HTTP_PIPE("HTTP Pipe");
+static LLTrace::BlockTimerStatHandle FTM_PROCESS_HTTP_GET("HTTP Get");
+static LLTrace::BlockTimerStatHandle FTM_PROCESS_HTTP_PUT("HTTP Put");
+static LLTrace::BlockTimerStatHandle FTM_PROCESS_HTTP_POST("HTTP Post");
+static LLTrace::BlockTimerStatHandle FTM_PROCESS_HTTP_DELETE("HTTP Delete");
LLIOPipe::EStatus LLHTTPPipe::process_impl(
const LLChannelDescriptors& channels,
@@ -151,9 +145,9 @@ LLIOPipe::EStatus LLHTTPPipe::process_impl(
LLSD& context,
LLPumpIO* pump)
{
- LLFastTimer t(FTM_PROCESS_HTTP_PIPE);
+ LL_RECORD_BLOCK_TIME(FTM_PROCESS_HTTP_PIPE);
PUMP_DEBUG;
- lldebugs << "LLSDHTTPServer::process_impl" << llendl;
+ LL_DEBUGS() << "LLSDHTTPServer::process_impl" << LL_ENDL;
// Once we have all the data, We need to read the sd on
// the the in channel, and respond on the out channel
@@ -180,12 +174,12 @@ LLIOPipe::EStatus LLHTTPPipe::process_impl(
std::string verb = context[CONTEXT_REQUEST][CONTEXT_VERB];
if(verb == HTTP_VERB_GET)
{
- LLFastTimer _(FTM_PROCESS_HTTP_GET);
+ LL_RECORD_BLOCK_TIME(FTM_PROCESS_HTTP_GET);
mNode.get(LLHTTPNode::ResponsePtr(mResponse), context);
}
else if(verb == HTTP_VERB_PUT)
{
- LLFastTimer _(FTM_PROCESS_HTTP_PUT);
+ LL_RECORD_BLOCK_TIME(FTM_PROCESS_HTTP_PUT);
LLSD input;
if (mNode.getContentType() == LLHTTPNode::CONTENT_TYPE_LLSD)
{
@@ -193,7 +187,7 @@ LLIOPipe::EStatus LLHTTPPipe::process_impl(
}
else if (mNode.getContentType() == LLHTTPNode::CONTENT_TYPE_TEXT)
{
- std::stringstream strstrm;
+ std::ostringstream strstrm;
strstrm << istr.rdbuf();
input = strstrm.str();
}
@@ -201,7 +195,7 @@ LLIOPipe::EStatus LLHTTPPipe::process_impl(
}
else if(verb == HTTP_VERB_POST)
{
- LLFastTimer _(FTM_PROCESS_HTTP_POST);
+ LL_RECORD_BLOCK_TIME(FTM_PROCESS_HTTP_POST);
LLSD input;
if (mNode.getContentType() == LLHTTPNode::CONTENT_TYPE_LLSD)
{
@@ -209,7 +203,7 @@ LLIOPipe::EStatus LLHTTPPipe::process_impl(
}
else if (mNode.getContentType() == LLHTTPNode::CONTENT_TYPE_TEXT)
{
- std::stringstream strstrm;
+ std::ostringstream strstrm;
strstrm << istr.rdbuf();
input = strstrm.str();
}
@@ -217,7 +211,7 @@ LLIOPipe::EStatus LLHTTPPipe::process_impl(
}
else if(verb == HTTP_VERB_DELETE)
{
- LLFastTimer _(FTM_PROCESS_HTTP_DELETE);
+ LL_RECORD_BLOCK_TIME(FTM_PROCESS_HTTP_DELETE);
mNode.del(LLHTTPNode::ResponsePtr(mResponse), context);
}
else if(verb == HTTP_VERB_OPTIONS)
@@ -244,15 +238,15 @@ LLIOPipe::EStatus LLHTTPPipe::process_impl(
// Log all HTTP transactions.
// TODO: Add a way to log these to their own file instead of indra.log
// It is just too spammy to be in indra.log.
- lldebugs << verb << " " << context[CONTEXT_REQUEST]["path"].asString()
+ LL_DEBUGS() << verb << " " << context[CONTEXT_REQUEST][CONTEXT_PATH].asString()
<< " " << mStatusCode << " " << mStatusMessage << " " << delta
- << "s" << llendl;
+ << "s" << LL_ENDL;
// Log Internal Server Errors
- //if(mStatusCode == 500)
+ //if(mStatusCode == HTTP_INTERNAL_SERVER_ERROR)
//{
- // llwarns << "LLHTTPPipe::process_impl:500:Internal Server Error"
- // << llendl;
+ // LL_WARNS() << "LLHTTPPipe::process_impl:500:Internal Server Error"
+ // << LL_ENDL;
//}
}
@@ -271,10 +265,10 @@ LLIOPipe::EStatus LLHTTPPipe::process_impl(
case STATE_GOOD_RESULT:
{
LLSD headers = mHeaders;
- headers["Content-Type"] = "application/llsd+xml";
+ headers[HTTP_OUT_HEADER_CONTENT_TYPE] = HTTP_CONTENT_LLSD_XML;
context[CONTEXT_RESPONSE][CONTEXT_HEADERS] = headers;
LLBufferStream ostr(channels, buffer.get());
- LLSDSerialize::toXML(mGoodResult, ostr);
+ LLSDSerialize::toXML(mResult, ostr);
return STATUS_DONE;
}
@@ -282,7 +276,7 @@ LLIOPipe::EStatus LLHTTPPipe::process_impl(
case STATE_STATUS_RESULT:
{
LLSD headers = mHeaders;
- headers["Content-Type"] = "text/plain";
+ headers[HTTP_OUT_HEADER_CONTENT_TYPE] = HTTP_CONTENT_TEXT_PLAIN;
context[CONTEXT_RESPONSE][CONTEXT_HEADERS] = headers;
context[CONTEXT_RESPONSE]["statusCode"] = mStatusCode;
context[CONTEXT_RESPONSE]["statusMessage"] = mStatusMessage;
@@ -300,9 +294,20 @@ LLIOPipe::EStatus LLHTTPPipe::process_impl(
return STATUS_DONE;
}
+ case STATE_EXTENDED_LLSD_RESULT:
+ {
+ LLSD headers = mHeaders;
+ headers[HTTP_OUT_HEADER_CONTENT_TYPE] = HTTP_CONTENT_LLSD_XML;
+ context[CONTEXT_RESPONSE][CONTEXT_HEADERS] = headers;
+ context[CONTEXT_RESPONSE]["statusCode"] = mStatusCode;
+ LLBufferStream ostr(channels, buffer.get());
+ LLSDSerialize::toXML(mResult, ostr);
+
+ return STATUS_DONE;
+ }
default:
- llwarns << "LLHTTPPipe::process_impl: unexpected state "
- << mState << llendl;
+ LL_WARNS() << "LLHTTPPipe::process_impl: unexpected state "
+ << mState << LL_ENDL;
return STATUS_BREAK;
}
@@ -331,23 +336,39 @@ void LLHTTPPipe::Response::result(const LLSD& r)
{
if(! mPipe)
{
- llwarns << "LLHTTPPipe::Response::result: NULL pipe" << llendl;
+ LL_WARNS() << "LLHTTPPipe::Response::result: NULL pipe" << LL_ENDL;
return;
}
- mPipe->mStatusCode = 200;
+ mPipe->mStatusCode = HTTP_OK;
mPipe->mStatusMessage = "OK";
- mPipe->mGoodResult = r;
+ mPipe->mResult = r;
mPipe->mState = STATE_GOOD_RESULT;
mPipe->mHeaders = mHeaders;
- mPipe->unlockChain();
+ mPipe->unlockChain();
+}
+
+void LLHTTPPipe::Response::extendedResult(S32 code, const LLSD& r, const LLSD& headers)
+{
+ if(! mPipe)
+ {
+ LL_WARNS() << "LLHTTPPipe::Response::extendedResult: NULL pipe" << LL_ENDL;
+ return;
+ }
+
+ mPipe->mStatusCode = code;
+ mPipe->mStatusMessage = "(LLSD)";
+ mPipe->mResult = r;
+ mPipe->mHeaders = headers;
+ mPipe->mState = STATE_EXTENDED_LLSD_RESULT;
+ mPipe->unlockChain();
}
void LLHTTPPipe::Response::extendedResult(S32 code, const std::string& body, const LLSD& headers)
{
if(! mPipe)
{
- llwarns << "LLHTTPPipe::Response::status: NULL pipe" << llendl;
+ LL_WARNS() << "LLHTTPPipe::Response::status: NULL pipe" << LL_ENDL;
return;
}
@@ -363,7 +384,7 @@ void LLHTTPPipe::Response::status(S32 code, const std::string& message)
{
if(! mPipe)
{
- llwarns << "LLHTTPPipe::Response::status: NULL pipe" << llendl;
+ LL_WARNS() << "LLHTTPPipe::Response::status: NULL pipe" << LL_ENDL;
return;
}
@@ -434,7 +455,7 @@ protected:
* LLHTTPResponseHeader
*/
-static LLFastTimer::DeclareTimer FTM_PROCESS_HTTP_HEADER("HTTP Header");
+static LLTrace::BlockTimerStatHandle FTM_PROCESS_HTTP_HEADER("HTTP Header");
// virtual
LLIOPipe::EStatus LLHTTPResponseHeader::process_impl(
@@ -444,7 +465,7 @@ LLIOPipe::EStatus LLHTTPResponseHeader::process_impl(
LLSD& context,
LLPumpIO* pump)
{
- LLFastTimer t(FTM_PROCESS_HTTP_HEADER);
+ LL_RECORD_BLOCK_TIME(FTM_PROCESS_HTTP_HEADER);
PUMP_DEBUG;
if(eos)
{
@@ -454,9 +475,9 @@ LLIOPipe::EStatus LLHTTPResponseHeader::process_impl(
std::string message = context[CONTEXT_RESPONSE]["statusMessage"];
int code = context[CONTEXT_RESPONSE]["statusCode"];
- if (code < 200)
+ if (code < HTTP_OK)
{
- code = 200;
+ code = HTTP_OK;
message = "OK";
}
@@ -465,7 +486,7 @@ LLIOPipe::EStatus LLHTTPResponseHeader::process_impl(
S32 content_length = buffer->countAfter(channels.in(), NULL);
if(0 < content_length)
{
- ostr << "Content-Length: " << content_length << "\r\n";
+ ostr << HTTP_OUT_HEADER_CONTENT_LENGTH << ": " << content_length << "\r\n";
}
// *NOTE: This guard can go away once the LLSD static map
// iterator is available. Phoenix. 2008-05-09
@@ -594,7 +615,7 @@ LLHTTPResponder::LLHTTPResponder(const LLHTTPNode& tree, const LLSD& ctx) :
// virtual
LLHTTPResponder::~LLHTTPResponder()
{
- //lldebugs << "destroying LLHTTPResponder" << llendl;
+ //LL_DEBUGS() << "destroying LLHTTPResponder" << LL_ENDL;
}
bool LLHTTPResponder::readHeaderLine(
@@ -611,7 +632,7 @@ bool LLHTTPResponder::readHeaderLine(
{
if(len)
{
- lldebugs << "readLine failed - too long maybe?" << llendl;
+ LL_DEBUGS() << "readLine failed - too long maybe?" << LL_ENDL;
markBad(channels, buffer);
}
return false;
@@ -634,7 +655,7 @@ void LLHTTPResponder::markBad(
<< "</body>\n</html>\n";
}
-static LLFastTimer::DeclareTimer FTM_PROCESS_HTTP_RESPONDER("HTTP Responder");
+static LLTrace::BlockTimerStatHandle FTM_PROCESS_HTTP_RESPONDER("HTTP Responder");
// virtual
LLIOPipe::EStatus LLHTTPResponder::process_impl(
@@ -644,7 +665,7 @@ LLIOPipe::EStatus LLHTTPResponder::process_impl(
LLSD& context,
LLPumpIO* pump)
{
- LLFastTimer t(FTM_PROCESS_HTTP_RESPONDER);
+ LL_RECORD_BLOCK_TIME(FTM_PROCESS_HTTP_RESPONDER);
PUMP_DEBUG;
LLIOPipe::EStatus status = STATUS_OK;
@@ -667,8 +688,8 @@ LLIOPipe::EStatus LLHTTPResponder::process_impl(
{
memcpy(buf, (*seg_iter).data(), (*seg_iter).size()); /*Flawfinder: ignore*/
buf[(*seg_iter).size()] = '\0';
- llinfos << (*seg_iter).getChannel() << ": " << buf
- << llendl;
+ LL_INFOS() << (*seg_iter).getChannel() << ": " << buf
+ << LL_ENDL;
++seg_iter;
}
}
@@ -694,10 +715,10 @@ LLIOPipe::EStatus LLHTTPResponder::process_impl(
header >> mAbsPathAndQuery;
header >> mVersion;
- lldebugs << "http request: "
+ LL_DEBUGS() << "http request: "
<< mVerb
<< " " << mAbsPathAndQuery
- << " " << mVersion << llendl;
+ << " " << mVersion << LL_ENDL;
std::string::size_type delimiter
= mAbsPathAndQuery.find('?');
@@ -727,7 +748,7 @@ LLIOPipe::EStatus LLHTTPResponder::process_impl(
{
read_next_line = false;
parse_all = false;
- lldebugs << "unknown http verb: " << mVerb << llendl;
+ LL_DEBUGS() << "unknown http verb: " << mVerb << LL_ENDL;
markBad(channels, buffer);
}
}
@@ -762,7 +783,7 @@ LLIOPipe::EStatus LLHTTPResponder::process_impl(
if(NULL == pos_colon)
{
keep_parsing = false;
- lldebugs << "bad header: " << buf << llendl;
+ LL_DEBUGS() << "bad header: " << buf << LL_ENDL;
markBad(channels, buffer);
break;
}
@@ -771,9 +792,9 @@ LLIOPipe::EStatus LLHTTPResponder::process_impl(
std::string name(buf, pos_colon - buf);
std::string value(pos_colon + 2);
LLStringUtil::toLower(name);
- if("content-length" == name)
+ if(HTTP_IN_HEADER_CONTENT_LENGTH == name)
{
- lldebugs << "Content-Length: " << value << llendl;
+ LL_DEBUGS() << "Content-Length: " << value << LL_ENDL;
mContentLength = atoi(value.c_str());
}
else
@@ -810,8 +831,8 @@ LLIOPipe::EStatus LLHTTPResponder::process_impl(
const LLHTTPNode* node = mRootNode.traverse(mPath, context);
if(node)
{
- //llinfos << "LLHTTPResponder::process_impl found node for "
- // << mAbsPathAndQuery << llendl;
+ //LL_INFOS() << "LLHTTPResponder::process_impl found node for "
+ // << mAbsPathAndQuery << LL_ENDL;
// Copy everything after mLast read to the out.
LLBufferArray::segment_iterator_t seg_iter;
@@ -831,8 +852,8 @@ LLIOPipe::EStatus LLHTTPResponder::process_impl(
{
memcpy(buf, (*seg_iter).data(), (*seg_iter).size()); /*Flawfinder: ignore*/
buf[(*seg_iter).size()] = '\0';
- llinfos << (*seg_iter).getChannel() << ": " << buf
- << llendl;
+ LL_INFOS() << (*seg_iter).getChannel() << ": " << buf
+ << LL_ENDL;
++seg_iter;
}
#endif
@@ -846,19 +867,19 @@ LLIOPipe::EStatus LLHTTPResponder::process_impl(
// HTTP headers.
LLPumpIO::chain_t chain;
chain.push_back(LLIOPipe::ptr_t(new LLIOFlush));
- context[CONTEXT_REQUEST]["path"] = mPath;
- context[CONTEXT_REQUEST]["query-string"] = mQuery;
- context[CONTEXT_REQUEST]["remote-host"]
- = mBuildContext["remote-host"];
- context[CONTEXT_REQUEST]["remote-port"]
- = mBuildContext["remote-port"];
+ context[CONTEXT_REQUEST][CONTEXT_PATH] = mPath;
+ context[CONTEXT_REQUEST][CONTEXT_QUERY_STRING] = mQuery;
+ context[CONTEXT_REQUEST][CONTEXT_REMOTE_HOST]
+ = mBuildContext[CONTEXT_REMOTE_HOST];
+ context[CONTEXT_REQUEST][CONTEXT_REMOTE_PORT]
+ = mBuildContext[CONTEXT_REMOTE_PORT];
context[CONTEXT_REQUEST][CONTEXT_HEADERS] = mHeaders;
const LLChainIOFactory* protocolHandler
= node->getProtocolHandler();
if (protocolHandler)
{
- lldebugs << "HTTP context: " << context << llendl;
+ LL_DEBUGS() << "HTTP context: " << context << LL_ENDL;
protocolHandler->build(chain, context);
}
else
@@ -917,8 +938,8 @@ LLIOPipe::EStatus LLHTTPResponder::process_impl(
}
else
{
- llwarns << "LLHTTPResponder::process_impl didn't find a node for "
- << mAbsPathAndQuery << llendl;
+ LL_WARNS() << "LLHTTPResponder::process_impl didn't find a node for "
+ << mAbsPathAndQuery << LL_ENDL;
LLBufferStream str(channels, buffer.get());
mState = STATE_SHORT_CIRCUIT;
str << HTTP_VERSION_STR << " 404 Not Found\r\n\r\n<html>\n"
@@ -971,7 +992,7 @@ LLHTTPNode& LLIOHTTPServer::create(
port);
if(!socket)
{
- llerrs << "Unable to initialize socket" << llendl;
+ LL_ERRS() << "Unable to initialize socket" << LL_ENDL;
}
LLHTTPResponseFactory* factory = new LLHTTPResponseFactory;