loolwsd/Admin.cpp | 3 + loolwsd/DocumentBroker.cpp | 107 +++++++++++++++++++++++++++++++++++++++++++++ loolwsd/DocumentBroker.hpp | 93 ++------------------------------------- loolwsd/Makefile.am | 2 loolwsd/Storage.hpp | 1 5 files changed, 119 insertions(+), 87 deletions(-)
New commits: commit 2f603139713181b41174a5d6803eae70733cd2a2 Author: Pranav Kant <[email protected]> Date: Wed Mar 23 19:51:53 2016 +0530 loolwsd: Cancel admin stats timer when thread finishes Change-Id: I19d6a5368e650f0de93ee15b82c3549344a1d4b4 diff --git a/loolwsd/Admin.cpp b/loolwsd/Admin.cpp index ca6052b..92a0dac 100644 --- a/loolwsd/Admin.cpp +++ b/loolwsd/Admin.cpp @@ -493,6 +493,9 @@ void Admin::run() Util::pollPipeForReading(pollPipeNotify, FIFO_NOTIFY, NotifyPipe, [this](std::string& message) { return handleInput(message); } ); + _memStatsTimer.cancel(); + _cpuStatsTimer.cancel(); + Log::debug("Thread [" + thread_name + "] finished."); } commit cfac07e3a1702baf77f41b97af9f14390a363061 Author: Pranav Kant <[email protected]> Date: Wed Mar 23 18:11:18 2016 +0530 loolwsd: Split DocumentBroker to its header and impl file Change-Id: I8219300e271892f9f8fdecd8b38d9ea445cb7199 diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp new file mode 100644 index 0000000..d3f3134 --- /dev/null +++ b/loolwsd/DocumentBroker.cpp @@ -0,0 +1,107 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <Poco/Path.h> + +#include "DocumentBroker.hpp" + +Poco::URI DocumentBroker::sanitizeURI(std::string uri) +{ + // The URI of the document should be url-encoded. + std::string decodedUri; + Poco::URI::decode(uri, decodedUri); + auto uriPublic = Poco::URI(decodedUri); + + if (uriPublic.isRelative() || uriPublic.getScheme() == "file") + { + // TODO: Validate and limit access to local paths! + uriPublic.normalize(); + } + + if (uriPublic.getPath().empty()) + { + throw std::runtime_error("Invalid URI."); + } + + return uriPublic; +} + +std::string DocumentBroker::getDocKey(const Poco::URI& uri) +{ + // Keep the host as part of the key to close a potential security hole. + std::string docKey; + Poco::URI::encode(uri.getHost() + uri.getPath(), "", docKey); + return docKey; +} + +DocumentBroker::DocumentBroker(const Poco::URI& uriPublic, + const std::string& docKey, + const std::string& childRoot) : + _uriPublic(uriPublic), + _docKey(docKey), + _childRoot(childRoot), + _sessionsCount(0) +{ + assert(!_docKey.empty()); + assert(!_childRoot.empty()); + Log::info("DocumentBroker [" + _uriPublic.toString() + "] created. DocKey: [" + _docKey + "]"); +} + +void DocumentBroker::validate(const Poco::URI& uri) +{ + Log::info("Validating: " + uri.toString()); + auto storage = createStorage("", "", uri); + storage->getFileInfo(uri); +} + +bool DocumentBroker::load(const std::string& jailId) +{ + Log::debug("Loading from URI: " + _uriPublic.toString()); + + std::unique_lock<std::mutex> lock(_mutex); + + if (_storage) + { + // Already loaded. Nothing to do. + return true; + } + + _jailId = jailId; + + // The URL is the publicly visible one, not visible in the chroot jail. + // We need to map it to a jailed path and copy the file there. + + // user/doc/jailId + const auto jailPath = Poco::Path(JailedDocumentRoot, jailId); + const std::string jailRoot = getJailRoot(); + + Log::info("jailPath: " + jailPath.toString() + ", jailRoot: " + jailRoot); + + _storage = createStorage(jailRoot, jailPath.toString(), _uriPublic); + + const auto localPath = _storage->loadStorageFileToLocal(); + _uriJailed = Poco::URI(Poco::URI("file://"), localPath); + return true; +} + +bool DocumentBroker::save() +{ + Log::debug("Saving to URI: " + _uriPublic.toString()); + + assert(_storage); + return _storage->saveLocalFileToStorage(); +} + +std::string DocumentBroker::getJailRoot() const +{ + assert(!_jailId.empty()); + return Poco::Path(_childRoot, _jailId).toString(); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp index 89087a0..efbd955 100644 --- a/loolwsd/DocumentBroker.hpp +++ b/loolwsd/DocumentBroker.hpp @@ -14,8 +14,6 @@ #include <mutex> #include <string> -#include <Poco/Path.h> - #include "Storage.hpp" /// DocumentBroker is responsible for setting up a document @@ -27,101 +25,28 @@ class DocumentBroker public: static - Poco::URI sanitizeURI(std::string uri) - { - // The URI of the document should be url-encoded. - std::string decodedUri; - Poco::URI::decode(uri, decodedUri); - auto uriPublic = Poco::URI(decodedUri); - - if (uriPublic.isRelative() || uriPublic.getScheme() == "file") - { - // TODO: Validate and limit access to local paths! - uriPublic.normalize(); - } - - if (uriPublic.getPath().empty()) - { - throw std::runtime_error("Invalid URI."); - } - - return uriPublic; - } + Poco::URI sanitizeURI(std::string uri); /// Returns a document-specific key based /// on the URI of the document. static - std::string getDocKey(const Poco::URI& uri) - { - // Keep the host as part of the key to close a potential security hole. - std::string docKey; - Poco::URI::encode(uri.getHost() + uri.getPath(), "", docKey); - return docKey; - } + std::string getDocKey(const Poco::URI& uri); DocumentBroker(const Poco::URI& uriPublic, const std::string& docKey, - const std::string& childRoot) : - _uriPublic(uriPublic), - _docKey(docKey), - _childRoot(childRoot), - _sessionsCount(0) - { - assert(!_docKey.empty()); - assert(!_childRoot.empty()); - Log::info("DocumentBroker [" + _uriPublic.toString() + "] created. DocKey: [" + _docKey + "]"); - } + const std::string& childRoot); ~DocumentBroker() { Log::info("~DocumentBroker [" + _uriPublic.toString() + "] destroyed."); } - void validate(const Poco::URI& uri) - { - Log::info("Validating: " + uri.toString()); - auto storage = createStorage("", "", uri); - storage->getFileInfo(uri); - } + void validate(const Poco::URI& uri); /// Loads a document from the public URI into the jail. - bool load(const std::string& jailId) - { - Log::debug("Loading from URI: " + _uriPublic.toString()); - - std::unique_lock<std::mutex> lock(_mutex); - - if (_storage) - { - // Already loaded. Nothing to do. - return true; - } + bool load(const std::string& jailId); - _jailId = jailId; - - // The URL is the publicly visible one, not visible in the chroot jail. - // We need to map it to a jailed path and copy the file there. - - // user/doc/jailId - const auto jailPath = Poco::Path(JailedDocumentRoot, jailId); - const std::string jailRoot = getJailRoot(); - - Log::info("jailPath: " + jailPath.toString() + ", jailRoot: " + jailRoot); - - _storage = createStorage(jailRoot, jailPath.toString(), _uriPublic); - - const auto localPath = _storage->loadStorageFileToLocal(); - _uriJailed = Poco::URI(Poco::URI("file://"), localPath); - return true; - } - - bool save() - { - Log::debug("Saving to URI: " + _uriPublic.toString()); - - assert(_storage); - return _storage->saveLocalFileToStorage(); - } + bool save(); Poco::URI getPublicUri() const { return _uriPublic; } Poco::URI getJailedUri() const { return _uriJailed; } @@ -131,11 +56,7 @@ public: unsigned incSessions() { return ++_sessionsCount; } unsigned getSessionsCount() { return _sessionsCount; } - std::string getJailRoot() const - { - assert(!_jailId.empty()); - return Poco::Path(_childRoot, _jailId).toString(); - } + std::string getJailRoot() const; private: const Poco::URI _uriPublic; diff --git a/loolwsd/Makefile.am b/loolwsd/Makefile.am index 2dec0ef..c498c45 100644 --- a/loolwsd/Makefile.am +++ b/loolwsd/Makefile.am @@ -12,7 +12,7 @@ AM_CTAGSFLAGS = $(AM_ETAGSFLAGS) shared_sources = LOOLProtocol.cpp LOOLSession.cpp MessageQueue.cpp Util.cpp -loolwsd_SOURCES = LOOLWSD.cpp ChildProcessSession.cpp MasterProcessSession.cpp TileCache.cpp Admin.cpp $(shared_sources) +loolwsd_SOURCES = LOOLWSD.cpp ChildProcessSession.cpp MasterProcessSession.cpp TileCache.cpp Admin.cpp DocumentBroker.cpp $(shared_sources) noinst_PROGRAMS = loadtest connect lokitclient diff --git a/loolwsd/Storage.hpp b/loolwsd/Storage.hpp index afe5408..dc0f2be 100644 --- a/loolwsd/Storage.hpp +++ b/loolwsd/Storage.hpp @@ -11,6 +11,7 @@ #ifndef INCLUDED_STORAGE_HPP #define INCLUDED_STORAGE_HPP +#include <cassert> #include <string> #include <fstream> _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
