[Libreoffice-commits] online.git: common/Protocol.hpp test/WhiteBoxTests.cpp wsd/README.vars wsd/Storage.cpp
Pranav Kant
pranavk at collabora.co.uk
Wed May 17 11:01:43 UTC 2017
common/Protocol.hpp | 14 +++++++-------
test/WhiteBoxTests.cpp | 10 ++++++++++
wsd/README.vars | 4 ++++
wsd/Storage.cpp | 23 ++++++++++++++++++++++-
4 files changed, 43 insertions(+), 8 deletions(-)
New commits:
commit 8a02e7a8fa818b2e7fe8e45aefbba0c8ff7e7610
Author: Pranav Kant <pranavk at collabora.co.uk>
Date: Wed May 17 14:18:51 2017 +0530
wsd: Debugging environment vars to debug storages
Also, extend the LOOLProtocol::tokenize to accept a custom delimeter.
Change-Id: I7f789e703c5c8d2ad325b3dd149ba888c722f5f3
diff --git a/common/Protocol.hpp b/common/Protocol.hpp
index c4048742..cae54d46 100644
--- a/common/Protocol.hpp
+++ b/common/Protocol.hpp
@@ -96,7 +96,7 @@ namespace LOOLProtocol
/// Tokenize space-delimited values until we hit new-line or the end.
inline
- std::vector<std::string> tokenize(const char* data, const size_t size)
+ std::vector<std::string> tokenize(const char* data, const size_t size, const char delimeter = ' ')
{
std::vector<std::string> tokens;
if (size == 0 || data == nullptr)
@@ -108,22 +108,22 @@ namespace LOOLProtocol
const char* end = data;
for (size_t i = 0; i < size && data[i] != '\n'; ++i, ++end)
{
- if (data[i] == ' ')
+ if (data[i] == delimeter)
{
- if (start != end && *start != ' ')
+ if (start != end && *start != delimeter)
{
tokens.emplace_back(start, end);
}
start = end;
}
- else if (*start == ' ')
+ else if (*start == delimeter)
{
++start;
}
}
- if (start != end && *start != ' ' && *start != '\n')
+ if (start != end && *start != delimeter && *start != '\n')
{
tokens.emplace_back(start, end);
}
@@ -132,9 +132,9 @@ namespace LOOLProtocol
}
inline
- std::vector<std::string> tokenize(const std::string& s)
+ std::vector<std::string> tokenize(const std::string& s, const char delimeter = ' ')
{
- return tokenize(s.data(), s.size());
+ return tokenize(s.data(), s.size(), delimeter);
}
inline bool getTokenIntegerFromMessage(const std::string& message, const std::string& name, int& value)
diff --git a/test/WhiteBoxTests.cpp b/test/WhiteBoxTests.cpp
index effb7659..de4e79aa 100644
--- a/test/WhiteBoxTests.cpp
+++ b/test/WhiteBoxTests.cpp
@@ -218,6 +218,16 @@ void WhiteBoxTests::testTokenizer()
CPPUNIT_ASSERT_EQUAL(std::string("tilewidth=3840"), tokens[6]);
CPPUNIT_ASSERT_EQUAL(std::string("tileheight=3840"), tokens[7]);
CPPUNIT_ASSERT_EQUAL(std::string("ver=-1"), tokens[8]);
+
+ // With custom delimeters
+ tokens = LOOLProtocol::tokenize(std::string("ABC:DEF"), ':');
+ CPPUNIT_ASSERT_EQUAL(std::string("ABC"), tokens[0]);
+ CPPUNIT_ASSERT_EQUAL(std::string("DEF"), tokens[1]);
+
+ tokens = LOOLProtocol::tokenize(std::string("ABC,DEF,XYZ"), ',');
+ CPPUNIT_ASSERT_EQUAL(std::string("ABC"), tokens[0]);
+ CPPUNIT_ASSERT_EQUAL(std::string("DEF"), tokens[1]);
+ CPPUNIT_ASSERT_EQUAL(std::string("XYZ"), tokens[2]);
}
void WhiteBoxTests::testReplace()
diff --git a/wsd/README.vars b/wsd/README.vars
index b55672ab..862465fd 100644
--- a/wsd/README.vars
+++ b/wsd/README.vars
@@ -31,3 +31,7 @@ LOOL_WS_DELAY <base delay in milliseconds in websocket communication>
LOOL_WS_JITTER <jitter in milliseconds for websocket communication>
Maximum Jitter in millseconds which is added to delay in
websocket communication.
+
+LOOL_STORAGE_COOKIE <key:value>
+ Sets a cookie to all the requests made to storage. This is extremely useful for
+ debugging WOPI implementations. For eg: Using XDebug with OwnCloud/NextCloud.
diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp
index bdaeab56..521479a2 100644
--- a/wsd/Storage.cpp
+++ b/wsd/Storage.cpp
@@ -26,6 +26,7 @@
#include <Poco/Net/HTTPRequest.h>
#include <Poco/Net/HTTPResponse.h>
#include <Poco/Net/HTTPSClientSession.h>
+#include <Poco/Net/NameValueCollection.h>
#include <Poco/Net/NetworkInterface.h>
#include <Poco/Net/SSLManager.h>
#include <Poco/StreamCopier.h>
@@ -437,6 +438,24 @@ void setQueryParameter(Poco::URI& uriObject, const std::string& key, const std::
uriObject.addQueryParameter(key, value);
}
+
+void addStorageDebugCookie(Poco::Net::HTTPRequest& request)
+{
+#if ENABLE_DEBUG
+ if (std::getenv("LOOL_STORAGE_COOKIE"))
+ {
+ Poco::Net::NameValueCollection nvcCookies;
+ std::vector<std::string> cookieTokens = LOOLProtocol::tokenize(std::string(std::getenv("LOOL_STORAGE_COOKIE")), ':');
+ if (cookieTokens.size() == 2)
+ {
+ nvcCookies.add(cookieTokens[0], cookieTokens[1]);
+ request.setCookies(nvcCookies);
+ LOG_TRC("Added storage debug cookie [" << cookieTokens[0] << "=" << cookieTokens[1] << "].");
+ }
+ }
+#endif
+}
+
} // anonymous namespace
std::unique_ptr<WopiStorage::WOPIFileInfo> WopiStorage::getWOPIFileInfo(Poco::URI uriObject, const std::string& accessToken)
@@ -455,6 +474,7 @@ std::unique_ptr<WopiStorage::WOPIFileInfo> WopiStorage::getWOPIFileInfo(Poco::UR
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, uriObject.getPathAndQuery(), Poco::Net::HTTPMessage::HTTP_1_1);
request.set("User-Agent", WOPI_AGENT_STRING);
+ addStorageDebugCookie(request);
psession->sendRequest(request);
Poco::Net::HTTPResponse response;
@@ -573,6 +593,7 @@ std::string WopiStorage::loadStorageFileToLocal(const std::string& accessToken)
Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, uriObject.getPathAndQuery(), Poco::Net::HTTPMessage::HTTP_1_1);
request.set("User-Agent", WOPI_AGENT_STRING);
+ addStorageDebugCookie(request);
psession->sendRequest(request);
Poco::Net::HTTPResponse response;
@@ -635,7 +656,7 @@ StorageBase::SaveResult WopiStorage::saveLocalFileToStorage(const std::string& a
request.set("X-WOPI-Override", "PUT");
request.setContentType("application/octet-stream");
request.setContentLength(size);
-
+ addStorageDebugCookie(request);
std::ostream& os = psession->sendRequest(request);
std::ifstream ifs(_jailedFilePath);
Poco::StreamCopier::copyStream(ifs, os);
More information about the Libreoffice-commits
mailing list