From bd646490c9fcd901ccdd9bad1ee67308d1a8fb25 Mon Sep 17 00:00:00 2001 From: Nicky Date: Wed, 4 Nov 2015 10:48:49 +0100 Subject: [PATCH] Move FS specific functions into their own files. --- indra/llmessage/fscorehttputil.cpp | 93 ++++++++++++++++++++++++++++++ indra/llmessage/fscorehttputil.h | 12 ++++ indra/llmessage/llcorehttputil.cpp | 93 +----------------------------- indra/llmessage/llcorehttputil.h | 10 +--- 4 files changed, 107 insertions(+), 101 deletions(-) create mode 100644 indra/llmessage/fscorehttputil.cpp create mode 100644 indra/llmessage/fscorehttputil.h diff --git a/indra/llmessage/fscorehttputil.cpp b/indra/llmessage/fscorehttputil.cpp new file mode 100644 index 0000000000..6cdf829632 --- /dev/null +++ b/indra/llmessage/fscorehttputil.cpp @@ -0,0 +1,93 @@ +namespace FSCoreHttpUtil +{ + void trivialPostCoroRaw(std::string url, LLCore::HttpRequest::policy_t policyId, LLCore::BufferArray::ptr_t postData, LLCore::HttpHeaders::ptr_t aHeader, completionCallback_t success, completionCallback_t failure) + { + LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("genericPostCoroRaw", policyId)); + LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest); + LLCore::HttpOptions::ptr_t httpOpts(new LLCore::HttpOptions); + + httpOpts->setWantHeaders(true); + + LL_INFOS("HttpCoroutineAdapter", "genericPostCoroRaw") << "Generic POST for " << url << LL_ENDL; + + LLSD result = httpAdapter->postRawAndSuspend(httpRequest, url, postData, httpOpts, aHeader ); + + LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; + LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); + + if (!status) + { + // If a failure routine is provided do it. + if (failure) + { + failure(httpResults); + } + } + else + { + // If a success routine is provided do it. + if (success) + { + success(result); + } + } + } + + void callbackHttpPostRaw(const std::string &url, std::string postData, completionCallback_t success, completionCallback_t failure, LLCore::HttpHeaders::ptr_t aHeader ) + { + + LLCore::BufferArray::ptr_t postDataBuffer( new LLCore::BufferArray() ); + postDataBuffer->append( postData.c_str(), postData.size() ); + + LLCoros::instance().launch("HttpCoroutineAdapter::genericPostCoroRaw", + boost::bind(trivialPostCoroRaw, url, LLCore::HttpRequest::DEFAULT_POLICY_ID, postDataBuffer, aHeader, success, failure)); + } + + void trivialGetCoroRaw(std::string url, LLCore::HttpRequest::policy_t policyId, LLCore::HttpHeaders::ptr_t aHeader, completionCallback_t success, completionCallback_t failure) + { + LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t + httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("genericGetCoro", policyId)); + LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest); + LLCore::HttpOptions::ptr_t httpOpts(new LLCore::HttpOptions); + + httpOpts->setWantHeaders(true); + + LL_INFOS("HttpCoroutineAdapter", "genericGetCoroRaw") << "Generic GET for " << url << LL_ENDL; + + LLSD result = httpAdapter->getRawAndSuspend(httpRequest, url, httpOpts, aHeader ); + + LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; + LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); + + if (!status) + { + if (failure) + { + failure(httpResults); + } + } + else + { + if (success) + { + success(result); + } + } + } + + void callbackHttpGetRaw(const std::string &url, completionCallback_t success, completionCallback_t failure, LLCore::HttpHeaders::ptr_t aHeader ) + { + LLCoros::instance().launch("HttpCoroutineAdapter::genericGetCoroRaw", + boost::bind(trivialGetCoroRaw, url, LLCore::HttpRequest::DEFAULT_POLICY_ID, aHeader, success, failure)); + } + + LLCore::HttpHeaders::ptr_t createModifiedSinceHeader( time_t aTime ) + { + std::string strDate = LLDate::toHTTPDateString( gmtime( &aTime ), "%A, %d %b %Y %H:%M:%S GMT" ); + + LLCore::HttpHeaders::ptr_t pHeader( new LLCore::HttpHeaders() ); + pHeader->append( "If-Modified-Since", strDate ); + + return pHeader; + } +} diff --git a/indra/llmessage/fscorehttputil.h b/indra/llmessage/fscorehttputil.h new file mode 100644 index 0000000000..5da2a72441 --- /dev/null +++ b/indra/llmessage/fscorehttputil.h @@ -0,0 +1,12 @@ + +namespace FSCoreHttpUtil +{ + typedef boost::function completionCallback_t; + + void callbackHttpPostRaw(const std::string &url, std::string postData, completionCallback_t success = NULL, completionCallback_t failure = NULL, LLCore::HttpHeaders::ptr_t aHeader = NULL ); + void callbackHttpGetRaw(const std::string &url, completionCallback_t success = NULL, completionCallback_t failure = NULL, LLCore::HttpHeaders::ptr_t aHeader = NULL); + + void trivialGetCoroRaw(std::string url, LLCore::HttpRequest::policy_t policyId, LLCore::HttpHeaders::ptr_t aHeader, completionCallback_t success, completionCallback_t failure); + void trivialPostCoroRaw(std::string url, LLCore::HttpRequest::policy_t policyId, LLCore::BufferArray::ptr_t postData, LLCore::HttpHeaders::ptr_t aHeader, completionCallback_t success, completionCallback_t failure); +} + diff --git a/indra/llmessage/llcorehttputil.cpp b/indra/llmessage/llcorehttputil.cpp index 8f9bdb5e28..631e027bb6 100644 --- a/indra/llmessage/llcorehttputil.cpp +++ b/indra/llmessage/llcorehttputil.cpp @@ -1307,95 +1307,4 @@ void HttpCoroutineAdapter::trivialPostCoro(std::string url, LLCore::HttpRequest: } // end namespace LLCoreHttpUtil -namespace FSCoreHttpUtil -{ -void trivialPostCoroRaw(std::string url, LLCore::HttpRequest::policy_t policyId, LLCore::BufferArray::ptr_t postData, LLCore::HttpHeaders::ptr_t aHeader, completionCallback_t success, completionCallback_t failure) -{ - LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("genericPostCoroRaw", policyId)); - LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest); - LLCore::HttpOptions::ptr_t httpOpts(new LLCore::HttpOptions); - - httpOpts->setWantHeaders(true); - - LL_INFOS("HttpCoroutineAdapter", "genericPostCoroRaw") << "Generic POST for " << url << LL_ENDL; - - LLSD result = httpAdapter->postRawAndSuspend(httpRequest, url, postData, httpOpts, aHeader ); - - LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; - LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); - - if (!status) - { - // If a failure routine is provided do it. - if (failure) - { - failure(httpResults); - } - } - else - { - // If a success routine is provided do it. - if (success) - { - success(result); - } - } -} -void callbackHttpPostRaw(const std::string &url, std::string postData, completionCallback_t success, completionCallback_t failure, LLCore::HttpHeaders::ptr_t aHeader ) -{ - - LLCore::BufferArray::ptr_t postDataBuffer( new LLCore::BufferArray() ); - postDataBuffer->append( postData.c_str(), postData.size() ); - - LLCoros::instance().launch("HttpCoroutineAdapter::genericPostCoroRaw", - boost::bind(trivialPostCoroRaw, url, LLCore::HttpRequest::DEFAULT_POLICY_ID, postDataBuffer, aHeader, success, failure)); -} - -void trivialGetCoroRaw(std::string url, LLCore::HttpRequest::policy_t policyId, LLCore::HttpHeaders::ptr_t aHeader, completionCallback_t success, completionCallback_t failure) -{ - LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t - httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("genericGetCoro", policyId)); - LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest); - LLCore::HttpOptions::ptr_t httpOpts(new LLCore::HttpOptions); - - httpOpts->setWantHeaders(true); - - LL_INFOS("HttpCoroutineAdapter", "genericGetCoroRaw") << "Generic GET for " << url << LL_ENDL; - - LLSD result = httpAdapter->getRawAndSuspend(httpRequest, url, httpOpts, aHeader ); - - LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; - LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); - - if (!status) - { - if (failure) - { - failure(httpResults); - } - } - else - { - if (success) - { - success(result); - } - } -} - -void callbackHttpGetRaw(const std::string &url, completionCallback_t success, completionCallback_t failure, LLCore::HttpHeaders::ptr_t aHeader ) -{ - LLCoros::instance().launch("HttpCoroutineAdapter::genericGetCoroRaw", - boost::bind(trivialGetCoroRaw, url, LLCore::HttpRequest::DEFAULT_POLICY_ID, aHeader, success, failure)); -} - -LLCore::HttpHeaders::ptr_t createModifiedSinceHeader( time_t aTime ) -{ - std::string strDate = LLDate::toHTTPDateString( gmtime( &aTime ), "%A, %d %b %Y %H:%M:%S GMT" ); - - LLCore::HttpHeaders::ptr_t pHeader( new LLCore::HttpHeaders() ); - pHeader->append( "If-Modified-Since", strDate ); - - return pHeader; -} -} +#include "fscorehttputil.cpp" diff --git a/indra/llmessage/llcorehttputil.h b/indra/llmessage/llcorehttputil.h index f4c825d984..03f159d987 100644 --- a/indra/llmessage/llcorehttputil.h +++ b/indra/llmessage/llcorehttputil.h @@ -677,14 +677,6 @@ private: } // end namespace LLCoreHttpUtil -namespace FSCoreHttpUtil -{ - typedef boost::function completionCallback_t; +#include "fscorehttputil.h" - void callbackHttpPostRaw(const std::string &url, std::string postData, completionCallback_t success = NULL, completionCallback_t failure = NULL, LLCore::HttpHeaders::ptr_t aHeader = NULL ); - void callbackHttpGetRaw(const std::string &url, completionCallback_t success = NULL, completionCallback_t failure = NULL, LLCore::HttpHeaders::ptr_t aHeader = NULL); - - void trivialGetCoroRaw(std::string url, LLCore::HttpRequest::policy_t policyId, LLCore::HttpHeaders::ptr_t aHeader, completionCallback_t success, completionCallback_t failure); - void trivialPostCoroRaw(std::string url, LLCore::HttpRequest::policy_t policyId, LLCore::BufferArray::ptr_t postData, LLCore::HttpHeaders::ptr_t aHeader, completionCallback_t success, completionCallback_t failure); -} #endif // LL_LLCOREHTTPUTIL_H