[Libreoffice-commits] online.git: loolwsd/LOOLProtocol.hpp loolwsd/LOOLWebSocket.hpp
loolwsd/LOOLProtocol.hpp |6 +++--- loolwsd/LOOLWebSocket.hpp |6 +- 2 files changed, 4 insertions(+), 8 deletions(-) New commits: commit 5d69d0abd608a447df0355152643608d8034b7a2 Author: Ashod Nakashian Date: Sat Nov 12 10:40:37 2016 -0500 loolwsd: log only abbreviated messages Change-Id: I3328a9171f8b85a802dc888de009bdbb8658cead Reviewed-on: https://gerrit.libreoffice.org/30815 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLProtocol.hpp b/loolwsd/LOOLProtocol.hpp index 2c158ff..e95090d 100644 --- a/loolwsd/LOOLProtocol.hpp +++ b/loolwsd/LOOLProtocol.hpp @@ -18,7 +18,7 @@ #include #include -#include +#include #define LOK_USE_UNSTABLE_API #include @@ -190,8 +190,8 @@ namespace LOOLProtocol return getAbbreviatedMessage(message.data(), message.size()); } -// Return a string dump of a LOOLWebSocket frame: Its opcode, length, first line (if present), -// flags. For human-readable logging purposes. Format not guaranteed to be stable. Not to be +// Return a string dump of a WebSocket frame: Its opcode, length, first line (if present), +// flags. For human-readable logging purposes. Format not guaranteed to be stable. Not to be // inspected programmatically. inline std::string getAbbreviatedFrameDump(const char *message, const int length, const int flags) diff --git a/loolwsd/LOOLWebSocket.hpp b/loolwsd/LOOLWebSocket.hpp index ffd4887..a8599f2 100644 --- a/loolwsd/LOOLWebSocket.hpp +++ b/loolwsd/LOOLWebSocket.hpp @@ -71,11 +71,7 @@ public: } int result = Poco::Net::WebSocket::sendFrame(buffer, length, flags); -// FIXME we want an abbreviated message here, but we'd have a circular -// dependency with LOOLProtocol, so use the full message here before -// we move getAbbreviatedMessage() to Log (where it belongs anyway). -//Log::debug("Sent frame: " + LOOLProtocol::getAbbreviatedMessage(static_cast(buffer), length)); -Log::debug("Sent frame: " + std::string(static_cast(buffer), length)); +Log::debug("Sent frame: " + LOOLProtocol::getAbbreviatedMessage(static_cast(buffer), length)); return result; } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLProtocol.hpp
loolwsd/LOOLProtocol.hpp |2 +- 1 file changed, 1 insertion(+), 1 deletion(-) New commits: commit 5656c1271316d6067b383f986d718a5234c9b832 Author: Ashod Nakashian Date: Mon Oct 31 21:22:49 2016 -0400 loolwsd: cap abbraviated message length Change-Id: Idddfd55ae9a9fe8c2ae0c78e416d541529adaa66 Reviewed-on: https://gerrit.libreoffice.org/30490 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLProtocol.hpp b/loolwsd/LOOLProtocol.hpp index 855ca94..fe11f2e 100644 --- a/loolwsd/LOOLProtocol.hpp +++ b/loolwsd/LOOLProtocol.hpp @@ -172,7 +172,7 @@ namespace LOOLProtocol return ""; } -const auto firstLine = getFirstLine(message, length); +const auto firstLine = getFirstLine(message, std::min(length, 120)); // If first line is less than the length (minus newline), add ellipsis. if (firstLine.size() < static_cast(length) - 1) ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLProtocol.hpp
loolwsd/LOOLProtocol.hpp |6 -- 1 file changed, 6 deletions(-) New commits: commit 027da26b5b63c6349b9d20b92ee76952fa08bf71 Author: Ashod Nakashian Date: Fri Oct 21 13:00:11 2016 -0400 loolwsd: kill redundant function Change-Id: I8ef30205794c13e5b89e9f32ba0ec17df4441ef4 Reviewed-on: https://gerrit.libreoffice.org/30191 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLProtocol.hpp b/loolwsd/LOOLProtocol.hpp index 7fd0f4a..f8204cc 100644 --- a/loolwsd/LOOLProtocol.hpp +++ b/loolwsd/LOOLProtocol.hpp @@ -184,12 +184,6 @@ namespace LOOLProtocol return firstLine; } -inline -std::string getAbbreviatedMessage(const std::string& message) -{ -return getAbbreviatedMessage(message.data(), message.size()); -} - template std::string getAbbreviatedMessage(const T& message) { ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLProtocol.hpp loolwsd/test
loolwsd/LOOLProtocol.hpp | 24 loolwsd/test/helpers.hpp | 37 - 2 files changed, 36 insertions(+), 25 deletions(-) New commits: commit 452888060d73e1283fead168249998ba9d9c757e Author: Ashod Nakashian Date: Fri Oct 21 12:59:03 2016 -0400 loolwsd: cleanup and improve getResponseMessage Proper parsing of incoming messages and better prefix matching is done, as well as slightly better logging when we timeout or hit exceptions. Change-Id: I11adbf24a5505f6cda4a18ba855898dc5f82e238 Reviewed-on: https://gerrit.libreoffice.org/30190 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLProtocol.hpp b/loolwsd/LOOLProtocol.hpp index e98d1ea..7fd0f4a 100644 --- a/loolwsd/LOOLProtocol.hpp +++ b/loolwsd/LOOLProtocol.hpp @@ -103,6 +103,30 @@ namespace LOOLProtocol return getFirstToken(message.data(), message.size(), delim); } +inline +bool matchPrefix(const std::string& prefix, const std::string& message) +{ +return (message.size() >= prefix.size() && +message.compare(0, prefix.size(), prefix) == 0); +} + +inline +bool matchPrefix(const std::string& prefix, const std::string& message, const bool ignoreWhitespace) +{ +if (ignoreWhitespace) +{ +const auto posPre = prefix.find_first_not_of(' '); +const auto posMsg = message.find_first_not_of(' '); + +return matchPrefix(posPre == std::string::npos ? prefix : prefix.substr(posPre), + posMsg == std::string::npos ? message : message.substr(posMsg)); +} +else +{ +return matchPrefix(prefix, message); +} +} + /// Returns true if the token is a user-interaction token. /// Currently this excludes commands sent automatically. /// Notice that this doesn't guarantee editing activity, diff --git a/loolwsd/test/helpers.hpp b/loolwsd/test/helpers.hpp index cdc7515..cb96a87 100644 --- a/loolwsd/test/helpers.hpp +++ b/loolwsd/test/helpers.hpp @@ -186,42 +186,24 @@ std::vector getResponseMessage(Poco::Net::WebSocket& ws, const std::string int bytes = ws.receiveFrame(response.data(), response.size(), flags); response.resize(bytes >= 0 ? bytes : 0); std::cerr << name << "Got " << LOOLProtocol::getAbbreviatedFrameDump(response.data(), bytes, flags) << std::endl; -auto message = LOOLProtocol::getAbbreviatedMessage(response); +const auto message = LOOLProtocol::getFirstLine(response); if (bytes > 0 && (flags & Poco::Net::WebSocket::FRAME_OP_BITMASK) != Poco::Net::WebSocket::FRAME_OP_CLOSE) { -// FIXME: This is wrong in two ways: - -// 1) The message variable is the return value from getAbbreviatedMessage(), -// That is a string that is intended for human-readable logging only. It is not -// intended to be used for actually decoding the protocol. Sure, at the moment -// it happens to work, but is still wrong. - -// 2) Using std::string::find() like this is silly. If message does not start -// with prefix, the find() function will search through the whole buffer. That -// is a waste of cycles. Use the LOOLProtocol functions to manipulate and -// inspect LOOL protocol frames, that is what they are there -// for. getFirstToken() should be quite efficient, and it doesn't incur the -// (potential) overhead of setting up a StringTokenizer. Or, if this is actually -// used to look for not just a first token, then introduce a startsWith() -// function. - -if (message.find(prefix) == 0) +if (LOOLProtocol::matchPrefix(prefix, message)) { return response; } -else if (message.find("nextmessage") == 0) +else if (LOOLProtocol::matchPrefix("nextmessage", message)) { -Poco::StringTokenizer tokens(message, " ", Poco::StringTokenizer::TOK_IGNORE_EMPTY | Poco::StringTokenizer::TOK_TRIM); int size = 0; -if (tokens.count() == 2 && -tokens[0] == "nextmessage:" && LOOLProtocol::getTokenInteger(tokens[1], "size", size) && size > 0) +if (LOOLProtocol::getTokenIntegerFromMessage(message, "size", size) && size > 0) { response.resize(size); bytes = ws.receiveFrame(response.data(), response.size(), flags);
[Libreoffice-commits] online.git: loolwsd/LOOLProtocol.hpp loolwsd/test
loolwsd/LOOLProtocol.hpp | 15 --- loolwsd/test/UnitFonts.cpp |4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) New commits: commit f7327115debc9c9d18f061ba9baef8fb993cc9de Author: Ashod Nakashian Date: Sat Oct 8 13:12:16 2016 -0400 loolwsd: allow for delimiter in LOOLProtocol parsers Change-Id: I9c7e503aed067dfe36953552237941e7c1841457 Reviewed-on: https://gerrit.libreoffice.org/29633 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLProtocol.hpp b/loolwsd/LOOLProtocol.hpp index e5e79b9..6120e0c 100644 --- a/loolwsd/LOOLProtocol.hpp +++ b/loolwsd/LOOLProtocol.hpp @@ -75,29 +75,29 @@ namespace LOOLProtocol bool parseStatus(const std::string& message, LibreOfficeKitDocumentType& type, int& nParts, int& currentPart, int& width, int& height); inline -std::string getDelimitedInitialSubstring(const char *message, const int length, const char delimiter) +std::string getDelimitedInitialSubstring(const char *message, const int length, const char delim) { if (message == nullptr || length <= 0) { return ""; } -const char *foundDelimiter = static_cast(std::memchr(message, delimiter, length)); -const auto size = (foundDelimiter == nullptr ? length : foundDelimiter - message); +const char *founddelim = static_cast(std::memchr(message, delim, length)); +const auto size = (founddelim == nullptr ? length : founddelim - message); return std::string(message, size); } /// Returns the first token of a message. inline -std::string getFirstToken(const char *message, const int length) +std::string getFirstToken(const char *message, const int length, const char delim) { -return getDelimitedInitialSubstring(message, length, ' '); +return getDelimitedInitialSubstring(message, length, delim); } template -std::string getFirstToken(const T& message) +std::string getFirstToken(const T& message, const char delim = ' ') { -return getFirstToken(message.data(), message.size()); +return getFirstToken(message.data(), message.size(), delim); } /// Returns true if the token is a user-interaction token. @@ -126,6 +126,7 @@ namespace LOOLProtocol return getDelimitedInitialSubstring(message, length, '\n'); } +/// Returns the first line of any data which payload char*. template std::string getFirstLine(const T& message) { diff --git a/loolwsd/test/UnitFonts.cpp b/loolwsd/test/UnitFonts.cpp index 2d1b157..c82dcbb 100644 --- a/loolwsd/test/UnitFonts.cpp +++ b/loolwsd/test/UnitFonts.cpp @@ -144,10 +144,10 @@ public: virtual bool filterKitMessage(const std::shared_ptr &ws, std::string &message) override { -std::string token = LOOLProtocol::getFirstToken(message.c_str(), message.length()); +const std::string token = LOOLProtocol::getFirstToken(message); if (token == "unit-getfontlist:") { -std::string fontListReply = getFontList() + "\n"; +const std::string fontListReply = getFontList() + "\n"; ws->sendFrame(fontListReply.c_str(), fontListReply.length()); return true; } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLProtocol.hpp
loolwsd/LOOLProtocol.hpp |9 +++-- 1 file changed, 7 insertions(+), 2 deletions(-) New commits: commit a4290ec4da0afb0c845bd2552689cab0fbbb018b Author: Tor Lillqvist Date: Mon Sep 26 10:12:48 2016 +0300 Add FIXME comment diff --git a/loolwsd/LOOLProtocol.hpp b/loolwsd/LOOLProtocol.hpp index f239bca..c7c42e1 100644 --- a/loolwsd/LOOLProtocol.hpp +++ b/loolwsd/LOOLProtocol.hpp @@ -85,8 +85,13 @@ namespace LOOLProtocol inline bool tokenIndicatesUserInteraction(const std::string& token) { -// Exclude tokens that include these keywords, -// such as canceltiles statusindicator. +// Exclude tokens that include these keywords, such as canceltiles statusindicator. + +// FIXME: This is wrong. That the token happens to contain (or not) a certain substring is +// no guarantee that it "indicates user interaction". It might be like that at the moment, +// but that is coincidental. We should check what the actual whole token is, at least, not +// look for a substring. + return (token.find("tile") == std::string::npos && token.find("status") == std::string::npos && token.find("state") == std::string::npos); ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLProtocol.hpp
loolwsd/LOOLProtocol.hpp | 12 ++-- 1 file changed, 6 insertions(+), 6 deletions(-) New commits: commit f20a9e94b64ca76f1ed09fedd066f630919a91e0 Author: Ashod Nakashian Date: Mon May 9 00:35:45 2016 -0400 loolwsd: templatize parsing helpers Change-Id: Ia52dbf59bf5f2a816578b75111ee9accdeaaf816 Reviewed-on: https://gerrit.libreoffice.org/24780 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLProtocol.hpp b/loolwsd/LOOLProtocol.hpp index 05cc4b4..21d488b 100644 --- a/loolwsd/LOOLProtocol.hpp +++ b/loolwsd/LOOLProtocol.hpp @@ -69,8 +69,8 @@ namespace LOOLProtocol return getDelimitedInitialSubstring(message, length, ' '); } -inline -std::string getFirstToken(const std::vector& message) +template +std::string getFirstToken(const T& message) { return getFirstToken(message.data(), message.size()); } @@ -96,8 +96,8 @@ namespace LOOLProtocol return getDelimitedInitialSubstring(message, length, '\n'); } -inline -std::string getFirstLine(const std::vector& message) +template +std::string getFirstLine(const T& message) { return getFirstLine(message.data(), message.size()); } @@ -111,8 +111,8 @@ namespace LOOLProtocol return getAbbreviatedMessage(message.data(), message.size()); } -inline -std::string getAbbreviatedMessage(const std::vector& message) +template +std::string getAbbreviatedMessage(const T& message) { return getAbbreviatedMessage(message.data(), message.size()); } ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLProtocol.hpp
loolwsd/LOOLProtocol.hpp |6 ++ 1 file changed, 6 insertions(+) New commits: commit c75725393991998ad38ec4a73fbb970feb0c99d0 Author: Ashod Nakashian Date: Sun May 1 20:31:40 2016 -0400 loolwsd: getAbbreviatedMessage from std::vector Change-Id: Ib901fb786839d48604a99a0eab0c7dd048e2004d Reviewed-on: https://gerrit.libreoffice.org/24578 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/loolwsd/LOOLProtocol.hpp b/loolwsd/LOOLProtocol.hpp index 673e75f..05cc4b4 100644 --- a/loolwsd/LOOLProtocol.hpp +++ b/loolwsd/LOOLProtocol.hpp @@ -110,6 +110,12 @@ namespace LOOLProtocol { return getAbbreviatedMessage(message.data(), message.size()); } + +inline +std::string getAbbreviatedMessage(const std::vector& message) +{ +return getAbbreviatedMessage(message.data(), message.size()); +} }; #endif ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLProtocol.hpp
loolwsd/LOOLProtocol.hpp | 16 +++- 1 file changed, 11 insertions(+), 5 deletions(-) New commits: commit a598ea869cb6684263e7c1961f2dd43613e56b4b Author: Tor Lillqvist Date: Mon Apr 11 10:11:49 2016 +0300 Use less misleading function and variable names Also, get rid of one default parameter that was passed a non-default value only 'internally'. diff --git a/loolwsd/LOOLProtocol.hpp b/loolwsd/LOOLProtocol.hpp index 66276b1..0ed166a 100644 --- a/loolwsd/LOOLProtocol.hpp +++ b/loolwsd/LOOLProtocol.hpp @@ -43,20 +43,26 @@ namespace LOOLProtocol // Functions that parse messages. All return false if parsing fails bool parseStatus(const std::string& message, LibreOfficeKitDocumentType& type, int& nParts, int& currentPart, int& width, int& height); -/// Returns the first token of a message given a delimiter. inline -std::string getFirstToken(const char *message, const int length, const char delim = ' ') +std::string getDelimitedInitialSubstring(const char *message, const int length, const char delimiter) { if (message == nullptr || length <= 0) { return ""; } -const char *endOfLine = static_cast(std::memchr(message, delim, length)); -const auto size = (endOfLine == nullptr ? length : endOfLine - message); +const char *foundDelimiter = static_cast(std::memchr(message, delimiter, length)); +const auto size = (foundDelimiter == nullptr ? length : foundDelimiter - message); return std::string(message, size); } +/// Returns the first token of a message. +inline +std::string getFirstToken(const char *message, const int length) +{ +return getDelimitedInitialSubstring(message, length, ' '); +} + inline std::string getFirstToken(const std::vector& message) { @@ -81,7 +87,7 @@ namespace LOOLProtocol inline std::string getFirstLine(const char *message, const int length) { -return getFirstToken(message, length, '\n'); +return getDelimitedInitialSubstring(message, length, '\n'); } inline ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
[Libreoffice-commits] online.git: loolwsd/LOOLProtocol.hpp loolwsd/LOOLSession.cpp loolwsd/LOOLSession.hpp loolwsd/protocol.txt
loolwsd/LOOLProtocol.hpp |3 ++- loolwsd/LOOLSession.cpp | 27 +-- loolwsd/LOOLSession.hpp |1 + loolwsd/protocol.txt |8 4 files changed, 36 insertions(+), 3 deletions(-) New commits: commit e8007ea405318ca8048c7487e2d4f0ede72597ee Author: Mihai Varga Date: Wed Jun 24 18:08:15 2015 +0300 Server getTextSelection implementation diff --git a/loolwsd/LOOLProtocol.hpp b/loolwsd/LOOLProtocol.hpp index 4aad0b3..42e82df 100644 --- a/loolwsd/LOOLProtocol.hpp +++ b/loolwsd/LOOLProtocol.hpp @@ -31,8 +31,9 @@ namespace LOOLProtocol // "commands". // Not sure if these enums will be needed -enum class Command +enum class Command { +GETTEXTSELECTION, KEY, LOAD, MOUSE, diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp index a485482..67a2bcf 100644 --- a/loolwsd/LOOLSession.cpp +++ b/loolwsd/LOOLSession.cpp @@ -240,6 +240,7 @@ bool MasterProcessSession::handleInput(const char *buffer, int length) return loadDocument(buffer, length, tokens); } else if (tokens[0] != "canceltiles" && + tokens[0] != "gettextselection" && tokens[0] != "invalidatetiles" && tokens[0] != "key" && tokens[0] != "mouse" && @@ -697,7 +698,8 @@ bool ChildProcessSession::handleInput(const char *buffer, int length) // All other commands are such that they always require a LibreOfficeKitDocument session, // i.e. need to be handled in a child process. -assert(tokens[0] == "key" || +assert(tokens[0] == "gettextselection" || + tokens[0] == "key" || tokens[0] == "mouse" || tokens[0] == "uno" || tokens[0] == "selecttext" || @@ -705,7 +707,11 @@ bool ChildProcessSession::handleInput(const char *buffer, int length) tokens[0] == "resetselection" || tokens[0] == "saveas"); -if (tokens[0] == "key") +if (tokens[0] == "gettextselection") +{ +return getTextSelection(buffer, length, tokens); +} +else if (tokens[0] == "key") { return keyEvent(buffer, length, tokens); } @@ -910,6 +916,23 @@ void ChildProcessSession::sendTile(const char *buffer, int length, StringTokeniz sendBinaryFrame(output.data(), output.size()); } +bool ChildProcessSession::getTextSelection(const char *buffer, int length, StringTokenizer& tokens) +{ +std::string mimeType; + +if (tokens.count() != 2 || +!getTokenString(tokens[1], "mimetype", mimeType)) +{ +sendTextFrame("error: cmd=gettextselection kind=syntax"); +return false; +} + +char *textSelection = _loKitDocument->pClass->getTextSelection(_loKitDocument, mimeType.c_str(), NULL); + +sendTextFrame("textselectioncontent: " + std::string(textSelection)); +return true; +} + bool ChildProcessSession::keyEvent(const char *buffer, int length, StringTokenizer& tokens) { int type, charcode, keycode; diff --git a/loolwsd/LOOLSession.hpp b/loolwsd/LOOLSession.hpp index 4e7e3dd..221de8b 100644 --- a/loolwsd/LOOLSession.hpp +++ b/loolwsd/LOOLSession.hpp @@ -166,6 +166,7 @@ public: virtual void sendTile(const char *buffer, int length, Poco::StringTokenizer& tokens); +bool getTextSelection(const char *buffer, int length, Poco::StringTokenizer& tokens); bool keyEvent(const char *buffer, int length, Poco::StringTokenizer& tokens); bool mouseEvent(const char *buffer, int length, Poco::StringTokenizer& tokens); bool unoCommand(const char *buffer, int length, Poco::StringTokenizer& tokens); diff --git a/loolwsd/protocol.txt b/loolwsd/protocol.txt index 74af6c3..491dc9d 100644 --- a/loolwsd/protocol.txt +++ b/loolwsd/protocol.txt @@ -17,6 +17,10 @@ canceltiles dropped and will not be handled. There is no guarantee of exactly which tile: messages might still be sent back to the client. +gettextselection mimetype= + +Request selection's content + invalidatetiles part= tileposx= tileposy= tilewidth= tileheight= All parameters are numbers. Makes the server remove any cached @@ -100,6 +104,10 @@ status: type= parts= current= width= is 'text, 'spreadsheet', 'presentation', 'drawing' or 'other. Others are numbers. +textselectioncontent: + +Current selection's content + tile: part= width= height= tileposx= tileposy= tilewidth= tileheight= ___ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits