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

Ashod Nakashian ashod.nakashian at collabora.co.uk
Thu Jan 26 02:12:18 UTC 2017


 wsd/DocumentBroker.cpp |   80 +++++++++++++++++++++----------------------------
 wsd/DocumentBroker.hpp |    3 +
 2 files changed, 37 insertions(+), 46 deletions(-)

New commits:
commit f73a17c759f1628db26ec3e8606b5ab799b1acf3
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sun Jan 22 23:18:37 2017 -0500

    wsd: use Message objects to handle kit responses
    
    Change-Id: Ifc9c53ead8d87e9aebfd8c60442a726de5270cc5
    Reviewed-on: https://gerrit.libreoffice.org/33440
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index fb19ca4..7b3ee4c 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -716,39 +716,42 @@ void DocumentBroker::alertAllUsers(const std::string& msg)
 
 bool DocumentBroker::handleInput(const std::vector<char>& payload)
 {
-    const auto msg = LOOLProtocol::getAbbreviatedMessage(payload);
+    auto message = std::make_shared<Message>(payload.data(), payload.size(), Message::Dir::Out);
+    const auto& msg = message->abbr();
     LOG_TRC("DocumentBroker handling child message: [" << msg << "].");
 
     LOOLWSD::dumpOutgoingTrace(getJailId(), "0", msg);
 
-    const auto command = LOOLProtocol::getFirstToken(msg);
-    if (command == "tile:")
+    if (LOOLProtocol::getFirstToken(message->forwardToken(), '-') == "client")
     {
-        handleTileResponse(payload);
-    }
-    else if (command == "tilecombine:")
-    {
-        handleTileCombinedResponse(payload);
-    }
-    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);
-        std::string cmd, kind;
-        LOOLProtocol::getTokenString(tokens, "cmd", cmd);
-        assert(cmd != "");
-        LOOLProtocol::getTokenString(tokens, "kind", kind);
-        assert(kind != "");
-        Util::alertAllUsers(cmd, kind);
+        forwardToClient(message);
     }
     else
     {
-        LOG_ERR("Unexpected message: [" << msg << "].");
-        return false;
+        const auto& command = message->firstToken();
+        if (command == "tile:")
+        {
+            handleTileResponse(payload);
+        }
+        else if (command == "tilecombine:")
+        {
+            handleTileCombinedResponse(payload);
+        }
+        else if (command == "errortoall:")
+        {
+            LOG_CHECK_RET(message->tokens().size() == 3, false);
+            std::string cmd, kind;
+            LOOLProtocol::getTokenString((*message)[1], "cmd", cmd);
+            LOG_CHECK_RET(cmd != "", false);
+            LOOLProtocol::getTokenString((*message)[2], "kind", kind);
+            LOG_CHECK_RET(kind != "", false);
+            Util::alertAllUsers(cmd, kind);
+        }
+        else
+        {
+            LOG_ERR("Unexpected message: [" << msg << "].");
+            return false;
+        }
     }
 
     return true;
@@ -1002,37 +1005,24 @@ bool DocumentBroker::forwardToChild(const std::string& viewId, const std::string
     return false;
 }
 
-bool DocumentBroker::forwardToClient(const std::string& prefix, const std::vector<char>& payload)
+bool DocumentBroker::forwardToClient(const std::shared_ptr<Message>& payload)
 {
-    assert(payload.size() > prefix.size());
-
-    // Remove the prefix and trim.
-    size_t index = prefix.size();
-    for ( ; index < payload.size(); ++index)
-    {
-        if (payload[index] != ' ')
-        {
-            break;
-        }
-    }
-
-    auto data = payload.data() + index;
-    auto size = payload.size() - index;
-    const auto message = getAbbreviatedMessage(data, size);
-    LOG_TRC("Forwarding payload to " << prefix << ' ' << message);
+    const std::string& msg = payload->abbr();
+    const std::string& prefix = payload->forwardToken();
+    LOG_TRC("Forwarding payload to [" << prefix << "]: " << msg);
 
     std::string name;
     std::string sid;
-    if (LOOLProtocol::parseNameValuePair(prefix, name, sid, '-') && name == "client")
+    if (LOOLProtocol::parseNameValuePair(payload->forwardToken(), name, sid, '-') && name == "client")
     {
         const auto it = _sessions.find(sid);
         if (it != _sessions.end())
         {
-            return it->second->handleKitToClientMessage(data, size);
+            return it->second->handleKitToClientMessage(payload->data().data(), payload->size());
         }
         else
         {
-            LOG_WRN("Client session [" << sid << "] not found to forward message: " << message);
+            LOG_WRN("Client session [" << sid << "] not found to forward message: " << msg);
         }
     }
     else
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 27c4916..8c416ba 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -35,6 +35,7 @@
 class DocumentBroker;
 class StorageBase;
 class TileCache;
+class Message;
 
 /// Represents a new LOK child that is read
 /// to host a document.
@@ -313,7 +314,7 @@ private:
     bool saveToStorage();
 
     /// Forward a message from child session to its respective client session.
-    bool forwardToClient(const std::string& prefix, const std::vector<char>& payload);
+    bool forwardToClient(const std::shared_ptr<Message>& payload);
 
 private:
     const Poco::URI _uriPublic;


More information about the Libreoffice-commits mailing list