summaryrefslogtreecommitdiff
path: root/indra/llmessage
diff options
context:
space:
mode:
Diffstat (limited to 'indra/llmessage')
-rw-r--r--indra/llmessage/llareslistener.cpp39
-rw-r--r--indra/llmessage/llsdmessage.cpp7
-rw-r--r--indra/llmessage/llsdmessage.h3
-rw-r--r--indra/llmessage/tests/llareslistener_test.cpp12
4 files changed, 37 insertions, 24 deletions
diff --git a/indra/llmessage/llareslistener.cpp b/indra/llmessage/llareslistener.cpp
index 8e1176cdd9..4bf375069d 100644
--- a/indra/llmessage/llareslistener.cpp
+++ b/indra/llmessage/llareslistener.cpp
@@ -24,6 +24,7 @@
#include "llares.h"
#include "llerror.h"
#include "llevents.h"
+#include "llsdutil.h"
LLAresListener::LLAresListener(const std::string& pumpname, LLAres* llares):
mAres(llares),
@@ -31,6 +32,8 @@ LLAresListener::LLAresListener(const std::string& pumpname, LLAres* llares):
obtain(pumpname).
listen("LLAresListener", boost::bind(&LLAresListener::process, this, _1)))
{
+ // Insert an entry into our mDispatch map for every method we want to be
+ // able to invoke via this event API.
mDispatch["rewriteURI"] = boost::bind(&LLAresListener::rewriteURI, this, _1);
}
@@ -60,9 +63,13 @@ bool LLAresListener::process(const LLSD& command)
class UriRewriteResponder: public LLAres::UriRewriteResponder
{
public:
- /// Specify the event pump name on which to send the reply
- UriRewriteResponder(const std::string& pumpname):
- mPumpName(pumpname)
+ /**
+ * Specify the request, containing the event pump name on which to send
+ * the reply.
+ */
+ UriRewriteResponder(const LLSD& request):
+ mReqID(request),
+ mPumpName(request["reply"])
{}
/// Called by base class with results. This is called in both the
@@ -76,33 +83,27 @@ public:
{
result.append(*ui);
}
+ // This call knows enough to avoid trying to insert a map key into an
+ // LLSD array. It's there so that if, for any reason, we ever decide
+ // to change the response from array to map, it will Just Start Working.
+ mReqID.stamp(result);
LLEventPumps::instance().obtain(mPumpName).post(result);
}
private:
+ LLReqID mReqID;
const std::string mPumpName;
};
void LLAresListener::rewriteURI(const LLSD& data)
{
- const std::string uri(data["uri"]);
- const std::string reply(data["reply"]);
+ static LLSD required(LLSD().insert("uri", LLSD()).insert("reply", LLSD()));
// Validate that the request is well-formed
- if (uri.empty() || reply.empty())
+ std::string mismatch(llsd_matches(required, data));
+ if (! mismatch.empty())
{
- LL_ERRS("LLAresListener") << "rewriteURI request missing";
- std::string separator;
- if (uri.empty())
- {
- LL_CONT << " 'uri'";
- separator = " and";
- }
- if (reply.empty())
- {
- LL_CONT << separator << " 'reply'";
- }
- LL_CONT << LL_ENDL;
+ LL_ERRS("LLAresListener") << "bad rewriteURI request: " << mismatch << LL_ENDL;
}
// Looks as though we have what we need; issue the request
- mAres->rewriteURI(uri, new UriRewriteResponder(reply));
+ mAres->rewriteURI(data["uri"], new UriRewriteResponder(data));
}
diff --git a/indra/llmessage/llsdmessage.cpp b/indra/llmessage/llsdmessage.cpp
index f663268466..ad6b8284aa 100644
--- a/indra/llmessage/llsdmessage.cpp
+++ b/indra/llmessage/llsdmessage.cpp
@@ -68,6 +68,7 @@ bool LLSDMessage::httpListener(const LLSD& request)
}
LLHTTPClient::post(url, payload,
new LLSDMessage::EventResponder(LLEventPumps::instance(),
+ request,
url, "POST", reply, error),
LLSD(), // headers
timeout);
@@ -81,7 +82,9 @@ void LLSDMessage::EventResponder::result(const LLSD& data)
// to the pump whose name is "".
if (! mReplyPump.empty())
{
- mPumps.obtain(mReplyPump).post(data);
+ LLSD response(data);
+ mReqID.stamp(response);
+ mPumps.obtain(mReplyPump).post(response);
}
else // default success handling
{
@@ -98,7 +101,7 @@ void LLSDMessage::EventResponder::error(U32 status, const std::string& reason, c
// explicit pump name.
if (! mErrorPump.empty())
{
- LLSD info;
+ LLSD info(mReqID.makeResponse());
info["target"] = mTarget;
info["message"] = mMessage;
info["status"] = LLSD::Integer(status);
diff --git a/indra/llmessage/llsdmessage.h b/indra/llmessage/llsdmessage.h
index 8ae9451243..672da6d3a6 100644
--- a/indra/llmessage/llsdmessage.h
+++ b/indra/llmessage/llsdmessage.h
@@ -121,9 +121,11 @@ private:
* (e.g. "POST") as @a message.
*/
EventResponder(LLEventPumps& pumps,
+ const LLSD& request,
const std::string& target, const std::string& message,
const std::string& replyPump, const std::string& errorPump):
mPumps(pumps),
+ mReqID(request),
mTarget(target),
mMessage(message),
mReplyPump(replyPump),
@@ -135,6 +137,7 @@ private:
private:
LLEventPumps& mPumps;
+ LLReqID mReqID;
const std::string mTarget, mMessage, mReplyPump, mErrorPump;
};
diff --git a/indra/llmessage/tests/llareslistener_test.cpp b/indra/llmessage/tests/llareslistener_test.cpp
index b8306d0fd9..215a3806f8 100644
--- a/indra/llmessage/tests/llareslistener_test.cpp
+++ b/indra/llmessage/tests/llareslistener_test.cpp
@@ -149,7 +149,9 @@ namespace tut
{
threw = e.what();
}
- ensure_contains("LLAresListener bad op", threw, "missing 'uri' and 'reply'");
+ ensure_contains("LLAresListener bad req", threw, "missing");
+ ensure_contains("LLAresListener bad req", threw, "reply");
+ ensure_contains("LLAresListener bad req", threw, "uri");
}
template<> template<>
@@ -169,7 +171,9 @@ namespace tut
{
threw = e.what();
}
- ensure_contains("LLAresListener bad op", threw, "missing 'uri'");
+ ensure_contains("LLAresListener bad req", threw, "missing");
+ ensure_contains("LLAresListener bad req", threw, "uri");
+ ensure_does_not_contain("LLAresListener bad req", threw, "reply");
}
template<> template<>
@@ -189,6 +193,8 @@ namespace tut
{
threw = e.what();
}
- ensure_contains("LLAresListener bad op", threw, "missing 'reply'");
+ ensure_contains("LLAresListener bad req", threw, "missing");
+ ensure_contains("LLAresListener bad req", threw, "reply");
+ ensure_does_not_contain("LLAresListener bad req", threw, "uri");
}
}