[Libreoffice-commits] online.git: Branch 'libreoffice-5-3' - wsd/ClientSession.hpp wsd/DocumentBroker.cpp wsd/Storage.cpp wsd/Storage.hpp

Pranav Kant pranavk at collabora.co.uk
Tue May 30 09:27:15 UTC 2017


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

New commits:
commit 79ac43be8d385675fc157f9bbff063d5ebb0c4da
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Tue Dec 13 14:43:58 2016 +0530

    wsd: Store wopifileinfo separately per client session
    
    Client needs to act accordingly as per permissions/settings set
    by the WOPI host.
    
    (cherry picked from commit 3e2a9df6dd0eb44958875d9f443c5c3fe0b96698)
    Reviewed-on: https://gerrit.libreoffice.org/32169
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Tested-by: Michael Meeks <michael.meeks at collabora.com>
    
    Change-Id: I7c9f311be50d4aff2562da0cfef2fff889f111d0
    Reviewed-on: https://gerrit.libreoffice.org/37996
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index 37035936..f7febe51 100644
--- a/wsd/ClientSession.hpp
+++ b/wsd/ClientSession.hpp
@@ -11,6 +11,7 @@
 #define INCLUDED_CLIENTSSESSION_HPP
 
 #include "Session.hpp"
+#include "Storage.hpp"
 #include "MessageQueue.hpp"
 
 #include <Poco/URI.h>
@@ -64,6 +65,9 @@ public:
     /// client made the request to us
     const Poco::URI& getPublicUri() const { return _uriPublic; }
 
+    /// Set WOPI fileinfo object
+    void setWopiFileInfo(std::unique_ptr<WopiStorage::WOPIFileInfo>& wopiFileInfo) { _wopiFileInfo = std::move(wopiFileInfo); }
+
 private:
     virtual bool _handleInput(const char* buffer, int length) override;
 
@@ -110,6 +114,9 @@ private:
     MessageQueue _saveAsQueue;
 
     int _loadPart;
+    
+    /// Wopi FileInfo object
+    std::unique_ptr<WopiStorage::WOPIFileInfo> _wopiFileInfo;
 };
 
 #endif
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 49873008..78f64059 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -248,11 +248,11 @@ bool DocumentBroker::load(std::shared_ptr<ClientSession>& session, const std::st
     std::chrono::duration<double> getInfoCallDuration(0);
     if (dynamic_cast<WopiStorage*>(_storage.get()) != nullptr)
     {
-        const WopiStorage::WOPIFileInfo wopifileinfo = static_cast<WopiStorage*>(_storage.get())->getWOPIFileInfo(uriPublic);
-        userid = wopifileinfo._userid;
-        username = wopifileinfo._username;
+        std::unique_ptr<WopiStorage::WOPIFileInfo> wopifileinfo = static_cast<WopiStorage*>(_storage.get())->getWOPIFileInfo(uriPublic);
+        userid = wopifileinfo->_userid;
+        username = wopifileinfo->_username;
 
-        if (!wopifileinfo._userCanWrite)
+        if (!wopifileinfo->_userCanWrite)
         {
             LOG_DBG("Setting the session as readonly");
             session->setReadOnly();
@@ -260,14 +260,14 @@ bool DocumentBroker::load(std::shared_ptr<ClientSession>& session, const std::st
 
         // Construct a JSON containing relevant WOPI host properties
         Object::Ptr wopiInfo = new Object();
-        if (!wopifileinfo._postMessageOrigin.empty())
+        if (!wopifileinfo->_postMessageOrigin.empty())
         {
-            wopiInfo->set("PostMessageOrigin", wopifileinfo._postMessageOrigin);
+            wopiInfo->set("PostMessageOrigin", wopifileinfo->_postMessageOrigin);
         }
 
-        wopiInfo->set("HidePrintOption", wopifileinfo._hidePrintOption);
-        wopiInfo->set("HideSaveOption", wopifileinfo._hideSaveOption);
-        wopiInfo->set("HideExportOption", wopifileinfo._hideExportOption);
+        wopiInfo->set("HidePrintOption", wopifileinfo->_hidePrintOption);
+        wopiInfo->set("HideSaveOption", wopifileinfo->_hideSaveOption);
+        wopiInfo->set("HideExportOption", wopifileinfo->_hideExportOption);
 
         std::ostringstream ossWopiInfo;
         wopiInfo->stringify(ossWopiInfo);
@@ -280,13 +280,16 @@ bool DocumentBroker::load(std::shared_ptr<ClientSession>& session, const std::st
             session->setDocumentOwner(true);
         }
 
-        getInfoCallDuration = wopifileinfo._callDuration;
+        getInfoCallDuration = wopifileinfo->_callDuration;
+
+        // Pass the ownership to client session
+        session->setWopiFileInfo(wopifileinfo);
     }
     else if (dynamic_cast<LocalStorage*>(_storage.get()) != nullptr)
     {
-        const LocalStorage::LocalFileInfo localfileinfo = static_cast<LocalStorage*>(_storage.get())->getLocalFileInfo(uriPublic);
-        userid = localfileinfo._userid;
-        username = localfileinfo._username;
+        std::unique_ptr<LocalStorage::LocalFileInfo> localfileinfo = static_cast<LocalStorage*>(_storage.get())->getLocalFileInfo(uriPublic);
+        userid = localfileinfo->_userid;
+        username = localfileinfo->_username;
     }
 
     LOG_DBG("Setting username [" << username << "] and userId [" << userid << "] for session [" << sessionId << "]");
diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp
index b9df6b2e..c54eceb3 100644
--- a/wsd/Storage.cpp
+++ b/wsd/Storage.cpp
@@ -186,7 +186,7 @@ std::unique_ptr<StorageBase> StorageBase::create(const Poco::URI& uri, const std
 
 std::atomic<unsigned> LocalStorage::LastLocalStorageId;
 
-LocalStorage::LocalFileInfo LocalStorage::getLocalFileInfo(const Poco::URI& uriPublic)
+std::unique_ptr<LocalStorage::LocalFileInfo> LocalStorage::getLocalFileInfo(const Poco::URI& uriPublic)
 {
     const auto path = Poco::Path(uriPublic.getPath());
     Log::debug("Getting info for local uri [" + uriPublic.toString() + "], path [" + path.toString() + "].");
@@ -202,7 +202,7 @@ LocalStorage::LocalFileInfo LocalStorage::getLocalFileInfo(const Poco::URI& uriP
     }
 
     // Set automatic userid and username
-    return LocalFileInfo({"localhost", std::string("Local Host #") + std::to_string(LastLocalStorageId++)});
+    return std::unique_ptr<LocalStorage::LocalFileInfo>(new LocalFileInfo({"localhost", std::string("Local Host #") + std::to_string(LastLocalStorageId++)}));
 }
 
 std::string LocalStorage::loadStorageFileToLocal()
@@ -353,7 +353,7 @@ void getWOPIValue(const Poco::JSON::Object::Ptr &object, const std::string& key,
 
 } // anonymous namespace
 
-WopiStorage::WOPIFileInfo WopiStorage::getWOPIFileInfo(const Poco::URI& uriPublic)
+std::unique_ptr<WopiStorage::WOPIFileInfo> WopiStorage::getWOPIFileInfo(const Poco::URI& uriPublic)
 {
     Log::debug("Getting info for wopi uri [" + uriPublic.toString() + "].");
 
@@ -422,7 +422,7 @@ WopiStorage::WOPIFileInfo WopiStorage::getWOPIFileInfo(const Poco::URI& uriPubli
         _fileInfo = FileInfo({filename, ownerId, Poco::Timestamp(), size});
     }
 
-    return WOPIFileInfo({userId, userName, canWrite, postMessageOrigin, hidePrintOption, hideSaveOption, hideExportOption, enableOwnerTermination, callDuration});
+    return std::unique_ptr<WopiStorage::WOPIFileInfo>(new WOPIFileInfo({userId, userName, canWrite, postMessageOrigin, hidePrintOption, hideSaveOption, hideExportOption, enableOwnerTermination, callDuration}));
 }
 
 /// uri format: http://server/<...>/wopi*/files/<id>/content
diff --git a/wsd/Storage.hpp b/wsd/Storage.hpp
index 8816a9e0..5c354db9 100644
--- a/wsd/Storage.hpp
+++ b/wsd/Storage.hpp
@@ -148,7 +148,7 @@ public:
     /// Returns the URI specific file data
     /// Also stores the basic file information which can then be
     /// obtained using getFileInfo method
-    LocalFileInfo getLocalFileInfo(const Poco::URI& uriPublic);
+    std::unique_ptr<LocalFileInfo> getLocalFileInfo(const Poco::URI& uriPublic);
 
     std::string loadStorageFileToLocal() override;
 
@@ -221,7 +221,7 @@ public:
     /// Returns the response of CheckFileInfo WOPI call for given URI
     /// Also extracts the basic file information from the response
     /// which can then be obtained using getFileInfo()
-    WOPIFileInfo getWOPIFileInfo(const Poco::URI& uriPublic);
+    std::unique_ptr<WOPIFileInfo> getWOPIFileInfo(const Poco::URI& uriPublic);
 
     /// uri format: http://server/<...>/wopi*/files/<id>/content
     std::string loadStorageFileToLocal() override;


More information about the Libreoffice-commits mailing list