loolwsd/ClientSession.cpp  |   14 +++++++-------
 loolwsd/DocumentBroker.cpp |    9 ++++++---
 loolwsd/DocumentBroker.hpp |    2 +-
 loolwsd/LOOLKit.cpp        |   12 +++++++-----
 4 files changed, 21 insertions(+), 16 deletions(-)

New commits:
commit 38cbfa96b0f3a197bf7445d4e32c64ac55be2fd0
Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk>
Date:   Sat Oct 8 18:21:35 2016 -0400

    loolwsd: forward client message to child via the process WS
    
    Change-Id: I368e727b79b44b509ba49ed30218b8368c5eaad8
    Reviewed-on: https://gerrit.libreoffice.org/29637
    Reviewed-by: Ashod Nakashian <ashnak...@gmail.com>
    Tested-by: Ashod Nakashian <ashnak...@gmail.com>

diff --git a/loolwsd/ClientSession.cpp b/loolwsd/ClientSession.cpp
index c4cfcdf..e4623ff 100644
--- a/loolwsd/ClientSession.cpp
+++ b/loolwsd/ClientSession.cpp
@@ -188,11 +188,11 @@ bool ClientSession::_handleInput(const char *buffer, int 
length)
              tokens[0] != "userinactive" && tokens[0] != "useractive")
         {
             std::string dummyFrame = "dummymsg";
-            return forwardToPeer(_peer, dummyFrame.c_str(), dummyFrame.size(), 
false);
+            return forwardToChild(dummyFrame.c_str(), dummyFrame.size());
         }
         else if (tokens[0] != "requestloksession")
         {
-            return forwardToPeer(_peer, buffer, length, false);
+            return forwardToChild(buffer, length);
         }
         else
         {
@@ -241,7 +241,7 @@ bool ClientSession::loadDocument(const char* /*buffer*/, 
int /*length*/, StringT
             oss << " options=" << _docOptions;
 
         const auto loadRequest = oss.str();
-        return forwardToPeer(_peer, loadRequest.c_str(), loadRequest.size(), 
false);
+        return forwardToChild(loadRequest.c_str(), loadRequest.size());
     }
     catch (const Poco::SyntaxException&)
     {
@@ -253,7 +253,7 @@ bool ClientSession::loadDocument(const char* /*buffer*/, 
int /*length*/, StringT
 
 bool ClientSession::getStatus(const char *buffer, int length)
 {
-    return forwardToPeer(_peer, buffer, length, false);
+    return forwardToChild(buffer, length);
 }
 
 bool ClientSession::getCommandValues(const char *buffer, int length, 
StringTokenizer& tokens)
@@ -270,7 +270,7 @@ bool ClientSession::getCommandValues(const char *buffer, 
int length, StringToken
         return sendTextFrame(cmdValues);
     }
 
-    return forwardToPeer(_peer, buffer, length, false);
+    return forwardToChild(buffer, length);
 }
 
 bool ClientSession::getPartPageRectangles(const char *buffer, int length)
@@ -281,7 +281,7 @@ bool ClientSession::getPartPageRectangles(const char 
*buffer, int length)
         return sendTextFrame(partPageRectangles);
     }
 
-    return forwardToPeer(_peer, buffer, length, false);
+    return forwardToChild(buffer, length);
 }
 
 bool ClientSession::sendFontRendering(const char *buffer, int length, 
StringTokenizer& tokens)
@@ -313,7 +313,7 @@ bool ClientSession::sendFontRendering(const char *buffer, 
int length, StringToke
         return sendBinaryFrame(output.data(), output.size());
     }
 
-    return forwardToPeer(_peer, buffer, length, false);
+    return forwardToChild(buffer, length);
 }
 
 bool ClientSession::sendTile(const char * /*buffer*/, int /*length*/, 
StringTokenizer& tokens)
diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index e2e5423..6c6cbb8 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -725,12 +725,15 @@ void DocumentBroker::setModified(const bool value)
 bool DocumentBroker::forwardToChild(const std::string& viewId, const char 
*buffer, int length)
 {
     const auto message = std::string(buffer, length);
-    Log::trace() << "Forwarding payload to child [" << viewId << "]: " << 
message << Log::end;
+    Log::warn() << "Forwarding payload to child [" << viewId << "]: " << 
message << Log::end;
 
     const auto it = _sessions.find(viewId);
     if (it != _sessions.end())
     {
-        return it->second->sendTextFrame("child-" + viewId + ' ' + message);
+        const auto msg = "child-" + viewId + ' ' + message;
+        Log::debug("DocBroker to Child: " + msg);
+        _childProcess->getWebSocket()->sendFrame(msg.data(), msg.size());
+        return true;
     }
     else
     {
@@ -743,7 +746,7 @@ bool DocumentBroker::forwardToChild(const std::string& 
viewId, const char *buffe
 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);
+    Log::warn("Forwarding payload to client: " + message);
 
     std::string name;
     std::string sid;
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index bd0f7f3..66ec29c 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -241,7 +241,7 @@ 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.
+    /// Forward a message from child session to its respective client session.
     bool forwardToClient(const std::string& prefix, const std::vector<char>& 
payload);
 
 private:
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index a2fbf97..41d39fc 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -1231,14 +1231,15 @@ private:
         Log::trace("Forwarding payload to client: " + message);
 
         std::string name;
-        int viewId = -1;
-        if (LOOLProtocol::parseNameIntegerPair(prefix, name, viewId, '-') && 
name == "child")
+        std::string value;
+        if (LOOLProtocol::parseNameValuePair(prefix, name, value, '-') && name 
== "child")
         {
+            const unsigned viewId = Util::decodeId(value);
             const auto it = _connections.find(viewId);
-            if (it != _connections.end() && it->second->isRunning())
+            if (it != _connections.end())
             {
                 auto session = it->second->getSession();
-                if (session && session->getViewId() == viewId)
+                if (session)
                 {
                     return session->handleInput(message.data(), 
message.size());
                 }
@@ -1613,7 +1614,8 @@ void lokit_main(const std::string& childRoot,
                             Log::debug("CreateSession failed.");
                         }
                     }
-                    else if (tokens[0] == "tile" || tokens[0] == "tilecombine" 
|| tokens[0] == "canceltiles")
+                    else if (tokens[0] == "tile" || tokens[0] == "tilecombine" 
|| tokens[0] == "canceltiles" ||
+                             LOOLProtocol::getFirstToken(tokens[0], '-') == 
"child")
                     {
                         if (document)
                         {
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to