summaryrefslogtreecommitdiff
path: root/indra/llmessage
diff options
context:
space:
mode:
authorRider Linden <rider@lindenlab.com>2015-09-10 16:48:01 -0700
committerRider Linden <rider@lindenlab.com>2015-09-10 16:48:01 -0700
commit6a204b1bddc711b768d598c6ac0a16413f48d3c3 (patch)
treefe4e526394ad1571ea18c9c4de1e0a709143d6d8 /indra/llmessage
parenta471ae72e4b48a12cfeeba544afde9d078428f0d (diff)
MAINT-5575: Finished converting experience cache to singleton
MAINT-4952: Coverted VMM to coroutines
Diffstat (limited to 'indra/llmessage')
-rw-r--r--indra/llmessage/llcorehttputil.cpp106
-rw-r--r--indra/llmessage/llcorehttputil.h69
2 files changed, 162 insertions, 13 deletions
diff --git a/indra/llmessage/llcorehttputil.cpp b/indra/llmessage/llcorehttputil.cpp
index d342888255..4c2e2c5ee7 100644
--- a/indra/llmessage/llcorehttputil.cpp
+++ b/indra/llmessage/llcorehttputil.cpp
@@ -35,7 +35,8 @@
#include "llsd.h"
#include "llsdjson.h"
#include "llsdserialize.h"
-#include "reader.h"
+#include "reader.h" // JSON
+#include "writer.h" // JSON
#include "llvfile.h"
#include "message.h" // for getting the port
@@ -570,7 +571,7 @@ LLSD HttpCoroutineAdapter::postAndYield(LLCore::HttpRequest::ptr_t request,
LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers)
{
LLEventStream replyPump(mAdapterName, true);
- HttpCoroHandler::ptr_t httpHandler = HttpCoroHandler::ptr_t(new HttpCoroLLSDHandler(replyPump));
+ HttpCoroHandler::ptr_t httpHandler(new HttpCoroLLSDHandler(replyPump));
return postAndYield_(request, url, body, options, headers, httpHandler);
}
@@ -607,7 +608,7 @@ LLSD HttpCoroutineAdapter::postAndYield(LLCore::HttpRequest::ptr_t request,
LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers)
{
LLEventStream replyPump(mAdapterName, true);
- HttpCoroHandler::ptr_t httpHandler = HttpCoroHandler::ptr_t(new HttpCoroLLSDHandler(replyPump));
+ HttpCoroHandler::ptr_t httpHandler(new HttpCoroLLSDHandler(replyPump));
return postAndYield_(request, url, rawbody, options, headers, httpHandler);
}
@@ -617,7 +618,7 @@ LLSD HttpCoroutineAdapter::postRawAndYield(LLCore::HttpRequest::ptr_t request,
LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers)
{
LLEventStream replyPump(mAdapterName, true);
- HttpCoroHandler::ptr_t httpHandler = HttpCoroHandler::ptr_t(new HttpCoroRawHandler(replyPump));
+ HttpCoroHandler::ptr_t httpHandler(new HttpCoroRawHandler(replyPump));
return postAndYield_(request, url, rawbody, options, headers, httpHandler);
}
@@ -676,6 +677,28 @@ LLSD HttpCoroutineAdapter::postFileAndYield(LLCore::HttpRequest::ptr_t request,
return postAndYield(request, url, fileData, options, headers);
}
+LLSD HttpCoroutineAdapter::postJsonAndYield(LLCore::HttpRequest::ptr_t request,
+ const std::string & url, const LLSD & body,
+ LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers)
+{
+ LLEventStream replyPump(mAdapterName, true);
+ HttpCoroHandler::ptr_t httpHandler(new HttpCoroJSONHandler(replyPump));
+
+ LLCore::BufferArray::ptr_t rawbody(new LLCore::BufferArray);
+
+ {
+ LLCore::BufferArrayStream outs(rawbody.get());
+ Json::Value root = LlsdToJson(body);
+ Json::FastWriter writer;
+
+ LL_WARNS("Http::post") << "JSON Generates: \"" << writer.write(root) << "\"" << LL_ENDL;
+
+ outs << writer.write(root);
+ }
+
+ return postAndYield_(request, url, rawbody, options, headers, httpHandler);
+}
+
LLSD HttpCoroutineAdapter::postAndYield_(LLCore::HttpRequest::ptr_t &request,
const std::string & url, LLCore::BufferArray::ptr_t &rawbody,
@@ -708,11 +731,32 @@ LLSD HttpCoroutineAdapter::putAndYield(LLCore::HttpRequest::ptr_t request,
LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers)
{
LLEventStream replyPump(mAdapterName + "Reply", true);
- HttpCoroHandler::ptr_t httpHandler = HttpCoroHandler::ptr_t(new HttpCoroLLSDHandler(replyPump));
+ HttpCoroHandler::ptr_t httpHandler(new HttpCoroLLSDHandler(replyPump));
return putAndYield_(request, url, body, options, headers, httpHandler);
}
+LLSD HttpCoroutineAdapter::putJsonAndYield(LLCore::HttpRequest::ptr_t request,
+ const std::string & url, const LLSD & body,
+ LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers)
+{
+ LLEventStream replyPump(mAdapterName, true);
+ HttpCoroHandler::ptr_t httpHandler(new HttpCoroJSONHandler(replyPump));
+
+ LLCore::BufferArray::ptr_t rawbody(new LLCore::BufferArray);
+
+ {
+ LLCore::BufferArrayStream outs(rawbody.get());
+ Json::Value root = LlsdToJson(body);
+ Json::FastWriter writer;
+
+ LL_WARNS("Http::put") << "JSON Generates: \"" << writer.write(root) << "\"" << LL_ENDL;
+ outs << writer.write(root);
+ }
+
+ return putAndYield_(request, url, rawbody, options, headers, httpHandler);
+}
+
LLSD HttpCoroutineAdapter::putAndYield_(LLCore::HttpRequest::ptr_t &request,
const std::string & url, const LLSD & body,
LLCore::HttpOptions::ptr_t &options, LLCore::HttpHeaders::ptr_t &headers,
@@ -740,12 +784,39 @@ LLSD HttpCoroutineAdapter::putAndYield_(LLCore::HttpRequest::ptr_t &request,
return results;
}
+LLSD HttpCoroutineAdapter::putAndYield_(LLCore::HttpRequest::ptr_t &request,
+ const std::string & url, const LLCore::BufferArray::ptr_t & rawbody,
+ LLCore::HttpOptions::ptr_t &options, LLCore::HttpHeaders::ptr_t &headers,
+ HttpCoroHandler::ptr_t &handler)
+{
+ HttpRequestPumper pumper(request);
+
+ checkDefaultHeaders(headers);
+
+ // The HTTPCoroHandler does not self delete, so retrieval of a the contained
+ // pointer from the smart pointer is safe in this case.
+ LLCore::HttpHandle hhandle = request->requestPut(mPolicyId, mPriority,
+ url, rawbody.get(), options, headers, handler.get());
+
+ if (hhandle == LLCORE_HTTP_HANDLE_INVALID)
+ {
+ return HttpCoroutineAdapter::buildImmediateErrorResult(request, url);
+ }
+
+ saveState(hhandle, request, handler);
+ LLSD results = llcoro::waitForEventOn(handler->getReplyPump());
+ cleanState();
+
+ return results;
+}
+
+
LLSD HttpCoroutineAdapter::getAndYield(LLCore::HttpRequest::ptr_t request,
const std::string & url,
LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers)
{
LLEventStream replyPump(mAdapterName + "Reply", true);
- HttpCoroHandler::ptr_t httpHandler = HttpCoroHandler::ptr_t(new HttpCoroLLSDHandler(replyPump));
+ HttpCoroHandler::ptr_t httpHandler(new HttpCoroLLSDHandler(replyPump));
return getAndYield_(request, url, options, headers, httpHandler);
}
@@ -755,7 +826,7 @@ LLSD HttpCoroutineAdapter::getRawAndYield(LLCore::HttpRequest::ptr_t request,
LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers)
{
LLEventStream replyPump(mAdapterName + "Reply", true);
- HttpCoroHandler::ptr_t httpHandler = HttpCoroHandler::ptr_t(new HttpCoroRawHandler(replyPump));
+ HttpCoroHandler::ptr_t httpHandler(new HttpCoroRawHandler(replyPump));
return getAndYield_(request, url, options, headers, httpHandler);
}
@@ -764,7 +835,7 @@ LLSD HttpCoroutineAdapter::getJsonAndYield(LLCore::HttpRequest::ptr_t request,
const std::string & url, LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers)
{
LLEventStream replyPump(mAdapterName + "Reply", true);
- HttpCoroHandler::ptr_t httpHandler = HttpCoroHandler::ptr_t(new HttpCoroJSONHandler(replyPump));
+ HttpCoroHandler::ptr_t httpHandler(new HttpCoroJSONHandler(replyPump));
return getAndYield_(request, url, options, headers, httpHandler);
}
@@ -801,11 +872,22 @@ LLSD HttpCoroutineAdapter::deleteAndYield(LLCore::HttpRequest::ptr_t request,
LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers)
{
LLEventStream replyPump(mAdapterName + "Reply", true);
- HttpCoroHandler::ptr_t httpHandler = HttpCoroHandler::ptr_t(new HttpCoroLLSDHandler(replyPump));
+ HttpCoroHandler::ptr_t httpHandler(new HttpCoroLLSDHandler(replyPump));
+
+ return deleteAndYield_(request, url, options, headers, httpHandler);
+}
+
+LLSD HttpCoroutineAdapter::deleteJsonAndYield(LLCore::HttpRequest::ptr_t request,
+ const std::string & url,
+ LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers)
+{
+ LLEventStream replyPump(mAdapterName + "Reply", true);
+ HttpCoroHandler::ptr_t httpHandler(new HttpCoroJSONHandler(replyPump));
return deleteAndYield_(request, url, options, headers, httpHandler);
}
+
LLSD HttpCoroutineAdapter::deleteAndYield_(LLCore::HttpRequest::ptr_t &request,
const std::string & url, LLCore::HttpOptions::ptr_t &options,
LLCore::HttpHeaders::ptr_t &headers, HttpCoroHandler::ptr_t &handler)
@@ -835,7 +917,7 @@ LLSD HttpCoroutineAdapter::patchAndYield(LLCore::HttpRequest::ptr_t request,
LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers)
{
LLEventStream replyPump(mAdapterName + "Reply", true);
- HttpCoroHandler::ptr_t httpHandler = HttpCoroHandler::ptr_t(new HttpCoroLLSDHandler(replyPump));
+ HttpCoroHandler::ptr_t httpHandler(new HttpCoroLLSDHandler(replyPump));
return patchAndYield_(request, url, body, options, headers, httpHandler);
}
@@ -873,7 +955,7 @@ LLSD HttpCoroutineAdapter::copyAndYield(LLCore::HttpRequest::ptr_t request,
LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers)
{
LLEventStream replyPump(mAdapterName + "Reply", true);
- HttpCoroHandler::ptr_t httpHandler = HttpCoroHandler::ptr_t(new HttpCoroLLSDHandler(replyPump));
+ HttpCoroHandler::ptr_t httpHandler(new HttpCoroLLSDHandler(replyPump));
if (!headers)
headers.reset(new LLCore::HttpHeaders);
@@ -915,7 +997,7 @@ LLSD HttpCoroutineAdapter::moveAndYield(LLCore::HttpRequest::ptr_t request,
LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers)
{
LLEventStream replyPump(mAdapterName + "Reply", true);
- HttpCoroHandler::ptr_t httpHandler = HttpCoroHandler::ptr_t(new HttpCoroLLSDHandler(replyPump));
+ HttpCoroHandler::ptr_t httpHandler(new HttpCoroLLSDHandler(replyPump));
if (!headers)
headers.reset(new LLCore::HttpHeaders);
diff --git a/indra/llmessage/llcorehttputil.h b/indra/llmessage/llcorehttputil.h
index 31a73bb900..6599a4f01a 100644
--- a/indra/llmessage/llcorehttputil.h
+++ b/indra/llmessage/llcorehttputil.h
@@ -337,6 +337,7 @@ public:
const std::string & url, LLCore::BufferArray::ptr_t rawbody,
LLCore::HttpOptions::ptr_t options = LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions()),
LLCore::HttpHeaders::ptr_t headers = LLCore::HttpHeaders::ptr_t(new LLCore::HttpHeaders()));
+
LLSD postAndYield(LLCore::HttpRequest::ptr_t &request,
const std::string & url, const LLSD & body,
LLCore::HttpHeaders::ptr_t &headers)
@@ -393,6 +394,19 @@ public:
LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions()), headers);
}
+ LLSD postJsonAndYield(LLCore::HttpRequest::ptr_t request,
+ const std::string & url, const LLSD & body,
+ LLCore::HttpOptions::ptr_t options = LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions()),
+ LLCore::HttpHeaders::ptr_t headers = LLCore::HttpHeaders::ptr_t(new LLCore::HttpHeaders()));
+ LLSD postJsonAndYield(LLCore::HttpRequest::ptr_t &request,
+ const std::string & url, const LLSD & body,
+ LLCore::HttpHeaders::ptr_t &headers)
+ {
+ return postJsonAndYield(request, url, body,
+ LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions()), headers);
+ }
+
+
/// Execute a Put transaction on the supplied URL and yield execution of
/// the coroutine until a result is available.
@@ -404,11 +418,32 @@ public:
LLCore::HttpOptions::ptr_t options = LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions()),
LLCore::HttpHeaders::ptr_t headers = LLCore::HttpHeaders::ptr_t(new LLCore::HttpHeaders()));
+ LLSD putAndYield(LLCore::HttpRequest::ptr_t request,
+ const std::string & url, const LLSD & body,
+ LLCore::HttpHeaders::ptr_t headers)
+ {
+ return putAndYield(request, url, body,
+ LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions()), headers);
+ }
+
+ LLSD putJsonAndYield(LLCore::HttpRequest::ptr_t request,
+ const std::string & url, const LLSD & body,
+ LLCore::HttpOptions::ptr_t options = LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions()),
+ LLCore::HttpHeaders::ptr_t headers = LLCore::HttpHeaders::ptr_t(new LLCore::HttpHeaders()));
+ LLSD putJsonAndYield(LLCore::HttpRequest::ptr_t &request,
+ const std::string & url, const LLSD & body,
+ LLCore::HttpHeaders::ptr_t &headers)
+ {
+ return putJsonAndYield(request, url, body,
+ LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions()), headers);
+ }
+
/// Execute a Get transaction on the supplied URL and yield execution of
/// the coroutine until a result is available.
///
/// @Note: the request's smart pointer is passed by value so that it will
/// not be deallocated during the yield.
+ ///
LLSD getAndYield(LLCore::HttpRequest::ptr_t request,
const std::string & url,
LLCore::HttpOptions::ptr_t options = LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions()),
@@ -433,11 +468,15 @@ public:
headers);
}
+ /// These methods have the same behavior as @getAndYield() however they are
+ /// expecting the server to return the results formatted in a JSON string.
+ /// On a successful GET call the JSON results will be converted into LLSD
+ /// before being returned to the caller.
LLSD getJsonAndYield(LLCore::HttpRequest::ptr_t request,
const std::string & url,
LLCore::HttpOptions::ptr_t options = LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions()),
LLCore::HttpHeaders::ptr_t headers = LLCore::HttpHeaders::ptr_t(new LLCore::HttpHeaders()));
- LLSD getJsonndYield(LLCore::HttpRequest::ptr_t &request,
+ LLSD getJsonAndYield(LLCore::HttpRequest::ptr_t &request,
const std::string & url, LLCore::HttpHeaders::ptr_t &headers)
{
return getJsonAndYield(request, url,
@@ -455,6 +494,29 @@ public:
const std::string & url,
LLCore::HttpOptions::ptr_t options = LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions()),
LLCore::HttpHeaders::ptr_t headers = LLCore::HttpHeaders::ptr_t(new LLCore::HttpHeaders()));
+ LLSD deleteAndYield(LLCore::HttpRequest::ptr_t request,
+ const std::string & url, LLCore::HttpHeaders::ptr_t headers)
+ {
+ return deleteAndYield(request, url,
+ LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions()),
+ headers);
+ }
+
+ /// These methods have the same behavior as @deleteAndYield() however they are
+ /// expecting the server to return any results formatted in a JSON string.
+ /// On a successful DELETE call the JSON results will be converted into LLSD
+ /// before being returned to the caller.
+ LLSD deleteJsonAndYield(LLCore::HttpRequest::ptr_t request,
+ const std::string & url,
+ LLCore::HttpOptions::ptr_t options = LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions()),
+ LLCore::HttpHeaders::ptr_t headers = LLCore::HttpHeaders::ptr_t(new LLCore::HttpHeaders()));
+ LLSD deleteJsonAndYield(LLCore::HttpRequest::ptr_t request,
+ const std::string & url, LLCore::HttpHeaders::ptr_t headers)
+ {
+ return deleteJsonAndYield(request, url,
+ LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions()),
+ headers);
+ }
/// Execute a PATCH transaction on the supplied URL and yield execution of
@@ -568,6 +630,11 @@ private:
LLCore::HttpOptions::ptr_t &options, LLCore::HttpHeaders::ptr_t &headers,
HttpCoroHandler::ptr_t &handler);
+ LLSD putAndYield_(LLCore::HttpRequest::ptr_t &request,
+ const std::string & url, const LLCore::BufferArray::ptr_t & rawbody,
+ LLCore::HttpOptions::ptr_t &options, LLCore::HttpHeaders::ptr_t &headers,
+ HttpCoroHandler::ptr_t &handler);
+
LLSD getAndYield_(LLCore::HttpRequest::ptr_t &request,
const std::string & url, LLCore::HttpOptions::ptr_t &options,
LLCore::HttpHeaders::ptr_t &headers, HttpCoroHandler::ptr_t &handler);