[Libreoffice-commits] online.git: 2 commits - loolwsd/ChildSession.cpp loolwsd/ChildSession.hpp loolwsd/ClientSession.cpp loolwsd/ClientSession.hpp loolwsd/DocumentBroker.cpp loolwsd/LOOLKit.cpp loolwsd/LOOLKit.hpp loolwsd/LOOLSession.cpp loolwsd/LOOLSession.hpp loolwsd/test

Pranav Kant pranavk at collabora.co.uk
Wed Oct 26 15:40:43 UTC 2016


 loolwsd/ChildSession.cpp       |    6 +++---
 loolwsd/ChildSession.hpp       |    6 ++++--
 loolwsd/ClientSession.cpp      |    6 +++++-
 loolwsd/ClientSession.hpp      |    1 +
 loolwsd/DocumentBroker.cpp     |    7 +++++--
 loolwsd/LOOLKit.cpp            |   19 ++++++++++---------
 loolwsd/LOOLKit.hpp            |   11 +++++++++++
 loolwsd/LOOLSession.cpp        |    6 ++++++
 loolwsd/LOOLSession.hpp        |    3 +++
 loolwsd/test/WhiteBoxTests.cpp |    2 +-
 10 files changed, 49 insertions(+), 18 deletions(-)

New commits:
commit 1c9e4f57d5ff870bc93039419e2e5ac158a81a3a
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Wed Oct 26 20:38:25 2016 +0530

    loolwsd: Include UserId in 'viewinfo' response
    
    Change-Id: Ia467086343ff2308f80d873dfe0a617733036a2e

diff --git a/loolwsd/ChildSession.cpp b/loolwsd/ChildSession.cpp
index 4e1243f..e1a5bbe 100644
--- a/loolwsd/ChildSession.cpp
+++ b/loolwsd/ChildSession.cpp
@@ -413,7 +413,7 @@ namespace
 {
 
 /// Given a view ID <-> user name map and a .uno:DocumentRepair result, annotate with user names.
-void insertUserNames(const std::map<int, std::string>& viewInfo, std::string& json)
+void insertUserNames(const std::map<int, UserInfo>& viewInfo, std::string& json)
 {
     Poco::JSON::Parser parser;
     auto root = parser.parse(json).extract<Poco::JSON::Object::Ptr>();
@@ -430,7 +430,7 @@ void insertUserNames(const std::map<int, std::string>& viewInfo, std::string& js
                 int viewId = action->getValue<int>("viewId");
                 auto it = viewInfo.find(viewId);
                 if (it != viewInfo.end())
-                    action->set("userName", Poco::Dynamic::Var(it->second));
+                    action->set("userName", Poco::Dynamic::Var(it->second.username));
             }
         }
     }
@@ -466,7 +466,7 @@ bool ChildSession::getCommandValues(const char* /*buffer*/, int /*length*/, Stri
                                         std::string(pValues == nullptr ? "" : pValues),
                                         std::string(pUndo == nullptr ? "" : pUndo));
         // json only contains view IDs, insert matching user names.
-        std::map<int, std::string> viewInfo = _docManager.getViewInfo();
+        std::map<int, UserInfo> viewInfo = _docManager.getViewInfo();
         insertUserNames(viewInfo, json);
         success = sendTextFrame("commandvalues: " + json);
         std::free(pValues);
diff --git a/loolwsd/ChildSession.hpp b/loolwsd/ChildSession.hpp
index e076b4f..7b0a3ca 100644
--- a/loolwsd/ChildSession.hpp
+++ b/loolwsd/ChildSession.hpp
@@ -16,6 +16,7 @@
 #include <Poco/NotificationQueue.h>
 
 #include "Common.hpp"
+#include "LOOLKit.hpp"
 #include "LOOLSession.hpp"
 #include "LibreOfficeKit.hpp"
 
@@ -43,9 +44,9 @@ public:
     /// Send updated view info to all active sessions
     virtual
     void notifyViewInfo(const std::vector<int>& viewIds) = 0;
-    /// Get a view ID <-> user name map.
+    /// Get a view ID <-> UserInfo map.
     virtual
-    std::map<int, std::string> getViewInfo() = 0;
+    std::map<int, UserInfo> getViewInfo() = 0;
     virtual
     std::mutex& getMutex() = 0;
     virtual
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index 07f2d25..e08c29b 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -844,16 +844,16 @@ private:
         notifyViewInfo(viewIds);
     }
 
-    std::map<int, std::string> getViewInfo() override
+    std::map<int, UserInfo> getViewInfo() override
     {
         std::unique_lock<std::mutex> lock(_mutex);
-        std::map<int, std::string> viewInfo;
+        std::map<int, UserInfo> viewInfo;
 
         for (auto& pair : _sessions)
         {
             const auto& session = pair.second;
             const auto viewId = session->getViewId();
-            viewInfo[viewId] = session->getViewUserName();
+            viewInfo[viewId] = UserInfo({session->getViewUserId(), session->getViewUserName()});
         }
 
         viewInfo.insert(_oldSessionIds.begin(), _oldSessionIds.end());
@@ -875,7 +875,7 @@ private:
     void notifyViewInfo(const std::vector<int>& viewIds) override
     {
         // Store the list of viewid, username mapping in a map
-        std::map<int, std::string> viewInfoMap = getViewInfo();
+        std::map<int, UserInfo> viewInfoMap = getViewInfo();
         std::map<std::string, int> viewColorsMap = getViewColors();
         std::unique_lock<std::mutex> lock(_mutex);
 
@@ -895,10 +895,11 @@ private:
             }
             else
             {
-                viewInfoObj->set("username", viewInfoMap[viewId]);
-                if (viewColorsMap.find(viewInfoMap[viewId]) != viewColorsMap.end())
+                viewInfoObj->set("userid", viewInfoMap[viewId].userid);
+                viewInfoObj->set("username", viewInfoMap[viewId].username);
+                if (viewColorsMap.find(viewInfoMap[viewId].username) != viewColorsMap.end())
                 {
-                    color = viewColorsMap[viewInfoMap[viewId]];
+                    color = viewColorsMap[viewInfoMap[viewId].username];
                 }
             }
             viewInfoObj->set("color", color);
@@ -1132,7 +1133,7 @@ private:
                 if (message == "disconnect")
                 {
                     Log::debug("Removing ChildSession " + sessionId);
-                    _oldSessionIds[it->second->getViewId()] = it->second->getViewUserName();
+                    _oldSessionIds[it->second->getViewId()] = UserInfo({it->second->getViewUserId(), it->second->getViewUserName()});
                     _sessions.erase(it);
                     return true;
                 }
@@ -1271,7 +1272,7 @@ private:
     std::atomic_size_t _isLoading;
     std::map<int, std::unique_ptr<CallbackDescriptor>> _viewIdToCallbackDescr;
     std::map<std::string, std::shared_ptr<ChildSession>> _sessions;
-    std::map<int, std::string> _oldSessionIds;
+    std::map<int, UserInfo> _oldSessionIds;
     Poco::Thread _callbackThread;
     std::atomic_size_t _clientViews;
 };
diff --git a/loolwsd/LOOLKit.hpp b/loolwsd/LOOLKit.hpp
index 25684b1..61196fa 100644
--- a/loolwsd/LOOLKit.hpp
+++ b/loolwsd/LOOLKit.hpp
@@ -30,6 +30,17 @@ struct CallbackDescriptor
     IDocumentManager* const Doc;
     const int ViewId;
 };
+
+/// User Info container used to store user information
+/// till the end of process lifecycle - including
+/// after any child session goes away
+struct UserInfo
+{
+    std::string userid;
+    std::string username;
+};
+
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/loolwsd/test/WhiteBoxTests.cpp b/loolwsd/test/WhiteBoxTests.cpp
index 45db538..fd3814a 100644
--- a/loolwsd/test/WhiteBoxTests.cpp
+++ b/loolwsd/test/WhiteBoxTests.cpp
@@ -178,7 +178,7 @@ public:
     {
     }
 
-    std::map<int, std::string> getViewInfo() override
+    std::map<int, UserInfo> getViewInfo() override
     {
         return {};
     }
commit cccf6dcb7d94304672558a92fb47fe278a1f9856
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Wed Oct 26 20:05:40 2016 +0530

    loolwsd: Store UserId in ChildSession
    
    Change-Id: I46593442f7f8c61bddf00a624977c9d32bffdf44

diff --git a/loolwsd/ChildSession.hpp b/loolwsd/ChildSession.hpp
index ccd0720..e076b4f 100644
--- a/loolwsd/ChildSession.hpp
+++ b/loolwsd/ChildSession.hpp
@@ -75,6 +75,7 @@ public:
     bool getPartPageRectangles(const char *buffer, int length);
     int getViewId() const { return _viewId; }
     void setViewId(const int viewId) { _viewId = viewId; }
+    const std::string& getViewUserId() const { return _userId; }
     const std::string& getViewUserName() const { return _userName; }
 
     void loKitCallback(const int nType, const std::string& rPayload);
diff --git a/loolwsd/ClientSession.cpp b/loolwsd/ClientSession.cpp
index 2faf494..69654da 100644
--- a/loolwsd/ClientSession.cpp
+++ b/loolwsd/ClientSession.cpp
@@ -227,8 +227,12 @@ bool ClientSession::loadDocument(const char* /*buffer*/, int /*length*/, StringT
         oss << " url=" << docBroker->getPublicUri().toString();
         oss << " jail=" << docBroker->getJailedUri().toString();
 
-        if (!_userName.empty())
+        if (!_userId.empty() && !_userName.empty())
         {
+            std::string encodedUserId;
+            Poco::URI::encode(_userId, "", encodedUserId);
+            oss << " authorid=" + encodedUserId;
+
             std::string encodedUserName;
             Poco::URI::encode(_userName, "", encodedUserName);
             oss << " author=" + encodedUserName;
diff --git a/loolwsd/ClientSession.hpp b/loolwsd/ClientSession.hpp
index 6ba901b..8136b00 100644
--- a/loolwsd/ClientSession.hpp
+++ b/loolwsd/ClientSession.hpp
@@ -37,6 +37,7 @@ public:
     std::shared_ptr<PrisonerSession> getPeer() const { return _peer; }
     bool shutdownPeer(Poco::UInt16 statusCode);
 
+    void setUserId(const std::string& userId) { _userId = userId; }
     void setUserName(const std::string& userName) { _userName = userName; }
 
     /**
diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 38846ac..5bc55ed 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -223,11 +223,12 @@ bool DocumentBroker::load(const std::string& sessionId, const std::string& jailI
     if (_storage)
     {
         // Call the storage specific file info functions
-        std::string username;
+        std::string userid, username;
         std::chrono::duration<double> getInfoCallDuration;
         if (dynamic_cast<WopiStorage*>(_storage.get()) != nullptr)
         {
             const WopiStorage::WOPIFileInfo wopifileinfo = static_cast<WopiStorage*>(_storage.get())->getWOPIFileInfo(uriPublic);
+            userid = wopifileinfo._userid;
             username = wopifileinfo._username;
 
             if (!wopifileinfo._userCanWrite)
@@ -241,10 +242,12 @@ bool DocumentBroker::load(const std::string& sessionId, const std::string& jailI
         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;
         }
 
-        Log::debug("Setting username of the session to: " + username);
+        Log::debug("Setting username [" + username + "] and userId [" + userid + "] for session [" + sessionId + "]");
+        it->second->setUserId(userid);
         it->second->setUserName(username);
 
         // Get basic file information from the storage
diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp
index ca94d00..0311c72 100644
--- a/loolwsd/LOOLSession.cpp
+++ b/loolwsd/LOOLSession.cpp
@@ -157,6 +157,12 @@ void LOOLSession::parseDocOptions(const StringTokenizer& tokens, int& part, std:
             _jailedFilePath = tokens[i].substr(strlen("jail="));
             ++offset;
         }
+        else if (tokens[i].find("authorid=") == 0)
+        {
+            std::string userId = tokens[i].substr(strlen("authorid="));
+            Poco::URI::decode(userId, _userId);
+            ++offset;
+        }
         else if (tokens[i].find("author=") == 0)
         {
             std::string userName = tokens[i].substr(strlen("author="));
diff --git a/loolwsd/LOOLSession.hpp b/loolwsd/LOOLSession.hpp
index 6015b9f..3c14f2d 100644
--- a/loolwsd/LOOLSession.hpp
+++ b/loolwsd/LOOLSession.hpp
@@ -178,6 +178,9 @@ protected:
     /// Document options: a JSON string, containing options (rendering, also possibly load in the future).
     std::string _docOptions;
 
+    /// Id of the user to whom the session belongs to
+    std::string _userId;
+
     /// Name of the user to whom the session belongs to
     std::string _userName;
 };


More information about the Libreoffice-commits mailing list