[Libreoffice-commits] online.git: common/Authorization.cpp common/IoUtil.cpp common/Session.hpp

Pranam Lashkari (via logerrit) logerrit at kemper.freedesktop.org
Fri Nov 15 13:54:47 UTC 2019


 common/Authorization.cpp |   29 +++++++++++++++++++----------
 common/IoUtil.cpp        |    1 -
 common/Session.hpp       |    1 -
 3 files changed, 19 insertions(+), 12 deletions(-)

New commits:
commit e95413d151c3f0d9476063c8520dd477342ed235
Author:     Pranam Lashkari <lpranam at collabora.com>
AuthorDate: Wed Nov 13 15:08:14 2019 +0530
Commit:     Jan Holesovsky <kendy at collabora.com>
CommitDate: Fri Nov 15 14:54:29 2019 +0100

    killpoco: removed StringTokenizer from common directory
    
    removed use of Poco::StringTokenizer from the common directory
    used LOOLProtocol::tokenize and std::vecor<std::string>
    
    regex is used in Authorization.cpp due to limitation of toeknize mathod
    regular expression helps to keep the original intention of the code
    
    Change-Id: Ic87597d8b30cb385000f983389a57dc5d2533d98
    Reviewed-on: https://gerrit.libreoffice.org/82575
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/common/Authorization.cpp b/common/Authorization.cpp
index 20e77acba..dce34abb0 100644
--- a/common/Authorization.cpp
+++ b/common/Authorization.cpp
@@ -10,11 +10,11 @@
 #include <config.h>
 
 #include "Authorization.hpp"
+#include "Protocol.hpp"
 
 #include <cstdlib>
 #include <cassert>
-
-#include <Poco/StringTokenizer.h>
+#include <regex>
 
 void Authorization::authorizeURI(Poco::URI& uri) const
 {
@@ -50,19 +50,28 @@ void Authorization::authorizeRequest(Poco::Net::HTTPRequest& request) const
             // there might be more headers in here; like
             //   Authorization: Basic ....
             //   X-Something-Custom: Huh
-            Poco::StringTokenizer tokens(_data, "\n\r", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM);
+            // Regular expression evaluates and finds "\n\r" and tokenizes accordingly
+            std::vector<std::string> tokens(LOOLProtocol::tokenize(_data, std::regex(R"(\n\r)"), /*skipEmpty =*/ true));
             for (const auto& token : tokens)
             {
-                size_t i = token.find_first_of(':');
-                if (i != std::string::npos)
+                size_t separator = token.find_first_of(':');
+                if (separator != std::string::npos)
                 {
-                    size_t separator = i;
-                    for (++i; i < token.length() && token[i] == ' ';)
-                        ++i;
+                    size_t headerStart = token.find_first_not_of(' ', 0);
+                    size_t headerEnd = token.find_last_not_of(' ', separator - 1);
+
+                    size_t valueStart = token.find_first_not_of(' ', separator + 1);
+                    size_t valueEnd = token.find_last_not_of(' ');
 
                     // set the header
-                    if (i < token.length())
-                        request.set(token.substr(0, separator), token.substr(i));
+                    if (headerStart != std::string::npos && headerEnd != std::string::npos &&
+                            valueStart != std::string::npos && valueEnd != std::string::npos)
+                    {
+                        size_t headerLength = headerEnd - headerStart + 1;
+                        size_t valueLength = valueEnd - valueStart + 1;
+
+                        request.set(token.substr(headerStart, headerLength), token.substr(valueStart, valueLength));
+                    }
                 }
             }
             break;
diff --git a/common/IoUtil.cpp b/common/IoUtil.cpp
index d2503d96d..209d0f5d3 100644
--- a/common/IoUtil.cpp
+++ b/common/IoUtil.cpp
@@ -23,7 +23,6 @@
 
 #include <Poco/Net/NetException.h>
 #include <Poco/Net/Socket.h>
-#include <Poco/StringTokenizer.h>
 #include <Poco/Thread.h>
 #include <Poco/URI.h>
 
diff --git a/common/Session.hpp b/common/Session.hpp
index 623a9d3c7..d06d18a44 100644
--- a/common/Session.hpp
+++ b/common/Session.hpp
@@ -19,7 +19,6 @@
 #include <Poco/Buffer.h>
 #include <Poco/Path.h>
 #include <Poco/Process.h>
-#include <Poco/StringTokenizer.h>
 #include <Poco/Types.h>
 
 #include "Protocol.hpp"


More information about the Libreoffice-commits mailing list