test/WhiteBoxTests.cpp |   16 ++++++++++++++++
 wsd/RequestDetails.cpp |   35 +++++++++++++++++++++++++----------
 wsd/RequestDetails.hpp |    3 +++
 3 files changed, 44 insertions(+), 10 deletions(-)

New commits:
commit 5cf0273c7fcc10b85a4aeaaef20d602dd1bd1969
Author:     Ashod Nakashian <ashod.nakash...@collabora.co.uk>
AuthorDate: Sat Jun 20 15:12:13 2020 -0400
Commit:     Ashod Nakashian <ashnak...@gmail.com>
CommitDate: Wed Jul 1 07:35:00 2020 +0200

    wsd: parse the URI params of the URI and DocumentURI
    
    Change-Id: Iefc8c10ff85270aa95f255cef29b3427a0efcfe6
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/96826
    Tested-by: Jenkins
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Ashod Nakashian <ashnak...@gmail.com>

diff --git a/test/WhiteBoxTests.cpp b/test/WhiteBoxTests.cpp
index dd32dbdd6..13a4ac572 100644
--- a/test/WhiteBoxTests.cpp
+++ b/test/WhiteBoxTests.cpp
@@ -1509,6 +1509,22 @@ void WhiteBoxTests::testRequestDetails()
         // LOK_ASSERT_EQUAL(docUri, details.getLegacyDocumentURI()); // Broken.
         LOK_ASSERT_EQUAL(docUri, details.getDocumentURI());
 
+        const std::map<std::string, std::string>& params = 
details.getDocumentURIParams();
+        LOK_ASSERT_EQUAL(static_cast<std::size_t>(3), params.size());
+        auto it = params.find("access_header");
+        const std::string access_header
+            = "Authorization: Bearer poiuytrewq\r\n\r\nX-Requested-With: 
XMLHttpRequest";
+        LOK_ASSERT_EQUAL(access_header, it != params.end() ? it->second : "");
+        it = params.find("reuse_cookies");
+        const std::string reuse_cookies
+            = 
"lang=en-us:_ga_LMX4TVJ02K=GS1.1:Token=eyJhbGciOiJIUzUxMiJ9.vajknfkfajksdljfiwjek-"
+              
"W90fmgVb3C-00-eSkJBDqDNSYA:PublicToken=abc:ZNPCQ003-32383700=e9c71c3b:JSESSIONID="
+              "node0.node0";
+        LOK_ASSERT_EQUAL(reuse_cookies, it != params.end() ? it->second : "");
+        it = params.find("permission");
+        const std::string permission = "edit";
+        LOK_ASSERT_EQUAL(permission, it != params.end() ? it->second : "");
+
         LOK_ASSERT_EQUAL(static_cast<std::size_t>(11), details.size());
         LOK_ASSERT_EQUAL(std::string("lool"), details[0]);
         LOK_ASSERT(details.equals(0, "lool"));
diff --git a/wsd/RequestDetails.cpp b/wsd/RequestDetails.cpp
index 9caf03f29..edb5c1c8c 100644
--- a/wsd/RequestDetails.cpp
+++ b/wsd/RequestDetails.cpp
@@ -15,6 +15,27 @@
 #include <Poco/URI.h>
 #include "Exceptions.hpp"
 
+namespace
+{
+
+std::map<std::string, std::string> getParams(const std::string& uri)
+{
+    std::map<std::string, std::string> result;
+    for (const auto& param : Poco::URI(uri).getQueryParameters())
+    {
+        std::string key;
+        Poco::URI::decode(param.first, key);
+        std::string value;
+        Poco::URI::decode(param.second, value);
+        LOG_TRC("Decoding param [" << param.first << "] = [" << param.second 
<< "] -> [" << key
+                                   << "] = [" << value << "].");
+
+        result.emplace(key, value);
+    }
+
+    return result;
+}
+
 /// Returns true iff the two containers are equal.
 template <typename T> bool equal(const T& lhs, const T& rhs)
 {
@@ -42,6 +63,7 @@ template <typename T> bool equal(const T& lhs, const T& rhs)
 
     return true;
 }
+}
 
 RequestDetails::RequestDetails(Poco::Net::HTTPRequest &request, const 
std::string& serviceRoot)
     : _isMobile(false)
@@ -86,16 +108,7 @@ RequestDetails::RequestDetails(const std::string &mobileURI)
 void RequestDetails::processURI()
 {
     // Poco::SyntaxException is thrown when the syntax is invalid.
-    Poco::URI uri(_uriString);
-    for (const auto& param : uri.getQueryParameters())
-    {
-        LOG_TRC("Decoding param [" << param.first << "] = [" << param.second 
<< "].");
-
-        std::string value;
-        Poco::URI::decode(param.second, value);
-
-        _params.emplace(param.first, value);
-    }
+    _params = getParams(_uriString);
 
     // First tokenize by '/' then by '?'.
     std::vector<StringToken> tokens;
@@ -169,6 +182,8 @@ void RequestDetails::processURI()
         _fields[Field::DocumentURI] = _uriString;
     }
 
+    _docUriParams = getParams(_fields[Field::DocumentURI]);
+
     _fields[Field::WOPISrc] = getParam("WOPISrc");
 
     // &compat=
diff --git a/wsd/RequestDetails.hpp b/wsd/RequestDetails.hpp
index e55f28535..93dd4ff50 100644
--- a/wsd/RequestDetails.hpp
+++ b/wsd/RequestDetails.hpp
@@ -119,6 +119,7 @@ private:
     StringVector _pathSegs;
     std::map<std::string, std::string> _params;
     std::map<Field, std::string> _fields;
+    std::map<std::string, std::string> _docUriParams;
 
     void processURI();
 
@@ -134,6 +135,8 @@ public:
     /// The DocumentURI, decoded. Doesn't contain WOPISrc or any other 
appendages.
     std::string getDocumentURI() const { return getField(Field::DocumentURI); }
 
+    const std::map<std::string, std::string>& getDocumentURIParams() const { 
return _docUriParams; }
+
     std::string getURI() const
     {
         return _uriString;
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to