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

Ashod Nakashian ashod.nakashian at collabora.co.uk
Sun Oct 16 22:14:18 UTC 2016


 loolwsd/ClientSession.cpp  |   26 +++++++++++---------------
 loolwsd/ClientSession.hpp  |    2 +-
 loolwsd/DocumentBroker.cpp |    5 ++---
 loolwsd/DocumentBroker.hpp |    2 +-
 4 files changed, 15 insertions(+), 20 deletions(-)

New commits:
commit d266d124dfb5383c113996d799d3efe8274e0a99
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sun Oct 16 13:43:44 2016 -0400

    loolwsd: argument cleanup
    
    Pass std::string instead of char* and length where
    a string is always constructed anyway. Also cleaner
    and safer code.
    
    Change-Id: I1c9341e2c81bbdb7adeb29d3fba59849b2617e95
    Reviewed-on: https://gerrit.libreoffice.org/29954
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/ClientSession.cpp b/loolwsd/ClientSession.cpp
index b46fe73..2aad600 100644
--- a/loolwsd/ClientSession.cpp
+++ b/loolwsd/ClientSession.cpp
@@ -172,7 +172,8 @@ bool ClientSession::_handleInput(const char *buffer, int length)
     }
     else if (tokens[0] == "status")
     {
-        return getStatus(buffer, length, docBroker);
+        assert(firstLine.size() == static_cast<size_t>(length));
+        return forwardToChild(firstLine, docBroker);
     }
     else if (tokens[0] == "tile")
     {
@@ -188,12 +189,12 @@ bool ClientSession::_handleInput(const char *buffer, int length)
         if ( (isReadOnly()) && tokens[0] != "downloadas" &&
              tokens[0] != "userinactive" && tokens[0] != "useractive")
         {
-            std::string dummyFrame = "dummymsg";
-            return forwardToChild(dummyFrame.c_str(), dummyFrame.size(), docBroker);
+            const std::string dummyFrame = "dummymsg";
+            return forwardToChild(dummyFrame, docBroker);
         }
         else if (tokens[0] != "requestloksession")
         {
-            return forwardToChild(buffer, length, docBroker);
+            return forwardToChild(std::string(buffer, length), docBroker);
         }
         else
         {
@@ -243,7 +244,7 @@ bool ClientSession::loadDocument(const char* /*buffer*/, int /*length*/, StringT
             oss << " options=" << _docOptions;
 
         const auto loadRequest = oss.str();
-        return forwardToChild(loadRequest.c_str(), loadRequest.size(), docBroker);
+        return forwardToChild(loadRequest, docBroker);
     }
     catch (const Poco::SyntaxException&)
     {
@@ -253,11 +254,6 @@ bool ClientSession::loadDocument(const char* /*buffer*/, int /*length*/, StringT
     return false;
 }
 
-bool ClientSession::getStatus(const char *buffer, int length, const std::shared_ptr<DocumentBroker>& docBroker)
-{
-    return forwardToChild(buffer, length, docBroker);
-}
-
 bool ClientSession::getCommandValues(const char *buffer, int length, StringTokenizer& tokens,
                                      const std::shared_ptr<DocumentBroker>& docBroker)
 {
@@ -273,7 +269,7 @@ bool ClientSession::getCommandValues(const char *buffer, int length, StringToken
         return sendTextFrame(cmdValues);
     }
 
-    return forwardToChild(buffer, length, docBroker);
+    return forwardToChild(std::string(buffer, length), docBroker);
 }
 
 bool ClientSession::getPartPageRectangles(const char *buffer, int length,
@@ -285,7 +281,7 @@ bool ClientSession::getPartPageRectangles(const char *buffer, int length,
         return sendTextFrame(partPageRectangles);
     }
 
-    return forwardToChild(buffer, length, docBroker);
+    return forwardToChild(std::string(buffer, length), docBroker);
 }
 
 bool ClientSession::sendFontRendering(const char *buffer, int length, StringTokenizer& tokens,
@@ -318,7 +314,7 @@ bool ClientSession::sendFontRendering(const char *buffer, int length, StringToke
         return sendBinaryFrame(output.data(), output.size());
     }
 
-    return forwardToChild(buffer, length, docBroker);
+    return forwardToChild(std::string(buffer, length), docBroker);
 }
 
 bool ClientSession::sendTile(const char * /*buffer*/, int /*length*/, StringTokenizer& tokens,
@@ -366,10 +362,10 @@ bool ClientSession::shutdownPeer(Poco::UInt16 statusCode)
     return false;
 }
 
-bool ClientSession::forwardToChild(const char *buffer, int length,
+bool ClientSession::forwardToChild(const std::string& message,
                                    const std::shared_ptr<DocumentBroker>& docBroker)
 {
-    return docBroker->forwardToChild(getId(), buffer, length);
+    return docBroker->forwardToChild(getId(), message);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/ClientSession.hpp b/loolwsd/ClientSession.hpp
index b645d58..201e7c1 100644
--- a/loolwsd/ClientSession.hpp
+++ b/loolwsd/ClientSession.hpp
@@ -81,7 +81,7 @@ private:
     bool sendFontRendering(const char *buffer, int length, Poco::StringTokenizer& tokens,
                            const std::shared_ptr<DocumentBroker>& docBroker);
 
-    bool forwardToChild(const char *buffer, int length,
+    bool forwardToChild(const std::string& message,
                         const std::shared_ptr<DocumentBroker>& docBroker);
 
 private:
diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index dceb1c5..624b2be 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -391,7 +391,7 @@ bool DocumentBroker::sendUnoSave(const bool dontSaveIfUnmodified)
         const auto saveArgs = oss.str();
         Log::trace(".uno:Save arguments: " + saveArgs);
         const auto command = "uno .uno:Save " + saveArgs;
-        forwardToChild(sessionIt.second->getId(), command.data(), command.size());
+        forwardToChild(sessionIt.second->getId(), command);
         return true;
     }
 
@@ -767,9 +767,8 @@ void DocumentBroker::setModified(const bool value)
     _isModified = value;
 }
 
-bool DocumentBroker::forwardToChild(const std::string& viewId, const char *buffer, int length)
+bool DocumentBroker::forwardToChild(const std::string& viewId, const std::string& message)
 {
-    const auto message = std::string(buffer, length);
     Log::trace() << "Forwarding payload to child [" << viewId << "]: " << message << Log::end;
 
     const auto it = _sessions.find(viewId);
diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 7972903..f9ef407 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -258,7 +258,7 @@ public:
     bool handleInput(const std::vector<char>& payload);
 
     /// Forward a message from client session to its respective child session.
-    bool forwardToChild(const std::string& viewId, const char *buffer, int length);
+    bool forwardToChild(const std::string& viewId, const std::string& message);
 
     int getRenderedTileCount() { return _debugRenderedTileCount; }
 


More information about the Libreoffice-commits mailing list