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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Mar 1 21:15:56 UTC 2019


 wsd/DocumentBroker.cpp |   10 ++++------
 wsd/DocumentBroker.hpp |    3 +--
 wsd/LOOLWSD.cpp        |   38 ++++++++++++++++++++++----------------
 3 files changed, 27 insertions(+), 24 deletions(-)

New commits:
commit 09211bad8cb195a5d1f44397e829793df52536a0
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Fri Mar 1 22:05:11 2019 +0100
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Fri Mar 1 22:05:11 2019 +0100

    Authenticate socket earlier.
    
    Change-Id: Idf3caba6276dd71450b86574ef39a1a16e73f61c

diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 7825e9067..26321eead 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -2328,11 +2328,7 @@ private:
         StringTokenizer tokens(request.getURI(), "/?");
         if (tokens.count() > 2 && tokens[2] == "convert-to")
         {
-            ConvertToPartHandler handler(/*convertTo =*/ true);
-            HTMLForm form(request, message, handler);
-
-            std::string format = (form.has("format") ? form.get("format") : "");
-
+            // Validate sender - FIXME: should do this even earlier.
             if (!allowConvertTo(socket->clientAddress(), request, true))
             {
                 LOG_TRC("Conversion not allowed from this address");
@@ -2347,6 +2343,11 @@ private:
                 return;
             }
 
+            ConvertToPartHandler handler(/*convertTo =*/ true);
+            HTMLForm form(request, message, handler);
+
+            std::string format = (form.has("format") ? form.get("format") : "");
+
             // prefer what is in the URI
             if (tokens.count() > 3)
                 format = tokens[3];
commit 51b72b04a9e0c39df525caeb0744ca44a8ba0143
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Fri Mar 1 22:03:35 2019 +0100
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Fri Mar 1 22:03:35 2019 +0100

    Simpify DocumentBroker constructor.
    
    Change-Id: I0bf29df9316b129d34862c7464bb6636d42a850d

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 8f86c0398..974fe7f3c 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -150,13 +150,11 @@ std::atomic<unsigned> DocumentBroker::DocBrokerId(1);
 
 DocumentBroker::DocumentBroker(const std::string& uri,
                                const Poco::URI& uriPublic,
-                               const std::string& docKey,
-                               const std::string& childRoot) :
+                               const std::string& docKey) :
     _uriOrig(uri),
     _uriPublic(uriPublic),
     _docKey(docKey),
     _docId(Util::encodeId(DocBrokerId++, 3)),
-    _childRoot(childRoot),
     _documentChangedInStorage(false),
     _lastSaveTime(std::chrono::steady_clock::now()),
     _lastSaveRequestTime(std::chrono::steady_clock::now() - std::chrono::milliseconds(COMMAND_TIMEOUT_MS)),
@@ -175,10 +173,10 @@ DocumentBroker::DocumentBroker(const std::string& uri,
     _debugRenderedTileCount(0)
 {
     assert(!_docKey.empty());
-    assert(!_childRoot.empty());
+    assert(!LOOLWSD::ChildRoot.empty());
 
     LOG_INF("DocumentBroker [" << LOOLWSD::anonymizeUrl(_uriPublic.toString()) <<
-            "] created with docKey [" << _docKey << "] and root [" << _childRoot << "]");
+            "] created with docKey [" << _docKey << "]");
 }
 
 void DocumentBroker::startThread()
@@ -1072,7 +1070,7 @@ bool DocumentBroker::sendUnoSave(const std::string& sessionId, bool dontTerminat
 std::string DocumentBroker::getJailRoot() const
 {
     assert(!_jailId.empty());
-    return Poco::Path(_childRoot, _jailId).toString();
+    return Poco::Path(LOOLWSD::ChildRoot, _jailId).toString();
 }
 
 size_t DocumentBroker::addSession(const std::shared_ptr<ClientSession>& session)
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index b5e4d65d9..46c300df1 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -221,8 +221,7 @@ public:
     /// Construct DocumentBroker with URI, docKey, and root path.
     DocumentBroker(const std::string& uri,
                    const Poco::URI& uriPublic,
-                   const std::string& docKey,
-                   const std::string& childRoot);
+                   const std::string& docKey);
 
     ~DocumentBroker();
 
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index e46cb6cca..7825e9067 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -1702,7 +1702,7 @@ static std::shared_ptr<DocumentBroker> findOrCreateDocBroker(WebSocketHandler& w
 
         // Set the one we just created.
         LOG_DBG("New DocumentBroker for docKey [" << docKey << "].");
-        docBroker = std::make_shared<DocumentBroker>(uri, uriPublic, docKey, LOOLWSD::ChildRoot);
+        docBroker = std::make_shared<DocumentBroker>(uri, uriPublic, docKey);
         DocBrokers.emplace(docKey, docBroker);
         LOG_TRC("Have " << DocBrokers.size() << " DocBrokers after inserting [" << docKey << "].");
     }
@@ -2364,7 +2364,7 @@ private:
                     std::unique_lock<std::mutex> docBrokersLock(DocBrokersMutex);
 
                     LOG_DBG("New DocumentBroker for docKey [" << docKey << "].");
-                    auto docBroker = std::make_shared<DocumentBroker>(fromPath, uriPublic, docKey, LOOLWSD::ChildRoot);
+                    auto docBroker = std::make_shared<DocumentBroker>(fromPath, uriPublic, docKey);
 
                     cleanupDocBrokers();
 
commit b255ce528bb6c7d037c99ff612a8efba92182abd
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Fri Mar 1 18:59:40 2019 +0100
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Fri Mar 1 21:59:55 2019 +0100

    Avoid using un-necessary reference.
    
    Change-Id: Id5a9fed8fb790f2af8facac119e9e0da476b1e47

diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 0919828ca..e46cb6cca 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -558,18 +558,24 @@ std::shared_ptr<ChildProcess> getNewChild_Blocks(
 
 #if !MOBILEAPP
 
-/// Handles the filename part of the convert-to POST request payload.
+/// Handles the filename part of the convert-to POST request payload,
+/// Also owns the file - cleaning it up when destroyed.
 class ConvertToPartHandler : public PartHandler
 {
-    std::string& _filename;
+    std::string _filename;
 
     /// Is it really a convert-to, ie. use an especially formed path?
     bool _convertTo;
 
 public:
-    ConvertToPartHandler(std::string& filename, bool convertTo = false)
-        : _filename(filename)
-        , _convertTo(convertTo)
+    std::string getFilename() const { return _filename; }
+
+    ConvertToPartHandler(bool convertTo = false)
+        : _convertTo(convertTo)
+    {
+    }
+
+    virtual ~ConvertToPartHandler()
     {
     }
 
@@ -2322,8 +2328,7 @@ private:
         StringTokenizer tokens(request.getURI(), "/?");
         if (tokens.count() > 2 && tokens[2] == "convert-to")
         {
-            std::string fromPath;
-            ConvertToPartHandler handler(fromPath, /*convertTo =*/ true);
+            ConvertToPartHandler handler(/*convertTo =*/ true);
             HTMLForm form(request, message, handler);
 
             std::string format = (form.has("format") ? form.get("format") : "");
@@ -2347,6 +2352,7 @@ private:
                 format = tokens[3];
 
             bool sent = false;
+            std::string fromPath = handler.getFilename();
             LOG_INF("Conversion request for URI [" << fromPath << "] format [" << format << "].");
             if (!fromPath.empty() && !format.empty())
             {
@@ -2432,8 +2438,7 @@ private:
         {
             LOG_INF("Insert file request.");
 
-            std::string tmpPath;
-            ConvertToPartHandler handler(tmpPath);
+            ConvertToPartHandler handler;
             HTMLForm form(request, message, handler);
 
             if (form.has("childid") && form.has("name"))
@@ -2463,7 +2468,7 @@ private:
                                               + JAILED_DOCUMENT_ROOT + "insertfile";
                     File(dirPath).createDirectories();
                     std::string fileName = dirPath + "/" + form.get("name");
-                    File(tmpPath).moveTo(fileName);
+                    File(handler.getFilename()).moveTo(fileName);
                     response.setContentLength(0);
                     socket->send(response);
                     return;


More information about the Libreoffice-commits mailing list