[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-2-1' - wsd/DocumentBroker.cpp wsd/LOOLWSD.cpp wsd/LOOLWSD.hpp wsd/Storage.hpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Wed Jun 7 17:34:14 UTC 2017


 wsd/DocumentBroker.cpp |    3 ++-
 wsd/LOOLWSD.cpp        |    8 +++++++-
 wsd/LOOLWSD.hpp        |    7 +++++++
 wsd/Storage.hpp        |    4 +++-
 4 files changed, 19 insertions(+), 3 deletions(-)

New commits:
commit 30918f82ef18fcc831a0e1c1f9e8ffacf3e83d4b
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Tue Jun 6 23:43:48 2017 -0400

    wsd: force readonly for view file types per discovery.xml
    
    File extensions marked as view (as opposed to edit)
    in discovery.xml are now forced to be read-only,
    regardless of what the client tries to request.
    
    Change-Id: I3eb00c33ff716800dc317f7377281c6d5f0909d7
    Reviewed-on: https://gerrit.libreoffice.org/38480
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>
    (cherry picked from commit 194faa6d693416ece2e17da34871b109e5243a6f)
    Reviewed-on: https://gerrit.libreoffice.org/38482
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index c04fa850..deae3326 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -405,7 +405,8 @@ bool DocumentBroker::load(const std::shared_ptr<ClientSession>& session, const s
         username = wopifileinfo->_username;
         userExtraInfo = wopifileinfo->_userExtraInfo;
 
-        if (!wopifileinfo->_userCanWrite)
+        if (!wopifileinfo->_userCanWrite ||
+            LOOLWSD::IsViewFileExtension(wopiStorage->getFileExtension()))
         {
             LOG_DBG("Setting the session as readonly");
             session->setReadOnly();
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 07277e9d..5e3ce0e4 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -546,6 +546,7 @@ std::string LOOLWSD::LOKitVersion;
 std::string LOOLWSD::ConfigFile = LOOLWSD_CONFIGDIR "/loolwsd.xml";
 Util::RuntimeConstant<bool> LOOLWSD::SSLEnabled;
 Util::RuntimeConstant<bool> LOOLWSD::SSLTermination;
+std::set<std::string> LOOLWSD::ViewFileExtensions;
 
 static std::string UnitTestLibrary;
 
@@ -2164,7 +2165,12 @@ private:
 
         for (unsigned long it = 0; it < listNodes->length(); ++it)
         {
-            static_cast<Element*>(listNodes->item(it))->setAttribute(urlsrc, uriValue);
+            Element* elem = static_cast<Element*>(listNodes->item(it));
+            elem->setAttribute(urlsrc, uriValue);
+
+            // Set the View extensions cache as well.
+            if (elem->getAttribute("name") == "view")
+                LOOLWSD::ViewFileExtensions.insert(elem->getAttribute("ext"));
         }
 
         std::ostringstream ostrXML;
diff --git a/wsd/LOOLWSD.hpp b/wsd/LOOLWSD.hpp
index 46538dc0..a608c6c1 100644
--- a/wsd/LOOLWSD.hpp
+++ b/wsd/LOOLWSD.hpp
@@ -55,6 +55,7 @@ public:
     static std::atomic<unsigned> NumConnections;
     static bool TileCachePersistent;
     static std::unique_ptr<TraceFileWriter> TraceDumper;
+    static std::set<std::string> ViewFileExtensions;
 
     /// Flag to shutdown the server.
     std::atomic<bool> ShutdownFlag;
@@ -81,6 +82,12 @@ public:
         return LOOLWSD::SSLTermination.get();
     }
 
+    /// Return truee iff extension is marked as view action in discovery.xml.
+    static bool IsViewFileExtension(const std::string& extension)
+    {
+        return ViewFileExtensions.find(extension) != ViewFileExtensions.end();
+    }
+
     /// Returns the value of the specified application configuration,
     /// of the default, if one doesn't exist.
     template<typename T>
diff --git a/wsd/Storage.hpp b/wsd/Storage.hpp
index 34b56de3..ed0331c0 100644
--- a/wsd/Storage.hpp
+++ b/wsd/Storage.hpp
@@ -83,7 +83,9 @@ public:
     bool isLoaded() const { return _isLoaded; }
 
     /// Returns the basic information about the file.
-    FileInfo getFileInfo() { return _fileInfo; }
+    const FileInfo& getFileInfo() const { return _fileInfo; }
+
+    std::string getFileExtension() const { return Poco::Path(_fileInfo._filename).getExtension(); }
 
     /// Returns a local file path for the given URI.
     /// If necessary copies the file locally first.


More information about the Libreoffice-commits mailing list