diff options
author | Rider Linden <none@none> | 2015-04-16 17:01:10 -0700 |
---|---|---|
committer | Rider Linden <none@none> | 2015-04-16 17:01:10 -0700 |
commit | c4bcc83336c623b97e982443ce2f91d82d1a187d (patch) | |
tree | 64a19ba7680f643dff4f61f12d0e7621546fcac8 /indra/llmessage | |
parent | 0d302e692fd25e5dd7a37b5ac4c9d14f3e5d470d (diff) |
Facebook conversion.
Diffstat (limited to 'indra/llmessage')
-rw-r--r-- | indra/llmessage/llcorehttputil.cpp | 91 | ||||
-rw-r--r-- | indra/llmessage/llcorehttputil.h | 39 |
2 files changed, 115 insertions, 15 deletions
diff --git a/indra/llmessage/llcorehttputil.cpp b/indra/llmessage/llcorehttputil.cpp index 2d6cca214c..a3226ee2c3 100644 --- a/indra/llmessage/llcorehttputil.cpp +++ b/indra/llmessage/llcorehttputil.cpp @@ -291,7 +291,7 @@ void HttpCoroHandler::onCompleted(LLCore::HttpHandle handle, LLCore::HttpRespons // this method can return a map to the caller. // *TODO: Should it always do this? LLSD newResult = LLSD::emptyMap(); - newResult["content"] = result; + newResult[HttpCoroutineAdapter::HTTP_RESULTS_CONTENT] = result; result = newResult; } } @@ -305,11 +305,6 @@ void HttpCoroHandler::buildStatusEntry(LLCore::HttpResponse *response, LLCore::H LLSD httpresults = LLSD::emptyMap(); writeStatusCodes(status, response->getRequestURL(), httpresults); - // httpresults["success"] = static_cast<LLSD::Boolean>(status); - // httpresults["type"] = static_cast<LLSD::Integer>(status.getType()); - // httpresults["status"] = static_cast<LLSD::Integer>(status.getStatus()); - // httpresults["message"] = static_cast<LLSD::String>(status.getMessage()); - // httpresults["url"] = static_cast<LLSD::String>(response->getRequestURL()); LLSD httpHeaders = LLSD::emptyMap(); LLCore::HttpHeaders * hdrs = response->getHeaders(); @@ -329,24 +324,24 @@ void HttpCoroHandler::buildStatusEntry(LLCore::HttpResponse *response, LLCore::H } } - httpresults["headers"] = httpHeaders; - result["http_result"] = httpresults; + httpresults[HttpCoroutineAdapter::HTTP_RESULTS_HEADERS] = httpHeaders; + result[HttpCoroutineAdapter::HTTP_RESULTS] = httpresults; } void HttpCoroHandler::writeStatusCodes(LLCore::HttpStatus status, const std::string &url, LLSD &result) { - result["success"] = static_cast<LLSD::Boolean>(status); - result["type"] = static_cast<LLSD::Integer>(status.getType()); - result["status"] = static_cast<LLSD::Integer>(status.getStatus()); - result["message"] = static_cast<LLSD::String>(status.getMessage()); - result["url"] = static_cast<LLSD::String>(url); + result[HttpCoroutineAdapter::HTTP_RESULTS_SUCCESS] = static_cast<LLSD::Boolean>(status); + result[HttpCoroutineAdapter::HTTP_RESULTS_TYPE] = static_cast<LLSD::Integer>(status.getType()); + result[HttpCoroutineAdapter::HTTP_RESULTS_STATUS] = static_cast<LLSD::Integer>(status.getStatus()); + result[HttpCoroutineAdapter::HTTP_RESULTS_MESSAGE] = static_cast<LLSD::String>(status.getMessage()); + result[HttpCoroutineAdapter::HTTP_RESULTS_URL] = static_cast<LLSD::String>(url); } LLCore::HttpStatus HttpCoroHandler::getStatusFromLLSD(const LLSD &httpResults) { - LLCore::HttpStatus::type_enum_t type = static_cast<LLCore::HttpStatus::type_enum_t>(httpResults["type"].asInteger()); - short code = static_cast<short>(httpResults["status"].asInteger()); + LLCore::HttpStatus::type_enum_t type = static_cast<LLCore::HttpStatus::type_enum_t>(httpResults[HttpCoroutineAdapter::HTTP_RESULTS_TYPE].asInteger()); + short code = static_cast<short>(httpResults[HttpCoroutineAdapter::HTTP_RESULTS_STATUS].asInteger()); return LLCore::HttpStatus(type, code); } @@ -377,6 +372,16 @@ bool HttpRequestPumper::pollRequest(const LLSD&) } //======================================================================== +const std::string HttpCoroutineAdapter::HTTP_RESULTS("http_result"); +const std::string HttpCoroutineAdapter::HTTP_RESULTS_SUCCESS("success"); +const std::string HttpCoroutineAdapter::HTTP_RESULTS_TYPE("type"); +const std::string HttpCoroutineAdapter::HTTP_RESULTS_STATUS("status"); +const std::string HttpCoroutineAdapter::HTTP_RESULTS_MESSAGE("message"); +const std::string HttpCoroutineAdapter::HTTP_RESULTS_URL("url"); +const std::string HttpCoroutineAdapter::HTTP_RESULTS_HEADERS("headers"); +const std::string HttpCoroutineAdapter::HTTP_RESULTS_CONTENT("content"); + + HttpCoroutineAdapter::HttpCoroutineAdapter(const std::string &name, LLCore::HttpRequest::policy_t policyId, LLCore::HttpRequest::priority_t priority) : mAdapterName(name), @@ -422,6 +427,34 @@ LLSD HttpCoroutineAdapter::postAndYield(LLCoros::self & self, LLCore::HttpReques return results; } +LLSD HttpCoroutineAdapter::postAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t request, + const std::string & url, LLCore::BufferArray::ptr_t rawbody, + LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers) +{ + LLEventStream replyPump(mAdapterName, true); + LLCoreHttpUtil::HttpCoroHandler::ptr_t httpHandler = + LLCoreHttpUtil::HttpCoroHandler::ptr_t(new LLCoreHttpUtil::HttpCoroHandler(replyPump)); + + //LL_INFOS() << "Requesting transaction " << transactionId << LL_ENDL; + LLCoreHttpUtil::HttpRequestPumper pumper(request); + // 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->requestPost(mPolicyId, mPriority, url, rawbody.get(), + options.get(), headers.get(), httpHandler.get()); + + if (hhandle == LLCORE_HTTP_HANDLE_INVALID) + { + return HttpCoroutineAdapter::buildImmediateErrorResult(request, url); + } + + saveState(hhandle, request, httpHandler); + LLSD results = waitForEventOn(self, replyPump); + cleanState(); + + //LL_INFOS() << "Results for transaction " << transactionId << LL_ENDL; + return results; +} + LLSD HttpCoroutineAdapter::putAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t request, const std::string & url, const LLSD & body, LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers) @@ -477,6 +510,34 @@ LLSD HttpCoroutineAdapter::getAndYield(LLCoros::self & self, LLCore::HttpRequest return results; } +LLSD HttpCoroutineAdapter::deleteAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t request, + const std::string & url, + LLCore::HttpOptions::ptr_t options, LLCore::HttpHeaders::ptr_t headers) +{ + LLEventStream replyPump(mAdapterName + "Reply", true); + LLCoreHttpUtil::HttpCoroHandler::ptr_t httpHandler = + LLCoreHttpUtil::HttpCoroHandler::ptr_t(new LLCoreHttpUtil::HttpCoroHandler(replyPump)); + + //LL_INFOS() << "Requesting transaction " << transactionId << LL_ENDL; + LLCoreHttpUtil::HttpRequestPumper pumper(request); + // 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->requestDelete(mPolicyId, mPriority, + url, options.get(), headers.get(), httpHandler.get()); + + if (hhandle == LLCORE_HTTP_HANDLE_INVALID) + { + return HttpCoroutineAdapter::buildImmediateErrorResult(request, url); + } + + saveState(hhandle, request, httpHandler); + LLSD results = waitForEventOn(self, replyPump); + cleanState(); + //LL_INFOS() << "Results for transaction " << transactionId << LL_ENDL; + return results; +} + + void HttpCoroutineAdapter::cancelYieldingOperation() { LLCore::HttpRequest::ptr_t request = mWeakRequest.lock(); diff --git a/indra/llmessage/llcorehttputil.h b/indra/llmessage/llcorehttputil.h index 6fcf03b95c..cd137dbbe1 100644 --- a/indra/llmessage/llcorehttputil.h +++ b/indra/llmessage/llcorehttputil.h @@ -205,6 +205,7 @@ LLCore::HttpHandle requestPatchWithLLSD(LLCore::HttpRequest::ptr_t & request, class HttpCoroHandler : public LLCore::HttpHandler { public: + typedef boost::shared_ptr<HttpCoroHandler> ptr_t; typedef boost::weak_ptr<HttpCoroHandler> wptr_t; @@ -248,6 +249,15 @@ private: class HttpCoroutineAdapter { public: + static const std::string HTTP_RESULTS; + static const std::string HTTP_RESULTS_SUCCESS; + static const std::string HTTP_RESULTS_TYPE; + static const std::string HTTP_RESULTS_STATUS; + static const std::string HTTP_RESULTS_MESSAGE; + static const std::string HTTP_RESULTS_URL; + static const std::string HTTP_RESULTS_HEADERS; + static const std::string HTTP_RESULTS_CONTENT; + typedef boost::shared_ptr<HttpCoroutineAdapter> ptr_t; typedef boost::weak_ptr<HttpCoroutineAdapter> wptr_t; @@ -264,6 +274,25 @@ public: const std::string & url, const LLSD & body, LLCore::HttpOptions::ptr_t options = LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions(), false), LLCore::HttpHeaders::ptr_t headers = LLCore::HttpHeaders::ptr_t(new LLCore::HttpHeaders(), false)); + LLSD postAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t request, + const std::string & url, LLCore::BufferArray::ptr_t rawbody, + LLCore::HttpOptions::ptr_t options = LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions(), false), + LLCore::HttpHeaders::ptr_t headers = LLCore::HttpHeaders::ptr_t(new LLCore::HttpHeaders(), false)); + LLSD postAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t &request, + const std::string & url, const LLSD & body, + LLCore::HttpHeaders::ptr_t &headers) + { + return postAndYield(self, request, url, body, + LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions(), false), headers); + } + + LLSD postAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t &request, + const std::string & url, LLCore::BufferArray::ptr_t &rawbody, + LLCore::HttpHeaders::ptr_t &headers) + { + return postAndYield(self, request, url, rawbody, + LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions(), false), headers); + } /// Execute a Put transaction on the supplied URL and yield execution of /// the coroutine until a result is available. @@ -285,6 +314,16 @@ public: LLCore::HttpOptions::ptr_t options = LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions(), false), LLCore::HttpHeaders::ptr_t headers = LLCore::HttpHeaders::ptr_t(new LLCore::HttpHeaders(), false)); + /// Execute a DELETE 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 deleteAndYield(LLCoros::self & self, LLCore::HttpRequest::ptr_t request, + const std::string & url, + LLCore::HttpOptions::ptr_t options = LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions(), false), + LLCore::HttpHeaders::ptr_t headers = LLCore::HttpHeaders::ptr_t(new LLCore::HttpHeaders(), false)); + /// void cancelYieldingOperation(); |