[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp
Michael Meeks (via logerrit)
logerrit at kemper.freedesktop.org
Thu Mar 5 16:10:54 UTC 2020
wsd/DocumentBroker.cpp | 32 ++++++++++++++++++++++++++++++++
wsd/DocumentBroker.hpp | 7 +++++++
wsd/LOOLWSD.cpp | 38 ++------------------------------------
3 files changed, 41 insertions(+), 36 deletions(-)
New commits:
commit da944760a62a82c21a32017b9c04526ea00d3cbd
Author: Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Wed Mar 4 21:56:48 2020 +0000
Commit: Michael Meeks <michael.meeks at collabora.com>
CommitDate: Thu Mar 5 17:10:36 2020 +0100
re-factor: move createNewSession into DocumentBroker.
Change-Id: I78f07a61fd79dfdd1c0d0ef21cf19218beec46ee
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/90025
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 74b827678..18bcdce63 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1497,6 +1497,38 @@ void DocumentBroker::finalRemoveSession(const std::string& id)
}
}
+std::shared_ptr<ClientSession> DocumentBroker::createNewClientSession(const WebSocketHandler* ws,
+ const std::string& id,
+ const Poco::URI& uriPublic,
+ const bool isReadOnly,
+ const std::string& hostNoTrust)
+{
+ try
+ {
+ // Now we have a DocumentBroker and we're ready to process client commands.
+ if (ws)
+ {
+ const std::string statusReady = "statusindicator: ready";
+ LOG_TRC("Sending to Client [" << statusReady << "].");
+ ws->sendMessage(statusReady);
+ }
+
+ // 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, shared_from_this(), uriPublic, isReadOnly, hostNoTrust);
+ session->construct();
+
+ return session;
+ }
+ catch (const std::exception& exc)
+ {
+ LOG_WRN("Exception while preparing session [" << id << "]: " << exc.what());
+ }
+
+ return nullptr;
+}
+
void DocumentBroker::addCallback(const SocketPoll::CallbackFn& fn)
{
_poll->addCallback(fn);
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 5e3bea9aa..f56bd1e3f 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -243,6 +243,13 @@ public:
/// Hard removes a session by ID, only for ClientSession.
void finalRemoveSession(const std::string& id);
+ /// Create new client session
+ std::shared_ptr<ClientSession> createNewClientSession(const WebSocketHandler* ws,
+ const std::string& id,
+ const Poco::URI& uriPublic,
+ const bool isReadOnly,
+ const std::string& hostNoTrust);
+
/// Thread safe termination of this broker if it has a lingering thread
void joinThread();
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 61b9d8f09..eb35d601c 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1780,40 +1780,6 @@ static std::shared_ptr<DocumentBroker> findOrCreateDocBroker(WebSocketHandler& w
return docBroker;
}
-static std::shared_ptr<ClientSession> createNewClientSession(const WebSocketHandler* ws,
- const std::string& id,
- const Poco::URI& uriPublic,
- const std::shared_ptr<DocumentBroker>& docBroker,
- const bool isReadOnly,
- const std::string& hostNoTrust)
-{
- LOG_CHECK_RET(docBroker && "Null docBroker instance", nullptr);
- try
- {
- // Now we have a DocumentBroker and we're ready to process client commands.
- if (ws)
- {
- const std::string statusReady = "statusindicator: ready";
- LOG_TRC("Sending to Client [" << statusReady << "].");
- ws->sendMessage(statusReady);
- }
-
- // 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, docBroker, uriPublic, isReadOnly, hostNoTrust);
- session->construct();
-
- return session;
- }
- catch (const std::exception& exc)
- {
- LOG_WRN("Exception while preparing session [" << id << "]: " << exc.what());
- }
-
- return nullptr;
-}
-
/// Handles the socket that the prisoner kit connected to WSD on.
class PrisonerRequestDispatcher : public WebSocketHandler
{
@@ -2850,8 +2816,8 @@ private:
const std::string hostNoTrust = (LOOLWSD::ServerName.empty() ? request.getHost() : LOOLWSD::ServerName);
#endif
- std::shared_ptr<ClientSession> clientSession = createNewClientSession(&ws, _id, uriPublic,
- docBroker, isReadOnly, hostNoTrust);
+ std::shared_ptr<ClientSession> clientSession =
+ docBroker->createNewClientSession(&ws, _id, uriPublic, isReadOnly, hostNoTrust);
if (clientSession)
{
// Transfer the client socket to the DocumentBroker when we get back to the poll:
More information about the Libreoffice-commits
mailing list