[Libreoffice-commits] online.git: loolwsd/DocumentBroker.cpp loolwsd/DocumentBroker.hpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Mon Oct 10 06:20:46 UTC 2016


 loolwsd/DocumentBroker.cpp |   38 +++++++++++++++++++++++++++++++++++---
 loolwsd/DocumentBroker.hpp |    3 +++
 2 files changed, 38 insertions(+), 3 deletions(-)

New commits:
commit f17ff9c1d9d3081251f5341a5954161dd548f450
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sat Oct 8 13:13:23 2016 -0400

    loolwsd: forward client messages to the respective client's WS
    
    Change-Id: Ie28223f985a7f24a7569300b846432bf77813ab0
    Reviewed-on: https://gerrit.libreoffice.org/29634
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 896e7e4..e8bab09 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -465,15 +465,20 @@ bool DocumentBroker::handleInput(const std::vector<char>& payload)
 
     LOOLWSD::dumpOutgoingTrace(getJailId(), "0", msg);
 
-    if (msg.find("tile:") == 0)
+    const auto command = LOOLProtocol::getFirstToken(msg);
+    if (command == "tile:")
     {
         handleTileResponse(payload);
     }
-    else if (msg.find("tilecombine:") == 0)
+    else if (command == "tilecombine:")
     {
        handleTileCombinedResponse(payload);
     }
-    else if (msg.find("errortoall:") == 0)
+    else if (LOOLProtocol::getFirstToken(command, '-') == "client")
+    {
+        forwardToClient(command, payload);
+    }
+    else if (command == "errortoall:")
     {
         StringTokenizer tokens(msg, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
         assert(tokens.count() == 3);
@@ -717,4 +722,31 @@ void DocumentBroker::setModified(const bool value)
     _isModified = value;
 }
 
+bool DocumentBroker::forwardToClient(const std::string& prefix, const std::vector<char>& payload)
+{
+    const std::string message(payload.data() + prefix.size(), payload.size() - prefix.size());
+    Log::trace("Forwarding payload to client: " + message);
+
+    std::string name;
+    std::string sid;
+    if (LOOLProtocol::parseNameValuePair(prefix, name, sid, '-') && name == "client")
+    {
+        const auto it = _sessions.find(sid);
+        if (it != _sessions.end())
+        {
+            return it->second->sendTextFrame(message);
+        }
+        else
+        {
+            Log::warn() << "Client session [" << sid << "] not found to forward message: " << message << Log::end;
+        }
+    }
+    else
+    {
+        Log::error("Failed to parse prefix of forward-to-client message: " + message);
+    }
+
+    return false;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 4909e34..80e93b2 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -238,6 +238,9 @@ private:
     /// Saves the document to Storage (assuming LO Core saved to local copy).
     bool saveToStorage();
 
+    /// Forward a message from child process to a certain client.
+    bool forwardToClient(const std::string& prefix, const std::vector<char>& payload);
+
 private:
     const Poco::URI _uriPublic;
     const std::string _docKey;


More information about the Libreoffice-commits mailing list