summaryrefslogtreecommitdiff
path: root/indra/llmessage
diff options
context:
space:
mode:
authorMerov Linden <merov@lindenlab.com>2014-11-11 11:40:19 -0800
committerMerov Linden <merov@lindenlab.com>2014-11-11 11:40:19 -0800
commit4ea33a3b3cb7fa06cd3f84cbdc866cc8ad9bdefa (patch)
tree753588ae96193cf376ec16f759bd12ea4407afdb /indra/llmessage
parentb31f7381ae85a0aa6c4d9e93b1d8bac5854fdd01 (diff)
parent2301cf800f40101baed7a5936683d0b1e4968be1 (diff)
Pull merge from lindenlanb/viewer-release
Diffstat (limited to 'indra/llmessage')
-rwxr-xr-xindra/llmessage/CMakeLists.txt4
-rw-r--r--indra/llmessage/llcorehttputil.cpp139
-rw-r--r--indra/llmessage/llcorehttputil.h115
-rwxr-xr-xindra/llmessage/llhttpconstants.cpp6
-rwxr-xr-xindra/llmessage/llhttpconstants.h3
5 files changed, 262 insertions, 5 deletions
diff --git a/indra/llmessage/CMakeLists.txt b/indra/llmessage/CMakeLists.txt
index 8bd134dc84..40eddcb0ab 100755
--- a/indra/llmessage/CMakeLists.txt
+++ b/indra/llmessage/CMakeLists.txt
@@ -6,6 +6,7 @@ include(00-Common)
include(GoogleMock)
include(LLAddBuildTest)
include(LLCommon)
+include(LLCoreHttp)
include(LLMath)
include(LLMessage)
include(LLVFS)
@@ -18,6 +19,7 @@ include_directories (${CMAKE_CURRENT_SOURCE_DIR})
include_directories(
${LLCOMMON_INCLUDE_DIRS}
+ ${LLCOREHTTP_INCLUDE_DIRS}
${LLMATH_INCLUDE_DIRS}
${LLMESSAGE_INCLUDE_DIRS}
${LLVFS_INCLUDE_DIRS}
@@ -36,6 +38,7 @@ set(llmessage_SOURCE_FILES
llchainio.cpp
llcircuit.cpp
llclassifiedflags.cpp
+ llcorehttputil.cpp
llcurl.cpp
lldatapacker.cpp
lldispatcher.cpp
@@ -124,6 +127,7 @@ set(llmessage_HEADER_FILES
llcipher.h
llcircuit.h
llclassifiedflags.h
+ llcorehttputil.h
llcurl.h
lldatapacker.h
lldbstrings.h
diff --git a/indra/llmessage/llcorehttputil.cpp b/indra/llmessage/llcorehttputil.cpp
new file mode 100644
index 0000000000..ee80b0fd94
--- /dev/null
+++ b/indra/llmessage/llcorehttputil.cpp
@@ -0,0 +1,139 @@
+/**
+ * @file llcorehttputil.cpp
+ * @date 2014-08-25
+ * @brief Implementation of adapter and utility classes expanding the llcorehttp interfaces.
+ *
+ * $LicenseInfo:firstyear=2014&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2014, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+#include "linden_common.h"
+
+#include <sstream>
+
+#include "llcorehttputil.h"
+#include "llsdserialize.h"
+
+
+using namespace LLCore;
+
+
+namespace LLCoreHttpUtil
+{
+
+// *TODO: Currently converts only from XML content. A mode
+// to convert using fromBinary() might be useful as well. Mesh
+// headers could use it.
+bool responseToLLSD(HttpResponse * response, bool log, LLSD & out_llsd)
+{
+ // Convert response to LLSD
+ BufferArray * body(response->getBody());
+ if (! body || ! body->size())
+ {
+ return false;
+ }
+
+ LLCore::BufferArrayStream bas(body);
+ LLSD body_llsd;
+ S32 parse_status(LLSDSerialize::fromXML(body_llsd, bas, log));
+ if (LLSDParser::PARSE_FAILURE == parse_status){
+ return false;
+ }
+ out_llsd = body_llsd;
+ return true;
+}
+
+
+HttpHandle requestPostWithLLSD(HttpRequest * request,
+ HttpRequest::policy_t policy_id,
+ HttpRequest::priority_t priority,
+ const std::string & url,
+ const LLSD & body,
+ HttpOptions * options,
+ HttpHeaders * headers,
+ HttpHandler * handler)
+{
+ HttpHandle handle(LLCORE_HTTP_HANDLE_INVALID);
+
+ BufferArray * ba = new BufferArray();
+ BufferArrayStream bas(ba);
+ LLSDSerialize::toXML(body, bas);
+
+ handle = request->requestPost(policy_id,
+ priority,
+ url,
+ ba,
+ options,
+ headers,
+ handler);
+ ba->release();
+ return handle;
+}
+
+
+std::string responseToString(LLCore::HttpResponse * response)
+{
+ static const std::string empty("[Empty]");
+
+ if (! response)
+ {
+ return empty;
+ }
+
+ BufferArray * body(response->getBody());
+ if (! body || ! body->size())
+ {
+ return empty;
+ }
+
+ // Attempt to parse as LLSD regardless of content-type
+ LLSD body_llsd;
+ if (responseToLLSD(response, false, body_llsd))
+ {
+ std::ostringstream tmp;
+
+ LLSDSerialize::toPrettyNotation(body_llsd, tmp);
+ std::size_t temp_len(tmp.tellp());
+
+ if (temp_len)
+ {
+ return tmp.str().substr(0, std::min(temp_len, std::size_t(1024)));
+ }
+ }
+ else
+ {
+ // *TODO: More elaborate forms based on Content-Type as needed.
+ char content[1024];
+
+ size_t len(body->read(0, content, sizeof(content)));
+ if (len)
+ {
+ return std::string(content, 0, len);
+ }
+ }
+
+ // Default
+ return empty;
+}
+
+
+} // end namespace LLCoreHttpUtil
+
diff --git a/indra/llmessage/llcorehttputil.h b/indra/llmessage/llcorehttputil.h
new file mode 100644
index 0000000000..d40172bc7a
--- /dev/null
+++ b/indra/llmessage/llcorehttputil.h
@@ -0,0 +1,115 @@
+/**
+ * @file llcorehttputil.h
+ * @date 2014-08-25
+ * @brief Adapter and utility classes expanding the llcorehttp interfaces.
+ *
+ * $LicenseInfo:firstyear=2014&license=viewerlgpl$
+ * Second Life Viewer Source Code
+ * Copyright (C) 2014, Linden Research, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation;
+ * version 2.1 of the License only.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
+ * $/LicenseInfo$
+ */
+
+#ifndef LL_LLCOREHTTPUTIL_H
+#define LL_LLCOREHTTPUTIL_H
+
+#include <string>
+
+#include "httpcommon.h"
+#include "httprequest.h"
+#include "httpresponse.h"
+#include "httpheaders.h"
+#include "httpoptions.h"
+#include "httphandler.h"
+#include "bufferarray.h"
+#include "bufferstream.h"
+#include "llsd.h"
+
+///
+/// The base llcorehttp library implements many HTTP idioms
+/// used in the viewer but not all. That library intentionally
+/// avoids the use of LLSD and its conventions which aren't
+/// universally applicable. This module, using namespace
+/// LLCoreHttpUtil, provides the additional helper functions
+/// that support idiomatic LLSD transport via the newer
+/// llcorehttp library.
+///
+namespace LLCoreHttpUtil
+{
+
+/// Attempt to convert a response object's contents to LLSD.
+/// It is expected that the response body will be of non-zero
+/// length on input but basic checks will be performed and
+/// and error (false status) returned if there is no data.
+/// If there is data but it cannot be successfully parsed,
+/// an error is also returned. If successfully parsed,
+/// the output LLSD object, out_llsd, is written with the
+/// result and true is returned.
+///
+/// @arg response Response object as returned in
+/// in an HttpHandler onCompleted() callback.
+/// @arg log If true, LLSD parser will emit errors
+/// as LL_INFOS-level messages as it parses.
+/// Otherwise, it *should* be a quiet parse.
+/// @arg out_llsd Output LLSD object written only upon
+/// successful parse of the response object.
+///
+/// @return Returns true (and writes to out_llsd) if
+/// parse was successful. False otherwise.
+///
+bool responseToLLSD(LLCore::HttpResponse * response,
+ bool log,
+ LLSD & out_llsd);
+
+/// Create a std::string representation of a response object
+/// suitable for logging. Mainly intended for logging of
+/// failures and debug information. This won't be fast,
+/// just adequate.
+std::string responseToString(LLCore::HttpResponse * response);
+
+
+/// Issue a standard HttpRequest::requestPost() call but using
+/// and LLSD object as the request body. Conventions are the
+/// same as with that method. Caller is expected to provide
+/// an HttpHeaders object with a correct 'Content-Type:' header.
+/// One will not be provided by this call. You might look after
+/// the 'Accept:' header as well.
+///
+/// @return If request is successfully issued, the
+/// HttpHandle representing the request.
+/// On error, LLCORE_HTTP_HANDLE_INVALID
+/// is returned and caller can fetch detailed
+/// status with the getStatus() method on the
+/// request object. In case of error, no
+/// request is queued and caller may need to
+/// perform additional cleanup such as freeing
+/// a now-useless HttpHandler object.
+///
+LLCore::HttpHandle requestPostWithLLSD(LLCore::HttpRequest * request,
+ LLCore::HttpRequest::policy_t policy_id,
+ LLCore::HttpRequest::priority_t priority,
+ const std::string & url,
+ const LLSD & body,
+ LLCore::HttpOptions * options,
+ LLCore::HttpHeaders * headers,
+ LLCore::HttpHandler * handler);
+
+} // end namespace LLCoreHttpUtil
+
+
+#endif // LL_LLCOREHTTPUTIL_H
diff --git a/indra/llmessage/llhttpconstants.cpp b/indra/llmessage/llhttpconstants.cpp
index 01f4a080b0..32f76f0d70 100755
--- a/indra/llmessage/llhttpconstants.cpp
+++ b/indra/llmessage/llhttpconstants.cpp
@@ -3,11 +3,8 @@
* @brief Implementation of the HTTP request / response constant lookups
*
* $LicenseInfo:firstyear=2013&license=viewerlgpl$
- *
- * Copyright (c) 2013, Linden Research, Inc.
- *
* Second Life Viewer Source Code
- * Copyright (C) 2013, Linden Research, Inc.
+ * Copyright (C) 2013-2014, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -107,6 +104,7 @@ const std::string HTTP_IN_HEADER_X_FORWARDED_FOR("x-forwarded-for");
const std::string HTTP_CONTENT_LLSD_XML("application/llsd+xml");
const std::string HTTP_CONTENT_OCTET_STREAM("application/octet-stream");
+const std::string HTTP_CONTENT_VND_LL_MESH("application/vnd.ll.mesh");
const std::string HTTP_CONTENT_XML("application/xml");
const std::string HTTP_CONTENT_JSON("application/json");
const std::string HTTP_CONTENT_TEXT_HTML("text/html");
diff --git a/indra/llmessage/llhttpconstants.h b/indra/llmessage/llhttpconstants.h
index 4aa3cc6394..d6bcbd3c19 100755
--- a/indra/llmessage/llhttpconstants.h
+++ b/indra/llmessage/llhttpconstants.h
@@ -4,7 +4,7 @@
*
* $LicenseInfo:firstyear=2001&license=viewerlgpl$
* Second Life Viewer Source Code
- * Copyright (C) 2001-2013, Linden Research, Inc.
+ * Copyright (C) 2001-2014, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -203,6 +203,7 @@ extern const std::string HTTP_IN_HEADER_X_FORWARDED_FOR;
extern const std::string HTTP_CONTENT_LLSD_XML;
extern const std::string HTTP_CONTENT_OCTET_STREAM;
+extern const std::string HTTP_CONTENT_VND_LL_MESH;
extern const std::string HTTP_CONTENT_XML;
extern const std::string HTTP_CONTENT_JSON;
extern const std::string HTTP_CONTENT_TEXT_HTML;