diff options
author | Pranam Lashkari <lpranam@collabora.com> | 2019-11-13 15:08:14 +0530 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2019-11-15 14:54:29 +0100 |
commit | e95413d151c3f0d9476063c8520dd477342ed235 (patch) | |
tree | 5eee2b3f9ef2f0def0a4118109841336141fd21f /common | |
parent | 1ed89ae2200ddbe591193079a597986c5c5f0dc6 (diff) |
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@collabora.com>
Tested-by: Jan Holesovsky <kendy@collabora.com>
Diffstat (limited to 'common')
-rw-r--r-- | common/Authorization.cpp | 29 | ||||
-rw-r--r-- | common/IoUtil.cpp | 1 | ||||
-rw-r--r-- | common/Session.hpp | 1 |
3 files changed, 19 insertions, 12 deletions
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" |