[Libreoffice-commits] online.git: loolwsd/DocumentBroker.hpp

2016-11-23 Thread Ashod Nakashian
 loolwsd/DocumentBroker.hpp |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 55c1e7568f7e87fa9dc2e7309ca74e5f182e7e89
Author: Ashod Nakashian 
Date:   Wed Nov 23 00:21:12 2016 -0500

loolwsd: kill redundant exception logging

Change-Id: I86ea48c4deaa42d164d2b0963931081d78d5f3ff
Reviewed-on: https://gerrit.libreoffice.org/31118
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 6672aaf..f31471a 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -81,7 +81,7 @@ public:
 }
 catch (const std::exception&)
 {
-LOG_ERR("Failed to send 'exit' command to child [" << _pid << 
"].");
+// Already logged in sendTextFrame.
 }
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.hpp

2016-11-09 Thread Ashod Nakashian
 loolwsd/DocumentBroker.hpp |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

New commits:
commit 4c6aae20d5d57266fdefe9193b4e9d5be9bf3201
Author: Ashod Nakashian 
Date:   Wed Nov 9 23:30:20 2016 -0500

loolwsd: don't error when killing a dead child process

Change-Id: I615911fb40a5218a6d1992dd94b63bff428699ee
Reviewed-on: https://gerrit.libreoffice.org/30742
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index b5c1fa2..94a13f2 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -98,10 +98,10 @@ public:
 _ws.reset();
 if (_pid != -1 && kill(_pid, 0) != 0)
 {
-if (rude)
+if (errno != ESRCH && rude)
 {
 LOG_INF("Killing child [" << _pid << "].");
-if (kill(_pid, SIGINT) != 0 && kill(_pid, 0) != 0)
+if (kill(_pid, SIGINT) != 0 && kill(_pid, 0) != 0 && errno 
!= ESRCH)
 {
 Log::syserror("Cannot terminate lokit [" + 
std::to_string(_pid) + "]. Abandoning.");
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.hpp

2016-11-08 Thread Ashod Nakashian
 loolwsd/DocumentBroker.hpp |   12 
 1 file changed, 4 insertions(+), 8 deletions(-)

New commits:
commit 462f71a632a6fda87b195b893eda6c74a8fb295f
Author: Ashod Nakashian 
Date:   Wed Nov 9 00:47:42 2016 -0500

loolwsd: no need to ping to check for live socket

Ping message needs to be echoed and that messes
up reading large messages that come in two parts.

Luckily, it's not necessary to do so as it's
sufficient to poll the state of the socket.

It's true polling is less accurate as there is
a timeout when a socket is disconnected, but
that doesn't seem to be an issue in practice.

Change-Id: I7a5744a621c4416b8f9d003871f6d613cc6ca7dc
Reviewed-on: https://gerrit.libreoffice.org/30705
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 2b0f162..b5c1fa2 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -146,14 +146,10 @@ public:
 {
 try
 {
-if (_pid > 1 && _ws && kill(_pid, 0) == 0)
-{
-// We don't care about the response (and shouldn't read here).
-_ws->sendFrame("PING", 4, Poco::Net::WebSocket::FRAME_OP_PING);
-LOG_DBG("Sent a PING.");
-
-return true;
-}
+using namespace Poco::Net;
+return (_pid > 1 && _ws && kill(_pid, 0) == 0 &&
+_ws->poll(Poco::Timespan(0), 
Socket::SelectMode::SELECT_WRITE) &&
+!_ws->poll(Poco::Timespan(0), 
Socket::SelectMode::SELECT_ERROR));
 }
 catch (const std::exception& exc)
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.hpp loolwsd/LOOLKit.cpp loolwsd/protocol.txt

2016-11-06 Thread Ashod Nakashian
 loolwsd/DocumentBroker.hpp |   37 -
 loolwsd/LOOLKit.cpp|5 +
 loolwsd/protocol.txt   |4 
 3 files changed, 37 insertions(+), 9 deletions(-)

New commits:
commit 8cd8ca27a642c3049476a575948f63e34ebb8df8
Author: Ashod Nakashian 
Date:   Sun Nov 6 21:16:11 2016 -0500

loolwsd: new 'exit' command to request child process termination

Change-Id: Id3f9bc67096b422630e04f59ed4ccbca012ddd4a
Reviewed-on: https://gerrit.libreoffice.org/30641
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index fdb7fac..60a7099 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -69,6 +69,18 @@ public:
 {
 LOG_DBG("Stopping ChildProcess [" << _pid << "]");
 _stop = true;
+
+try
+{
+if (_pid != -1 && _ws)
+{
+sendTextFrame("exit");
+}
+}
+catch (const std::exception&)
+{
+LOG_ERR("Failed to send 'exit' command to child [" << _pid << 
"].");
+}
 }
 
 void close(const bool rude)
@@ -84,16 +96,19 @@ public:
 }
 
 _ws.reset();
-if (_pid != -1)
+if (_pid != -1 && kill(_pid, 0) != 0)
 {
-LOG_INF("Closing child [" << _pid << "].");
-if (rude && kill(_pid, SIGINT) != 0 && kill(_pid, 0) != 0)
+if (rude)
 {
-Log::syserror("Cannot terminate lokit [" + 
std::to_string(_pid) + "]. Abandoning.");
+LOG_INF("Killing child [" << _pid << "].");
+if (kill(_pid, SIGINT) != 0 && kill(_pid, 0) != 0)
+{
+Log::syserror("Cannot terminate lokit [" + 
std::to_string(_pid) + "]. Abandoning.");
+}
 }
-
-_pid = -1;
 }
+
+_pid = -1;
 }
 catch (const std::exception& ex)
 {
@@ -108,9 +123,12 @@ public:
 {
 try
 {
-LOG_TRC("DocBroker to Child: " << data);
-_ws->sendFrame(data.data(), data.size());
-return true;
+if (_ws)
+{
+LOG_TRC("DocBroker to Child: " << data);
+_ws->sendFrame(data.data(), data.size());
+return true;
+}
 }
 catch (const std::exception& exc)
 {
@@ -119,6 +137,7 @@ public:
 throw;
 }
 
+LOG_WRN("No socket between DocBroker and child to send [" << data << 
"]");
 return false;
 }
 
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index 2fc199d..a89ba53 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -1521,6 +1521,11 @@ void lokit_main(const std::string& childRoot,
 LOG_DBG("CreateSession failed.");
 }
 }
+else if (tokens[0] == "exit")
+{
+LOG_TRC("Setting TerminationFlag due to 'exit' command 
from parent.");
+TerminationFlag = true;
+}
 else if (tokens[0] == "tile" || tokens[0] == "tilecombine" 
|| tokens[0] == "canceltiles" ||
  LOOLProtocol::getFirstToken(tokens[0], '-') == 
"child")
 {
diff --git a/loolwsd/protocol.txt b/loolwsd/protocol.txt
index 560208f..f6035b9 100644
--- a/loolwsd/protocol.txt
+++ b/loolwsd/protocol.txt
@@ -395,6 +395,10 @@ disconnect
 Signals to the child that the client for the respective connection
 has disconnected.
 
+exit
+
+Signals to the child that the process must end and exit.
+
 Admin console
 ===
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.hpp

2016-11-01 Thread Andras Timar
 loolwsd/DocumentBroker.hpp |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit ac86cdf764191d20aae56702e4029af90e4ba822
Author: Andras Timar 
Date:   Tue Nov 1 22:35:18 2016 +0100

typo fix

diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index f538fc3..c1d0936 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -97,7 +97,7 @@ public:
 }
 catch (const std::exception& ex)
 {
-Log::error("Eror while closing child process: " + 
std::string(ex.what()));
+Log::error("Error while closing child process: " + 
std::string(ex.what()));
 }
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.hpp

2016-10-16 Thread Ashod Nakashian
 loolwsd/DocumentBroker.hpp |   29 -
 1 file changed, 20 insertions(+), 9 deletions(-)

New commits:
commit 35fcaa1592b5a78bd46f326271a27b1710c0731b
Author: Ashod Nakashian 
Date:   Fri Oct 14 08:37:43 2016 -0400

loolwsd: don't join unjoinable thread and contain exceptions

Change-Id: I309153c3c05a152e4ef3d5a0948bcc589c9c
Reviewed-on: https://gerrit.libreoffice.org/29939
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 6891507..00d27e2 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -70,19 +70,30 @@ public:
 
 void close(const bool rude)
 {
-_stop = true;
-IoUtil::shutdownWebSocket(_ws);
-_thread.join();
-_ws.reset();
-if (_pid != -1)
+try
 {
-Log::info("Closing child [" + std::to_string(_pid) + "].");
-if (rude && kill(_pid, SIGINT) != 0 && kill(_pid, 0) != 0)
+_stop = true;
+IoUtil::shutdownWebSocket(_ws);
+if (_thread.joinable())
 {
-Log::syserror("Cannot terminate lokit [" + 
std::to_string(_pid) + "]. Abandoning.");
+_thread.join();
 }
 
-   _pid = -1;
+_ws.reset();
+if (_pid != -1)
+{
+Log::info("Closing child [" + std::to_string(_pid) + "].");
+if (rude && kill(_pid, SIGINT) != 0 && kill(_pid, 0) != 0)
+{
+Log::syserror("Cannot terminate lokit [" + 
std::to_string(_pid) + "]. Abandoning.");
+}
+
+   _pid = -1;
+}
+}
+catch (const std::exception& ex)
+{
+Log::error("Eror while closing child process: " + 
std::string(ex.what()));
 }
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.hpp loolwsd/LOOLKit.cpp loolwsd/LOOLWSD.cpp loolwsd/Unit.hpp loolwsd/Util.cpp

2016-08-30 Thread Miklos Vajna
 loolwsd/DocumentBroker.hpp |2 +-
 loolwsd/LOOLKit.cpp|4 ++--
 loolwsd/LOOLWSD.cpp|8 
 loolwsd/Unit.hpp   |2 +-
 loolwsd/Util.cpp   |2 +-
 5 files changed, 9 insertions(+), 9 deletions(-)

New commits:
commit e4bbc1513258d7d8ee50d93527439abdd0ea86ed
Author: Miklos Vajna 
Date:   Tue Aug 30 09:06:39 2016 +0200

Avoid inclusion of deprecated C++ headers

Change-Id: I29abf3feeb8419f4e15ccb8dc7c34c086696ce07

diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index e404e82..54ca138 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -10,7 +10,7 @@
 #ifndef INCLUDED_DOCUMENTBROKER_HPP
 #define INCLUDED_DOCUMENTBROKER_HPP
 
-#include 
+#include 
 
 #include 
 #include 
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index 39e98e7..44b8b2c 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -13,9 +13,9 @@
 
 #include 
 #include 
-#include 
+#include 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 21e867b..0de8e73 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -24,16 +24,16 @@
 // parent process that listens on the TCP port and accepts connections from 
LOOL clients, and a
 // number of child processes, each which handles a viewing (editing) session 
for one document.
 
-#include 
-#include 
+#include 
+#include 
 #include 
 
 #include 
 #include 
 #include 
 
-#include 
-#include 
+#include 
+#include 
 
 #include 
 #include 
diff --git a/loolwsd/Unit.hpp b/loolwsd/Unit.hpp
index 1fdec4c..f32047b 100644
--- a/loolwsd/Unit.hpp
+++ b/loolwsd/Unit.hpp
@@ -12,7 +12,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 
 #include 
 
diff --git a/loolwsd/Util.cpp b/loolwsd/Util.cpp
index 328957e..6599959 100644
--- a/loolwsd/Util.cpp
+++ b/loolwsd/Util.cpp
@@ -11,7 +11,7 @@
 #include "config.h"
 
 #include 
-#include 
+#include 
 #include 
 #include 
 #include 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.hpp

2016-05-01 Thread Ashod Nakashian
 loolwsd/DocumentBroker.hpp |   25 ++---
 1 file changed, 2 insertions(+), 23 deletions(-)

New commits:
commit 3dc72cab18a5fdc3b623dc18740e5143d40c7618
Author: Ashod Nakashian 
Date:   Sun May 1 20:30:52 2016 -0400

loolwsd: ChildProcess cleanup

Change-Id: I1ae4911d3f5d527af86f39ed2723bbceef12cffe
Reviewed-on: https://gerrit.libreoffice.org/24577
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 9bf290b..965ced3 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -35,11 +35,6 @@ class TileCache;
 class ChildProcess
 {
 public:
-ChildProcess() :
-_pid(-1)
-{
-}
-
 /// @param pid is the process ID of the child.
 /// @param ws is the control WebSocket to the child.
 ChildProcess(const Poco::Process::PID pid, const 
std::shared_ptr& ws) :
@@ -49,25 +44,9 @@ public:
 Log::info("ChildProcess ctor [" + std::to_string(_pid) + "].");
 }
 
-ChildProcess(ChildProcess&& other) :
-_pid(other._pid),
-_ws(other._ws)
-{
-Log::info("ChildProcess move ctor [" + std::to_string(_pid) + "].");
-other._pid = -1;
-other._ws.reset();
-}
-
-const ChildProcess& operator=(ChildProcess&& other)
-{
-Log::info("ChildProcess assign [" + std::to_string(_pid) + "].");
-_pid = other._pid;
-other._pid = -1;
-_ws = other._ws;
-other._ws.reset();
+ChildProcess(ChildProcess&& other) = delete;
 
-return *this;
-}
+const ChildProcess& operator=(ChildProcess&& other) = delete;
 
 ~ChildProcess()
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-04-24 Thread Ashod Nakashian
 loolwsd/DocumentBroker.hpp |   21 +++
 loolwsd/LOOLWSD.cpp|   48 ++---
 2 files changed, 53 insertions(+), 16 deletions(-)

New commits:
commit 2b5ecbd945b2d46cc9c7e0bead6e8304e5c31f21
Author: Ashod Nakashian 
Date:   Sun Apr 24 11:56:02 2016 -0400

loolwsd: validate child and spawn new ones before using

Change-Id: Icf7c8a2c0fa6c455cea4a65207f1727638169a28
Reviewed-on: https://gerrit.libreoffice.org/24335
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 9129fec..dcf2d2a 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -20,6 +20,7 @@
 #include 
 
 #include 
+#include 
 
 #include "IoUtil.hpp"
 #include "MasterProcessSession.hpp"
@@ -95,6 +96,25 @@ public:
 Poco::Process::PID getPid() const { return _pid; }
 std::shared_ptr getWebSocket() const { return _ws; }
 
+/// Check whether this child is alive and able to respond.
+bool isAlive() const
+{
+try
+{
+if (_pid > 1 && _ws && kill(_pid, 0) == 0)
+{
+// We don't care about the response (and shouldn't read here).
+_ws->sendFrame("PING", 4, Poco::Net::WebSocket::FRAME_OP_PING);
+return true;
+}
+}
+catch (const std::exception& exc)
+{
+}
+
+return false;
+}
+
 private:
 Poco::Process::PID _pid;
 std::shared_ptr _ws;
@@ -152,6 +172,7 @@ public:
 const std::string& getDocKey() const { return _docKey; }
 const std::string& getFilename() const { return _filename; };
 TileCache& tileCache() { return *_tileCache; }
+bool isAlive() const { return _childProcess && _childProcess->isAlive(); }
 size_t getSessionsCount() const
 {
 std::lock_guard lock(_mutex);
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index a0e46ef..ea40a49 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -190,27 +190,43 @@ static std::shared_ptr getNewChild()
 {
 std::unique_lock lock(newChildrenMutex);
 
-const int available = newChildren.size();
-int balance = LOOLWSD::NumPreSpawnedChildren;
-if (available == 0)
+namespace chrono = std::chrono;
+const auto startTime = chrono::steady_clock::now();
+do
 {
-Log::error("No available child. Sending spawn request to forkit and 
failing.");
-}
-else
-{
-balance -= available - 1;
-}
+const int available = newChildren.size();
+int balance = LOOLWSD::NumPreSpawnedChildren;
+if (available == 0)
+{
+Log::error("getNewChild: No available child. Sending spawn request 
to forkit and failing.");
+}
+else
+{
+balance -= available - 1; // Minus the one we'll dispatch just now.
+}
 
-forkChildren(balance);
+Log::debug("getNewChild: Have " + std::to_string(available) + " 
children, forking " + std::to_string(balance));
+forkChildren(balance);
 
-const auto timeout = std::chrono::milliseconds(CHILD_TIMEOUT_SECS * 1000);
-if (newChildrenCV.wait_for(lock, timeout, [](){ return 
!newChildren.empty(); }))
-{
-auto child = newChildren.back();
-newChildren.pop_back();
-return child;
+const auto timeout = chrono::milliseconds(CHILD_TIMEOUT_SECS * 1000);
+if (newChildrenCV.wait_for(lock, timeout, [](){ return 
!newChildren.empty(); }))
+{
+auto child = newChildren.back();
+newChildren.pop_back();
+
+// Validate before returning.
+if (child && child->isAlive())
+{
+Log::debug("getNewChild: Returning new child [" + 
std::to_string(child->getPid()) + "].");
+return child;
+}
+
+Log::debug("getNewChild: No live child, forking more.");
+}
 }
+while 
(chrono::duration_cast(chrono::steady_clock::now() - 
startTime).count() < CHILD_TIMEOUT_SECS * 2000);
 
+Log::debug("getNewChild: Timed out while waiting for new child.");
 return nullptr;
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-04-17 Thread Ashod Nakashian
 loolwsd/DocumentBroker.hpp |9 ++---
 loolwsd/LOOLWSD.cpp|6 --
 2 files changed, 10 insertions(+), 5 deletions(-)

New commits:
commit 8af52337a585dee81c552073ee8a42554a7980f8
Author: Ashod Nakashian 
Date:   Sun Apr 17 12:04:23 2016 -0400

loolwsd: clean and quick shutdown

Change-Id: Idfac3a27d19dd0a1b141d95a62c9e3453bd399a1
Reviewed-on: https://gerrit.libreoffice.org/24166
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index df8287a..260a78d 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -70,16 +70,19 @@ public:
 
 ~ChildProcess()
 {
-Log::info("~ChildProcess dtor [" + std::to_string(_pid) + "].");
-close(false);
+if (_pid > 0)
+{
+Log::info("~ChildProcess dtor [" + std::to_string(_pid) + "].");
+close(false);
+}
 }
 
 void close(const bool rude)
 {
-Log::info("Closing child [" + std::to_string(_pid) + "].");
 _ws.reset();
 if (_pid != -1)
 {
+Log::info("Closing child [" + std::to_string(_pid) + "].");
 if (rude && kill(_pid, SIGINT) != 0 && kill(_pid, 0) != 0)
 {
 Log::syserror("Cannot terminate lokit [" + 
std::to_string(_pid) + "]. Abandoning.");
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 9c62d0c..42a0149 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1545,13 +1545,15 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 threadPool.joinAll();
 
 // Terminate child processes
-IoUtil::writeFIFO(ForKitWritePipe, "eof\n");
 Log::info("Requesting child process " + std::to_string(forKitPid) + " to 
terminate");
 Util::requestTermination(forKitPid);
+for (auto& child : newChildren)
+{
+child->close(true);
+}
 
 // Wait for forkit process finish
 waitpid(forKitPid, , WUNTRACED);
-
 close(ForKitWritePipe);
 
 Log::info("Cleaning up childroot directory [" + ChildRoot + "].");
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.hpp

2016-04-09 Thread Ashod Nakashian
 loolwsd/DocumentBroker.hpp |6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

New commits:
commit dc137081a788b9be0d372cbb518e4836813555cb
Author: Ashod Nakashian 
Date:   Sat Apr 9 23:52:52 2016 -0400

loolwsd: session container can be private to DocumentBroker

Change-Id: I1539f2ec3ab1bd11d659dab11359cf25a46e1f97
Reviewed-on: https://gerrit.libreoffice.org/23952
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 66e2497..259572f 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -161,10 +161,6 @@ public:
 
 unsigned getWSSessionsCount() { return _wsSessions.size(); }
 
-public:
-std::map _wsSessions;
-std::mutex _wsSessionsMutex;
-
 private:
 const Poco::URI _uriPublic;
 const std::string _docKey;
@@ -174,6 +170,8 @@ private:
 std::string _jailId;
 std::string _filename;
 std::chrono::steady_clock::time_point _lastSaveTime;
+std::map _wsSessions;
+std::mutex _wsSessionsMutex;
 std::unique_ptr _storage;
 std::unique_ptr _tileCache;
 std::shared_ptr _childProcess;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.hpp loolwsd/LOOLForKit.cpp

2016-04-06 Thread Ashod Nakashian
 loolwsd/DocumentBroker.hpp |4 ++--
 loolwsd/LOOLForKit.cpp |5 ++---
 2 files changed, 4 insertions(+), 5 deletions(-)

New commits:
commit 5e41763386cdcf5c48a8b9b93411f9a604d41593
Author: Ashod Nakashian 
Date:   Tue Apr 5 22:37:29 2016 -0400

loolwsd: disconnect WS before killing/abandoning child

Change-Id: Iff0ac1b57ce9e0fe61871fad9a499d370c2c9294
Reviewed-on: https://gerrit.libreoffice.org/23858
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 622eab5..f63c5a5 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -20,6 +20,7 @@
 
 #include 
 
+#include "IoUtil.hpp"
 #include "MasterProcessSession.hpp"
 #include "Util.hpp"
 
@@ -75,6 +76,7 @@ public:
 void close(const bool rude)
 {
 Log::info("Closing child [" + std::to_string(_pid) + "].");
+_ws.reset();
 if (_pid != -1)
 {
 if (rude && kill(_pid, SIGINT) != 0 && kill(_pid, 0) != 0)
@@ -90,8 +92,6 @@ public:
 //IoUtil::writeFIFO(WriterNotify, message.str());
_pid = -1;
 }
-
-_ws.reset();
 }
 
 Poco::Process::PID getPid() const { return _pid; }
diff --git a/loolwsd/LOOLForKit.cpp b/loolwsd/LOOLForKit.cpp
index 42deaff..1bfbdae 100644
--- a/loolwsd/LOOLForKit.cpp
+++ b/loolwsd/LOOLForKit.cpp
@@ -236,8 +236,7 @@ int main(int argc, char** argv)
 
 if (ForkCounter > 0)
 {
-// Figure out how many children we need. Always create at least as 
many
-// as configured pre-spawn or one more than requested (whichever 
is larger).
+// Create as many as requested.
 int spawn = ForkCounter;
 Log::info() << "Creating " << spawn << " new child." << Log::end;
 size_t newInstances = 0;
@@ -255,7 +254,7 @@ int main(int argc, char** argv)
 while (--spawn > 0);
 
 // If we need to spawn more, retry later.
-ForkCounter = (newInstances > ForkCounter ? 0 : ForkCounter - 
newInstances);
+ForkCounter = (newInstances >= ForkCounter ? 0 : ForkCounter - 
newInstances);
 }
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.hpp loolwsd/LOOLKit.cpp

2016-04-03 Thread Ashod Nakashian
 loolwsd/DocumentBroker.hpp |4 ++--
 loolwsd/LOOLKit.cpp|   18 ++
 2 files changed, 16 insertions(+), 6 deletions(-)

New commits:
commit ed1790d7a30933860010a6c24083229b2cac06f0
Author: Ashod Nakashian 
Date:   Sun Apr 3 23:26:06 2016 -0400

loolwsd: kit destruction improvements

Change-Id: Ia491e5dc85e13eda12bb47690a8d335ad0917468
Reviewed-on: https://gerrit.libreoffice.org/23791
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 458090f..622eab5 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -69,7 +69,7 @@ public:
 ~ChildProcess()
 {
 Log::info("~ChildProcess dtor [" + std::to_string(_pid) + "].");
-close(true);
+close(false);
 }
 
 void close(const bool rude)
@@ -77,7 +77,7 @@ public:
 Log::info("Closing child [" + std::to_string(_pid) + "].");
 if (_pid != -1)
 {
-if (kill(_pid, SIGINT) != 0 && rude && kill(_pid, 0) != 0)
+if (rude && kill(_pid, SIGINT) != 0 && kill(_pid, 0) != 0)
 {
 Log::error("Cannot terminate lokit [" + std::to_string(_pid) + 
"]. Abandoning.");
 }
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index 9b012d9..e3fd8ce 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -398,11 +398,20 @@ public:
 // Destroy all connections and views.
 _connections.clear();
 
-// TODO. check what is happening when destroying lokit document
+// TODO. check what is happening when destroying lokit document,
+// often it blows up.
 // Destroy the document.
 if (_loKitDocument != nullptr)
 {
-_loKitDocument->pClass->destroy(_loKitDocument);
+try
+{
+_loKitDocument->pClass->destroy(_loKitDocument);
+}
+catch (const std::exception& exc)
+{
+Log::error() << "Document::~Document: " << exc.what()
+ << Log::end;
+}
 }
 }
 
@@ -670,7 +679,10 @@ private:
 auto sessionLock = session->getLock();
 std::unique_lock lock(_mutex);
 
+Log::info("Session " + sessionId + " is unloading. Erasing 
connection.");
+_connections.erase(it);
 --_clientViews;
+Log::info("Session " + sessionId + " is unloading. " + 
std::to_string(_clientViews) + " views will remain.");
 
 std::ostringstream message;
 message << "rmview" << " "
@@ -679,8 +691,6 @@ private:
 << "\n";
 IoUtil::writeFIFO(WriterNotify, message.str());
 
-Log::info("Session " + sessionId + " is unloading. " + 
std::to_string(_clientViews) + " views will remain.");
-
 if (_multiView && _loKitDocument)
 {
 Log::info() << "Document [" << _url << "] session ["
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.hpp loolwsd/LOOLWSD.cpp loolwsd/Storage.hpp

2016-03-22 Thread Ashod Nakashian
 loolwsd/DocumentBroker.hpp |4 ++--
 loolwsd/LOOLWSD.cpp|1 +
 loolwsd/Storage.hpp|   21 -
 3 files changed, 15 insertions(+), 11 deletions(-)

New commits:
commit 8081db3fd9d47c37e6cca6e89efbb4c50d772384
Author: Ashod Nakashian 
Date:   Tue Mar 22 18:46:04 2016 -0400

loolwsd: fixed file info for local files

Change-Id: I8e2588d55d5ecccb9d0becafad4757b7fcb99eaf
Reviewed-on: https://gerrit.libreoffice.org/23453
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 471df0c..89087a0 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -79,9 +79,9 @@ public:
 
 void validate(const Poco::URI& uri)
 {
-Log::info("validating: " + uri.toString());
+Log::info("Validating: " + uri.toString());
 auto storage = createStorage("", "", uri);
-storage->getFileInfo(uri.toString());
+storage->getFileInfo(uri);
 }
 
 /// Loads a document from the public URI into the jail.
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 8c518fc..ae896a3 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -579,6 +579,7 @@ private:
 
 // Validate the URI and Storage before moving on.
 docBroker->validate(uriPublic);
+Log::debug("Validated [" + uriPublic.toString() + "].");
 
 auto ws = std::make_shared(request, response);
 auto session = std::make_shared(id, 
LOOLSession::Kind::ToClient, ws, docBroker);
diff --git a/loolwsd/Storage.hpp b/loolwsd/Storage.hpp
index 574c844..fbc1708 100644
--- a/loolwsd/Storage.hpp
+++ b/loolwsd/Storage.hpp
@@ -66,7 +66,7 @@ public:
 const std::string& getUri() const { return _uri; }
 
 /// Returns information about the file.
-virtual FileInfo getFileInfo(const std::string& uri) = 0;
+virtual FileInfo getFileInfo(const Poco::URI& uri) = 0;
 
 /// Returns a local file path for the given URI.
 /// If necessary copies the file locally first.
@@ -104,10 +104,12 @@ public:
 {
 }
 
-FileInfo getFileInfo(const std::string& uri)
+FileInfo getFileInfo(const Poco::URI& uri)
 {
-const auto filename = Poco::Path(uri).getFileName();
-const auto size = Poco::File(uri).getSize();
+const auto path = uri.getPath();
+Log::debug("Getting info for local uri [" + uri.toString() + "], path 
[" + path + "].");
+const auto filename = Poco::Path(path).getFileName();
+const auto size = Poco::File(path).getSize();
 return FileInfo({filename, size});
 }
 
@@ -185,9 +187,9 @@ public:
 {
 }
 
-FileInfo getFileInfo(const std::string& uri)
+FileInfo getFileInfo(const Poco::URI& uri)
 {
-Log::info("FileInfo for URI [" + uri + "].");
+Log::debug("Getting info for wopi uri [" + uri.toString() + "].");
 
 Poco::URI uriObject(uri);
 Poco::Net::HTTPClientSession session(uriObject.getHost(), 
uriObject.getPort());
@@ -199,7 +201,7 @@ public:
 std::istream& rs = session.receiveResponse(response);
 
 auto logger = Log::trace();
-logger << "WOPI::CheckFileInfo header for URI [" << uri << "]:\n";
+logger << "WOPI::CheckFileInfo header for URI [" << uri.toString() << 
"]:\n";
 for (auto& pair : response)
 {
 logger << '\t' + pair.first + ": " + pair.second << " / ";
@@ -232,7 +234,7 @@ public:
 {
 Log::info("Downloading URI [" + _uri + "].");
 
-_fileInfo = getFileInfo(_uri);
+_fileInfo = getFileInfo(Poco::URI(_uri));
 if (_fileInfo.Size == 0 && _fileInfo.Filename.empty())
 {
 //TODO: Should throw a more appropriate exception.
@@ -320,8 +322,9 @@ public:
 {
 }
 
-FileInfo getFileInfo(const std::string& uri)
+FileInfo getFileInfo(const Poco::URI& uri)
 {
+Log::debug("Getting info for webdav uri [" + uri.toString() + "].");
 (void)uri;
 assert(!"Not Implemented!");
 return FileInfo({"bazinga", 0});
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.hpp loolwsd/LOOLWSD.cpp loolwsd/Storage.hpp

2016-03-22 Thread Ashod Nakashian
 loolwsd/DocumentBroker.hpp |8 +++
 loolwsd/LOOLWSD.cpp|3 +
 loolwsd/Storage.hpp|   95 +
 3 files changed, 99 insertions(+), 7 deletions(-)

New commits:
commit ef95d51b672b336772d832aad4c0c899955d1786
Author: Ashod Nakashian 
Date:   Mon Mar 21 19:12:00 2016 -0400

loolwsd: FileInfo used to authenticate and store with original name

Change-Id: I94105441134ded2146736affba7b763eb3d54791
Reviewed-on: https://gerrit.libreoffice.org/23452
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 3f7c75e..471df0c 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -77,6 +77,13 @@ public:
 Log::info("~DocumentBroker [" + _uriPublic.toString() + "] 
destroyed.");
 }
 
+void validate(const Poco::URI& uri)
+{
+Log::info("validating: " + uri.toString());
+auto storage = createStorage("", "", uri);
+storage->getFileInfo(uri.toString());
+}
+
 /// Loads a document from the public URI into the jail.
 bool load(const std::string& jailId)
 {
@@ -136,6 +143,7 @@ private:
 const std::string _childRoot;
 Poco::URI _uriJailed;
 std::string _jailId;
+std::string _filename;
 std::unique_ptr _storage;
 std::mutex _mutex;
 std::atomic _sessionsCount;
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 2d3dd66..8c518fc 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -577,6 +577,9 @@ private:
 docBrokers.emplace(docKey, docBroker);
 }
 
+// Validate the URI and Storage before moving on.
+docBroker->validate(uriPublic);
+
 auto ws = std::make_shared(request, response);
 auto session = std::make_shared(id, 
LOOLSession::Kind::ToClient, ws, docBroker);
 docBroker->incSessions();
diff --git a/loolwsd/Storage.hpp b/loolwsd/Storage.hpp
index edc8569..574c844 100644
--- a/loolwsd/Storage.hpp
+++ b/loolwsd/Storage.hpp
@@ -16,6 +16,8 @@
 
 #include 
 #include 
+#include 
+#include 
 
 #include "Common.hpp"
 #include "Auth.hpp"
@@ -26,6 +28,13 @@ class StorageBase
 {
 public:
 
+class FileInfo
+{
+public:
+std::string Filename;
+size_t Size;
+};
+
 /// localStorePath the absolute root path of the chroot.
 /// jailPath the path within the jail that the child uses.
 StorageBase(const std::string& localStorePath,
@@ -56,11 +65,17 @@ public:
 
 const std::string& getUri() const { return _uri; }
 
-/// Returns a local file path given a URI or ID.
+/// Returns information about the file.
+virtual FileInfo getFileInfo(const std::string& uri) = 0;
+
+/// Returns a local file path for the given URI.
 /// If necessary copies the file locally first.
 virtual std::string loadStorageFileToLocal() = 0;
 
 /// Writes the contents of the file back to the source.
+/// TODO: Should we save to the specific client's URI?
+/// The advantage is that subseqent views (to the first)
+/// will not depend on the token of the first.
 virtual bool saveLocalFileToStorage() = 0;
 
 static
@@ -74,7 +89,7 @@ protected:
 const std::string _jailPath;
 const std::string _uri;
 std::string _jailedFilePath;
-std::string _filename;
+FileInfo _fileInfo;
 };
 
 /// Trivial implementation of local storage that does not need do anything.
@@ -89,6 +104,13 @@ public:
 {
 }
 
+FileInfo getFileInfo(const std::string& uri)
+{
+const auto filename = Poco::Path(uri).getFileName();
+const auto size = Poco::File(uri).getSize();
+return FileInfo({filename, size});
+}
+
 std::string loadStorageFileToLocal() override
 {
 const auto rootPath = getLocalRootPath();
@@ -163,14 +185,68 @@ public:
 {
 }
 
+FileInfo getFileInfo(const std::string& uri)
+{
+Log::info("FileInfo for URI [" + uri + "].");
+
+Poco::URI uriObject(uri);
+Poco::Net::HTTPClientSession session(uriObject.getHost(), 
uriObject.getPort());
+Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, 
uriObject.getPathAndQuery(), Poco::Net::HTTPMessage::HTTP_1_1);
+request.set("User-Agent", "LOOLWSD WOPI Agent");
+session.sendRequest(request);
+
+Poco::Net::HTTPResponse response;
+std::istream& rs = session.receiveResponse(response);
+
+auto logger = Log::trace();
+logger << "WOPI::CheckFileInfo header for URI [" << uri << "]:\n";
+for (auto& pair : response)
+{
+logger << '\t' + pair.first + ": " + pair.second << " / ";
+}
+
+logger << Log::end;
+
+// Parse the response.
+std::string filename;
+size_t size = 0;
+std::string resMsg;
+

[Libreoffice-commits] online.git: loolwsd/DocumentBroker.hpp loolwsd/Storage.hpp

2016-03-22 Thread Ashod Nakashian
 loolwsd/DocumentBroker.hpp |   13 +
 loolwsd/Storage.hpp|   17 +
 2 files changed, 18 insertions(+), 12 deletions(-)

New commits:
commit cf3811a7fb2a87489c44d80b0de36af00d102af4
Author: Ashod Nakashian 
Date:   Mon Mar 21 08:31:07 2016 -0400

loolwsd: refactored storage construction into factory

Change-Id: I5e1453b100d852424b472d08746d8636b7656755
Reviewed-on: https://gerrit.libreoffice.org/23451
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index ac59213..3f7c75e 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -101,18 +101,7 @@ public:
 
 Log::info("jailPath: " + jailPath.toString() + ", jailRoot: " + 
jailRoot);
 
-if (_uriPublic.isRelative() || _uriPublic.getScheme() == "file")
-{
-Log::info("Public URI [" + _uriPublic.toString() + "] is a file.");
-_storage.reset(new LocalStorage(jailRoot, jailPath.toString(), 
_uriPublic.getPath()));
-}
-else
-{
-Log::info("Public URI [" + _uriPublic.toString() +
-  "] assuming cloud storage.");
-//TODO: Configure the storage to use. For now, assume it's WOPI.
-_storage.reset(new WopiStorage(jailRoot, jailPath.toString(), 
_uriPublic.toString()));
-}
+_storage = createStorage(jailRoot, jailPath.toString(), _uriPublic);
 
 const auto localPath = _storage->loadStorageFileToLocal();
 _uriJailed = Poco::URI(Poco::URI("file://"), localPath);
diff --git a/loolwsd/Storage.hpp b/loolwsd/Storage.hpp
index 4fe14af..edc8569 100644
--- a/loolwsd/Storage.hpp
+++ b/loolwsd/Storage.hpp
@@ -262,5 +262,22 @@ private:
 std::unique_ptr _authAgent;
 };
 
+inline
+std::unique_ptr createStorage(const std::string& jailRoot, const 
std::string& jailPath, const Poco::URI& uri)
+{
+if (uri.isRelative() || uri.getScheme() == "file")
+{
+Log::info("Public URI [" + uri.toString() + "] is a file.");
+return std::unique_ptr(new LocalStorage(jailRoot, 
jailPath, uri.getPath()));
+}
+else
+{
+Log::info("Public URI [" + uri.toString() +
+  "] assuming cloud storage.");
+//TODO: Configure the storage to use. For now, assume it's WOPI.
+return std::unique_ptr(new WopiStorage(jailRoot, 
jailPath, uri.toString()));
+}
+}
+
 #endif
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.hpp loolwsd/LOOLBroker.cpp loolwsd/LOOLWSD.cpp loolwsd/MasterProcessSession.cpp loolwsd/Storage.hpp

2016-03-22 Thread Ashod Nakashian
 loolwsd/DocumentBroker.hpp   |3 +--
 loolwsd/LOOLBroker.cpp   |2 +-
 loolwsd/LOOLWSD.cpp  |2 ++
 loolwsd/MasterProcessSession.cpp |1 +
 loolwsd/Storage.hpp  |3 ++-
 5 files changed, 7 insertions(+), 4 deletions(-)

New commits:
commit ca9c14dfdd7bd1f7007121b24867b46d7e9c3940
Author: Ashod Nakashian 
Date:   Mon Mar 21 08:28:18 2016 -0400

loolwsd: logs and comments

Change-Id: I2fbfb7ee7ada48390bec65ee6911bde00885fbdb
Reviewed-on: https://gerrit.libreoffice.org/23450
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 2686af3..ac59213 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -86,8 +86,7 @@ public:
 
 if (_storage)
 {
-// Already loaded. Only validate.
-
+// Already loaded. Nothing to do.
 return true;
 }
 
diff --git a/loolwsd/LOOLBroker.cpp b/loolwsd/LOOLBroker.cpp
index 81bf06f..890bf04 100644
--- a/loolwsd/LOOLBroker.cpp
+++ b/loolwsd/LOOLBroker.cpp
@@ -836,7 +836,7 @@ int main(int argc, char** argv)
 // Figure out how many children we need. Always create at least as 
many
 // as configured pre-spawn or one more than requested (whichever 
is larger).
 int spawn = std::max(static_cast(forkCounter) + 1, 
numPreSpawnedChildren);
-Log::debug() << "Creating " << spawn << (spawn == 1 ? "child" : 
"children") << ". Current total: "
+Log::debug() << "Creating " << spawn << (spawn == 1 ? " child" : " 
children") << ". Current total: "
  << total << ", Empty: " << empty << Log::end;
 do
 {
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 38b57cc..2d3dd66 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -630,6 +630,8 @@ private:
 
 if (docBroker->getSessionsCount() == 1 && !normalShutdown)
 {
+//TODO: This really should move to the kit, where it
+// knows if a doc is unsaved, and if other views are open.
 Log::info("Non-deliberate shutdown of the last session, saving the 
document before tearing down.");
 queue.put("uno .uno:Save");
 }
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 52c8b81..f7b26ce 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -778,6 +778,7 @@ void MasterProcessSession::dispatchChild()
 _peer = childSession;
 childSession->_peer = shared_from_this();
 childSession->_docBroker = _docBroker;
+Log::debug("Connected " + getName() + " - " + childSession->getName() + 
".");
 
 std::ostringstream oss;
 oss << "load";
diff --git a/loolwsd/Storage.hpp b/loolwsd/Storage.hpp
index d185957..4fe14af 100644
--- a/loolwsd/Storage.hpp
+++ b/loolwsd/Storage.hpp
@@ -35,6 +35,7 @@ public:
 _jailPath(jailPath),
 _uri(uri)
 {
+Log::debug("Storage ctor: " + uri);
 }
 
 std::string getLocalRootPath() const
@@ -180,7 +181,7 @@ public:
 logger << "WOPI::GetFile header for URI [" << _uri << "]:\n";
 for (auto& pair : response)
 {
-logger << '\t' + pair.first + ": " + pair.second << '\n';
+logger << '\t' + pair.first + ": " + pair.second << " / ";
 }
 
 logger << Log::end;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-03-22 Thread Ashod Nakashian
 loolwsd/DocumentBroker.hpp |   46 +
 loolwsd/LOOLWSD.cpp|   12 ++-
 2 files changed, 33 insertions(+), 25 deletions(-)

New commits:
commit 66c8c0a3007737d3e07f8307bf732893de16dfad
Author: Ashod Nakashian 
Date:   Sat Mar 19 18:49:36 2016 -0400

loolwsd: refactored DocumentBroker

Change-Id: Ie7d9f46e49db8978541b4775fbf6d2578879a111
Reviewed-on: https://gerrit.libreoffice.org/23449
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 141fb2d..2686af3 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -27,10 +27,8 @@ class DocumentBroker
 public:
 
 static
-std::shared_ptr create(std::string uri, const std::string& 
childRoot)
+Poco::URI sanitizeURI(std::string uri)
 {
-Log::info("Creating DocumentBroker for uri: " + uri + ".");
-
 // The URI of the document should be url-encoded.
 std::string decodedUri;
 Poco::URI::decode(uri, decodedUri);
@@ -47,10 +45,31 @@ public:
 throw std::runtime_error("Invalid URI.");
 }
 
+return uriPublic;
+}
+
+/// Returns a document-specific key based
+/// on the URI of the document.
+static
+std::string getDocKey(const Poco::URI& uri)
+{
+// Keep the host as part of the key to close a potential security hole.
 std::string docKey;
-Poco::URI::encode(uriPublic.getPath(), "", docKey);
+Poco::URI::encode(uri.getHost() + uri.getPath(), "", docKey);
+return docKey;
+}
 
-return std::shared_ptr(new DocumentBroker(uriPublic, 
docKey, childRoot));
+DocumentBroker(const Poco::URI& uriPublic,
+   const std::string& docKey,
+   const std::string& childRoot) :
+   _uriPublic(uriPublic),
+   _docKey(docKey),
+   _childRoot(childRoot),
+   _sessionsCount(0)
+{
+assert(!_docKey.empty());
+assert(!_childRoot.empty());
+Log::info("DocumentBroker [" + _uriPublic.toString() + "] created. 
DocKey: [" + _docKey + "]");
 }
 
 ~DocumentBroker()
@@ -67,7 +86,8 @@ public:
 
 if (_storage)
 {
-// Already loaded. Just return.
+// Already loaded. Only validate.
+
 return true;
 }
 
@@ -123,20 +143,6 @@ public:
 }
 
 private:
-DocumentBroker(const Poco::URI& uriPublic,
-   const std::string& docKey,
-   const std::string& childRoot) :
-   _uriPublic(uriPublic),
-   _docKey(docKey),
-   _childRoot(childRoot),
-   _sessionsCount(0)
-{
-assert(!_docKey.empty());
-assert(!_childRoot.empty());
-Log::info("DocumentBroker [" + _uriPublic.toString() + "] created. 
DocKey: [" + _docKey + "]");
-}
-
-private:
 const Poco::URI _uriPublic;
 const std::string _docKey;
 const std::string _childRoot;
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 1f7789d..38b57cc 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -372,8 +372,9 @@ private:
 if (!format.empty())
 {
 Log::info("Conversion request for URI [" + fromPath + 
"].");
-auto docBroker = DocumentBroker::create(fromPath, 
LOOLWSD::ChildRoot);
-const auto docKey = docBroker->getDocKey();
+auto uriPublic = DocumentBroker::sanitizeURI(fromPath);
+const auto docKey = DocumentBroker::getDocKey(uriPublic);
+auto docBroker = 
std::make_shared(uriPublic, docKey, LOOLWSD::ChildRoot);
 
 // This lock could become a bottleneck.
 // In that case, we can use a pool and index by publicPath.
@@ -552,9 +553,9 @@ private:
 uri.erase(0, 1);
 }
 
-auto docBroker = DocumentBroker::create(uri, LOOLWSD::ChildRoot);
-const auto docKey = docBroker->getDocKey();
-
+const auto uriPublic = DocumentBroker::sanitizeURI(uri);
+const auto docKey = DocumentBroker::getDocKey(uriPublic);
+std::shared_ptr docBroker;
 // This lock could become a bottleneck.
 // In that case, we can use a pool and index by publicPath.
 std::unique_lock docBrokersLock(docBrokersMutex);
@@ -572,6 +573,7 @@ private:
 {
 // Set one we just created.
 Log::debug("New DocumentBroker for docKey [" + docKey + "].");
+docBroker = std::make_shared(uriPublic, docKey, 
LOOLWSD::ChildRoot);
 docBrokers.emplace(docKey, docBroker);
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

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

2016-03-13 Thread Ashod Nakashian
 loolwsd/DocumentBroker.hpp |9 ---
 loolwsd/LOOLWSD.cpp|   57 ++---
 2 files changed, 39 insertions(+), 27 deletions(-)

New commits:
commit 981e83ece6cc93d5d6c20fef45773b5dfb6b647d
Author: Ashod Nakashian 
Date:   Sun Mar 13 14:00:19 2016 -0400

loolwsd: fixed convert-to (POST) tests

Change-Id: I6d48971b9daf0beaa16defa0b5f4dfb94575713c
Reviewed-on: https://gerrit.libreoffice.org/23228
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index fd9efa3..ad068d1 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -31,14 +31,7 @@ public:
 {
 Log::info("Creating DocumentBroker for uri: " + uri + ".");
 
-// The URI of the document is url-encoded
-// and passed in our URL.
-if (uri.size() > 0 && uri[0] == '/')
-{
-// Remove leading '/'.
-uri.erase(0, 1);
-}
-
+// The URI of the document should be url-encoded.
 std::string decodedUri;
 Poco::URI::decode(uri, decodedUri);
 auto uriPublic = Poco::URI(decodedUri);
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 1dc41a2..5435669 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -329,55 +329,67 @@ private:
 
 void handlePostRequest(HTTPServerRequest& request, HTTPServerResponse& 
response, const std::string& id)
 {
-Log::info("Post request.");
+Log::info("Post request: " + request.getURI() + "]");
 StringTokenizer tokens(request.getURI(), "/?");
 if (tokens.count() >= 2 && tokens[1] == "convert-to")
 {
-Log::info("Conversion request.");
 std::string fromPath;
 ConvertToPartHandler handler(fromPath);
 HTMLForm form(request, request.stream(), handler);
-std::string format;
-if (form.has("format"))
-format = form.get("format");
+const std::string format = (form.has("format") ? 
form.get("format") : "");
 
 bool sent = false;
 if (!fromPath.empty())
 {
 if (!format.empty())
 {
+Log::info("Conversion request for URI [" + fromPath + 
"].");
+auto docBroker = DocumentBroker::create(fromPath, 
LOOLWSD::ChildRoot);
+const auto docKey = docBroker->getDocKey();
+
+// This lock could become a bottleneck.
+// In that case, we can use a pool and index by publicPath.
+std::unique_lock 
lock(LOOLWSD::DocBrokersMutex);
+
+Log::debug("New DocumentBroker for docKey [" + docKey + 
"].");
+LOOLWSD::DocBrokers.emplace(docKey, docBroker);
+
 // Load the document.
 std::shared_ptr ws;
 const LOOLSession::Kind kind = LOOLSession::Kind::ToClient;
-auto session = std::make_shared(id, 
kind, ws, nullptr);
-const std::string filePrefix("file://");
+auto session = std::make_shared(id, 
kind, ws, docBroker);
+docBroker->incSessions();
+lock.unlock();
+
 std::string encodedFrom;
-URI::encode(filePrefix + fromPath, "", encodedFrom);
+URI::encode(docBroker->getPublicUri().getPath(), "", 
encodedFrom);
 const std::string load = "load url=" + encodedFrom;
 session->handleInput(load.data(), load.size());
 
 // Convert it to the requested format.
-Path toPath(fromPath);
+Path toPath(docBroker->getPublicUri().getPath());
 toPath.setExtension(format);
-std::string toJailURL = filePrefix + JailedDocumentRoot + 
toPath.getFileName();
+const std::string toJailURL = "file://" + 
JailedDocumentRoot + toPath.getFileName();
 std::string encodedTo;
 URI::encode(toJailURL, "", encodedTo);
 std::string saveas = "saveas url=" + encodedTo + " 
format=" + format + " options=";
 session->handleInput(saveas.data(), saveas.size());
 
-std::string toURL = session->getSaveAs();
-std::string resultingURL;
-URI::decode(toURL, resultingURL);
-
 // Send it back to the client.
-if (resultingURL.find(filePrefix) == 0)
-resultingURL = 
resultingURL.substr(filePrefix.length());
-if (!resultingURL.empty())
+Poco::URI resultURL(session->getSaveAs());
+

[Libreoffice-commits] online.git: loolwsd/DocumentBroker.hpp loolwsd/MasterProcessSession.cpp

2016-03-13 Thread Ashod Nakashian
 loolwsd/DocumentBroker.hpp   |2 +-
 loolwsd/MasterProcessSession.cpp |2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

New commits:
commit e0b14c0e22f46a05de3cba3561f2f8300b90c5e5
Author: Ashod Nakashian 
Date:   Sun Mar 13 13:19:14 2016 -0400

loolwsd: give Broker the docKey, not URL

And reject connections with no doc URL.

Change-Id: I11490be6aaea6a4ca2d66d8d2c8d6b52e1e48a04
Reviewed-on: https://gerrit.libreoffice.org/23225
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 544efbb..fd9efa3 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -33,7 +33,7 @@ public:
 
 // The URI of the document is url-encoded
 // and passed in our URL.
-if (uri.size() > 1 && uri[0] == '/')
+if (uri.size() > 0 && uri[0] == '/')
 {
 // Remove leading '/'.
 uri.erase(0, 1);
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index e1b7a6d..98941b3 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -750,7 +750,7 @@ void MasterProcessSession::dispatchChild()
 {
 Log::info() << "Retrying child permission... " << retries << 
Log::end;
 // request again new URL session
-const std::string message = "request " + getId() + " " + _docURL + 
"\r\n";
+const std::string message = "request " + getId() + " " + 
_docBroker->getDocKey() + "\r\n";
 Log::trace("MasterToBroker: " + message.substr(0, 
message.length()-2));
 Util::writeFIFO(LOOLWSD::BrokerWritePipe, message);
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.hpp

2016-03-13 Thread Ashod Nakashian
 loolwsd/DocumentBroker.hpp |   37 -
 1 file changed, 4 insertions(+), 33 deletions(-)

New commits:
commit 1aa7a6cf05526282f93516713a1bfee143e1c3f8
Author: Ashod Nakashian 
Date:   Sun Mar 13 10:05:40 2016 -0400

loolwsd: simplified DocumentBroker::create

Change-Id: Ia97be0861c7c178859d695ae5e2862e88cb3ca77
Reviewed-on: https://gerrit.libreoffice.org/23221
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index f4fc674..544efbb 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -27,8 +27,10 @@ class DocumentBroker
 public:
 
 static
-Poco::URI getUri(std::string uri)
+std::shared_ptr create(std::string uri, const std::string& 
childRoot)
 {
+Log::info("Creating DocumentBroker for uri: " + uri + ".");
+
 // The URI of the document is url-encoded
 // and passed in our URL.
 if (uri.size() > 1 && uri[0] == '/')
@@ -47,42 +49,11 @@ public:
 uriPublic.normalize();
 }
 
-Log::info("Public URI [" + uriPublic.toString() + "].");
 if (uriPublic.getPath().empty())
 {
 throw std::runtime_error("Invalid URI.");
 }
 
-return uriPublic;
-}
-
-static
-std::shared_ptr create(const std::string& uri, const 
std::string& childRoot)
-{
-std::string decodedUri;
-Poco::URI::decode(uri, decodedUri);
-auto uriPublic = Poco::URI(decodedUri);
-
-if (uriPublic.isRelative() || uriPublic.getScheme() == "file")
-{
-// TODO: Validate and limit access to local paths!
-uriPublic.normalize();
-}
-
-Log::info("Public URI [" + uriPublic.toString() + "].");
-if (uriPublic.getPath().empty())
-{
-throw std::runtime_error("Invalid URI.");
-}
-
-return create(uriPublic, childRoot);
-}
-
-static
-std::shared_ptr create(const Poco::URI& uriPublic, const 
std::string& childRoot)
-{
-Log::info("Creating DocumentBroker for uri: " + uriPublic.toString());
-
 std::string docKey;
 Poco::URI::encode(uriPublic.getPath(), "", docKey);
 
@@ -168,7 +139,7 @@ private:
 {
 assert(!_docKey.empty());
 assert(!_childRoot.empty());
-Log::info("DocumentBroker [" + _uriPublic.toString() + "] created.");
+Log::info("DocumentBroker [" + _uriPublic.toString() + "] created. 
DocKey: [" + _docKey + "]");
 }
 
 private:
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-03-13 Thread Ashod Nakashian
 loolwsd/DocumentBroker.hpp |6 +-
 loolwsd/LOOLWSD.cpp|7 ++-
 2 files changed, 11 insertions(+), 2 deletions(-)

New commits:
commit 0b18a67da21debd051f151718f271cea27c30bc8
Author: Ashod Nakashian 
Date:   Sun Mar 13 10:04:54 2016 -0400

loolwsd: DocumentBroker cleanup

Change-Id: Iedf2e0afd3c63d24b96ce1c7923c90d86d82bc13
Reviewed-on: https://gerrit.libreoffice.org/23220
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index 71c9681..f4fc674 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -148,6 +148,8 @@ public:
 Poco::URI getJailedUri() const { return _uriJailed; }
 const std::string& getJailId() const { return _jailId; }
 const std::string& getDocKey() const { return _docKey; }
+unsigned decSessions() { return --_sessionsCount; }
+unsigned incSessions() { return ++_sessionsCount; }
 
 std::string getJailRoot() const
 {
@@ -161,7 +163,8 @@ private:
const std::string& childRoot) :
_uriPublic(uriPublic),
_docKey(docKey),
-   _childRoot(childRoot)
+   _childRoot(childRoot),
+   _sessionsCount(0)
 {
 assert(!_docKey.empty());
 assert(!_childRoot.empty());
@@ -176,6 +179,7 @@ private:
 std::string _jailId;
 std::unique_ptr _storage;
 std::mutex _mutex;
+std::atomic _sessionsCount;
 };
 
 #endif
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 1d63532..ca08811 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -535,6 +535,7 @@ private:
 
 auto ws = std::make_shared(request, response);
 auto session = std::make_shared(id, 
LOOLSession::Kind::ToClient, ws, docBroker);
+docBroker->incSessions();
 
 // For ToClient sessions, we store incoming messages in a queue and 
have a separate
 // thread that handles them. This is so that we can empty the queue 
when we get a
@@ -569,7 +570,11 @@ private:
 queue.put("eof");
 queueHandlerThread.join();
 
-//TODO: Cleanup DocumentBroker.
+std::unique_lock lock(LOOLWSD::DocBrokersMutex);
+if (docBroker->decSessions() == 0)
+{
+LOOLWSD::DocBrokers.erase(docKey);
+}
 }
 
 public:
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.hpp loolwsd/MasterProcessSession.cpp

2016-03-13 Thread Ashod Nakashian
 loolwsd/DocumentBroker.hpp   |3 ++-
 loolwsd/MasterProcessSession.cpp |   10 ++
 2 files changed, 4 insertions(+), 9 deletions(-)

New commits:
commit c6b47cc43768a37324691c7f003bfe7ad7fe68e1
Author: Ashod Nakashian 
Date:   Sat Mar 12 20:20:49 2016 -0500

loolwsd: removed superfluous getJailPath

Change-Id: Iff11ea791866f31a47cf0d0b1d1fb06d18f5be40
Reviewed-on: https://gerrit.libreoffice.org/23218
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index e2cd9ee..71c9681 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -95,7 +95,7 @@ public:
 }
 
 /// Loads a document from the public URI into the jail.
-bool load(const std::string& jailRoot, const std::string& jailId)
+bool load(const std::string& jailId)
 {
 Log::debug("Loading from URI: " + _uriPublic.toString());
 
@@ -114,6 +114,7 @@ public:
 
 // user/doc/jailId
 const auto jailPath = Poco::Path(JailedDocumentRoot, jailId);
+const std::string jailRoot = getJailRoot();
 
 Log::info("jailPath: " + jailPath.toString() + ", jailRoot: " + 
jailRoot);
 
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index d47f2b2..bdb730f 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -195,7 +195,7 @@ bool MasterProcessSession::_handleInput(const char *buffer, 
int length)
 if (url.find(filePrefix) == 0)
 {
 // Rewrite file:// URLs, as they are visible to the 
outside world.
-Path path(MasterProcessSession::getJailPath(_childId), 
url.substr(filePrefix.length()));
+const Path path(_docBroker->getJailRoot(), 
url.substr(filePrefix.length()));
 url = filePrefix + path.toString().substr(1);
 }
 peer->_saveAsQueue.put(url);
@@ -424,12 +424,6 @@ bool MasterProcessSession::haveSeparateProcess()
 {
 return !_childId.empty();
 }
-
-Poco::Path MasterProcessSession::getJailPath(const std::string& childId)
-{
-return Path::forDirectory(LOOLWSD::ChildRoot + Path::separator() + 
childId);
-}
-
 bool MasterProcessSession::invalidateTiles(const char* /*buffer*/, int 
/*length*/, StringTokenizer& tokens)
 {
 int part, tilePosX, tilePosY, tileWidth, tileHeight;
@@ -808,7 +802,7 @@ void MasterProcessSession::dispatchChild()
 }
 
 const auto jailRoot = Poco::Path(LOOLWSD::ChildRoot, 
childSession->_childId);
-_docBroker->load(jailRoot.toString(), childSession->_childId);
+_docBroker->load(childSession->_childId);
 
 _peer = childSession;
 childSession->_peer = shared_from_this();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-03-13 Thread Ashod Nakashian
 loolwsd/DocumentBroker.hpp |   23 +--
 loolwsd/LOOLWSD.cpp|2 +-
 2 files changed, 18 insertions(+), 7 deletions(-)

New commits:
commit c0cf48f5ac885b878afd0b67c63332bdc91a94b8
Author: Ashod Nakashian 
Date:   Sat Mar 12 20:14:32 2016 -0500

loolwsd: jailRoot moved in DocumentBroker

Change-Id: Ic9dfce0cb0f2f87fae9a918df500c89673f15716
Reviewed-on: https://gerrit.libreoffice.org/23217
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/DocumentBroker.hpp b/loolwsd/DocumentBroker.hpp
index e78ccc3..e2cd9ee 100644
--- a/loolwsd/DocumentBroker.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -57,7 +57,7 @@ public:
 }
 
 static
-std::shared_ptr create(const std::string& uri)
+std::shared_ptr create(const std::string& uri, const 
std::string& childRoot)
 {
 std::string decodedUri;
 Poco::URI::decode(uri, decodedUri);
@@ -75,18 +75,18 @@ public:
 throw std::runtime_error("Invalid URI.");
 }
 
-return create(uriPublic);
+return create(uriPublic, childRoot);
 }
 
 static
-std::shared_ptr create(const Poco::URI& uriPublic)
+std::shared_ptr create(const Poco::URI& uriPublic, const 
std::string& childRoot)
 {
 Log::info("Creating DocumentBroker for uri: " + uriPublic.toString());
 
 std::string docKey;
 Poco::URI::encode(uriPublic.getPath(), "", docKey);
 
-return std::shared_ptr(new DocumentBroker(uriPublic, 
docKey));
+return std::shared_ptr(new DocumentBroker(uriPublic, 
docKey, childRoot));
 }
 
 ~DocumentBroker()
@@ -148,18 +148,29 @@ public:
 const std::string& getJailId() const { return _jailId; }
 const std::string& getDocKey() const { return _docKey; }
 
+std::string getJailRoot() const
+{
+assert(!_jailId.empty());
+return Poco::Path(_childRoot, _jailId).toString();
+}
+
 private:
 DocumentBroker(const Poco::URI& uriPublic,
-   const std::string& docKey) :
+   const std::string& docKey,
+   const std::string& childRoot) :
_uriPublic(uriPublic),
-   _docKey(docKey)
+   _docKey(docKey),
+   _childRoot(childRoot)
 {
+assert(!_docKey.empty());
+assert(!_childRoot.empty());
 Log::info("DocumentBroker [" + _uriPublic.toString() + "] created.");
 }
 
 private:
 const Poco::URI _uriPublic;
 const std::string _docKey;
+const std::string _childRoot;
 Poco::URI _uriJailed;
 std::string _jailId;
 std::unique_ptr _storage;
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index d382e35..28b1a8e 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -505,7 +505,7 @@ private:
 // request.getCookies(cookies);
 // Log::info("Cookie: " + cookies.get("PHPSESSID", ""));
 
-auto docBroker = DocumentBroker::create(request.getURI());
+auto docBroker = DocumentBroker::create(request.getURI(), 
LOOLWSD::ChildRoot);
 const auto docKey = docBroker->getDocKey();
 
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/DocumentBroker.hpp loolwsd/DocumentStoreManager.hpp loolwsd/LOOLWSD.cpp loolwsd/LOOLWSD.hpp loolwsd/MasterProcessSession.cpp loolwsd/MasterProcessSession.hpp

2016-03-13 Thread Ashod Nakashian
 loolwsd/DocumentBroker.hpp   |  171 +++
 loolwsd/DocumentStoreManager.hpp |  160 
 loolwsd/LOOLWSD.cpp  |   62 --
 loolwsd/LOOLWSD.hpp  |8 -
 loolwsd/MasterProcessSession.cpp |   16 +--
 loolwsd/MasterProcessSession.hpp |8 -
 6 files changed, 240 insertions(+), 185 deletions(-)

New commits:
commit bb16272e11d30acbfc2ec2c033f80bfa2a4c65bc
Author: Ashod Nakashian 
Date:   Sat Mar 12 19:29:17 2016 -0500

loolwsd: DocumentStoreManager -> DocumentBroker

Renamed DocumentStoreManager to DocumentBroker and
restructured the handshake process.

Currently, at first client connection to a given doc
a DocumentBroker is created to serve as the clearing house
of all client-side activities on the document.

Prime goals is loading and saving of the document, but
also to guarantee race-free management of the doc.

Each doc has a unique DocKey based on the URL (the path,
without queries). This DocKey is used as key into a map
of all DocumentBrokers. The latter is shared among
MasterProcessSession instances.

Change-Id: I569f2d235676e88ddc690147f3cb89faa60388c2
Reviewed-on: https://gerrit.libreoffice.org/23216
Reviewed-by: Ashod Nakashian 
Tested-by: Ashod Nakashian 

diff --git a/loolwsd/DocumentStoreManager.hpp b/loolwsd/DocumentBroker.hpp
similarity index 54%
rename from loolwsd/DocumentStoreManager.hpp
rename to loolwsd/DocumentBroker.hpp
index 68ecdae..e78ccc3 100644
--- a/loolwsd/DocumentStoreManager.hpp
+++ b/loolwsd/DocumentBroker.hpp
@@ -7,8 +7,8 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
-#ifndef INCLUDED_DOCUMENTSTOREMANAGER_HPP
-#define INCLUDED_DOCUMENTSTOREMANAGER_HPP
+#ifndef INCLUDED_DOCUMENTBROKER_HPP
+#define INCLUDED_DOCUMENTBROKER_HPP
 
 #include 
 #include 
@@ -18,9 +18,11 @@
 
 #include "Storage.hpp"
 
-/// A DocumentStoreManager as mananged by us.
+/// DocumentBroker is responsible for setting up a document
+/// in jail and brokering loading it from Storage
+/// and saving it back.
 /// Contains URI, physical path, etc.
-class DocumentStoreManager
+class DocumentBroker
 {
 public:
 
@@ -55,9 +57,7 @@ public:
 }
 
 static
-std::shared_ptr create(const std::string& uri,
- const std::string& jailRoot,
- const std::string& jailId)
+std::shared_ptr create(const std::string& uri)
 {
 std::string decodedUri;
 Poco::URI::decode(uri, decodedUri);
@@ -75,17 +75,39 @@ public:
 throw std::runtime_error("Invalid URI.");
 }
 
-return create(uriPublic, jailRoot, jailId);
+return create(uriPublic);
 }
 
 static
-std::shared_ptr create(
-const Poco::URI& uriPublic,
-const std::string& jailRoot,
-const std::string& jailId)
+std::shared_ptr create(const Poco::URI& uriPublic)
 {
-Log::info("Creating DocumentStoreManager with uri: " + 
uriPublic.toString() +
-  ", jailRoot: " + jailRoot + ", jailId: " + jailId);
+Log::info("Creating DocumentBroker for uri: " + uriPublic.toString());
+
+std::string docKey;
+Poco::URI::encode(uriPublic.getPath(), "", docKey);
+
+return std::shared_ptr(new DocumentBroker(uriPublic, 
docKey));
+}
+
+~DocumentBroker()
+{
+Log::info("~DocumentBroker [" + _uriPublic.toString() + "] 
destroyed.");
+}
+
+/// Loads a document from the public URI into the jail.
+bool load(const std::string& jailRoot, const std::string& jailId)
+{
+Log::debug("Loading from URI: " + _uriPublic.toString());
+
+std::unique_lock lock(_mutex);
+
+if (_storage)
+{
+// Already loaded. Just return.
+return true;
+}
+
+_jailId = jailId;
 
 // The URL is the publicly visible one, not visible in the chroot jail.
 // We need to map it to a jailed path and copy the file there.
@@ -95,64 +117,53 @@ public:
 
 Log::info("jailPath: " + jailPath.toString() + ", jailRoot: " + 
jailRoot);
 
-auto uriJailed = uriPublic;
-std::unique_ptr storage;
-if (uriPublic.isRelative() || uriPublic.getScheme() == "file")
+if (_uriPublic.isRelative() || _uriPublic.getScheme() == "file")
 {
-Log::info("Public URI [" + uriPublic.toString() + "] is a file.");
-storage.reset(new LocalStorage(jailRoot, jailPath.toString(), 
uriPublic.getPath()));
-const auto localPath = storage->loadStorageFileToLocal();
-uriJailed = Poco::URI(Poco::URI("file://"), localPath);
+