[Libreoffice-commits] online.git: wsd/LOOLWSD.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Mon Jan 16 01:53:16 UTC 2017


 wsd/LOOLWSD.cpp |   66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 64 insertions(+), 2 deletions(-)

New commits:
commit 296d25d24c9d772b47e2896444eef948bf59c2a5
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Mon Jan 9 23:48:22 2017 -0500

    wsd: refactor create new client session
    
    Change-Id: Ida08901563c5d2aa4e3708f8d21a7e7bc0685ac6
    Reviewed-on: https://gerrit.libreoffice.org/33122
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 4809bf8..5cc6b2c 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1020,6 +1020,68 @@ private:
         return docBroker;
     }
 
+    static std::shared_ptr<ClientSession> createNewClientSession(const std::string& uri,
+                                                                 std::shared_ptr<LOOLWebSocket>& ws,
+                                                                 const std::string& id,
+                                                                 const Poco::URI& uriPublic,
+                                                                 const std::shared_ptr<DocumentBroker>& docBroker,
+                                                                 const bool isReadOnly)
+    {
+        LOG_CHECK_RET(docBroker && "Null docBroker instance", nullptr);
+        try
+        {
+            auto lock = docBroker->getLock();
+
+            // Validate the broker.
+            if (!docBroker->isAlive())
+            {
+                LOG_ERR("DocBroker is invalid or premature termination of child process.");
+                removeDocBrokerSession(docBroker);
+                return nullptr;
+            }
+
+            if (docBroker->isMarkedToDestroy())
+            {
+                LOG_ERR("DocBroker is marked to destroy, can't add session.");
+                removeDocBrokerSession(docBroker);
+                return nullptr;
+            }
+
+            // Now we have a DocumentBroker and we're ready to process client commands.
+            const std::string statusReady = "statusindicator: ready";
+            LOG_TRC("Sending to Client [" << statusReady << "].");
+            ws->sendFrame(statusReady.data(), statusReady.size());
+
+            // In case of WOPI, if this session is not set as readonly, it might be set so
+            // later after making a call to WOPI host which tells us the permission on files
+            // (UserCanWrite param).
+            auto session = std::make_shared<ClientSession>(id, ws, docBroker, uriPublic, isReadOnly);
+
+            LOOLWSD::dumpEventTrace(docBroker->getJailId(), id, "NewSession: " + uri);
+            docBroker->addSession(session);
+
+            lock.unlock();
+
+            const std::string fs = FileUtil::checkDiskSpaceOnRegisteredFileSystems();
+            if (!fs.empty())
+            {
+                LOG_WRN("File system of [" << fs << "] is dangerously low on disk space.");
+                const std::string diskfullMsg = "error: cmd=internal kind=diskfull";
+                // Alert all other existing sessions also
+                Util::alertAllUsers(diskfullMsg);
+            }
+
+            return session;
+        }
+        catch (const std::exception& exc)
+        {
+            LOG_WRN("Exception while preparing session [" << id << "]: " << exc.what());
+            removeDocBrokerSession(docBroker, id);
+        }
+
+        return nullptr;
+    }
+
     /// Remove DocumentBroker session and instance from DocBrokers.
     static void removeDocBrokerSession(const std::shared_ptr<DocumentBroker>& docBroker, const std::string& id = "")
     {
@@ -1030,7 +1092,7 @@ private:
 
         if (!id.empty())
         {
-             docBroker->removeSession(id);
+            docBroker->removeSession(id);
         }
 
         if (docBroker->getSessionsCount() == 0 || !docBroker->isAlive())
@@ -1039,7 +1101,7 @@ private:
             LOG_INF("Removing unloaded DocumentBroker for docKey [" << docKey << "].");
             DocBrokers.erase(docKey);
             docBroker->terminateChild(lock);
-         }
+        }
     }
 
     /// Process GET requests.


More information about the Libreoffice-commits mailing list