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

Pranav Kant pranavk at collabora.co.uk
Mon Dec 19 12:58:54 UTC 2016


 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 3547023b9db99e2468dbb335ff46cc58b834d3db
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.
    
    Change-Id: I7c9f311be50d4aff2562da0cfef2fff889f111d0
    (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>

diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp
index ae233e9..36a1f85 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 "SenderQueue.hpp"
 
@@ -93,6 +94,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;
 
@@ -145,6 +149,9 @@ private:
     SenderQueue<std::shared_ptr<MessagePayload>> _senderQueue;
     std::thread _senderThread;
     std::atomic<bool> _stop;
+    
+    /// Wopi FileInfo object
+    std::unique_ptr<WopiStorage::WOPIFileInfo> _wopiFileInfo;
 };
 
 #endif
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 6b061ea..365bd0b 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -249,11 +249,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();
@@ -261,14 +261,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);
@@ -281,13 +281,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 a2ca75b..b99c556 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()
@@ -355,7 +355,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() + "].");
 
@@ -424,7 +424,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 684488f..689f7db 100644
--- a/wsd/Storage.hpp
+++ b/wsd/Storage.hpp
@@ -143,7 +143,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;
 
@@ -216,7 +216,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