[Libreoffice-commits] online.git: 3 commits - loolwsd/LOOLSession.cpp loolwsd/LOOLSession.hpp loolwsd/LOOLWSD.cpp loolwsd/test
Pranav Kant
pranavk at collabora.co.uk
Thu Jul 21 07:25:25 UTC 2016
loolwsd/LOOLSession.cpp | 3 +-
loolwsd/LOOLSession.hpp | 16 ++++++++++++-
loolwsd/LOOLWSD.cpp | 7 ++++-
loolwsd/test/integration-http-server.cpp | 37 +++++++++++++++++++++++++++++++
4 files changed, 59 insertions(+), 4 deletions(-)
New commits:
commit f684e505da11f0c800910cafde7d49de0bb5a568
Author: Pranav Kant <pranavk at collabora.co.uk>
Date: Thu Jul 21 12:52:14 2016 +0530
loolwsd: Restore test for convert-to API
This got accidently removed in
8e266391f13a7daa3b074ba2ae33ac4958d39ae0
Change-Id: I3d03b1b75f05f5855397e46a7fccc30c794ca151
diff --git a/loolwsd/test/integration-http-server.cpp b/loolwsd/test/integration-http-server.cpp
index abc78ff..390ea55 100644
--- a/loolwsd/test/integration-http-server.cpp
+++ b/loolwsd/test/integration-http-server.cpp
@@ -42,6 +42,7 @@ class HTTPServerTest : public CPPUNIT_NS::TestFixture
CPPUNIT_TEST(testLoleafletPost);
CPPUNIT_TEST(testScriptsAndLinksGet);
CPPUNIT_TEST(testScriptsAndLinksPost);
+ CPPUNIT_TEST(testConvertTo);
CPPUNIT_TEST_SUITE_END();
@@ -52,6 +53,7 @@ class HTTPServerTest : public CPPUNIT_NS::TestFixture
void testLoleafletPost();
void testScriptsAndLinksGet();
void testScriptsAndLinksPost();
+ void testConvertTo();
void testNoExtraLoolKitsLeft();
@@ -235,6 +237,41 @@ void HTTPServerTest::testScriptsAndLinksPost()
assertHTTPFilesExist(_uri, link, html);
}
+void HTTPServerTest::testConvertTo()
+{
+ const auto srcPath = Util::getTempFilePath(TDOC, "hello.odt");
+ std::unique_ptr<Poco::Net::HTTPClientSession> session(helpers::createSession(_uri));
+
+ Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_POST, "/lool/convert-to");
+ Poco::Net::HTMLForm form;
+ form.setEncoding(Poco::Net::HTMLForm::ENCODING_MULTIPART);
+ form.set("format", "txt");
+ form.addPart("data", new Poco::Net::FilePartSource(srcPath));
+ form.prepareSubmit(request);
+ // If this results in a Poco::Net::ConnectionRefusedException, loolwsd is not running.
+ form.write(session->sendRequest(request));
+
+ Poco::Net::HTTPResponse response;
+ std::stringstream actualStream;
+ // receiveResponse() resulted in a Poco::Net::NoMessageException.
+ std::istream& responseStream = session->receiveResponse(response);
+ Poco::StreamCopier::copyStream(responseStream, actualStream);
+
+ std::ifstream fileStream(TDOC "/hello.txt");
+ std::stringstream expectedStream;
+ expectedStream << fileStream.rdbuf();
+
+ // Remove the temp files.
+ Util::removeFile(srcPath);
+
+ // In some cases the result is prefixed with (the UTF-8 encoding of) the Unicode BOM
+ // (U+FEFF). Skip that.
+ std::string actualString = actualStream.str();
+ if (actualString.size() > 3 && actualString[0] == '\xEF' && actualString[1] == '\xBB' && actualString[2] == '\xBF')
+ actualString = actualString.substr(3);
+ CPPUNIT_ASSERT_EQUAL(expectedStream.str(), actualString);
+}
+
void HTTPServerTest::testNoExtraLoolKitsLeft()
{
const auto countNow = countLoolKitProcesses(InitialLoolKitCount);
commit 39645c974d38c9494ec773ac493b2b7590e803fd
Author: Pranav Kant <pranavk at collabora.co.uk>
Date: Thu Jul 21 12:33:14 2016 +0530
loolwsd: Fix convert-to regression; fix incorrect filepath formed
Regressed with 886af28bc2f6d1d27bf78de09978f3858d2db705
Poco::URI::encode appends to given string, and encodedTo already
had content leading to incorrect path. Use a new std::string variable.
Change-Id: Ia72ff60ed9cf7f14ff649416a2ceeeda13ff6197
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index fd939a4..5e01803 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -435,8 +435,9 @@ private:
if (!resultURL.getPath().empty())
{
const std::string mimeType = "application/octet-stream";
- URI::encode(resultURL.getPath(), "", encodedTo);
- response.sendFile(encodedTo, mimeType);
+ std::string encodedFilePath;
+ URI::encode(resultURL.getPath(), "", encodedFilePath);
+ response.sendFile(encodedFilePath, mimeType);
sent = true;
}
commit 9417ec839cde784ff1ec194175387fc125d14734
Author: Pranav Kant <pranavk at collabora.co.uk>
Date: Thu Jul 21 11:46:43 2016 +0530
loolwsd: Introduce headless peer;fix convert-to API partially
Convert-to API got broken in
80786cc79d4197fef6e58b2f8a0d5096b74196d6
In case of convert-to API, there is no actual client facing
websocket connection (and we use an invalid websocket
connection). So, when prisoner session tries to forward messages to
client it would fail as we have now started to propagate errors
from forwardToPeer.
Introduce a headless (without an actual client) peer mode, and
fail silently when someone tries to forward messages to such a peer.
Change-Id: I8a9f93f798dca9fea45c41e99bf373cd23d32e2c
diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp
index c2b80f8..c72ae4d 100644
--- a/loolwsd/LOOLSession.cpp
+++ b/loolwsd/LOOLSession.cpp
@@ -61,7 +61,8 @@ LOOLSession::LOOLSession(const std::string& id, const Kind kind,
_isCloseFrame(false),
_disconnected(false),
_isActive(true),
- _lastActivityTime(std::chrono::steady_clock::now())
+ _lastActivityTime(std::chrono::steady_clock::now()),
+ _isHeadless(false)
{
// Only a post request can have a null ws.
if (_kind != Kind::ToClient)
diff --git a/loolwsd/LOOLSession.hpp b/loolwsd/LOOLSession.hpp
index 5746d38..3d6e3f3 100644
--- a/loolwsd/LOOLSession.hpp
+++ b/loolwsd/LOOLSession.hpp
@@ -75,6 +75,9 @@ public:
Kind getKind() const { return _kind; }
+ void setHeadless(bool val) { _isHeadless = val; }
+ bool isHeadless() const { return _isHeadless; }
+
protected:
LOOLSession(const std::string& id, const Kind kind,
std::shared_ptr<Poco::Net::WebSocket> ws);
@@ -109,6 +112,13 @@ protected:
Log::trace(getName() + ": peer began the closing handshake. Dropping forward message [" + message + "].");
return false;
}
+ else if (peer->isHeadless())
+ {
+ // Fail silently and return as there is no actual websocket
+ // connection in this case.
+ Log::info(getName() + ": Ignoring forward message due to peer being headless");
+ return true;
+ }
Log::trace(getName() + " -> " + peer->getName() + ": " + message);
return peer->sendBinaryFrame(buffer, length);
@@ -149,7 +159,6 @@ protected:
// Whether websocket received close frame. Closing Handshake
std::atomic<bool> _isCloseFrame;
-
private:
virtual bool _handleInput(const char *buffer, int length) = 0;
@@ -166,6 +175,11 @@ private:
std::chrono::steady_clock::time_point _lastActivityTime;
+ // Whether it is dummy session
+ // For eg. In case of convert-to requests (HTTP Post), there is no actual websocket
+ // connection on client side
+ bool _isHeadless;
+
std::mutex _mutex;
static constexpr auto InactivityThresholdMS = 120 * 1000;
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 3fe3c96..fd939a4 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -399,6 +399,8 @@ private:
// Load the document.
std::shared_ptr<WebSocket> ws;
auto session = std::make_shared<ClientSession>(id, ws, docBroker, nullptr);
+ // There is no actual client websocket connnection here
+ session->setHeadless(true);
// Request the child to connect to us and add this session.
auto sessionsCount = docBroker->addSession(session);
More information about the Libreoffice-commits
mailing list