summaryrefslogtreecommitdiff
path: root/indra/llcommon
diff options
context:
space:
mode:
authorOz Linden <oz@lindenlab.com>2015-03-23 22:39:18 -0400
committerOz Linden <oz@lindenlab.com>2015-03-23 22:39:18 -0400
commitd6f7a16a686a32a3369661b8db35860e7cae6e8f (patch)
tree07b0117b098fef20dd9ddc597e4c0599c4235a4d /indra/llcommon
parent7ba82a6409e4fc096407f0247b084950d1e3c14a (diff)
parentc489f1f8647a77c8c7d5fb5b721433dd72cb49c8 (diff)
merge changes for 3.7.26-release
Diffstat (limited to 'indra/llcommon')
-rwxr-xr-xindra/llcommon/CMakeLists.txt5
-rw-r--r--indra/llcommon/lluriparser.cpp228
-rw-r--r--indra/llcommon/lluriparser.h84
3 files changed, 317 insertions, 0 deletions
diff --git a/indra/llcommon/CMakeLists.txt b/indra/llcommon/CMakeLists.txt
index 763f5a3521..debb42fb5f 100755
--- a/indra/llcommon/CMakeLists.txt
+++ b/indra/llcommon/CMakeLists.txt
@@ -12,12 +12,14 @@ include(GoogleBreakpad)
include(GooglePerfTools)
include(Copy3rdPartyLibs)
include(ZLIB)
+include(URIPARSER)
include_directories(
${EXPAT_INCLUDE_DIRS}
${LLCOMMON_INCLUDE_DIRS}
${ZLIB_INCLUDE_DIRS}
${BREAKPAD_INCLUDE_DIRECTORIES}
+ ${URIPARSER_INCLUDE_DIRS}
)
# add_executable(lltreeiterators lltreeiterators.cpp)
@@ -103,6 +105,7 @@ set(llcommon_SOURCE_FILES
lltracerecording.cpp
lltracethreadrecorder.cpp
lluri.cpp
+ lluriparser.cpp
lluuid.cpp
llworkerthread.cpp
timing.cpp
@@ -217,6 +220,7 @@ set(llcommon_HEADER_FILES
llunits.h
llunittype.h
lluri.h
+ lluriparser.h
lluuid.h
llwin32headers.h
llwin32headerslean.h
@@ -261,6 +265,7 @@ target_link_libraries(
${BOOST_PROGRAM_OPTIONS_LIBRARY}
${BOOST_REGEX_LIBRARY}
${GOOGLE_PERFTOOLS_LIBRARIES}
+ ${URIPARSER_LIBRARIES}
)
if (DARWIN)
diff --git a/indra/llcommon/lluriparser.cpp b/indra/llcommon/lluriparser.cpp
new file mode 100644
index 0000000000..ef4481d32f
--- /dev/null
+++ b/indra/llcommon/lluriparser.cpp
@@ -0,0 +1,228 @@
+/**
+ * @file lluriparser.cpp
+ * @author Protey
+ * @date 2014-10-07
+ * @brief Implementation of the LLUriParser class.
+ *
+ * $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 "lluriparser.h"
+
+LLUriParser::LLUriParser(const std::string& u) : mTmpScheme(false), mRes(0)
+{
+ mState.uri = &mUri;
+
+ if (u.find("://") == std::string::npos)
+ {
+ mNormalizedUri = "http://";
+ mTmpScheme = true;
+ }
+
+ mNormalizedUri += u.c_str();
+
+ mRes = parse();
+}
+
+LLUriParser::~LLUriParser()
+{
+ uriFreeUriMembersA(&mUri);
+}
+
+S32 LLUriParser::parse()
+{
+ mRes = uriParseUriA(&mState, mNormalizedUri.c_str());
+ return mRes;
+}
+
+const char * LLUriParser::scheme() const
+{
+ return mScheme.c_str();
+}
+
+void LLUriParser::sheme(const std::string& s)
+{
+ mTmpScheme = !s.size();
+ mScheme = s;
+}
+
+const char * LLUriParser::port() const
+{
+ return mPort.c_str();
+}
+
+void LLUriParser::port(const std::string& s)
+{
+ mPort = s;
+}
+
+const char * LLUriParser::host() const
+{
+ return mHost.c_str();
+}
+
+void LLUriParser::host(const std::string& s)
+{
+ mHost = s;
+}
+
+const char * LLUriParser::path() const
+{
+ return mPath.c_str();
+}
+
+void LLUriParser::path(const std::string& s)
+{
+ mPath = s;
+}
+
+const char * LLUriParser::query() const
+{
+ return mQuery.c_str();
+}
+
+void LLUriParser::query(const std::string& s)
+{
+ mQuery = s;
+}
+
+const char * LLUriParser::fragment() const
+{
+ return mFragment.c_str();
+}
+
+void LLUriParser::fragment(const std::string& s)
+{
+ mFragment = s;
+}
+
+void LLUriParser::textRangeToString(UriTextRangeA& textRange, std::string& str)
+{
+ S32 len = textRange.afterLast - textRange.first;
+ if (len)
+ {
+ str = textRange.first;
+ str = str.substr(0, len);
+ }
+}
+
+void LLUriParser::extractParts()
+{
+ if (mTmpScheme)
+ {
+ mScheme.clear();
+ }
+ else
+ {
+ textRangeToString(mUri.scheme, mScheme);
+ }
+
+ textRangeToString(mUri.hostText, mHost);
+ textRangeToString(mUri.portText, mPort);
+ textRangeToString(mUri.query, mQuery);
+ textRangeToString(mUri.fragment, mFragment);
+
+ UriPathSegmentA * pathHead = mUri.pathHead;
+ while (pathHead)
+ {
+ std::string partOfPath;
+ textRangeToString(pathHead->text, partOfPath);
+
+ mPath += '/';
+ mPath += partOfPath;
+
+ pathHead = pathHead->next;
+ }
+}
+
+S32 LLUriParser::normalize()
+{
+ if (!mRes)
+ {
+ mRes = uriNormalizeSyntaxExA(&mUri, URI_NORMALIZE_SCHEME | URI_NORMALIZE_HOST);
+
+ if (!mRes)
+ {
+ S32 chars_required;
+ mRes = uriToStringCharsRequiredA(&mUri, &chars_required);
+
+ if (!mRes)
+ {
+ chars_required++;
+ std::vector<char> label_buf(chars_required);
+ mRes = uriToStringA(&label_buf[0], &mUri, chars_required, NULL);
+
+ if (!mRes)
+ {
+ mNormalizedUri = &label_buf[mTmpScheme ? 7 : 0];
+ }
+ }
+ }
+ }
+
+ return mRes;
+}
+
+void LLUriParser::glue(std::string& uri) const
+{
+ if (mScheme.size())
+ {
+ uri = mScheme;
+ uri += "://";
+ }
+
+ uri += mHost;
+
+ if (mPort.size())
+ {
+ uri += ':';
+ uri += mPort;
+ }
+
+ uri += mPath;
+
+ if (mQuery.size())
+ {
+ uri += '?';
+ uri += mQuery;
+
+ if (mFragment.size())
+ {
+ uri += '#';
+ uri += mFragment;
+ }
+ }
+}
+
+bool LLUriParser::test() const
+{
+ std::string uri;
+ glue(uri);
+
+ return uri == mNormalizedUri;
+}
+
+const char * LLUriParser::normalizedUri() const
+{
+ return mNormalizedUri.c_str();
+}
diff --git a/indra/llcommon/lluriparser.h b/indra/llcommon/lluriparser.h
new file mode 100644
index 0000000000..719f916837
--- /dev/null
+++ b/indra/llcommon/lluriparser.h
@@ -0,0 +1,84 @@
+/**
+ * @file lluriparser.h
+ * @author Protey
+ * @date 20146-10-07
+ * @brief Declaration of the UriParser class.
+ *
+ * $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_LLURIPARSER_H
+#define LL_LLURIPARSER_H
+
+#include <string>
+#include "uriparser/Uri.h"
+
+class LL_COMMON_API LLUriParser
+{
+public:
+ LLUriParser(const std::string& u);
+ virtual ~LLUriParser();
+
+ const char * scheme() const;
+ void sheme (const std::string& s);
+
+ const char * port() const;
+ void port (const std::string& s);
+
+ const char * host() const;
+ void host (const std::string& s);
+
+ const char * path() const;
+ void path (const std::string& s);
+
+ const char * query() const;
+ void query (const std::string& s);
+
+ const char * fragment() const;
+ void fragment (const std::string& s);
+
+ const char * normalizedUri() const;
+
+ void extractParts();
+ void glue(std::string& uri) const;
+ bool test() const;
+ S32 normalize();
+
+private:
+ S32 parse();
+ void textRangeToString(UriTextRangeA& textRange, std::string& str);
+ std::string mScheme;
+ std::string mHost;
+ std::string mPort;
+ std::string mPath;
+ std::string mQuery;
+ std::string mFragment;
+ std::string mNormalizedUri;
+
+ UriParserStateA mState;
+ UriUriA mUri;
+
+ S32 mRes;
+ bool mTmpScheme;
+};
+
+#endif // LL_LLURIPARSER_H