loolwsd/ChildProcessSession.hpp | 2 loolwsd/ClientSession.cpp | 359 +++------------------------------------ loolwsd/ClientSession.hpp | 4 loolwsd/LOOLSession.hpp | 2 loolwsd/MasterProcessSession.cpp | 28 --- loolwsd/MasterProcessSession.hpp | 2 6 files changed, 31 insertions(+), 366 deletions(-)
New commits: commit 8af51d0270ef4d4358027420d841356d89ce453b Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> Date: Mon May 16 19:11:34 2016 -0400 loolwsd: MasterProcessSession splitting: moved loadDocument Change-Id: Iaf32014ab5cbceb6ca5d443a85b0d03d6ccd9876 Reviewed-on: https://gerrit.libreoffice.org/25041 Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> Tested-by: Ashod Nakashian <ashnak...@gmail.com> diff --git a/loolwsd/ChildProcessSession.hpp b/loolwsd/ChildProcessSession.hpp index 8a760cb..7b6275e 100644 --- a/loolwsd/ChildProcessSession.hpp +++ b/loolwsd/ChildProcessSession.hpp @@ -65,7 +65,7 @@ public: void setDocState(const int type, const std::string& payload) { _lastDocStates[type] = payload; } protected: - virtual bool loadDocument(const char *buffer, int length, Poco::StringTokenizer& tokens) override; + bool loadDocument(const char *buffer, int length, Poco::StringTokenizer& tokens); virtual void sendFontRendering(const char *buffer, int length, Poco::StringTokenizer& tokens) override; diff --git a/loolwsd/ClientSession.cpp b/loolwsd/ClientSession.cpp index 36e3185..401831d 100644 --- a/loolwsd/ClientSession.cpp +++ b/loolwsd/ClientSession.cpp @@ -172,6 +172,34 @@ bool ClientSession::_handleInput(const char *buffer, int length) return true; } +bool ClientSession::loadDocument(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens) +{ + if (tokens.count() < 2) + { + sendTextFrame("error: cmd=load kind=syntax"); + return false; + } + + try + { + std::string timestamp; + parseDocOptions(tokens, _loadPart, timestamp); + + // Finally, wait for the Child to connect to Master, + // link the document in jail and dispatch load to child. + Log::trace("Dispatching child to handle [load]."); + dispatchChild(); + + return true; + } + catch (const Poco::SyntaxException&) + { + sendTextFrame("error: cmd=load kind=uriinvalid"); + } + + return false; +} + /* void ClientSession::setEditLock(const bool value) { @@ -210,337 +238,6 @@ MasterProcessSession::~MasterProcessSession() _saveAsQueue.put(""); } -bool MasterProcessSession::_handleInput(const char *buffer, int length) -{ - const std::string firstLine = getFirstLine(buffer, length); - StringTokenizer tokens(firstLine, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM); - Log::trace(getName() + ": handling [" + firstLine + "]."); - - if (LOOLProtocol::tokenIndicatesUserInteraction(tokens[0])) - { - // Keep track of timestamps of incoming client messages that indicate user activity. - updateLastActivityTime(); - } - - if (tokens[0] == "loolclient") - { - const auto versionTuple = ParseVersion(tokens[1]); - if (std::get<0>(versionTuple) != ProtocolMajorVersionNumber || - std::get<1>(versionTuple) != ProtocolMinorVersionNumber) - { - sendTextFrame("error: cmd=loolclient kind=badversion"); - return false; - } - - sendTextFrame("loolserver " + GetProtocolVersion()); - return true; - } - - if (_kind == Kind::ToPrisoner) - { - // Note that this handles both forwarding requests from the client to the child process, and - // forwarding replies from the child process to the client. Or does it? - - // Snoop at some messages and manipulate tile cache information as needed - auto peer = _peer.lock(); - - { - if (!peer) - { - throw Poco::ProtocolException("The session has not been assigned a peer."); - } - - if (tokens[0] == "unocommandresult:") - { - const std::string stringMsg(buffer, length); - Log::info(getName() + "Command: " + stringMsg); - const auto index = stringMsg.find_first_of('{'); - if (index != std::string::npos) - { - const std::string stringJSON = stringMsg.substr(index); - Poco::JSON::Parser parser; - const auto result = parser.parse(stringJSON); - const auto& object = result.extract<Poco::JSON::Object::Ptr>(); - if (object->get("commandName").toString() == ".uno:Save" && - object->get("success").toString() == "true") - { - _docBroker->save(); - return true; - } - } - } - - if (tokens[0] == "error:") - { - std::string errorCommand; - std::string errorKind; - if (getTokenString(tokens[1], "cmd", errorCommand) && - getTokenString(tokens[2], "kind", errorKind) ) - { - if (errorCommand == "load") - { - if (errorKind == "passwordrequired:to-view" || - errorKind == "passwordrequired:to-modify" || - errorKind == "wrongpassword") - { - forwardToPeer(buffer, length); - peer->_bLoadError = true; - return false; - } - } - } - } - - if (tokens[0] == "curpart:" && - tokens.count() == 2 && - getTokenInteger(tokens[1], "part", _curPart)) - { - return true; - } - - if (tokens.count() == 2 && tokens[0] == "saveas:") - { - std::string url; - if (!getTokenString(tokens[1], "url", url)) - return true; - - if (peer) - { - // Save as completed, inform the other (Kind::ToClient) - // MasterProcessSession about it. - - const std::string filePrefix("file:///"); - if (url.find(filePrefix) == 0) - { - // Rewrite file:// URLs, as they are visible to the outside world. - const Path path(_docBroker->getJailRoot(), url.substr(filePrefix.length())); - url = filePrefix + path.toString().substr(1); - } - peer->_saveAsQueue.put(url); - } - - return true; - } - else if (tokens.count() == 2 && tokens[0] == "statechanged:") - { - StringTokenizer stateTokens(tokens[1], "=", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM); - if (stateTokens.count() == 2 && stateTokens[0] == ".uno:ModifiedStatus") - { - if (_docBroker) - { - _docBroker->setModified(stateTokens[1] == "true"); - } - } - } - } - - if (peer && !_isDocPasswordProtected) - { - if (tokens[0] == "tile:") - { - assert(!"Tile traffic should go through the DocumentBroker-LoKit WS."); - } - else if (tokens[0] == "status:") - { - _docBroker->setLoaded(); - _docBroker->tileCache().saveTextFile(std::string(buffer, length), "status.txt"); - - // Forward the status response to the client. - forwardToPeer(buffer, length); - - // And let clients know if they hold the edit lock. - std::string message = "editlock: "; - message += std::to_string(peer->isEditLocked()); - Log::debug("Forwarding [" + message + "] in response to status."); - forwardToPeer(message.c_str(), message.size()); - return true; - } - else if (tokens[0] == "commandvalues:") - { - const std::string stringMsg(buffer, length); - const auto index = stringMsg.find_first_of('{'); - if (index != std::string::npos) - { - const std::string stringJSON = stringMsg.substr(index); - Poco::JSON::Parser parser; - const auto result = parser.parse(stringJSON); - const auto& object = result.extract<Poco::JSON::Object::Ptr>(); - const std::string commandName = object->get("commandName").toString(); - if (commandName.find(".uno:CharFontName") != std::string::npos || - commandName.find(".uno:StyleApply") != std::string::npos) - { - // other commands should not be cached - _docBroker->tileCache().saveTextFile(stringMsg, "cmdValues" + commandName + ".txt"); - } - } - } - else if (tokens[0] == "partpagerectangles:") - { - if (tokens.count() > 1 && !tokens[1].empty()) - _docBroker->tileCache().saveTextFile(std::string(buffer, length), "partpagerectangles.txt"); - } - else if (tokens[0] == "invalidatetiles:") - { - assert(firstLine.size() == static_cast<std::string::size_type>(length)); - _docBroker->tileCache().invalidateTiles(firstLine); - } - else if (tokens[0] == "renderfont:") - { - std::string font; - if (tokens.count() < 2 || - !getTokenString(tokens[1], "font", font)) - assert(false); - - assert(firstLine.size() < static_cast<std::string::size_type>(length)); - _docBroker->tileCache().saveRendering(font, "font", buffer + firstLine.size() + 1, length - firstLine.size() - 1); - } - } - - forwardToPeer(buffer, length); - return true; - } - - if (_kind == Kind::ToPrisoner) - { - // Message from child process to be forwarded to client. - - // I think we should never get here - Log::error(getName() + ": Unexpected request [" + tokens[0] + "]."); - assert(false); - } - else if (tokens[0] == "takeedit") - { - _docBroker->takeEditLock(getId()); - return true; - } - else if (tokens[0] == "load") - { - if (_docURL != "") - { - sendTextFrame("error: cmd=load kind=docalreadyloaded"); - return false; - } - return loadDocument(buffer, length, tokens); - } - else if (tokens[0] != "canceltiles" && - tokens[0] != "clientzoom" && - tokens[0] != "clientvisiblearea" && - tokens[0] != "commandvalues" && - tokens[0] != "downloadas" && - tokens[0] != "getchildid" && - tokens[0] != "gettextselection" && - tokens[0] != "paste" && - tokens[0] != "insertfile" && - tokens[0] != "key" && - tokens[0] != "mouse" && - tokens[0] != "partpagerectangles" && - tokens[0] != "renderfont" && - tokens[0] != "requestloksession" && - tokens[0] != "resetselection" && - tokens[0] != "saveas" && - tokens[0] != "selectgraphic" && - tokens[0] != "selecttext" && - tokens[0] != "setclientpart" && - tokens[0] != "setpage" && - tokens[0] != "status" && - tokens[0] != "tile" && - tokens[0] != "tilecombine" && - tokens[0] != "uno" && - tokens[0] != "useractive" && - tokens[0] != "userinactive") - { - sendTextFrame("error: cmd=" + tokens[0] + " kind=unknown"); - return false; - } - else if (_docURL == "") - { - sendTextFrame("error: cmd=" + tokens[0] + " kind=nodocloaded"); - return false; - } - else if (tokens[0] == "canceltiles") - { - if (!_peer.expired()) - forwardToPeer(buffer, length); - } - else if (tokens[0] == "commandvalues") - { - return getCommandValues(buffer, length, tokens); - } - else if (tokens[0] == "partpagerectangles") - { - return getPartPageRectangles(buffer, length); - } - else if (tokens[0] == "renderfont") - { - sendFontRendering(buffer, length, tokens); - } - else if (tokens[0] == "status") - { - return getStatus(buffer, length); - } - else if (tokens[0] == "tile") - { - sendTile(buffer, length, tokens); - } - else if (tokens[0] == "tilecombine") - { - sendCombinedTiles(buffer, length, tokens); - } - else - { - // All other commands are such that they always require a - // LibreOfficeKitDocument session, i.e. need to be handled in - // a child process. - - if (_peer.expired()) - { - Log::trace("Dispatching child to handle [" + tokens[0] + "]."); - dispatchChild(); - } - - // Allow 'downloadas' for all kinds of views irrespective of editlock - if (_kind == Kind::ToClient && !isEditLocked() && tokens[0] != "downloadas" && - tokens[0] != "userinactive" && tokens[0] != "useractive") - { - std::string dummyFrame = "dummymsg"; - forwardToPeer(dummyFrame.c_str(), dummyFrame.size()); - } - else if (tokens[0] != "requestloksession") - { - forwardToPeer(buffer, length); - } - } - return true; -} - -bool MasterProcessSession::loadDocument(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens) -{ - if (tokens.count() < 2) - { - sendTextFrame("error: cmd=load kind=syntax"); - return false; - } - - try - { - std::string timestamp; - parseDocOptions(tokens, _loadPart, timestamp); - - // Finally, wait for the Child to connect to Master, - // link the document in jail and dispatch load to child. - Log::trace("Dispatching child to handle [load]."); - dispatchChild(); - - return true; - } - catch (const Poco::SyntaxException&) - { - sendTextFrame("error: cmd=load kind=uriinvalid"); - } - - return false; -} - bool MasterProcessSession::getStatus(const char *buffer, int length) { const std::string status = _docBroker->tileCache().getTextFile("status.txt"); diff --git a/loolwsd/ClientSession.hpp b/loolwsd/ClientSession.hpp index 980b26f..19f27e1 100644 --- a/loolwsd/ClientSession.hpp +++ b/loolwsd/ClientSession.hpp @@ -53,6 +53,8 @@ private: virtual bool _handleInput(const char *buffer, int length) override; + bool loadDocument(const char *buffer, int length, Poco::StringTokenizer& tokens); + private: // If this document holds the edit lock. @@ -95,8 +97,6 @@ public: bool _bLoadError = false; protected: - virtual bool loadDocument(const char *buffer, int length, Poco::StringTokenizer& tokens) override; - virtual void sendTile(const char *buffer, int length, Poco::StringTokenizer& tokens); virtual void sendCombinedTiles(const char *buffer, int length, Poco::StringTokenizer& tokens); diff --git a/loolwsd/LOOLSession.hpp b/loolwsd/LOOLSession.hpp index 13fa109..e28fd4b 100644 --- a/loolwsd/LOOLSession.hpp +++ b/loolwsd/LOOLSession.hpp @@ -85,8 +85,6 @@ protected: /// Parses the options of the "load" command, shared between MasterProcessSession::loadDocument() and ChildProcessSession::loadDocument(). void parseDocOptions(const Poco::StringTokenizer& tokens, int& part, std::string& timestamp); - virtual bool loadDocument(const char *buffer, int length, Poco::StringTokenizer& tokens) = 0; - virtual void sendFontRendering(const char *buffer, int length, Poco::StringTokenizer& tokens) = 0; void updateLastActivityTime() diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp index 91c0997..f8b94d7 100644 --- a/loolwsd/MasterProcessSession.cpp +++ b/loolwsd/MasterProcessSession.cpp @@ -49,34 +49,6 @@ MasterProcessSession::~MasterProcessSession() { } -bool MasterProcessSession::loadDocument(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens) -{ - if (tokens.count() < 2) - { - sendTextFrame("error: cmd=load kind=syntax"); - return false; - } - - try - { - std::string timestamp; - parseDocOptions(tokens, _loadPart, timestamp); - - // Finally, wait for the Child to connect to Master, - // link the document in jail and dispatch load to child. - Log::trace("Dispatching child to handle [load]."); - dispatchChild(); - - return true; - } - catch (const Poco::SyntaxException&) - { - sendTextFrame("error: cmd=load kind=uriinvalid"); - } - - return false; -} - bool MasterProcessSession::getStatus(const char *buffer, int length) { const std::string status = _docBroker->tileCache().getTextFile("status.txt"); diff --git a/loolwsd/MasterProcessSession.hpp b/loolwsd/MasterProcessSession.hpp index 5dc3b46..83437c4 100644 --- a/loolwsd/MasterProcessSession.hpp +++ b/loolwsd/MasterProcessSession.hpp @@ -50,8 +50,6 @@ public: bool _bLoadError = false; protected: - virtual bool loadDocument(const char *buffer, int length, Poco::StringTokenizer& tokens) override; - virtual void sendTile(const char *buffer, int length, Poco::StringTokenizer& tokens); virtual void sendCombinedTiles(const char *buffer, int length, Poco::StringTokenizer& tokens); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits