wsd/ClientSession.cpp | 20 +++++++++++++++++--- wsd/ClientSession.hpp | 4 ++++ 2 files changed, 21 insertions(+), 3 deletions(-)
New commits: commit fa65cbeb87a760b2dcb2094de6a9ec79471c0ca1 Author: Pranav Kant <pran...@collabora.co.uk> Date: Mon Dec 5 17:48:33 2016 +0530 wsd: readonly message filtering in separate function Change-Id: I1c02be876aa4cf2a878082b593de3c83e45e15b3 Reviewed-on: https://gerrit.libreoffice.org/35359 Reviewed-by: pranavk <pran...@collabora.co.uk> Tested-by: pranavk <pran...@collabora.co.uk> diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp index cedbc5e3..30bc33b2 100644 --- a/wsd/ClientSession.cpp +++ b/wsd/ClientSession.cpp @@ -213,9 +213,7 @@ bool ClientSession::_handleInput(const char *buffer, int length) } else { - // Allow 'downloadas' for all kinds of views - if ( (isReadOnly()) && tokens[0] != "downloadas" && - tokens[0] != "userinactive" && tokens[0] != "useractive") + if (!filterMessage(firstLine)) { const std::string dummyFrame = "dummymsg"; return forwardToChild(dummyFrame, docBroker); @@ -391,6 +389,22 @@ bool ClientSession::forwardToChild(const std::string& message, return docBroker->forwardToChild(getId(), message); } +bool ClientSession::filterMessage(const std::string& message) const +{ + bool allowed = true; + StringTokenizer tokens(message, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM); + if (isReadOnly()) + { + allowed = false; + if (tokens[0] == "downloadas" || tokens[0] == "userinactive" || tokens[0] == "useractive") + { + allowed = true; + } + } + + return allowed; +} + void ClientSession::setReadOnly() { _isReadOnly = true; diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp index bf484f43..37035936 100644 --- a/wsd/ClientSession.hpp +++ b/wsd/ClientSession.hpp @@ -87,6 +87,10 @@ private: bool forwardToChild(const std::string& message, const std::shared_ptr<DocumentBroker>& docBroker); + /// Returns true if given message from the client should be allowed or not + /// Eg. in readonly mode only few messages should be allowed + bool filterMessage(const std::string& msg) const; + private: std::weak_ptr<DocumentBroker> _docBroker; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits