[Libreoffice-commits] online.git: loleaflet/src loolwsd/ChildProcessSession.cpp loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp loolwsd/protocol.txt loolwsd/test

Miklos Vajna vmiklos at collabora.co.uk
Fri Jan 15 05:44:23 PST 2016


 loleaflet/src/layer/tile/TileLayer.js |    2 +-
 loolwsd/ChildProcessSession.cpp       |   11 ++++++-----
 loolwsd/LOOLKit.cpp                   |   12 ++++++++----
 loolwsd/LOOLWSD.cpp                   |    6 +++---
 loolwsd/protocol.txt                  |    3 ++-
 loolwsd/test/httpwstest.cpp           |    2 +-
 6 files changed, 21 insertions(+), 15 deletions(-)

New commits:
commit 1977f07d5c406b5bcecc9a0f8e9a2da7af4e2c09
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Fri Jan 15 14:42:02 2016 +0100

    paste: handle data containing newlines
    
    By changing the protocol, so that instead of "paste ... data=<data>",
    the client is now expected to send "paste ...\n<data>".

diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index c868b8e..e08754f 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -934,7 +934,7 @@ L.TileLayer = L.GridLayer.extend({
 	_onPaste: function (e) {
 		e = e.originalEvent;
 		e.preventDefault();
-		this._map._socket.sendMessage('paste mimetype=text/plain;charset=utf-8 data=' + e.clipboardData.getData('text/plain'));
+		this._map._socket.sendMessage('paste mimetype=text/plain;charset=utf-8\n' + e.clipboardData.getData('text/plain'));
 	},
 
 	_onDragOver: function (e) {
diff --git a/loolwsd/ChildProcessSession.cpp b/loolwsd/ChildProcessSession.cpp
index 90ebb57..6f5f030 100644
--- a/loolwsd/ChildProcessSession.cpp
+++ b/loolwsd/ChildProcessSession.cpp
@@ -637,25 +637,26 @@ bool ChildProcessSession::getTextSelection(const char* /*buffer*/, int /*length*
     return true;
 }
 
-bool ChildProcessSession::paste(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens)
+bool ChildProcessSession::paste(const char* buffer, int length, StringTokenizer& tokens)
 {
     std::string mimeType;
-    std::string data;
 
-    if (tokens.count() < 3 || !getTokenString(tokens[1], "mimetype", mimeType) || !getTokenString(tokens[2], "data", data))
+    if (tokens.count() < 2 || !getTokenString(tokens[1], "mimetype", mimeType))
     {
         sendTextFrame("error: cmd=paste kind=syntax");
         return false;
     }
 
-    data = Poco::cat(std::string(" "), tokens.begin() + 2, tokens.end()).substr(strlen("data="));
+    const std::string firstLine = getFirstLine(buffer, length);
+    const char* data = buffer + firstLine.size() + 1;
+    size_t size = length - firstLine.size() - 1;
 
     std::unique_lock<std::recursive_mutex> lock(_mutex);
 
     if (_multiView)
         _loKitDocument->pClass->setView(_loKitDocument, _viewId);
 
-    _loKitDocument->pClass->paste(_loKitDocument, mimeType.c_str(), data.c_str(), std::strlen(data.c_str()));
+    _loKitDocument->pClass->paste(_loKitDocument, mimeType.c_str(), data, size);
 
     return true;
 }
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index cf8aef8..b0b98bd 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -389,10 +389,14 @@ public:
 
                     StringTokenizer tokens(firstLine, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
 
-                    // The only kind of messages a child process receives are the single-line ones (?)
-                    assert(firstLine.size() == static_cast<std::string::size_type>(n));
-
-                    queue.put(firstLine);
+                    if (firstLine.find("paste") != 0)
+                    {
+                        // Everything else is expected to be a single line.
+                        assert(firstLine.size() == static_cast<std::string::size_type>(n));
+                        queue.put(firstLine);
+                    }
+                    else
+                        queue.put(std::string(buffer, n));
                 }
             }
             while (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE && !_stop);
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 3f264ee..d69d951 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -467,10 +467,10 @@ public:
                     // synchronously and A is waiting in the queue thread.
                     // The fix is to push everything into the queue
                     // (i.e. change MessageQueue to vector<char>).
-                    if (singleLine)
+                    const std::string firstLine = getFirstLine(data, size);
+                    if (singleLine || firstLine.find("paste") == 0)
                     {
-                        const std::string firstLine = getFirstLine(data, size);
-                        queue.put(firstLine);
+                        queue.put(std::string(data, size));
                         return true;
                     }
                     else
diff --git a/loolwsd/protocol.txt b/loolwsd/protocol.txt
index 81a069b..fd10e40 100644
--- a/loolwsd/protocol.txt
+++ b/loolwsd/protocol.txt
@@ -41,7 +41,8 @@ gettextselection mimetype=<mimeType>
 
     Request selection's content
 
-paste mimetype=<mimeType> data=<data>
+paste mimetype=<mimeType>
+<binaryPasteData>
 
     Paste content at the current cursor position.
 
diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp
index 302993e..65c0899 100644
--- a/loolwsd/test/httpwstest.cpp
+++ b/loolwsd/test/httpwstest.cpp
@@ -58,7 +58,7 @@ void HTTPWSTest::testPaste()
     sendTextFrame(_socket, "uno .uno:Delete");
 
     // Paste some text into it.
-    sendTextFrame(_socket, "paste mimetype=text/plain;charset=utf-8 data=aaa bbb ccc");
+    sendTextFrame(_socket, "paste mimetype=text/plain;charset=utf-8\naaa bbb ccc");
 
     // Check if the document contains the pasted text.
     sendTextFrame(_socket, "uno .uno:SelectAll");


More information about the Libreoffice-commits mailing list