[Libreoffice-commits] online.git: common/Session.hpp wsd/PrisonerSession.cpp wsd/PrisonerSession.hpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Mon Dec 12 05:26:09 UTC 2016
common/Session.hpp | 28 ----------------------------
wsd/PrisonerSession.cpp | 31 +++++++++++++++++++++++++++----
wsd/PrisonerSession.hpp | 3 +++
3 files changed, 30 insertions(+), 32 deletions(-)
New commits:
commit d8c8737597d056208af1bbc3f63a5cce838a6ca7
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Sun Dec 11 18:50:32 2016 -0500
loolwsd: move forwardToPeer into PrisonerSession
Change-Id: I771af0ea066d3d7cb16173861ae70dcc052122aa
Reviewed-on: https://gerrit.libreoffice.org/31888
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/common/Session.hpp b/common/Session.hpp
index 9873aad..fe0fc3b 100644
--- a/common/Session.hpp
+++ b/common/Session.hpp
@@ -94,34 +94,6 @@ protected:
_lastActivityTime = std::chrono::steady_clock::now();
}
- template <typename T>
- bool forwardToPeer(T& p, const char* buffer, int length, const bool binary)
- {
- const auto message = LOOLProtocol::getAbbreviatedMessage(buffer, length);
-
- auto peer = p.lock();
- if (!peer)
- {
- throw Poco::ProtocolException(getName() + ": no peer to forward to: [" + message + "].");
- }
- else if (peer->isCloseFrame())
- {
- LOG_TRC(getName() << ": peer began the closing handshake. Dropping forward message [" << message << "].");
- return true;
- }
- else if (peer->isHeadless())
- {
- // Fail silently and return as there is no actual websocket
- // connection in this case.
- LOG_INF(getName() << ": Headless peer, not forwarding message [" << message << "].");
- return true;
- }
-
- LOG_TRC(getName() << " -> " << peer->getName() << ": " << message);
- return binary ? peer->sendBinaryFrame(buffer, length)
- : peer->sendTextFrame(buffer, length);
- }
-
/// Internal lock shared with derived classes.
std::unique_lock<std::mutex> getLock()
{
diff --git a/wsd/PrisonerSession.cpp b/wsd/PrisonerSession.cpp
index bbfd902..9c31982 100644
--- a/wsd/PrisonerSession.cpp
+++ b/wsd/PrisonerSession.cpp
@@ -109,7 +109,7 @@ bool PrisonerSession::_handleInput(const char *buffer, int length)
errorKind == "passwordrequired:to-modify" ||
errorKind == "wrongpassword")
{
- forwardToPeer(_peer, buffer, length, isBinary);
+ forwardToPeer(peer, buffer, length, isBinary);
LOG_WRN("Document load failed: " << errorKind);
return false;
}
@@ -175,7 +175,7 @@ bool PrisonerSession::_handleInput(const char *buffer, int length)
_docBroker->setLoaded();
// Forward the status response to the client.
- return forwardToPeer(_peer, buffer, length, isBinary);
+ return forwardToPeer(peer, buffer, length, isBinary);
}
else if (tokens[0] == "commandvalues:")
{
@@ -242,7 +242,7 @@ bool PrisonerSession::_handleInput(const char *buffer, int length)
getTokenString(tokens[2], "char", text);
assert(firstLine.size() < static_cast<std::string::size_type>(length));
_docBroker->tileCache().saveRendering(font+text, "font", buffer + firstLine.size() + 1, length - firstLine.size() - 1);
- forwardToPeer(_peer, buffer, length, true);
+ forwardToPeer(peer, buffer, length, true);
return true;
}
}
@@ -257,8 +257,31 @@ bool PrisonerSession::_handleInput(const char *buffer, int length)
isBinary = buffer[length - 1] != '}' && firstLine.find('{') == std::string::npos;
// Forward everything else.
- forwardToPeer(_peer, buffer, length, isBinary);
+ forwardToPeer(peer, buffer, length, isBinary);
return true;
}
+bool PrisonerSession::forwardToPeer(const std::shared_ptr<ClientSession>& clientSession,
+ const char* buffer, int length, const bool binary)
+{
+ const auto message = LOOLProtocol::getAbbreviatedMessage(buffer, length);
+
+ if (clientSession->isCloseFrame())
+ {
+ LOG_TRC(getName() << ": peer began the closing handshake. Dropping forward message [" << message << "].");
+ return true;
+ }
+ else if (clientSession->isHeadless())
+ {
+ // Fail silently and return as there is no actual websocket
+ // connection in this case.
+ LOG_INF(getName() << ": Headless peer, not forwarding message [" << message << "].");
+ return true;
+ }
+
+ LOG_TRC(getName() << " -> " << clientSession->getName() << ": " << message);
+ return binary ? clientSession->sendBinaryFrame(buffer, length)
+ : clientSession->sendTextFrame(buffer, length);
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/wsd/PrisonerSession.hpp b/wsd/PrisonerSession.hpp
index 1518ab4..aee1266 100644
--- a/wsd/PrisonerSession.hpp
+++ b/wsd/PrisonerSession.hpp
@@ -30,6 +30,9 @@ private:
/// Handle messages from the Kit to the client.
virtual bool _handleInput(const char* buffer, int length) override;
+ bool forwardToPeer(const std::shared_ptr<ClientSession>& clientSession,
+ const char* buffer, int length, const bool binary);
+
private:
std::shared_ptr<DocumentBroker> _docBroker;
std::weak_ptr<ClientSession> _peer;
More information about the Libreoffice-commits
mailing list