[Libreoffice-commits] online.git: loolwsd/DocumentStoreManager.hpp loolwsd/LOOLWSD.cpp loolwsd/LOOLWSD.hpp loolwsd/MasterProcessSession.cpp loolwsd/MasterProcessSession.hpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Mon Mar 14 03:00:53 UTC 2016
loolwsd/DocumentStoreManager.hpp | 148 +++++++++++++++++++++++++++++++++++++++
loolwsd/LOOLWSD.cpp | 2
loolwsd/LOOLWSD.hpp | 124 --------------------------------
loolwsd/MasterProcessSession.cpp | 2
loolwsd/MasterProcessSession.hpp | 2
5 files changed, 150 insertions(+), 128 deletions(-)
New commits:
commit 73bde2b5d2ca37ab167f0164e773eda7d431866e
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Thu Mar 10 21:42:33 2016 -0500
loolwsd: moved DocumentURI into own file and renamed to DocumentStoreManager
Change-Id: I5948ae532f0fd5917b99369733ec5ea36da2e437
Reviewed-on: https://gerrit.libreoffice.org/23204
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/DocumentStoreManager.hpp b/loolwsd/DocumentStoreManager.hpp
new file mode 100644
index 0000000..76ae479
--- /dev/null
+++ b/loolwsd/DocumentStoreManager.hpp
@@ -0,0 +1,148 @@
+/* -*- 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/.
+ */
+
+#ifndef INCLUDED_DOCUMENTSTOREMANAGER_HPP
+#define INCLUDED_DOCUMENTSTOREMANAGER_HPP
+
+#include <atomic>
+#include <mutex>
+#include <string>
+
+#include <Poco/Path.h>
+
+#include "Storage.hpp"
+
+/// A DocumentStoreManager as mananged by us.
+/// Contains URI, physical path, etc.
+class DocumentStoreManager
+{
+public:
+
+ static
+ Poco::URI getUri(std::string uri)
+ {
+ // The URI of the document is url-encoded
+ // and passed in our URL.
+ if (uri.size() > 1 && uri[0] == '/')
+ {
+ // Remove leading '/'.
+ uri.erase(0, 1);
+ }
+
+ 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();
+ }
+
+ Log::info("Public URI [" + uriPublic.toString() + "].");
+ if (uriPublic.getPath().empty())
+ {
+ throw std::runtime_error("Invalid URI.");
+ }
+
+ return uriPublic;
+ }
+
+ static
+ std::shared_ptr<DocumentStoreManager> create(const std::string& uri,
+ const std::string& jailRoot,
+ const std::string& childId)
+ {
+ 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();
+ }
+
+ Log::info("Public URI [" + uriPublic.toString() + "].");
+ if (uriPublic.getPath().empty())
+ {
+ throw std::runtime_error("Invalid URI.");
+ }
+
+ return create(uriPublic, jailRoot, childId);
+ }
+
+ static
+ std::shared_ptr<DocumentStoreManager> create(
+ const Poco::URI& uriPublic,
+ const std::string& jailRoot,
+ const std::string& childId)
+ {
+ Log::info("Creating DocumentStoreManager with uri: " + uriPublic.toString() + ", jailRoot: " + jailRoot + ", childId: " + childId);
+
+ // 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/childId
+ const auto jailPath = Poco::Path(JailedDocumentRoot, childId);
+
+ Log::info("jailPath: " + jailPath.toString() + ", jailRoot: " + jailRoot);
+
+ auto uriJailed = uriPublic;
+ if (uriPublic.isRelative() || uriPublic.getScheme() == "file")
+ {
+ Log::info("Public URI [" + uriPublic.toString() + "] is a file.");
+ std::unique_ptr<StorageBase> storage(new LocalStorage(jailRoot, jailPath.toString(), uriPublic.getPath()));
+ const auto localPath = storage->getLocalFilePathFromStorage();
+ uriJailed = Poco::URI(Poco::URI("file://"), localPath);
+ }
+ else
+ {
+ Log::info("Public URI [" + uriPublic.toString() +
+ "] assuming cloud storage.");
+ //TODO: Configure the storage to use. For now, assume it's WOPI.
+ std::unique_ptr<StorageBase> storage(new WopiStorage(jailRoot, jailPath.toString(), uriPublic.toString()));
+ const auto localPath = storage->getLocalFilePathFromStorage();
+ uriJailed = Poco::URI(Poco::URI("file://"), localPath);
+ }
+
+ auto document = std::shared_ptr<DocumentStoreManager>(new DocumentStoreManager(uriPublic, uriJailed, childId));
+
+ return document;
+ }
+
+ ~DocumentStoreManager()
+ {
+ Log::info("~DocumentStoreManager [" + _uriPublic.toString() + "] destroyed.");
+ }
+
+ Poco::URI getPublicUri() const { return _uriPublic; }
+ Poco::URI getJailedUri() const { return _uriJailed; }
+ std::string getJailId() const { return _jailId; }
+
+private:
+ DocumentStoreManager(const Poco::URI& uriPublic,
+ const Poco::URI& uriJailed,
+ const std::string& jailId) :
+ _uriPublic(uriPublic),
+ _uriJailed(uriJailed),
+ _jailId(jailId)
+ {
+ Log::info("DocumentStoreManager [" + _uriPublic.toString() + "] created.");
+ }
+
+private:
+ const Poco::URI _uriPublic;
+ const Poco::URI _uriJailed;
+ const std::string _jailId;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 5f841d8..23cc2a1 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -149,8 +149,6 @@ using Poco::Util::Option;
using Poco::Util::OptionSet;
using Poco::Util::ServerApplication;
-// Document management mutex.
-std::mutex DocumentURI::DocumentURIMutex;
/// Handles the filename part of the convert-to POST request payload.
class ConvertToPartHandler : public PartHandler
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index d18ba1f..e0120fe 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -22,132 +22,8 @@
#include "Auth.hpp"
#include "Common.hpp"
-#include "Storage.hpp"
#include "Util.hpp"
-/// A DocumentURI as mananged by us.
-/// Contains URI, physical path, etc.
-class DocumentURI
-{
-public:
-
- static
- Poco::URI getUri(std::string uri)
- {
- // The URI of the document is url-encoded
- // and passed in our URL.
- if (uri.size() > 1 && uri[0] == '/')
- {
- // Remove leading '/'.
- uri.erase(0, 1);
- }
-
- 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();
- }
-
- Log::info("Public URI [" + uriPublic.toString() + "].");
- if (uriPublic.getPath().empty())
- {
- throw std::runtime_error("Invalid URI.");
- }
-
- return uriPublic;
- }
-
- static
- std::shared_ptr<DocumentURI> create(const std::string& uri,
- const std::string& jailRoot,
- const std::string& childId)
- {
- 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();
- }
-
- Log::info("Public URI [" + uriPublic.toString() + "].");
- if (uriPublic.getPath().empty())
- {
- throw std::runtime_error("Invalid URI.");
- }
-
- return create(uriPublic, jailRoot, childId);
- }
-
- static
- std::shared_ptr<DocumentURI> create(const Poco::URI& uriPublic,
- const std::string& jailRoot,
- const std::string& childId)
- {
- Log::info("DocumentURI: uri: " + uriPublic.toString() + ", jailRoot: " + jailRoot + ", childId: " + childId);
-
- // 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/childId
- const auto jailPath = Poco::Path(JailedDocumentRoot, childId);
-
- Log::info("jailPath: " + jailPath.toString() + ", jailRoot: " + jailRoot);
-
- auto uriJailed = uriPublic;
- if (uriPublic.isRelative() || uriPublic.getScheme() == "file")
- {
- Log::info("Public URI [" + uriPublic.toString() + "] is a file.");
- std::unique_ptr<StorageBase> storage(new LocalStorage(jailRoot, jailPath.toString(), uriPublic.getPath()));
- const auto localPath = storage->getLocalFilePathFromStorage();
- uriJailed = Poco::URI(Poco::URI("file://"), localPath);
- }
- else
- {
- Log::info("Public URI [" + uriPublic.toString() +
- "] assuming cloud storage.");
- //TODO: Configure the storage to use. For now, assume it's WOPI.
- std::unique_ptr<StorageBase> storage(new WopiStorage(jailRoot, jailPath.toString(), uriPublic.toString()));
- const auto localPath = storage->getLocalFilePathFromStorage();
- uriJailed = Poco::URI(Poco::URI("file://"), localPath);
- }
-
- auto document = std::shared_ptr<DocumentURI>(new DocumentURI(uriPublic, uriJailed, childId));
-
- Log::info("DocumentURI [" + uriPublic.toString() + "] created.");
- return document;
- }
-
- Poco::URI getPublicUri() const { return _uriPublic; }
- Poco::URI getJailedUri() const { return _uriJailed; }
- std::string getJailId() const { return _jailId; }
-
-private:
- DocumentURI(const Poco::URI& uriPublic,
- const Poco::URI& uriJailed,
- const std::string& jailId) :
- _uriPublic(uriPublic),
- _uriJailed(uriJailed),
- _jailId(jailId)
- {
- }
-
-private:
-
- // DocumentURI management mutex.
- static std::mutex DocumentURIMutex;
-
-private:
- const Poco::URI _uriPublic;
- const Poco::URI _uriJailed;
- const std::string _jailId;
-};
class LOOLWSD: public Poco::Util::ServerApplication
{
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 18b9cec..307b1ae 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -799,7 +799,7 @@ void MasterProcessSession::dispatchChild()
}
const auto jailRoot = Poco::Path(LOOLWSD::ChildRoot, childSession->_childId);
- auto document = DocumentURI::create(_docURL, jailRoot.toString(), childSession->_childId);
+ auto document = DocumentStoreManager::create(_docURL, jailRoot.toString(), childSession->_childId);
_peer = childSession;
childSession->_peer = shared_from_this();
diff --git a/loolwsd/MasterProcessSession.hpp b/loolwsd/MasterProcessSession.hpp
index 68c82d2..d6cceb0 100644
--- a/loolwsd/MasterProcessSession.hpp
+++ b/loolwsd/MasterProcessSession.hpp
@@ -10,9 +10,9 @@
#ifndef INCLUDED_MASTERPROCESSSESSION_HPP
#define INCLUDED_MASTERPROCESSSESSION_HPP
-
#include <Poco/Random.h>
+#include "DocumentStoreManager.hpp"
#include "LOOLSession.hpp"
#include "TileCache.hpp"
More information about the Libreoffice-commits
mailing list