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

2016-04-09 Thread Henry Castro
 loolwsd/LOOLWSD.cpp  |   83 +--
 loolwsd/MasterProcessSession.cpp |   48 --
 loolwsd/MasterProcessSession.hpp |2 
 3 files changed, 81 insertions(+), 52 deletions(-)

New commits:
commit 9ae7fa5b9b26ef4fa2bee1d48362ea384787ea65
Author: Henry Castro 
Date:   Sat Apr 9 11:54:22 2016 -0400

loolwsd: wait until bridge is completed

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 9e32cbd..34291f8 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -151,6 +151,12 @@ static std::mutex newChildrenMutex;
 static std::condition_variable newChildrenCV;
 static std::map docBrokers;
 static std::mutex docBrokersMutex;
+// Sessions to pre-spawned child processes that have connected but are not yet 
assigned a
+// document to work on.
+static std::mutex AvailableChildSessionMutex;
+static std::condition_variable AvailableChildSessionCV;
+static std::map 
AvailableChildSessions;
+
 
 static void forkChildren(const int number)
 {
@@ -244,6 +250,51 @@ class ClientRequestHandler: public HTTPRequestHandler
 {
 private:
 
+static bool waitBridgeCompleted(const 
std::shared_ptr& clientSession,
+const std::shared_ptr& 
docBroker)
+{
+int retries = 5;
+bool isFound = false;
+
+// Wait until the client has connected with a prison socket.
+std::shared_ptr prisonSession;
+std::unique_lock lock(AvailableChildSessionMutex);
+
+Log::debug() << "Waiting for client session [" << 
clientSession->getId() << "] to connect." << Log::end;
+while (retries-- && !isFound)
+{
+AvailableChildSessionCV.wait_for(
+lock,
+std::chrono::milliseconds(3000),
+[, ]
+{
+return (isFound = 
AvailableChildSessions.find(clientSession->getId()) != 
AvailableChildSessions.end());
+});
+
+if (!isFound)
+{
+Log::info() << "Retrying client permission... " << retries 
<< Log::end;
+// request again new URL session
+const std::string message = "request " + 
clientSession->getId() + " " + docBroker->getDocKey() + '\n';
+Log::trace("MasterToBroker: " + message.substr(0, 
message.length()-1));
+IoUtil::writeFIFO(LOOLWSD::ForKitWritePipe, message);
+}
+}
+
+if (isFound)
+{
+Log::debug("Waiting child session permission, done!");
+prisonSession = AvailableChildSessions[clientSession->getId()];
+AvailableChildSessions.erase(clientSession->getId());
+
+clientSession->setPeer(prisonSession);
+prisonSession->setPeer(clientSession);
+Log::debug("Connected " + clientSession->getName() + " - " + 
prisonSession->getName() + ".");
+}
+
+return isFound;
+}
+
 static void handlePostRequest(HTTPServerRequest& request, 
HTTPServerResponse& response, const std::string& id)
 {
 Log::info("Post request: [" + request.getURI() + "]");
@@ -295,6 +346,18 @@ private:
 docBroker->incSessions();
 lock.unlock();
 
+if (!waitBridgeCompleted(session, docBroker))
+{
+Log::error(session->getName() + ": Failed to connect 
to lokit child.");
+// Let the client know we can't serve now.
+
response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_SERVICE_UNAVAILABLE);
+response.setContentLength(0);
+response.send();
+return;
+}
+// Now the bridge beetween the client and kit process is 
connected
+// Let messages flow
+
 std::string encodedFrom;
 URI::encode(docBroker->getPublicUri().getPath(), "", 
encodedFrom);
 const std::string load = "load url=" + encodedFrom;
@@ -495,6 +558,18 @@ private:
 if (wsSessionsCount == 1)
 session->setEditLock(true);
 
+if (!waitBridgeCompleted(session, docBroker))
+{
+Log::error(session->getName() + ": Failed to connect to child. 
Client cannot serve now.");
+// Let the client know we can't serve now.
+
response.setStatusAndReason(Poco::Net::HTTPResponse::HTTP_SERVICE_UNAVAILABLE);
+response.setContentLength(0);
+response.send();
+return;
+}
+// Now the bridge beetween the client and kit process is connected
+// Let messages flow
+
 QueueHandler handler(queue, session, "wsd_queue_" + session->getId());
 
 Thread 

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

2016-04-06 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp |   38 +-
 loolwsd/LOOLWSD.hpp |9 -
 loolwsd/loolwsd.xml |9 +
 3 files changed, 50 insertions(+), 6 deletions(-)

New commits:
commit 00940d5a0bffb0c2a0224ed16a052f6989ac4062
Author: Ashod Nakashian 
Date:   Wed Apr 6 23:51:58 2016 -0400

loolwsd: configure wsd using the config file

Most all configuration values can now be defined
in the configuration XML. The command-line arguments
can be used to override some of these values (for
the convenience of developement and testing) and,
in a few cases, as a security measure to avoid
storing sensitive data in the configuration file.

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 91bbf4d..46860d0 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -965,7 +965,7 @@ std::string LOOLWSD::LoSubPath = "lo";
 std::string LOOLWSD::FileServerRoot;
 std::string LOOLWSD::AdminCreds;
 
-int LOOLWSD::NumPreSpawnedChildren = 10;
+unsigned int LOOLWSD::NumPreSpawnedChildren = 0;
 bool LOOLWSD::DoTest = false;
 
 LOOLWSD::LOOLWSD()
@@ -997,6 +997,42 @@ void LOOLWSD::initialize(Application& self)
 }
 }
 
+if (Cache.empty())
+{
+Cache = getPathFromConfig("tile_cache_path");
+}
+
+if (SysTemplate.empty())
+{
+SysTemplate = getPathFromConfig("sys_template_path");
+}
+
+if (LoTemplate.empty())
+{
+LoTemplate = getPathFromConfig("lo_template_path");
+}
+
+if (ChildRoot.empty())
+{
+ChildRoot = getPathFromConfig("child_root_path");
+}
+
+if (LoSubPath.empty())
+{
+LoSubPath = getPathFromConfig("lo_jail_subpath");
+}
+
+if (FileServerRoot.empty())
+{
+FileServerRoot = getPathFromConfig("file_server_root_path");
+}
+
+if (NumPreSpawnedChildren == 0)
+{
+// Default to 10 children.
+NumPreSpawnedChildren = config().getUInt("num_prespawn_children", 10);
+}
+
 ServerApplication::initialize(self);
 }
 
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index 76e5246..ea87f50 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -36,7 +36,7 @@ public:
 // An Application is a singleton anyway,
 // so just keep these as statics.
 static std::atomic NextSessionId;
-static int NumPreSpawnedChildren;
+static unsigned int NumPreSpawnedChildren;
 static int BrokerWritePipe;
 static bool DoTest;
 static std::string Cache;
@@ -73,6 +73,13 @@ private:
 std::string getPathFromConfig(const std::string& property) const
 {
 auto path = config().getString(property);
+if (path.empty() && config().hasProperty(property + "[@default]"))
+{
+// Use the default value if empty and a default provided.
+path = config().getString(property + "[@default]");
+}
+
+// Reconstruct absolute path if relative.
 if (config().hasProperty(property + "[@relative]") &&
 config().getBool(property + "[@relative]"))
 {
diff --git a/loolwsd/loolwsd.xml b/loolwsd/loolwsd.xml
index 96d7202..7d356b1 100644
--- a/loolwsd/loolwsd.xml
+++ b/loolwsd/loolwsd.xml
@@ -1,12 +1,13 @@
 
 
-1
-
+
+
 
-
+
 lo
-../loleaflet/
+
 
+1
 
 true
 trace
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-04-06 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp |   23 +++
 loolwsd/LOOLWSD.hpp |   16 
 2 files changed, 19 insertions(+), 20 deletions(-)

New commits:
commit e8ffea5d1c0d0f18334a6b07a804f66a251cf609
Author: Ashod Nakashian 
Date:   Wed Apr 6 18:17:59 2016 -0400

loolwsd: minor cleanup of path handling in config

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 4a222e8..adcde45 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -990,30 +990,13 @@ void LOOLWSD::initialize(Application& self)
 
 void LOOLWSD::initializeSSL()
 {
-auto& conf = config();
-
-auto ssl_cert_file_path = conf.getString("ssl.cert_file_path");
-if (conf.getBool("ssl.cert_file_path[@relative]"))
-{
-ssl_cert_file_path = 
Poco::Path(Application::instance().commandPath()).parent().append(ssl_cert_file_path).toString();
-}
-
+const auto ssl_cert_file_path = getPathFromConfig("ssl.cert_file_path");
 Log::info("SSL Cert file: " + ssl_cert_file_path);
 
-auto ssl_key_file_path = conf.getString("ssl.key_file_path");
-if (conf.getBool("ssl.key_file_path[@relative]"))
-{
-ssl_key_file_path = 
Poco::Path(Application::instance().commandPath()).parent().append(ssl_key_file_path).toString();
-}
-
+const auto ssl_key_file_path = getPathFromConfig("ssl.key_file_path");
 Log::info("SSL Key file: " + ssl_key_file_path);
 
-auto ssl_ca_file_path = conf.getString("ssl.ca_file_path");
-if (conf.getBool("ssl.ca_file_path[@relative]"))
-{
-ssl_ca_file_path = 
Poco::Path(Application::instance().commandPath()).parent().append(ssl_ca_file_path).toString();
-}
-
+const auto ssl_ca_file_path = getPathFromConfig("ssl.ca_file_path");
 Log::info("SSL CA file: " + ssl_ca_file_path);
 
 Poco::Crypto::initializeCrypto();
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index 59d7111..f4964bb 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -65,6 +65,22 @@ private:
 void displayHelp();
 void displayVersion();
 Poco::Process::PID createBroker();
+
+/// Reads and processes path entries with the given property
+/// from the configuration.
+/// Converts relative paths to absolute.
+//TODO: Move to a better namespace.
+std::string getPathFromConfig(const std::string& property) const
+{
+auto path = config().getString(property);
+if (config().hasProperty(property + "[@relative]") &&
+config().getBool(property + "[@relative]"))
+{
+path = 
Poco::Path(Application::instance().commandPath()).parent().append(path).toString();
+}
+
+return path;
+}
 };
 
 #endif
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

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

New commits:
commit 36a3810541f82d1f9bf001c6e50bf63c40b787a1
Author: Ashod Nakashian 
Date:   Mon Apr 4 22:50:57 2016 -0400

loolwsd: fixed convert-to and re-enabled test

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 6b05fca..93e65ee 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -291,17 +291,16 @@ private:
 // In that case, we can use a pool and index by publicPath.
 std::unique_lock lock(docBrokersMutex);
 
+//FIXME: What if the same document is already open? Need a 
fake dockey here.
 Log::debug("New DocumentBroker for docKey [" + docKey + 
"].");
 docBrokers.emplace(docKey, docBroker);
 
-// Request a kit process for this doc.
-const std::string aMessage = "request " + id + " " + 
docKey + "\n";
-Log::debug("MasterToBroker: " + aMessage.substr(0, 
aMessage.length() - 1));
-IoUtil::writeFIFO(LOOLWSD::BrokerWritePipe, aMessage);
-
 // Load the document.
 std::shared_ptr ws;
 auto session = std::make_shared(id, 
LOOLSession::Kind::ToClient, ws, docBroker, nullptr);
+docBroker->addWSSession(id, session);
+unsigned wsSessionsCount = docBroker->getWSSessionsCount();
+Log::warn(docKey + ", ws_sessions++: " + 
std::to_string(wsSessionsCount));
 session->setEditLock(true);
 docBroker->incSessions();
 lock.unlock();
diff --git a/loolwsd/test/httpposttest.cpp b/loolwsd/test/httpposttest.cpp
index a4b0b03..2a39f58 100644
--- a/loolwsd/test/httpposttest.cpp
+++ b/loolwsd/test/httpposttest.cpp
@@ -28,7 +28,7 @@
 class HTTPPostTest : public CPPUNIT_NS::TestFixture
 {
 CPPUNIT_TEST_SUITE(HTTPPostTest);
-//CPPUNIT_TEST(testConvertTo);
+CPPUNIT_TEST(testConvertTo);
 CPPUNIT_TEST_SUITE_END();
 
 void testConvertTo();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-04-04 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp |6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

New commits:
commit 4bc26f25d51c336bf904c0b7e07a26bc486959a4
Author: Ashod Nakashian 
Date:   Mon Apr 4 22:40:18 2016 -0400

loolwsd: wait for new child instances if none is available

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 9c29d63..6b05fca 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -172,8 +172,10 @@ using Poco::XML::Node;
 using Poco::XML::NodeList;
 
 /// New LOK child processes ready to host documents.
+//TODO: Move to a more sensible namespace.
 static std::vector newChilds;
 static std::mutex newChildsMutex;
+static std::condition_variable newChildsCV;
 static std::map docBrokers;
 static std::mutex docBrokersMutex;
 
@@ -199,7 +201,8 @@ std::shared_ptr getNewChild()
 IoUtil::writeFIFO(LOOLWSD::BrokerWritePipe, aMessage);
 }
 
-if (available > 0)
+const auto timeout = std::chrono::milliseconds(CHILD_TIMEOUT_SECS * 1000);
+if (newChildsCV.wait_for(lock, timeout, [](){ return !newChilds.empty(); 
}))
 {
 auto child = newChilds.back();
 newChilds.pop_back();
@@ -671,6 +674,7 @@ public:
 std::unique_lock lock(newChildsMutex);
 newChilds.emplace_back(std::make_shared(pid, ws));
 Log::info("Have " + std::to_string(newChilds.size()) + " childs.");
+newChildsCV.notify_one();
 return;
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-04-03 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp |   97 
 1 file changed, 97 insertions(+)

New commits:
commit 25a68bf7e965e284deabe23ed4132c5dd997ab43
Author: Ashod Nakashian 
Date:   Sun Apr 3 10:33:35 2016 -0400

loolwsd: support for child control WS

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 6a382e1..f4224be 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -173,6 +173,77 @@ using Poco::XML::InputSource;
 using Poco::XML::Node;
 using Poco::XML::NodeList;
 
+/// Represents a new LOK child that is read
+/// to host a document.
+class ChildProcess
+{
+public:
+ChildProcess() :
+_pid(-1)
+{
+}
+
+ChildProcess(const Poco::Process::PID pid, const 
std::shared_ptr& ws) :
+_pid(pid),
+_ws(ws)
+{
+}
+
+ChildProcess(ChildProcess&& other) :
+_pid(other._pid),
+_ws(other._ws)
+{
+other._pid = -1;
+other._ws.reset();
+}
+
+const ChildProcess& operator=(ChildProcess&& other)
+{
+_pid = other._pid;
+other._pid = -1;
+_ws = other._ws;
+other._ws.reset();
+
+return *this;
+}
+
+~ChildProcess()
+{
+close(true);
+}
+
+void close(const bool rude)
+{
+if (_pid != -1)
+{
+if (kill(_pid, SIGINT) != 0 && rude && kill(_pid, 0) != 0)
+{
+Log::error("Cannot terminate lokit [" + std::to_string(_pid) + 
"]. Abandoning.");
+}
+
+//TODO: Notify Admin.
+std::ostringstream message;
+message << "rmdoc" << " "
+<< _pid << " "
+<< "\n";
+//IoUtil::writeFIFO(WriterNotify, message.str());
+   _pid = -1;
+}
+
+_ws.reset();
+}
+
+Poco::Process::PID getPid() const { return _pid; }
+std::shared_ptr getWebSocket() const { return _ws; }
+
+private:
+Poco::Process::PID _pid;
+std::shared_ptr _ws;
+};
+
+/// New LOK child processes ready to host documents.
+static std::vector newChilds;
+static std::mutex newChildsMutex;
 static std::map docBrokers;
 static std::mutex docBrokersMutex;
 
@@ -597,6 +668,32 @@ public:
 Log::debug("Child connection with URI [" + request.getURI() + "].");
 
 assert(request.serverAddress().port() == MASTER_PORT_NUMBER);
+if (request.getURI().find(NEW_CHILD_URI) == 0)
+{
+// New Child is spawned.
+const auto params = 
Poco::URI(request.getURI()).getQueryParameters();
+Poco::Process::PID pid = -1;
+for (const auto& param : params)
+{
+if (param.first == "pid")
+{
+pid = std::stoi(param.second);
+}
+}
+
+if (pid <= 0)
+{
+Log::error("Invalid PID in child URI [" + request.getURI() + 
"].");
+return;
+}
+
+Log::info("New child [" + std::to_string(pid) + "].");
+auto ws = std::make_shared(request, response);
+std::unique_lock lock(newChildsMutex);
+newChilds.emplace_back(std::make_shared(pid, ws));
+return;
+}
+
 if (request.getURI().find(CHILD_URI) != 0)
 {
 Log::error("Invalid request URI: [" + request.getURI() + "].");
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-04-03 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp |5 +
 1 file changed, 5 insertions(+)

New commits:
commit 504ffec64886dab597748c7437659f42d3a1272e
Author: Ashod Nakashian 
Date:   Sat Apr 2 17:34:51 2016 -0400

loolwsd: request new child from Broker for convert-to requests

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 538ff82..535edb0 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -246,6 +246,11 @@ private:
 Log::debug("New DocumentBroker for docKey [" + docKey + 
"].");
 docBrokers.emplace(docKey, docBroker);
 
+// Request a kit process for this doc.
+const std::string aMessage = "request " + id + " " + 
docKey + "\n";
+Log::debug("MasterToBroker: " + aMessage.substr(0, 
aMessage.length() - 1));
+IoUtil::writeFIFO(LOOLWSD::BrokerWritePipe, aMessage);
+
 // Load the document.
 std::shared_ptr ws;
 auto session = std::make_shared(id, 
LOOLSession::Kind::ToClient, ws, docBroker, nullptr);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-04-03 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp |   25 -
 1 file changed, 25 deletions(-)

New commits:
commit 21cdf9d503e267d6dd6c91076fd7c595b4c3d7ca
Author: Ashod Nakashian 
Date:   Sat Apr 2 17:32:01 2016 -0400

loolwsd: removed unused authentication function for now

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 033c2ec..538ff82 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -381,35 +381,10 @@ private:
 }
 }
 
-bool authenticate(HTTPServerRequest& request, HTTPServerResponse& 
response, const std::string& id)
-{
-(void)response;
-Log::info("Authenticating Get request processor for session [" + id + 
"].");
-std::string token;
-for (auto& pair : URI(request.getURI()).getQueryParameters())
-{
-if (pair.first == "token")
-{
-token = pair.second;
-break;
-}
-}
-
-//TODO:
-//AuthAgent.verify(token);
-return true;
-}
-
 void handleGetRequest(HTTPServerRequest& request, HTTPServerResponse& 
response, const std::string& id)
 {
 Log::info("Starting GET request handler for session [" + id + "].");
 
-//TODO: Authenticate the caller.
-// authenticate(request, response);
-// NameValueCollection cookies;
-// request.getCookies(cookies);
-// Log::info("Cookie: " + cookies.get("PHPSESSID", ""));
-
 // Remove the leading '/' in the GET URL.
 std::string uri = request.getURI();
 if (uri.size() > 0 && uri[0] == '/')
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-04-01 Thread Andras Timar
 loolwsd/LOOLWSD.cpp |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 324f72d844c49ad3ffb7a8447bf835a1d59fd20d
Author: Andras Timar 
Date:   Fri Apr 1 16:31:33 2016 +0200

Revert "serve loleaflet from apache2, until we solve access control problem"

This reverts commit 21cd9167c4ed9c0e716ecb3b00de626c456515dd.

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 8246a01..8174add 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -534,7 +534,7 @@ private:
 const std::string mediaType = "text/xml";
 const std::string action = "action";
 const std::string urlsrc = "urlsrc";
-const std::string uriValue = "https://; + uri.getHost() + 
"/loleaflet/dist/loleaflet.html?";
+const std::string uriValue = "https://; + uri.getHost() + ":" + 
std::to_string(uri.getPort()) + "/loleaflet/dist/loleaflet.html?";
 
 InputSource inputSrc(discoveryPath);
 AutoPtr docXML = parser.parse();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: loolwsd/LOOLWSD.cpp loolwsd/MasterProcessSession.cpp loolwsd/MessageQueue.hpp loolwsd/QueueHandler.hpp

2016-03-28 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp  |   32 +++-
 loolwsd/MasterProcessSession.cpp |3 ++-
 loolwsd/MessageQueue.hpp |6 +-
 loolwsd/QueueHandler.hpp |8 +---
 4 files changed, 23 insertions(+), 26 deletions(-)

New commits:
commit 3217b4592a6e196486440c2149132233b79d5982
Author: Ashod Nakashian 
Date:   Sat Mar 26 22:56:10 2016 -0400

loolwsd: queue payload changed to vector

All messages now pass through the queue.
This resolves a race between single-line
messages and multi-line ones.

Previously, single-line messages were
processed on the queue (on a background
thread) while multi-line ones were handled
immediatly. This resulted in order-inversion
due to a race between the queue thread and the
next multi-line message, which caused stability
issues every so often.

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 749b2e2..b4cc910 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -221,7 +221,7 @@ public:
 // Handler returns false to end.
 void SocketProcessor(std::shared_ptr ws,
  HTTPServerResponse& response,
- std::function 
handler)
+ std::function handler)
 {
 Log::info("Starting Socket Processor.");
 
@@ -322,7 +322,7 @@ void SocketProcessor(std::shared_ptr ws,
 }
 
 // Call the handler.
-if (!handler(payload.data(), payload.size()))
+if (!handler(payload))
 {
 Log::info("Socket handler flagged for finishing.");
 }
@@ -614,30 +614,20 @@ private:
 queueHandlerThread.start(handler);
 bool normalShutdown = false;
 
-SocketProcessor(ws, response, [, , 
](const char* data, const int size, const bool singleLine)
+SocketProcessor(ws, response, [, , 
](const std::vector& payload)
 {
-// FIXME: There is a race here when a request A gets in the 
queue and
-// is processed _after_ a later request B, because B gets 
processed
-// synchronously and A is waiting in the queue thread.
-// The fix is to push everything into the queue
-// (i.e. change MessageQueue to vector).
-const std::string firstLine = getFirstLine(data, size);
+const auto firstLine = getFirstLine(payload.data(), 
payload.size());
 time(>_lastMessageTime);
-if (singleLine || firstLine.find("paste") == 0)
+if (firstLine.compare(0, 10, "disconnect") == 0) // starts 
with "disconnect"
 {
-if (firstLine.compare(0, 10, "disconnect") == 0) // starts 
with "disconnect"
-{
-normalShutdown = true;
-return true;
-}
-
-queue.put(std::string(data, size));
-return true;
+normalShutdown = true;
 }
 else
 {
-return session->handleInput(data, size);
+queue.put(payload);
 }
+
+return true;
 });
 
 if (docBroker->getSessionsCount() == 1 && !normalShutdown)
@@ -831,9 +821,9 @@ public:
 lock.unlock();
 MasterProcessSession::AvailableChildSessionCV.notify_one();
 
-SocketProcessor(ws, response, [](const char* data, const 
int size, bool)
+SocketProcessor(ws, response, [](const std::vector& 
payload)
 {
-return session->handleInput(data, size);
+return session->handleInput(payload.data(), 
payload.size());
 });
 }
 catch (const Exception& exc)
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 62e4d6f..0fbf70c 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -500,7 +500,8 @@ bool MasterProcessSession::getPartPageRectangles(const char 
*buffer, int length)
 
 std::string MasterProcessSession::getSaveAs()
 {
-return _saveAsQueue.get();
+const auto payload = _saveAsQueue.get();
+return std::string(payload.data(), payload.size());
 }
 
 void MasterProcessSession::sendFontRendering(const char *buffer, int length, 
StringTokenizer& tokens)
diff --git a/loolwsd/MessageQueue.hpp b/loolwsd/MessageQueue.hpp
index 2d62173..5a0c439 100644
--- a/loolwsd/MessageQueue.hpp
+++ b/loolwsd/MessageQueue.hpp
@@ -21,7 +21,7 @@ class MessageQueue
 {
 

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

2016-03-28 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp |  170 +++-
 1 file changed, 89 insertions(+), 81 deletions(-)

New commits:
commit 7c92e263e808d75ffd79a12a1ae55b48de5ef187
Author: Ashod Nakashian 
Date:   Sat Mar 26 22:30:54 2016 -0400

loolwsd: improved websocket reading

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index ce23783..749b2e2 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -221,112 +221,120 @@ public:
 // Handler returns false to end.
 void SocketProcessor(std::shared_ptr ws,
  HTTPServerResponse& response,
- std::function handler)
+ std::function 
handler)
 {
 Log::info("Starting Socket Processor.");
 
 const Timespan waitTime(POLL_TIMEOUT_MS * 1000);
 try
 {
+ws->setReceiveTimeout(0);
+
 int flags = 0;
 int n = 0;
-ws->setReceiveTimeout(0);
-do
+std::vector payload(READ_BUFFER_SIZE * 100);
+
+while (!TerminationFlag &&
+   (flags & WebSocket::FRAME_OP_BITMASK) != 
WebSocket::FRAME_OP_CLOSE)
 {
-char buffer[20]; //FIXME: Dynamic?
+if (!ws->poll(waitTime, Socket::SELECT_READ))
+{
+// Wait some more.
+continue;
+}
 
-if (ws->poll(waitTime, Socket::SELECT_READ))
+payload.resize(payload.capacity());
+n = ws->receiveFrame(payload.data(), payload.capacity(), flags);
+if (n >= 0)
 {
-n = ws->receiveFrame(buffer, sizeof(buffer), flags);
+payload.resize(n);
+}
 
-if ((flags & WebSocket::FRAME_OP_BITMASK) == 
WebSocket::FRAME_OP_PING)
-{
-// Echo back the ping payload as pong.
-// Technically, we should send back a PONG control frame.
-// However Firefox (probably) or Node.js (possibly) doesn't
-// like that and closes the socket when we do.
-// Echoing the payload as a normal frame works with 
Firefox.
-ws->sendFrame(buffer, n /*, WebSocket::FRAME_OP_PONG*/);
-}
-else if ((flags & WebSocket::FRAME_OP_BITMASK) == 
WebSocket::FRAME_OP_PONG)
-{
-// In case we do send pings in the future.
-}
-else if (n <= 0)
-{
-// Connection closed.
-Log::warn() << "Received " << n
-<< " bytes. Connection closed. Flags: "
-<< std::hex << flags << Log::end;
-break;
-}
-else if ((flags & WebSocket::FRAME_OP_BITMASK) != 
WebSocket::FRAME_OP_CLOSE)
-{
-assert(n > 0);
-const std::string firstLine = getFirstLine(buffer, n);
-StringTokenizer tokens(firstLine, " ", 
StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
-int size;
+if ((flags & WebSocket::FRAME_OP_BITMASK) == 
WebSocket::FRAME_OP_PING)
+{
+// Echo back the ping payload as pong.
+// Technically, we should send back a PONG control frame.
+// However Firefox (probably) or Node.js (possibly) doesn't
+// like that and closes the socket when we do.
+// Echoing the payload as a normal frame works with Firefox.
+ws->sendFrame(payload.data(), n /*, 
WebSocket::FRAME_OP_PONG*/);
+}
+else if ((flags & WebSocket::FRAME_OP_BITMASK) == 
WebSocket::FRAME_OP_PONG)
+{
+// In case we do send pings in the future.
+}
+else if (n <= 0 || ((flags & WebSocket::FRAME_OP_BITMASK) == 
WebSocket::FRAME_OP_CLOSE))
+{
+// Connection closed.
+Log::warn() << "Received " << n
+<< " bytes. Connection closed. Flags: "
+<< std::hex << flags << Log::end;
+break;
+}
 
-if (firstLine == "eof")
-{
-Log::info("Received EOF. Finishing.");
-break;
-}
+assert(n > 0);
 
-if ((flags & WebSocket::FrameFlags::FRAME_FLAG_FIN) != 
WebSocket::FrameFlags::FRAME_FLAG_FIN)
+const 

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

2016-03-25 Thread Miklos Vajna
 loolwsd/LOOLWSD.cpp  |   14 +++---
 loolwsd/MasterProcessSession.cpp |6 +++---
 loolwsd/MasterProcessSession.hpp |6 +++---
 3 files changed, 13 insertions(+), 13 deletions(-)

New commits:
commit 08b52fae72a7794b75d30f6bd4a9225199abd2c3
Author: Miklos Vajna 
Date:   Fri Mar 25 17:10:16 2016 +0100

MasterProcessSession: fix missing prefixes

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index ea745ca..7412124 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -614,7 +614,7 @@ private:
 // The fix is to push everything into the queue
 // (i.e. change MessageQueue to vector).
 const std::string firstLine = getFirstLine(data, size);
-time(>lastMessageTime);
+time(>_lastMessageTime);
 if (singleLine || firstLine.find("paste") == 0)
 {
 if (firstLine.compare(0, 10, "disconnect") == 0) // starts 
with "disconnect"
@@ -1453,13 +1453,13 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 std::unique_lock sessionsLock(sessionsMutex);
 for (auto& it : sessions)
 {
-if (it->lastMessageTime > it->idleSaveTime &&
-it->lastMessageTime < now - 30)
+if (it->_lastMessageTime > it->_idleSaveTime &&
+it->_lastMessageTime < now - 30)
 {
 // Trigger a .uno:Save
 Log::info("Idle save triggered for session " + 
it->getId());
 
-it->idleSaveTime = now;
+it->_idleSaveTime = now;
 }
 }
 }
@@ -1471,13 +1471,13 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 std::unique_lock sessionsLock(sessionsMutex);
 for (auto& it : sessions)
 {
-if (it->lastMessageTime >= it->idleSaveTime &&
-it->lastMessageTime >= it->autoSaveTime)
+if (it->_lastMessageTime >= it->_idleSaveTime &&
+it->_lastMessageTime >= it->_autoSaveTime)
 {
 // Trigger a .uno:Save
 Log::info("Auto-save triggered for session " + 
it->getId());
 
-it->autoSaveTime = now;
+it->_autoSaveTime = now;
 }
 }
 }
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index f7b26ce..52e96c9 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -35,9 +35,9 @@ MasterProcessSession::MasterProcessSession(const std::string& 
id,

std::shared_ptr ws,
std::shared_ptr 
docBroker) :
 LOOLSession(id, kind, ws),
-lastMessageTime(0),
-idleSaveTime(0),
-autoSaveTime(0),
+_lastMessageTime(0),
+_idleSaveTime(0),
+_autoSaveTime(0),
 _curPart(0),
 _loadPart(-1),
 _docBroker(docBroker)
diff --git a/loolwsd/MasterProcessSession.hpp b/loolwsd/MasterProcessSession.hpp
index 7b0b0cb..defe5ea 100644
--- a/loolwsd/MasterProcessSession.hpp
+++ b/loolwsd/MasterProcessSession.hpp
@@ -50,9 +50,9 @@ class MasterProcessSession final : public LOOLSession, public 
std::enable_shared
 static std::mutex AvailableChildSessionMutex;
 static std::condition_variable AvailableChildSessionCV;
 
-time_t lastMessageTime;
-time_t idleSaveTime;
-time_t autoSaveTime;
+time_t _lastMessageTime;
+time_t _idleSaveTime;
+time_t _autoSaveTime;
 
  protected:
 bool invalidateTiles(const char *buffer, int length, 
Poco::StringTokenizer& tokens);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-03-25 Thread Pranav Kant
 loolwsd/LOOLWSD.cpp |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit e7ff2399e163eea9dbd921b19d206e2f764ec4f0
Author: Pranav Kant 
Date:   Fri Mar 25 15:55:36 2016 +0530

loolwsd: Fix WOPI urlsrc

Since we are serving loleaflet from loolwsd now

Change-Id: Ie9b1150f59fcbfef8e22fcf94fa1fbdbfd1ab9cc

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index caeb378..ea745ca 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -672,7 +672,7 @@ private:
 const std::string mediaType = "text/xml";
 const std::string action = "action";
 const std::string urlsrc = "urlsrc";
-const std::string uriValue = "http://; + uri.getHost() + 
LOLEAFLET_PATH;
+const std::string uriValue = "https://; + uri.getHost() + ":" + 
std::to_string(uri.getPort()) + LOLEAFLET_PATH;
 
 InputSource inputSrc(discoveryPath);
 AutoPtr docXML = parser.parse();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-03-25 Thread Pranav Kant
 loolwsd/LOOLWSD.cpp |9 +
 loolwsd/loolwsd.xml |1 +
 2 files changed, 10 insertions(+)

New commits:
commit 31200eec6f753f6606d1510f1ba6c064639341a1
Author: Pranav Kant 
Date:   Fri Mar 25 08:12:37 2016 +0530

loolwsd: Add CA path during SSL initialize

Change-Id: I09071b5fc0c32360524506c92f444ed8c6d8e0df

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index d299c38..caeb378 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1067,12 +1067,21 @@ void LOOLWSD::initializeSSL()
 
 Log::info("SSL Key file: " + ssl_key_file_path);
 
+auto ssl_ca_file_path = conf.getString("ssl.ca_file_path");
+if (conf.getBool("ssl.ca_file_path[@relative]"))
+{
+ssl_ca_file_path = 
Poco::Path(Application::instance().commandPath()).parent().append(ssl_ca_file_path).toString();
+}
+
+Log::info("SSL CA file: " + ssl_ca_file_path);
+
 Poco::Crypto::initializeCrypto();
 
 Poco::Net::initializeSSL();
 Poco::Net::Context::Params sslParams;
 sslParams.certificateFile = ssl_cert_file_path;
 sslParams.privateKeyFile = ssl_key_file_path;
+sslParams.caLocation = ssl_ca_file_path;
 // Don't ask clients for certificate
 sslParams.verificationMode = Poco::Net::Context::VERIFY_NONE;
 
diff --git a/loolwsd/loolwsd.xml b/loolwsd/loolwsd.xml
index 5945ba2..d058910 100644
--- a/loolwsd/loolwsd.xml
+++ b/loolwsd/loolwsd.xml
@@ -2,6 +2,7 @@
 
 /etc/loolwsd/cert.pem
 /etc/loolwsd/key.pem
+/etc/loolwsd/CollaboraCloudSuiteCA_ca-chain.cert.pem
 
 
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-03-19 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |   14 +-
 1 file changed, 5 insertions(+), 9 deletions(-)

New commits:
commit 3f93cdc1d1e5ff8146e76ed2e277cdc0aa923850
Author: Henry Castro 
Date:   Wed Mar 16 19:57:18 2016 -0400

Revert "loolwsd: read WOPI scheme, hostname from config values"

This reverts commit ad980bee0217cf4e49962e1e8baa876afd99033f.

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 23db1d3..2c47456 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -629,21 +629,17 @@ private:
 }
 }
 
-void handleGetDiscovery(HTTPServerResponse& response)
+void handleGetDiscovery(HTTPServerRequest& request, HTTPServerResponse& 
response)
 {
 DOMParser parser;
 DOMWriter writer;
+URI uri("http", request.getHost(), request.getURI());
 
-LOOLWSD& appSrv = static_cast(Application::instance());
-const std::string discoveryPath = 
Path(appSrv.commandPath()).parent().toString() + "discovery.xml";
+const std::string discoveryPath = 
Path(Application::instance().commandPath()).parent().toString() + 
"discovery.xml";
 const std::string mediaType = "text/xml";
 const std::string action = "action";
 const std::string urlsrc = "urlsrc";
-const std::string uriValue = 
appSrv.config().getString("loolwsd.wopi.scheme", "http") + "://" +
- 
appSrv.config().getString("loolwsd.wopi.hostname", "localhost") +
- // TODO. LOOLWSD does not serve 
loleaflet.html, so set default 80
- 
//appSrv.config().getString("loolwsd.wopi.port", "9980") +
- LOLEAFLET_PATH;
+const std::string uriValue = "http://; + uri.getHost() + 
LOLEAFLET_PATH;
 
 InputSource inputSrc(discoveryPath);
 AutoPtr docXML = parser.parse();
@@ -683,7 +679,7 @@ public:
 if (request.getMethod() == HTTPRequest::HTTP_GET && 
request.getURI() == "/hosting/discovery")
 {
 // http://server/hosting/discovery
-handleGetDiscovery(response);
+handleGetDiscovery(request, response);
 }
 else if (!(request.find("Upgrade") != request.end() && 
Poco::icompare(request["Upgrade"], "websocket") == 0))
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-03-19 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |   14 +-
 1 file changed, 9 insertions(+), 5 deletions(-)

New commits:
commit ad980bee0217cf4e49962e1e8baa876afd99033f
Author: Henry Castro 
Date:   Wed Mar 16 16:45:20 2016 -0400

loolwsd: read WOPI scheme, hostname from config values

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 2c47456..23db1d3 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -629,17 +629,21 @@ private:
 }
 }
 
-void handleGetDiscovery(HTTPServerRequest& request, HTTPServerResponse& 
response)
+void handleGetDiscovery(HTTPServerResponse& response)
 {
 DOMParser parser;
 DOMWriter writer;
-URI uri("http", request.getHost(), request.getURI());
 
-const std::string discoveryPath = 
Path(Application::instance().commandPath()).parent().toString() + 
"discovery.xml";
+LOOLWSD& appSrv = static_cast(Application::instance());
+const std::string discoveryPath = 
Path(appSrv.commandPath()).parent().toString() + "discovery.xml";
 const std::string mediaType = "text/xml";
 const std::string action = "action";
 const std::string urlsrc = "urlsrc";
-const std::string uriValue = "http://; + uri.getHost() + 
LOLEAFLET_PATH;
+const std::string uriValue = 
appSrv.config().getString("loolwsd.wopi.scheme", "http") + "://" +
+ 
appSrv.config().getString("loolwsd.wopi.hostname", "localhost") +
+ // TODO. LOOLWSD does not serve 
loleaflet.html, so set default 80
+ 
//appSrv.config().getString("loolwsd.wopi.port", "9980") +
+ LOLEAFLET_PATH;
 
 InputSource inputSrc(discoveryPath);
 AutoPtr docXML = parser.parse();
@@ -679,7 +683,7 @@ public:
 if (request.getMethod() == HTTPRequest::HTTP_GET && 
request.getURI() == "/hosting/discovery")
 {
 // http://server/hosting/discovery
-handleGetDiscovery(request, response);
+handleGetDiscovery(response);
 }
 else if (!(request.find("Upgrade") != request.end() && 
Poco::icompare(request["Upgrade"], "websocket") == 0))
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-03-19 Thread Henry Castro
 loolwsd/LOOLWSD.cpp|3 +++
 loolwsd/loolwsd.properties |5 +
 2 files changed, 8 insertions(+)

New commits:
commit 8a6cfdf961ee63be6eb13321fb728d9168c58a7c
Author: Henry Castro 
Date:   Wed Mar 16 15:52:01 2016 -0400

loolwsd: load default configuration files

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 499391b..2c47456 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -947,6 +947,9 @@ LOOLWSD::~LOOLWSD()
 
 void LOOLWSD::initialize(Application& self)
 {
+// load default configuration files, if present
+loadConfiguration();
+
 ServerApplication::initialize(self);
 }
 
diff --git a/loolwsd/loolwsd.properties b/loolwsd/loolwsd.properties
new file mode 100644
index 000..0d83839
--- /dev/null
+++ b/loolwsd/loolwsd.properties
@@ -0,0 +1,5 @@
+# The Libre Office Online WOPI Client sets the request scheme,
+# hostname and port at the server uses to identify itself.
+loolwsd.wopi.scheme = http
+loolwsd.wopi.hostname = localhost
+loolwsd.wopi.port = 9980
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-03-13 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp |   46 --
 1 file changed, 24 insertions(+), 22 deletions(-)

New commits:
commit 66cd6cd5c3d3dc38b680c300b292c535fa981875
Author: Ashod Nakashian 
Date:   Sun Mar 13 13:21:36 2016 -0400

loolwsd: improved DocumentBroker lifetime and thread handling

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index ca08811..1dc41a2 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -508,35 +508,36 @@ private:
 auto docBroker = DocumentBroker::create(request.getURI(), 
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);
+// This lock could become a bottleneck.
+// In that case, we can use a pool and index by publicPath.
+std::unique_lock lock(LOOLWSD::DocBrokersMutex);
 
-// Lookup this document.
-auto it = LOOLWSD::DocBrokers.find(docKey);
-if (it != LOOLWSD::DocBrokers.end())
-{
-// Get the DocumentBroker from the Cache.
-docBroker = it->second;
-assert(docBroker);
-}
-else
-{
-// Set one we just created.
-LOOLWSD::DocBrokers.emplace(docKey, docBroker);
-}
+// Lookup this document.
+auto it = LOOLWSD::DocBrokers.find(docKey);
+if (it != LOOLWSD::DocBrokers.end())
+{
+// Get the DocumentBroker from the Cache.
+Log::debug("Found DocumentBroker for docKey [" + docKey + "].");
+docBroker = it->second;
+assert(docBroker);
+}
+else
+{
+// Set one we just created.
+Log::debug("New DocumentBroker for docKey [" + docKey + "].");
+LOOLWSD::DocBrokers.emplace(docKey, docBroker);
 }
 
+auto ws = std::make_shared(request, response);
+auto session = std::make_shared(id, 
LOOLSession::Kind::ToClient, ws, docBroker);
+docBroker->incSessions();
+lock.unlock();
+
 // Request a kit process for this doc.
 const std::string aMessage = "request " + id + " " + docKey + "\r\n";
 Log::debug("MasterToBroker: " + aMessage.substr(0, aMessage.length() - 
2));
 Util::writeFIFO(LOOLWSD::BrokerWritePipe, aMessage);
 
-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
 // "canceltiles" message.
@@ -570,9 +571,10 @@ private:
 queue.put("eof");
 queueHandlerThread.join();
 
-std::unique_lock lock(LOOLWSD::DocBrokersMutex);
+lock.lock();
 if (docBroker->decSessions() == 0)
 {
+Log::debug("Removing DocumentBroker for docKey [" + docKey + "].");
 LOOLWSD::DocBrokers.erase(docKey);
 }
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

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

New commits:
commit 38c4acd5f0ec6e96458e86ddb357e12177dd8dd0
Author: Ashod Nakashian 
Date:   Sat Mar 12 20:39:34 2016 -0500

loolwsd: moved document loading outside of MasterProcessSession

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 28b1a8e..1d63532 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -681,6 +681,8 @@ public:
 }
 }
 
+docBroker->load(jailId);
+
 auto ws = std::make_shared(request, response);
 auto session = std::make_shared(sessionId, 
LOOLSession::Kind::ToPrisoner, ws, docBroker);
 
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index bdb730f..d78a762 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -801,9 +801,6 @@ void MasterProcessSession::dispatchChild()
 return;
 }
 
-const auto jailRoot = Poco::Path(LOOLWSD::ChildRoot, 
childSession->_childId);
-_docBroker->load(childSession->_childId);
-
 _peer = childSession;
 childSession->_peer = shared_from_this();
 childSession->_docBroker = _docBroker;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-03-13 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp  |   37 ++-
 loolwsd/MasterProcessSession.cpp |   41 +++
 loolwsd/MasterProcessSession.hpp |   12 +--
 3 files changed, 46 insertions(+), 44 deletions(-)

New commits:
commit 64d2ff98b8e8329a8f0a2b57dbdc490733ecb28a
Author: Ashod Nakashian 
Date:   Sat Mar 12 09:07:33 2016 -0500

loolwsd: document saving and restructuring

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 162dae7..1e833d9 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -508,29 +508,13 @@ private:
 const auto uri = DocumentStoreManager::getUri(request.getURI());
 const auto docKey = uri.getPath();
 
-// This lock could become a bottleneck.
-// In that case, we can use a pool and index by publicPath.
-std::unique_lock lock(LOOLWSD::SessionsMutex);
-
-// Lookup this document.
-auto it = LOOLWSD::Sessions.find(docKey);
-std::shared_ptr document;
-if (it != LOOLWSD::Sessions.end())
-{
-// Get the DocumentStoreManager from the first session.
-auto sessionsMap = it->second;
-assert(!sessionsMap.empty());
-document = sessionsMap.begin()->second->getDocumentStoreManager();
-}
-else
-{
-// Set up the document and its storage.
-const auto jailRoot = Poco::Path(LOOLWSD::ChildRoot, id);
-document = DocumentStoreManager::create(uri, jailRoot.toString(), 
id);
-}
+// Request a kit process for this doc.
+const std::string aMessage = "request " + id + " " + docKey + "\r\n";
+Log::debug("MasterToBroker: " + aMessage.substr(0, aMessage.length() - 
2));
+Util::writeFIFO(LOOLWSD::BrokerWritePipe, aMessage);
 
 auto ws = std::make_shared(request, response);
-auto session = std::make_shared(id, 
LOOLSession::Kind::ToClient, ws, document);
+auto session = std::make_shared(id, 
LOOLSession::Kind::ToClient, ws, nullptr);
 
 // 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
@@ -646,7 +630,16 @@ public:
 Log::debug("Thread [" + thread_name + "] started.");
 
 auto ws = std::make_shared(request, response);
-auto session = std::make_shared(id, 
LOOLSession::Kind::ToPrisoner, ws, nullptr);
+auto session = std::make_shared(sessionId, 
LOOLSession::Kind::ToPrisoner, ws, nullptr);
+
+std::unique_lock 
lock(MasterProcessSession::AvailableChildSessionMutex);
+MasterProcessSession::AvailableChildSessions.emplace(sessionId, 
session);
+
+Log::info() << " mapped " << session << " jailId=" << jailId << ", 
id=" << sessionId
+<< " into _availableChildSessions, size=" << 
MasterProcessSession::AvailableChildSessions.size() << Log::end;
+
+lock.unlock();
+MasterProcessSession::AvailableChildSessionCV.notify_one();
 
 SocketProcessor(ws, response, [](const char* data, const 
int size, bool)
 {
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 46174c9..5e1e33b 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -117,7 +117,7 @@ bool MasterProcessSession::_handleInput(const char *buffer, 
int length)
 // Note that this handles both forwarding requests from the client to 
the child process, and
 // forwarding replies from the child process to the client. Or does it?
 
-// Snoop at some  messages and manipulate tile cache information as 
needed
+// Snoop at some messages and manipulate tile cache information as 
needed
 auto peer = _peer.lock();
 
 if (_kind == Kind::ToPrisoner)
@@ -128,6 +128,27 @@ bool MasterProcessSession::_handleInput(const char 
*buffer, int length)
 return false;
 }
 
+if (tokens[0] == "unocommandresult:")
+{
+const std::string stringMsg(buffer, length);
+Log::info(getName() +"Command: " + stringMsg);
+const auto index = stringMsg.find_first_of("{");
+if (index != std::string::npos)
+{
+const std::string stringJSON = stringMsg.substr(index);
+Poco::JSON::Parser parser;
+const auto result = parser.parse(stringJSON);
+const auto object = 
result.extract();
+if 

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

2016-03-13 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp  |   36 +++-
 loolwsd/LOOLWSD.hpp  |   10 --
 loolwsd/MasterProcessSession.cpp |9 ++---
 loolwsd/MasterProcessSession.hpp |6 +-
 loolwsd/test/httpwstest.cpp  |2 +-
 5 files changed, 51 insertions(+), 12 deletions(-)

New commits:
commit f1007266e1644d3d7fde6149036646ec0f8198eb
Author: Ashod Nakashian 
Date:   Thu Mar 10 22:33:03 2016 -0500

loolwsd: DocumentStoreManager shared by MasterProcessSession instances

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 23cc2a1..2fcc86c 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -149,6 +149,8 @@ using Poco::Util::Option;
 using Poco::Util::OptionSet;
 using Poco::Util::ServerApplication;
 
+std::map> LOOLWSD::Sessions;
+std::mutex LOOLWSD::SessionsMutex;
 
 /// Handles the filename part of the convert-to POST request payload.
 class ConvertToPartHandler : public PartHandler
@@ -347,7 +349,7 @@ private:
 // Load the document.
 std::shared_ptr ws;
 const LOOLSession::Kind kind = LOOLSession::Kind::ToClient;
-auto session = std::make_shared(id, 
kind, ws);
+auto session = std::make_shared(id, 
kind, ws, nullptr);
 const std::string filePrefix("file://");
 std::string encodedFrom;
 URI::encode(filePrefix + fromPath, "", encodedFrom);
@@ -495,7 +497,7 @@ private:
 
 void handleGetRequest(HTTPServerRequest& request, HTTPServerResponse& 
response, const std::string& id)
 {
-Log::info("Starting Get request processor for session [" + id + "].");
+Log::info("Starting GET request handler for session [" + id + "].");
 
 //TODO: Authenticate the caller.
 // authenticate(request, response);
@@ -503,8 +505,32 @@ private:
 // request.getCookies(cookies);
 // Log::info("Cookie: " + cookies.get("PHPSESSID", ""));
 
+const auto uri = DocumentStoreManager::getUri(request.getURI());
+const auto docKey = uri.getPath();
+
+// This lock could become a bottleneck.
+// In that case, we can use a pool and index by publicPath.
+std::unique_lock lock(LOOLWSD::SessionsMutex);
+
+// Lookup this document.
+auto it = LOOLWSD::Sessions.find(docKey);
+std::shared_ptr document;
+if (it != LOOLWSD::Sessions.end())
+{
+// Get the DocumentStoreManager from the first session.
+auto sessionsMap = it->second;
+assert(!sessionsMap.empty());
+document = sessionsMap.begin()->second->getDocumentStoreManager();
+}
+else
+{
+// Set up the document and its storage.
+const auto jailRoot = Poco::Path(LOOLWSD::ChildRoot, id);
+document = DocumentStoreManager::create(uri, jailRoot.toString(), 
id);
+}
+
 auto ws = std::make_shared(request, response);
-auto session = std::make_shared(id, 
LOOLSession::Kind::ToClient, ws);
+auto session = std::make_shared(id, 
LOOLSession::Kind::ToClient, ws, document);
 
 // 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
@@ -534,7 +560,7 @@ private:
 }
 });
 
-Log::info("Get request processor for session [" + id + "] finished. 
Clearing and joining the queue.");
+Log::info("Finishing GET request handler for session [" + id + "]. 
Clearing and joining the queue.");
 queue.clear();
 queue.put("eof");
 queueHandlerThread.join();
@@ -607,7 +633,7 @@ public:
 Log::debug("Thread [" + thread_name + "] started.");
 
 auto ws = std::make_shared(request, response);
-auto session = std::make_shared(id, 
LOOLSession::Kind::ToPrisoner, ws);
+auto session = std::make_shared(id, 
LOOLSession::Kind::ToPrisoner, ws, nullptr);
 
 SocketProcessor(ws, response, [](const char* data, const 
int size, bool)
 {
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index e0120fe..e7ce8eb 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -24,6 +24,7 @@
 #include "Common.hpp"
 #include "Util.hpp"
 
+class MasterProcessSession;
 
 class LOOLWSD: public Poco::Util::ServerApplication
 {
@@ -31,8 +32,8 @@ public:
 LOOLWSD();
 ~LOOLWSD();
 
-// An Application is a singleton anyway, so just keep these as
-// statics
+// An Application is a 

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

2016-03-09 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp  |7 +--
 loolwsd/MasterProcessSession.cpp |   77 +++
 2 files changed, 41 insertions(+), 43 deletions(-)

New commits:
commit 237e0c0e9abdd62f4107fa249e04b18c043eb8a8
Author: Ashod Nakashian 
Date:   Wed Mar 9 23:17:26 2016 -0500

loolwsd: minor cleanups and const correctness

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index dee237c..5f841d8 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -501,10 +501,9 @@ private:
 
 //TODO: Authenticate the caller.
 // authenticate(request, response);
-
-NameValueCollection cookies;
-request.getCookies(cookies);
-Log::info("Cookie: " + cookies.get("PHPSESSID", ""));
+// NameValueCollection cookies;
+// request.getCookies(cookies);
+// Log::info("Cookie: " + cookies.get("PHPSESSID", ""));
 
 auto ws = std::make_shared(request, response);
 auto session = std::make_shared(id, 
LOOLSession::Kind::ToClient, ws);
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 92e2126..99b147e 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -446,39 +446,36 @@ bool MasterProcessSession::loadDocument(const char* 
/*buffer*/, int /*length*/,
 return false;
 }
 
-std::string timestamp;
-parseDocOptions(tokens, _loadPart, timestamp);
-
 try
 {
-// Strip query params because we need unique URI (need a better 
solution!).
-StringTokenizer urlTokens(_docURL, "?", 
StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
+std::string timestamp;
+parseDocOptions(tokens, _loadPart, timestamp);
 
-// request new URL session
-const std::string aMessage = "request " + getId() + " " + urlTokens[0] 
+ "\r\n";
-Log::trace("MasterToBroker: " + aMessage.substr(0, 
aMessage.length()-2));
+// Request a kit process for this doc.
+Poco::URI uri(_docURL);
+const std::string aMessage = "request " + getId() + " " + 
uri.getPath() + "\n";
+Log::trace("MasterToBroker: " + aMessage.substr(0, aMessage.length() - 
1));
 Util::writeFIFO(LOOLWSD::BrokerWritePipe, aMessage);
+
+_tileCache.reset(new TileCache(_docURL, timestamp));
+
+// Finally, wait for the Child to connect to Master,
+// link the document in jail and dispatch load to child.
+dispatchChild();
+
+return true;
 }
 catch (const Poco::SyntaxException&)
 {
 sendTextFrame("error: cmd=load kind=uriinvalid");
-return false;
 }
 
-_tileCache.reset(new TileCache(_docURL, timestamp));
-
-// Finally, wait for the Child to connect to Master,
-// link the document in jail and dispatch load to child.
-dispatchChild();
-
-return true;
+return false;
 }
 
 bool MasterProcessSession::getStatus(const char *buffer, int length)
 {
-std::string status;
-
-status = _tileCache->getTextFile("status.txt");
+const std::string status = _tileCache->getTextFile("status.txt");
 if (status.size() > 0)
 {
 sendTextFrame(status);
@@ -500,7 +497,7 @@ bool MasterProcessSession::getCommandValues(const char 
*buffer, int length, Stri
 return false;
 }
 
-std::string cmdValues = _tileCache->getTextFile("cmdValues" + command + 
".txt");
+const std::string cmdValues = _tileCache->getTextFile("cmdValues" + 
command + ".txt");
 if (cmdValues.size() > 0)
 {
 sendTextFrame(cmdValues);
@@ -515,7 +512,7 @@ bool MasterProcessSession::getCommandValues(const char 
*buffer, int length, Stri
 
 bool MasterProcessSession::getPartPageRectangles(const char *buffer, int 
length)
 {
-std::string partPageRectangles = 
_tileCache->getTextFile("partpagerectangles.txt");
+const std::string partPageRectangles = 
_tileCache->getTextFile("partpagerectangles.txt");
 if (partPageRectangles.size() > 0)
 {
 sendTextFrame(partPageRectangles);
@@ -536,7 +533,6 @@ std::string MasterProcessSession::getSaveAs()
 void MasterProcessSession::sendFontRendering(const char *buffer, int length, 
StringTokenizer& tokens)
 {
 std::string font;
-
 if (tokens.count() < 2 ||
 !getTokenString(tokens[1], "font", font))
 {
@@ -544,7 +540,7 @@ void MasterProcessSession::sendFontRendering(const char 
*buffer, int length, Str
 return;
 }
 
-std::string response = "renderfont: " + Poco::cat(std::string(" "), 
tokens.begin() + 1, tokens.end()) + "\n";
+const std::string response = "renderfont: " + Poco::cat(std::string(" "), 
tokens.begin() + 1, tokens.end()) + "\n";
 
 std::vector output;

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

2016-03-03 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp  |1 -
 loolwsd/LOOLWSD.hpp  |   24 +---
 loolwsd/MasterProcessSession.cpp |5 +++--
 3 files changed, 16 insertions(+), 14 deletions(-)

New commits:
commit c980ece8bcca0bf8c6c569a9db37b085022952e5
Author: Ashod Nakashian 
Date:   Thu Mar 3 21:00:57 2016 -0500

loolwsd: preparing for wopi storage

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 8ad52d7..ad5726b 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -103,7 +103,6 @@ DEALINGS IN THE SOFTWARE.
 #include "LOOLWSD.hpp"
 #include "MasterProcessSession.hpp"
 #include "QueueHandler.hpp"
-#include "Storage.hpp"
 #include "Util.hpp"
 
 using namespace LOOLProtocol;
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index 696ca3a..ba11e68 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -23,6 +23,7 @@
 #include 
 
 #include "Auth.hpp"
+#include "Storage.hpp"
 #include "Common.hpp"
 #include "Util.hpp"
 
@@ -34,8 +35,8 @@ public:
 
 static
 std::shared_ptr create(const std::string& url,
- const std::string& jailRoot,
- const std::string& childId)
+const std::string& jailRoot,
+const std::string& childId)
 {
 // TODO: Sanitize the url and limit access!
 auto uriPublic = Poco::URI(url);
@@ -52,16 +53,17 @@ public:
 
 // 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.
+
+// chroot/jailId/user/doc
+const auto jailedDocRoot = Poco::Path(jailRoot, JailedDocumentRoot);
+
+// chroot/jailId/user/doc/childId
+const auto docPath = Poco::Path(jailedDocRoot, childId);
+Poco::File(docPath).createDirectories();
+
 auto uriJailed = uriPublic;
 if (uriPublic.isRelative() || uriPublic.getScheme() == "file")
 {
-// chroot/jailId/user/doc
-const auto jailedDocRoot = Poco::Path(jailRoot, 
JailedDocumentRoot);
-
-// chroot/jailId/user/doc/childId
-const auto docPath = Poco::Path(jailedDocRoot, childId);
-Poco::File(docPath).createDirectories();
-
 const auto filename = 
Poco::Path(uriPublic.getPath()).getFileName();
 
 // chroot/jailId/user/doc/childId/file.ext
@@ -113,8 +115,8 @@ public:
 
 private:
 DocumentURI(const Poco::URI& uriPublic,
- const Poco::URI& uriJailed,
- const std::string& jailId) :
+const Poco::URI& uriJailed,
+const std::string& jailId) :
_uriPublic(uriPublic),
_uriJailed(uriJailed),
_jailId(jailId)
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 126a12b..55ccdaf 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -451,10 +451,11 @@ bool MasterProcessSession::loadDocument(const char* 
/*buffer*/, int /*length*/,
 
 try
 {
-Poco::URI aUri(_docURL);
+// Strip query params because we need unique URI (need a better 
solution!).
+StringTokenizer tokens(_docURL, "?", StringTokenizer::TOK_IGNORE_EMPTY 
| StringTokenizer::TOK_TRIM);
 
 // request new URL session
-const std::string aMessage = "request " + getId() + " " + _docURL + 
"\r\n";
+const std::string aMessage = "request " + getId() + " " + tokens[0] + 
"\r\n";
 Log::trace("MasterToBroker: " + aMessage.substr(0, 
aMessage.length()-2));
 Util::writeFIFO(LOOLWSD::BrokerWritePipe, aMessage);
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-02-21 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |1 -
 loolwsd/LOOLWSD.hpp |   12 +---
 2 files changed, 1 insertion(+), 12 deletions(-)

New commits:
commit ba47e28581fbb3ff7076ba3c01b3e826f18a3731
Author: Henry Castro 
Date:   Sun Feb 21 08:26:29 2016 -0400

loolwsd: re-work UriToDocumentURIMap

This is not in synchronization with lokit process because
it is normal that lokit dies now.

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 276c5fe..b242df9 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -156,7 +156,6 @@ using Poco::URI;
 
 // Document management mutex.
 std::mutex DocumentURI::DocumentURIMutex;
-std::map 
DocumentURI::UriToDocumentURIMap;
 
 /// Handles the filename part of the convert-to POST request payload.
 class ConvertToPartHandler : public Poco::Net::PartHandler
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index 279f201..db26497 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -50,14 +50,6 @@ public:
 // In that case, we can use a pool and index by publicPath.
 std::unique_lock lock(DocumentURIMutex);
 
-// Find the document if already open.
-auto it = UriToDocumentURIMap.lower_bound(publicFilePath);
-if (it != UriToDocumentURIMap.end() && it->first == publicFilePath)
-{
-Log::info("DocumentURI [" + it->first + "] found.");
-return it->second;
-}
-
 // 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.
 auto uriJailed = uriPublic;
@@ -114,8 +106,7 @@ public:
 auto document = std::shared_ptr(new 
DocumentURI(uriPublic, uriJailed, childId));
 
 Log::info("DocumentURI [" + publicFilePath + "] created.");
-it = UriToDocumentURIMap.emplace_hint(it, publicFilePath, document);
-return it->second;
+return document;
 }
 
 Poco::URI getPublicUri() const { return _uriPublic; }
@@ -136,7 +127,6 @@ private:
 
 // DocumentURI management mutex.
 static std::mutex DocumentURIMutex;
-static std::map 
UriToDocumentURIMap;
 
 private:
 const Poco::URI _uriPublic;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-02-19 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp |1 
 loolwsd/Storage.hpp |   84 
 2 files changed, 85 insertions(+)

New commits:
commit 13f9b7a2dbd88974fb328498ae31bf1910d7f982
Author: Ashod Nakashian 
Date:   Fri Feb 19 16:19:15 2016 -0500

loolwsd: Storage Abstraction support

An abstract Storage abstraction class is added.
There will be a factory to instantiate concrete
implementation for a given backend.

For WebDAV and similar hosted backends, authentication
and authorization will be done by the implementation
with the help of the Auth abstraction.

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 75a83b2..276c5fe 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -111,6 +111,7 @@ DEALINGS IN THE SOFTWARE.
 #include "ChildProcessSession.hpp"
 #include "LOOLWSD.hpp"
 #include "QueueHandler.hpp"
+#include "Storage.hpp"
 #include "Util.hpp"
 
 using namespace LOOLProtocol;
diff --git a/loolwsd/Storage.hpp b/loolwsd/Storage.hpp
new file mode 100644
index 000..7597783
--- /dev/null
+++ b/loolwsd/Storage.hpp
@@ -0,0 +1,84 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+// Storage abstraction.
+#ifndef INCLUDED_STORAGE_HPP
+#define INCLUDED_STORAGE_HPP
+
+#include 
+
+#include "Auth.hpp"
+#include "Util.hpp"
+
+/// Base class of all Storage abstractions.
+class StorageBase
+{
+public:
+
+/// Returns a local file path given a URI.
+/// If necessary copies the file locally first.
+virtual std::string getFilePathFromURI(const std::string& uri) = 0;
+
+/// Writes the contents of the file back to the URI.
+virtual bool restoreFileToURI(const std::string& path, const std::string& 
uri) = 0;
+
+};
+
+/// Trivial implementation of local storage that does not need do anything.
+class LocalStorage : public StorageBase
+{
+public:
+
+std::string getFilePathFromURI(const std::string& uri) override
+{
+// It's local already.
+// TODO: Validate access?
+return uri;
+}
+
+bool restoreFileToURI(const std::string& path, const std::string& uri)
+{
+// Nothing to do.
+(void)path;
+(void)uri;
+return false;
+}
+};
+
+class WebDAVStorage : public StorageBase
+{
+public:
+
+WebDAVStorage(const std::string& url, std::unique_ptr authAgent) 
:
+_url(url),
+_authAgent(std::move(authAgent))
+{
+}
+
+std::string getFilePathFromURI(const std::string& uri) override
+{
+// TODO: implement webdav GET.
+return uri;
+}
+
+bool restoreFileToURI(const std::string& path, const std::string& uri)
+{
+// TODO: implement webdav PUT.
+(void)path;
+(void)uri;
+return false;
+}
+
+private:
+const std::string _url;
+std::unique_ptr _authAgent;
+};
+
+#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/LOOLWSD.cpp

2016-02-16 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 3ad641c7bd9a05cbb08b35cb3656adf59cd8b8b6
Author: Henry Castro 
Date:   Tue Feb 16 17:04:21 2016 -0400

loolwsd: check if the pipe path exists

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 1f1480e..ef37ab5 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -934,7 +934,7 @@ int LOOLWSD::main(const std::vector& /*args*/)
 }
 
 const Path pipePath = Path::forDirectory(ChildRoot + Path::separator() + 
FIFO_PATH);
-if (!File(pipePath).createDirectory())
+if (!File(pipePath).exists() && !File(pipePath).createDirectory())
 {
 Log::error("Error: Failed to create pipe directory [" + 
pipePath.toString() + "].");
 return Application::EXIT_SOFTWARE;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-01-30 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

New commits:
commit a956c61b0769ae9690341112c7b4087cc0f4a156
Author: Ashod Nakashian 
Date:   Tue Jan 26 08:53:01 2016 -0500

loolwsd: logging

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index ed555e8..83d4341 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -482,7 +482,7 @@ private:
 
 void handleGetRequest(HTTPServerRequest& request, HTTPServerResponse& 
response, const std::string& id)
 {
-Log::info("Get request.");
+Log::info("Starting Get request processor for session [" + id + "].");
 auto ws = std::make_shared(request, response);
 auto session = std::make_shared(id, 
LOOLSession::Kind::ToClient, ws);
 
@@ -514,6 +514,7 @@ private:
 }
 });
 
+Log::info("Get request processor for session [" + id + "] finished. 
Clearing and joining the queue.");
 queue.clear();
 queue.put("eof");
 queueHandlerThread.join();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-01-25 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |5 -
 loolwsd/LOOLWSD.hpp |1 -
 2 files changed, 6 deletions(-)

New commits:
commit e3fd07ad0e72bb035f1a1a4d8e18523fae49aad8
Author: Henry Castro 
Date:   Mon Jan 25 12:26:22 2016 -0400

loolwsd: remove unnecessary inter process mutex

It is no longer needed becuase loolbroker handle connections

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index bbb4c84..cd6a89c 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -729,7 +729,6 @@ std::string LOOLWSD::LoTemplate;
 std::string LOOLWSD::ChildRoot;
 std::string LOOLWSD::JailId;
 std::string LOOLWSD::LoSubPath = "lo";
-Poco::NamedMutex LOOLWSD::NamedMutexLOOL("loolwsd");
 
 int LOOLWSD::NumPreSpawnedChildren = 10;
 bool LOOLWSD::DoTest = false;
@@ -948,8 +947,6 @@ int LOOLWSD::main(const std::vector& /*args*/)
 return Application::EXIT_UNAVAILABLE;
 }
 
-NamedMutexLOOL.lock();
-
 JailId = Util::createRandomDir(ChildRoot);
 if (!createBroker(JailId))
 {
@@ -986,8 +983,6 @@ int LOOLWSD::main(const std::vector& /*args*/)
 return Application::EXIT_UNAVAILABLE;
 }
 
-NamedMutexLOOL.unlock();
-
 TestInput input(*this, svs, srv);
 Thread inputThread;
 if (LOOLWSD::DoTest)
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index 0e8e798..00c9b09 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -162,7 +162,6 @@ public:
 static std::string ChildRoot;
 static std::string JailId;
 static std::string LoSubPath;
-static Poco::NamedMutex NamedMutexLOOL;
 
 static const std::string CHILD_URI;
 static const std::string PIDLOG;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-01-25 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |   11 +++
 1 file changed, 11 insertions(+)

New commits:
commit 6b284332656eb2731157a3c88c62517c9d2b78d0
Author: Henry Castro 
Date:   Mon Jan 25 17:03:21 2016 -0400

loolwsd: Log::warn when the thread pool is full.

When thread pool is full no more connections are accepted.
It is confused as a deadlock

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index cd6a89c..a904ffd 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -993,8 +993,19 @@ int LOOLWSD::main(const std::vector& /*args*/)
 
 int status = 0;
 unsigned timeoutCounter = 0;
+std::chrono::steady_clock::time_point lastPoolTime = 
std::chrono::steady_clock::now();
+
 while (!TerminationFlag && !LOOLWSD::DoTest && 
MasterProcessSession::ChildProcesses.size() > 0)
 {
+const auto duration = (std::chrono::steady_clock::now() - 
lastPoolTime);
+if (duration >= std::chrono::seconds(10))
+{
+if (threadPool.available() ==  0)
+Log::warn("The thread pool is full, no more connections 
accepted.");
+
+lastPoolTime = std::chrono::steady_clock::now();
+}
+
 const pid_t pid = waitpid(-1, , WUNTRACED | WNOHANG);
 if (pid > 0)
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-01-25 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |   31 ---
 loolwsd/LOOLWSD.hpp |5 ++---
 2 files changed, 14 insertions(+), 22 deletions(-)

New commits:
commit 2baae1b3245801529647b4c0add95e6fad38493a
Author: Henry Castro 
Date:   Mon Jan 25 21:07:10 2016 -0400

loolwsd: simplify one loolbroker

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index a904ffd..10ddeeb 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -865,7 +865,7 @@ void LOOLWSD::displayVersion()
 std::cout << LOOLWSD_VERSION << std::endl;
 }
 
-bool LOOLWSD::createBroker(const std::string& rJailId)
+Poco::Process::PID LOOLWSD::createBroker(const std::string& rJailId)
 {
 Process::Args args;
 
@@ -879,17 +879,12 @@ bool LOOLWSD::createBroker(const std::string& rJailId)
 
 const std::string brokerPath = 
Path(Application::instance().commandPath()).parent().toString() + "loolbroker";
 
-const auto childIndex = MasterProcessSession::ChildProcesses.size() + 1;
-Log::info("Launching Broker #" + std::to_string(childIndex) +
-  ": " + brokerPath + " " +
+Log::info("Launching Broker #1: " + brokerPath + " " +
   Poco::cat(std::string(" "), args.begin(), args.end()));
 
 ProcessHandle child = Process::launch(brokerPath, args);
 
-Log::info() << "Adding Broker #" << childIndex << " PID " << child.id() << 
Log::end;
-MasterProcessSession::ChildProcesses[child.id()] = child.id();
-
-return true;
+return child.id();
 }
 
 int LOOLWSD::main(const std::vector& /*args*/)
@@ -948,7 +943,8 @@ int LOOLWSD::main(const std::vector& /*args*/)
 }
 
 JailId = Util::createRandomDir(ChildRoot);
-if (!createBroker(JailId))
+const Poco::Process::PID pidBroker = createBroker(JailId);
+if (pidBroker < 0)
 {
 Log::error("Failed to spawn loolBroker.");
 return Application::EXIT_UNAVAILABLE;
@@ -995,13 +991,13 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 unsigned timeoutCounter = 0;
 std::chrono::steady_clock::time_point lastPoolTime = 
std::chrono::steady_clock::now();
 
-while (!TerminationFlag && !LOOLWSD::DoTest && 
MasterProcessSession::ChildProcesses.size() > 0)
+while (!TerminationFlag && !LOOLWSD::DoTest)
 {
 const auto duration = (std::chrono::steady_clock::now() - 
lastPoolTime);
 if (duration >= std::chrono::seconds(10))
 {
 if (threadPool.available() ==  0)
-Log::warn("The thread pool is full, no more connections 
accepted.");
+Log::warn("The thread pool is full, no more connections are 
accepted.");
 
 lastPoolTime = std::chrono::steady_clock::now();
 }
@@ -1009,14 +1005,14 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 const pid_t pid = waitpid(-1, , WUNTRACED | WNOHANG);
 if (pid > 0)
 {
-if ( MasterProcessSession::ChildProcesses.find(pid) != 
MasterProcessSession::ChildProcesses.end() )
+if (pidBroker == pid)
 {
 if (WIFEXITED(status))
 {
 Log::info() << "Child process [" << pid << "] exited with 
code: "
 << WEXITSTATUS(status) << "." << Log::end;
 
-MasterProcessSession::ChildProcesses.erase(pid);
+break;
 }
 else
 if (WIFSIGNALED(status))
@@ -1030,7 +1026,7 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
  << " with " << 
Util::signalName(WTERMSIG(status))
  << " signal. " << Log::end;
 
-MasterProcessSession::ChildProcesses.erase(pid);
+break;
 }
 else if (WIFSTOPPED(status))
 {
@@ -1077,11 +1073,8 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 
 // Terminate child processes
 Util::writeFIFO(LOOLWSD::BrokerWritePipe, "eof");
-for (auto i : MasterProcessSession::ChildProcesses)
-{
-Log::info("Requesting child process " + std::to_string(i.first) + " to 
terminate");
-Process::requestTermination(i.first);
-}
+Log::info("Requesting child process " + std::to_string(pidBroker) + " to 
terminate");
+Process::requestTermination(pidBroker);
 
 // wait broker process finish
 waitpid(-1, , WUNTRACED);
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index 00c9b09..7b77371 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -20,8 +20,7 @@
 #include 
 #include 
 #include 
-#include 
-#include 
+#include 
 
 #include "Common.hpp"
 #include "Util.hpp"
@@ -191,7 +190,7 @@ private:
 int  createComponent();
 int  createDesktop();
 
-bool createBroker(const std::string& jailId);
+Poco::Process::PID createBroker(const std::string& jailId);
 };
 
 #endif
___
Libreoffice-commits mailing 

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

2016-01-24 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp  |   89 ++-
 loolwsd/MasterProcessSession.cpp |3 +
 2 files changed, 55 insertions(+), 37 deletions(-)

New commits:
commit b85b4423b0e189d24d0374f5c0511011ee58780c
Author: Ashod Nakashian 
Date:   Sat Jan 23 19:41:01 2016 -0500

loolwsd: break the wait on save-as queue and better failure handling

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 4db32fb..138fde7 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -344,9 +344,11 @@ public:
 
 if (!(request.find("Upgrade") != request.end() && 
Poco::icompare(request["Upgrade"], "websocket") == 0))
 {
+Log::info("Post request.");
 StringTokenizer tokens(request.getURI(), "/?");
 if (tokens.count() >= 2 && tokens[1] == "convert-to")
 {
+Log::info("Conversion request.");
 std::string fromPath;
 ConvertToPartHandler handler(fromPath);
 Poco::Net::HTMLForm form(request, request.stream(), handler);
@@ -354,51 +356,61 @@ public:
 if (form.has("format"))
 format = form.get("format");
 
-if (!fromPath.empty() && !format.empty())
+bool sent = false;
+if (!fromPath.empty())
 {
-// Load the document.
-std::shared_ptr ws;
-const LOOLSession::Kind kind = LOOLSession::Kind::ToClient;
-auto session = std::make_shared(id, 
kind, ws);
-const std::string filePrefix("file://");
-std::string encodedFrom;
-URI::encode(filePrefix + fromPath, std::string(), 
encodedFrom);
-const std::string load = "load url=" + encodedFrom;
-session->handleInput(load.data(), load.size());
-
-// Convert it to the requested format.
-Path toPath(fromPath);
-toPath.setExtension(format);
-std::string toJailURL = filePrefix + JailedDocumentRoot + 
toPath.getFileName();
-std::string encodedTo;
-URI::encode(toJailURL, std::string(), 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.
-std::string mimeType = "application/octet-stream";
-if (resultingURL.find(filePrefix) == 0)
-resultingURL = 
resultingURL.substr(filePrefix.length());
-response.sendFile(resultingURL, mimeType);
+if (!format.empty())
+{
+// Load the document.
+std::shared_ptr ws;
+const LOOLSession::Kind kind = 
LOOLSession::Kind::ToClient;
+auto session = 
std::make_shared(id, kind, ws);
+const std::string filePrefix("file://");
+std::string encodedFrom;
+URI::encode(filePrefix + fromPath, std::string(), 
encodedFrom);
+const std::string load = "load url=" + encodedFrom;
+session->handleInput(load.data(), load.size());
+
+// Convert it to the requested format.
+Path toPath(fromPath);
+toPath.setExtension(format);
+std::string toJailURL = filePrefix + 
JailedDocumentRoot + toPath.getFileName();
+std::string encodedTo;
+URI::encode(toJailURL, std::string(), 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())
+{
+const 

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

2016-01-24 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp |  337 +++-
 1 file changed, 175 insertions(+), 162 deletions(-)

New commits:
commit f9fd4c917a3acb75ee86dfca29e084542a77f756
Author: Ashod Nakashian 
Date:   Sun Jan 24 14:48:09 2016 -0500

loolwsd: refactored HTTP Request Handler

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 138fde7..bbb4c84 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -329,206 +329,219 @@ void SocketProcessor(std::shared_ptr ws,
 /// Handle a public connection from a client.
 class ClientRequestHandler: public HTTPRequestHandler
 {
-public:
+private:
 
-void handleRequest(HTTPServerRequest& request, HTTPServerResponse& 
response) override
+void handlePostRequest(HTTPServerRequest& request, HTTPServerResponse& 
response, const std::string& id)
 {
-const auto id = LOOLWSD::GenSessionId();
-const std::string thread_name = "client_ws_" + id;
-
-#ifdef __linux
-if (prctl(PR_SET_NAME, reinterpret_cast(thread_name.c_str()), 0, 0, 0) != 0)
-Log::error("Cannot set thread name to " + thread_name + ".");
-#endif
-Log::debug("Thread [" + thread_name + "] started.");
-
-if (!(request.find("Upgrade") != request.end() && 
Poco::icompare(request["Upgrade"], "websocket") == 0))
+Log::info("Post request.");
+StringTokenizer tokens(request.getURI(), "/?");
+if (tokens.count() >= 2 && tokens[1] == "convert-to")
 {
-Log::info("Post request.");
-StringTokenizer tokens(request.getURI(), "/?");
-if (tokens.count() >= 2 && tokens[1] == "convert-to")
+Log::info("Conversion request.");
+std::string fromPath;
+ConvertToPartHandler handler(fromPath);
+Poco::Net::HTMLForm form(request, request.stream(), handler);
+std::string format;
+if (form.has("format"))
+format = form.get("format");
+
+bool sent = false;
+if (!fromPath.empty())
 {
-Log::info("Conversion request.");
-std::string fromPath;
-ConvertToPartHandler handler(fromPath);
-Poco::Net::HTMLForm form(request, request.stream(), handler);
-std::string format;
-if (form.has("format"))
-format = form.get("format");
-
-bool sent = false;
-if (!fromPath.empty())
+if (!format.empty())
 {
-if (!format.empty())
-{
-// Load the document.
-std::shared_ptr ws;
-const LOOLSession::Kind kind = 
LOOLSession::Kind::ToClient;
-auto session = 
std::make_shared(id, kind, ws);
-const std::string filePrefix("file://");
-std::string encodedFrom;
-URI::encode(filePrefix + fromPath, std::string(), 
encodedFrom);
-const std::string load = "load url=" + encodedFrom;
-session->handleInput(load.data(), load.size());
-
-// Convert it to the requested format.
-Path toPath(fromPath);
-toPath.setExtension(format);
-std::string toJailURL = filePrefix + 
JailedDocumentRoot + toPath.getFileName();
-std::string encodedTo;
-URI::encode(toJailURL, std::string(), encodedTo);
+// Load the document.
+std::shared_ptr ws;
+const LOOLSession::Kind kind = LOOLSession::Kind::ToClient;
+auto session = std::make_shared(id, 
kind, ws);
+const std::string filePrefix("file://");
+std::string encodedFrom;
+URI::encode(filePrefix + fromPath, std::string(), 
encodedFrom);
+const std::string load = "load url=" + encodedFrom;
+session->handleInput(load.data(), load.size());
+
+// Convert it to the requested format.
+Path toPath(fromPath);
+toPath.setExtension(format);
+std::string toJailURL = filePrefix + JailedDocumentRoot + 
toPath.getFileName();
+std::string encodedTo;
+URI::encode(toJailURL, std::string(), encodedTo);
 std::string saveas = "saveas url=" + encodedTo + " 
format=" + format + " options=";
-session->handleInput(saveas.data(), 

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

2016-01-21 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp |8 +++-
 1 file changed, 7 insertions(+), 1 deletion(-)

New commits:
commit bccfd79d35f7be542831d0a8acaab3dd1fbd19b3
Author: Ashod Nakashian 
Date:   Tue Jan 19 20:38:43 2016 -0500

loolwsd: reset http request handler's thread name as it's reused

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 98adeb0..f3187d7 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -404,7 +404,8 @@ public:
 
 if (goodRequest)
 {
-try {
+try
+{
 Log::info() << "Perform insertfile: " << formChildid 
<< ", " << formName << Log::end;
 const std::string dirPath = LOOLWSD::ChildRoot + 
formChildid
   + JailedDocumentRoot + 
"insertfile";
@@ -577,6 +578,11 @@ class RequestHandlerFactory: public 
HTTPRequestHandlerFactory
 public:
 HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request) 
override
 {
+#ifdef __linux
+if (prctl(PR_SET_NAME, reinterpret_cast("request_handler"), 0, 0, 0) != 0)
+Log::error("Cannot set thread name to request_handler.");
+#endif
+
 auto logger = Log::info();
 logger << "Request from " << request.clientAddress().toString() << ": "
<< request.getMethod() << " " << request.getURI() << " "
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-01-21 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp |   50 +++---
 1 file changed, 35 insertions(+), 15 deletions(-)

New commits:
commit 8e8e7c70c275c8942d8481b76f52e8f4ef6f260b
Author: Ashod Nakashian 
Date:   Thu Jan 14 22:31:02 2016 -0500

loolwsd: cleanup and correction of child signal handling

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index f629d8e..98adeb0 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -954,28 +954,48 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 unsigned timeoutCounter = 0;
 while (!TerminationFlag && !LOOLWSD::DoTest && 
MasterProcessSession::ChildProcesses.size() > 0)
 {
-pid_t pid = waitpid(-1, , WUNTRACED | WNOHANG);
+const pid_t pid = waitpid(-1, , WUNTRACED | WNOHANG);
 if (pid > 0)
 {
 if ( MasterProcessSession::ChildProcesses.find(pid) != 
MasterProcessSession::ChildProcesses.end() )
 {
-if ((WIFEXITED(status) || WIFSIGNALED(status) || 
WTERMSIG(status) ) )
+if (WIFEXITED(status))
 {
-Log::error("Child [" + std::to_string(pid) + "] processes 
died.");
+Log::info() << "Child process [" << pid << "] exited with 
code: "
+<< WEXITSTATUS(status) << "." << Log::end;
+
 MasterProcessSession::ChildProcesses.erase(pid);
 }
+else
+if (WIFSIGNALED(status))
+{
+std::string fate = "died";
+#ifdef WCOREDUMP
+if (WCOREDUMP(status))
+fate = "core-dumped";
+#endif
+Log::error() << "Child process [" << pid << "] " << fate
+ << " with " << 
Util::signalName(WTERMSIG(status))
+ << " signal. " << Log::end;
 
-if ( WCOREDUMP(status) )
-Log::error("Child [" + std::to_string(pid) + "] produced a 
core dump.");
-
-if ( WIFSTOPPED(status) )
-Log::error("Child [" + std::to_string(pid) + "] process 
was stopped by delivery of a signal.");
-
-if ( WSTOPSIG(status) )
-Log::error("Child [" + std::to_string(pid) + "] process 
was stopped.");
-
-if ( WIFCONTINUED(status) )
-Log::error("Child [" + std::to_string(pid) + "] process 
was resumed.");
+MasterProcessSession::ChildProcesses.erase(pid);
+}
+else if (WIFSTOPPED(status))
+{
+Log::info() << "Child process [" << pid << "] stopped with 
"
+<< Util::signalName(WSTOPSIG(status))
+<< " signal. " << Log::end;
+}
+else if (WIFCONTINUED(status))
+{
+Log::info() << "Child process [" << pid << "] resumed with 
SIGCONT."
+<< Log::end;
+}
+else
+{
+Log::warn() << "Unknown status returned by waitpid: "
+<< std::hex << status << "." << Log::end;
+}
 }
 else
 {
@@ -983,7 +1003,7 @@ int LOOLWSD::main(const std::vector& /*args*/)
 }
 }
 else if (pid < 0)
-Log::error("Error: Child error.");
+Log::error("Error: waitpid failed.");
 
 if (timeoutCounter++ == INTERVAL_PROBES)
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-01-21 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp |4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

New commits:
commit d310d3f3f562b4e0ebc7a4873e5296e59c727804
Author: Ashod Nakashian 
Date:   Thu Jan 21 09:04:16 2016 -0500

loolwsd: proper ping handling by echoing

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 78d53fd..2c3384c 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -216,11 +216,13 @@ void SocketProcessor(std::shared_ptr ws,
 
 if ((flags & WebSocket::FRAME_OP_BITMASK) == 
WebSocket::FRAME_OP_PING)
 {
-ws->sendFrame("PONG", 4);
+// Echo back the ping payload as pong.
+ws->sendFrame(buffer, n, WebSocket::FRAME_OP_PONG);
 continue;
 }
 else if ((flags & WebSocket::FRAME_OP_BITMASK) == 
WebSocket::FRAME_OP_PONG)
 {
+// In case we do send pings in the future.
 continue;
 }
 else if (n <= 0)
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-01-21 Thread Jan Holesovsky
 loolwsd/LOOLWSD.cpp |   17 -
 1 file changed, 12 insertions(+), 5 deletions(-)

New commits:
commit 0c509e17c1800f96dbc2f8f732148ecbb825f746
Author: Jan Holesovsky 
Date:   Thu Jan 21 23:11:01 2016 +0100

loolwsd: Fix /convert-to to handle filenames containing spaces.

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 531818d..edfcb7d 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -356,22 +356,29 @@ public:
 const LOOLSession::Kind kind = LOOLSession::Kind::ToClient;
 auto session = std::make_shared(id, 
kind, ws);
 const std::string filePrefix("file://");
-const std::string load = "load url=" + filePrefix + 
fromPath;
+std::string encodedFrom;
+URI::encode(filePrefix + fromPath, std::string(), 
encodedFrom);
+const std::string load = "load url=" + encodedFrom;
 session->handleInput(load.data(), load.size());
 
 // Convert it to the requested format.
 Path toPath(fromPath);
 toPath.setExtension(format);
 std::string toJailURL = filePrefix + JailedDocumentRoot + 
toPath.getFileName();
-std::string saveas = "saveas url=" + toJailURL + " 
format=" + format + " options=";
+std::string encodedTo;
+URI::encode(toJailURL, std::string(), 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.
 std::string mimeType = "application/octet-stream";
-if (toURL.find(filePrefix) == 0)
-toURL = toURL.substr(filePrefix.length());
-response.sendFile(toURL, mimeType);
+if (resultingURL.find(filePrefix) == 0)
+resultingURL = 
resultingURL.substr(filePrefix.length());
+response.sendFile(resultingURL, mimeType);
 }
 else
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-01-18 Thread Miklos Vajna
 loolwsd/LOOLWSD.cpp |   20 +++-
 1 file changed, 19 insertions(+), 1 deletion(-)

New commits:
commit c8ea8bcacd1bc7503cb86a044d0bf320f0d45355
Author: Miklos Vajna 
Date:   Mon Jan 18 16:54:22 2016 +0100

loolwsd: handle WS messages split into multiple frames

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index d71e39c..78fcc7c 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -236,7 +236,25 @@ void SocketProcessor(std::shared_ptr ws,
 break;
 }
 
-if (firstLine.size() == 
static_cast(n))
+if ((flags & WebSocket::FrameFlags::FRAME_FLAG_FIN) != 
WebSocket::FrameFlags::FRAME_FLAG_FIN)
+{
+// One WS message split into multiple frames.
+std::vector message(buffer, buffer + n);
+while (true)
+{
+n = ws->receiveFrame(buffer, sizeof(buffer), 
flags);
+message.insert(message.end(), buffer, buffer + n);
+if ((flags & 
WebSocket::FrameFlags::FRAME_FLAG_FIN) == WebSocket::FrameFlags::FRAME_FLAG_FIN)
+{
+// No more frames: invoke the handler. Assume
+// for now that this is always a multi-line
+// message.
+handler(message.data(), message.size(), false);
+break;
+}
+}
+}
+else if (firstLine.size() == 
static_cast(n))
 {
 handler(firstLine.c_str(), firstLine.size(), true);
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-01-15 Thread Miklos Vajna
 loolwsd/LOOLWSD.cpp  |   72 +++
 loolwsd/LOOLWSD.hpp  |   14 +++
 loolwsd/MasterProcessSession.cpp |6 +--
 loolwsd/TileCache.cpp|2 -
 4 files changed, 47 insertions(+), 47 deletions(-)

New commits:
commit de7823744e5805aa2ab0712d1ac5e561288aba3f
Author: Miklos Vajna 
Date:   Fri Jan 15 09:40:54 2016 +0100

loolwsd: fix naming style of LOOLWSD static members

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 3e7ee14..3f264ee 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -388,7 +388,7 @@ public:
 {
 try {
 Log::info() << "Perform insertfile: " << formChildid 
<< ", " << formName << Log::end;
-const std::string dirPath = LOOLWSD::childRoot + 
formChildid
+const std::string dirPath = LOOLWSD::ChildRoot + 
formChildid
   + JailedDocumentRoot + 
"insertfile";
 File(dirPath).createDirectories();
 std::string fileName = dirPath + Path::separator() + 
form.get("name");
@@ -413,7 +413,7 @@ public:
 else if (tokens.count() >= 4)
 {
 // The user might request a file to download
-const std::string dirPath = LOOLWSD::childRoot + tokens[1]
+const std::string dirPath = LOOLWSD::ChildRoot + tokens[1]
   + JailedDocumentRoot + tokens[2];
 std::string fileName;
 URI::decode(tokens[3], fileName);
@@ -659,16 +659,16 @@ private:
 
 std::atomic LOOLWSD::NextSessionId;
 int LOOLWSD::BrokerWritePipe = -1;
-std::string LOOLWSD::cache = LOOLWSD_CACHEDIR;
-std::string LOOLWSD::sysTemplate;
-std::string LOOLWSD::loTemplate;
-std::string LOOLWSD::childRoot;
-std::string LOOLWSD::jailId;
-std::string LOOLWSD::loSubPath = "lo";
+std::string LOOLWSD::Cache = LOOLWSD_CACHEDIR;
+std::string LOOLWSD::SysTemplate;
+std::string LOOLWSD::LoTemplate;
+std::string LOOLWSD::ChildRoot;
+std::string LOOLWSD::JailId;
+std::string LOOLWSD::LoSubPath = "lo";
 Poco::NamedMutex LOOLWSD::NamedMutexLOOL("loolwsd");
 
 int LOOLWSD::NumPreSpawnedChildren = 10;
-bool LOOLWSD::doTest = false;
+bool LOOLWSD::DoTest = false;
 const std::string LOOLWSD::CHILD_URI = "/loolws/child/";
 const std::string LOOLWSD::PIDLOG = "/tmp/loolwsd.pid";
 const std::string LOOLWSD::LOKIT_PIDLOG = "/tmp/lokit.pid";
@@ -726,7 +726,7 @@ void LOOLWSD::defineOptions(OptionSet& optionSet)
 .repeatable(false)
 .argument("directory"));
 
-optionSet.addOption(Option("losubpath", "", "Relative path where the 
LibreOffice installation will be copied inside a jail (default: '" + loSubPath 
+ "').")
+optionSet.addOption(Option("losubpath", "", "Relative path where the 
LibreOffice installation will be copied inside a jail (default: '" + LoSubPath 
+ "').")
 .required(false)
 .repeatable(false)
 .argument("relative path"));
@@ -760,19 +760,19 @@ void LOOLWSD::handleOption(const std::string& optionName, 
const std::string& val
 else if (optionName == "port")
 ClientPortNumber = std::stoi(value);
 else if (optionName == "cache")
-cache = value;
+Cache = value;
 else if (optionName == "systemplate")
-sysTemplate = value;
+SysTemplate = value;
 else if (optionName == "lotemplate")
-loTemplate = value;
+LoTemplate = value;
 else if (optionName == "childroot")
-childRoot = value;
+ChildRoot = value;
 else if (optionName == "losubpath")
-loSubPath = value;
+LoSubPath = value;
 else if (optionName == "numprespawns")
 NumPreSpawnedChildren = std::stoi(value);
 else if (optionName == "test")
-LOOLWSD::doTest = true;
+LOOLWSD::DoTest = true;
 #if ENABLE_DEBUG
 else if (optionName == "uid")
 uid = std::stoull(value);
@@ -792,10 +792,10 @@ bool LOOLWSD::createBroker(const std::string& rJailId)
 {
 Process::Args args;
 
-args.push_back("--losubpath=" + LOOLWSD::loSubPath);
-args.push_back("--systemplate=" + sysTemplate);
-args.push_back("--lotemplate=" + loTemplate);
-args.push_back("--childroot=" + childRoot);
+args.push_back("--losubpath=" + LOOLWSD::LoSubPath);
+args.push_back("--systemplate=" + SysTemplate);
+args.push_back("--lotemplate=" + LoTemplate);
+args.push_back("--childroot=" + ChildRoot);
 args.push_back("--jailid=" + rJailId);
 args.push_back("--numprespawns=" + std::to_string(NumPreSpawnedChildren));
 args.push_back("--clientport=" + std::to_string(ClientPortNumber));
@@ -830,9 +830,9 @@ int LOOLWSD::main(const std::vector& /*args*/)
 
 Util::setSignals(false);
 
-if 

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

2016-01-14 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp  |4 ++--
 loolwsd/LOOLWSD.hpp  |   28 ++--
 loolwsd/MasterProcessSession.cpp |2 +-
 3 files changed, 17 insertions(+), 17 deletions(-)

New commits:
commit 3d803dd9b03b7858f69e2bd2e6cb4d3a4722e83d
Author: Ashod Nakashian 
Date:   Tue Jan 12 18:11:04 2016 -0500

loolwsd: Document -> DocumentURI

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 6435958..3e7ee14 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -152,8 +152,8 @@ using Poco::ProcessHandle;
 using Poco::URI;
 
 // Document management mutex.
-std::mutex Document::DocumentsMutex;
-std::map Document::UriToDocumentMap;
+std::mutex DocumentURI::DocumentURIMutex;
+std::map 
DocumentURI::UriToDocumentURIMap;
 
 /// Handles the filename part of the convert-to POST request payload.
 class ConvertToPartHandler : public Poco::Net::PartHandler
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index 50bde75..c520e1d 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -26,14 +26,14 @@
 #include "Common.hpp"
 #include "Util.hpp"
 
-// A Document as mananged by us.
+// A DocumentURI as mananged by us.
 // Contains URI, physical path, etc.
-class Document
+class DocumentURI
 {
 public:
 
 static
-std::shared_ptr create(const std::string& url,
+std::shared_ptr create(const std::string& url,
  const std::string& jailRoot,
  const std::string& childId)
 {
@@ -48,13 +48,13 @@ public:
 
 // This lock could become a bottleneck.
 // In that case, we can use a pool and index by publicPath.
-std::unique_lock lock(DocumentsMutex);
+std::unique_lock lock(DocumentURIMutex);
 
 // Find the document if already open.
-auto it = UriToDocumentMap.lower_bound(publicFilePath);
-if (it != UriToDocumentMap.end() && it->first == publicFilePath)
+auto it = UriToDocumentURIMap.lower_bound(publicFilePath);
+if (it != UriToDocumentURIMap.end() && it->first == publicFilePath)
 {
-Log::info("Document [" + it->first + "] found.");
+Log::info("DocumentURI [" + it->first + "] found.");
 return it->second;
 }
 
@@ -111,10 +111,10 @@ public:
   "] is not a file.");
 }
 
-auto document = std::shared_ptr(new Document(uriPublic, 
uriJailed, childId));
+auto document = std::shared_ptr(new 
DocumentURI(uriPublic, uriJailed, childId));
 
-Log::info("Document [" + publicFilePath + "] created.");
-it = UriToDocumentMap.emplace_hint(it, publicFilePath, document);
+Log::info("DocumentURI [" + publicFilePath + "] created.");
+it = UriToDocumentURIMap.emplace_hint(it, publicFilePath, document);
 return it->second;
 }
 
@@ -123,7 +123,7 @@ public:
 std::string getChildId() const { return _childId; }
 
 private:
-Document(const Poco::URI& uriPublic,
+DocumentURI(const Poco::URI& uriPublic,
  const Poco::URI& uriJailed,
  const std::string& childId) :
_uriPublic(uriPublic),
@@ -134,9 +134,9 @@ private:
 
 private:
 
-// Document management mutex.
-static std::mutex DocumentsMutex;
-static std::map UriToDocumentMap;
+// DocumentURI management mutex.
+static std::mutex DocumentURIMutex;
+static std::map 
UriToDocumentURIMap;
 
 private:
 const Poco::URI _uriPublic;
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index 32a3098..1c2ca83 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -634,7 +634,7 @@ void MasterProcessSession::dispatchChild()
 const auto jailRoot = Poco::Path(LOOLWSD::childRoot, LOOLWSD::jailId);
 const auto childId = std::to_string(childSession->_pidChild);
 
-auto document = Document::create(_docURL, jailRoot.toString(), childId);
+auto document = DocumentURI::create(_docURL, jailRoot.toString(), childId);
 
 _peer = childSession;
 childSession->_peer = shared_from_this();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-01-06 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp |  275 ++--
 1 file changed, 161 insertions(+), 114 deletions(-)

New commits:
commit c2c41ceb63fee92b9d958434c843a96ea976c7e1
Author: Ashod Nakashian 
Date:   Tue Jan 5 21:29:12 2016 -0500

loolwsd: refactored HttpRequestHandler

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index cf4658e..5f1ad43 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -240,21 +240,107 @@ public:
 }
 };
 
-/// Handle a WebSocket connection or a simple HTTP request.
-class RequestHandler: public HTTPRequestHandler
+// Synchronously process WebSocket requests and dispatch to handler.
+// Handler returns false to end.
+void SocketProcessor(std::shared_ptr ws,
+ HTTPServerResponse& response,
+ std::function 
handler)
 {
-public:
-RequestHandler()
+const Poco::Timespan waitTime(POLL_TIMEOUT);
+try
+{
+// Loop, receiving WebSocket messages either from the client, or from 
the child
+// process (to be forwarded to the client).
+int flags;
+int n;
+bool pollTimeout = true;
+ws->setReceiveTimeout(0);
+
+do
+{
+char buffer[20]; //FIXME: Dynamic?
+
+if ((pollTimeout = ws->poll(waitTime, Socket::SELECT_READ)))
+{
+n = ws->receiveFrame(buffer, sizeof(buffer), flags);
+
+if ((flags & WebSocket::FRAME_OP_BITMASK) == 
WebSocket::FRAME_OP_PING)
+{
+ws->sendFrame("", 0, WebSocket::FRAME_OP_PONG);
+}
+else if ((flags & WebSocket::FRAME_OP_BITMASK) == 
WebSocket::FRAME_OP_PONG)
+{
+n = 1;
+}
+else if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != 
WebSocket::FRAME_OP_CLOSE)
+{
+const std::string firstLine = getFirstLine(buffer, n);
+if (firstLine == "eof")
+break;
+
+StringTokenizer tokens(firstLine, " ", 
StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
+
+if (firstLine.size() == 
static_cast(n))
+{
+handler(firstLine.c_str(), firstLine.size());
+}
+else
+{
+// Check if it is a "nextmessage:" and in that case 
read the large
+// follow-up message separately, and handle that only.
+int size;
+if (tokens.count() == 2 &&
+tokens[0] == "nextmessage:" && 
getTokenInteger(tokens[1], "size", size) && size > 0)
+{
+char largeBuffer[size]; //FIXME: Security 
risk! Flooding may segfault us.
+
+n = ws->receiveFrame(largeBuffer, size, flags);
+if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) 
!= WebSocket::FRAME_OP_CLOSE)
+{
+if (!handler(largeBuffer, n))
+n = 0;
+}
+}
+else
+{
+if (!handler(buffer, n))
+n = 0;
+}
+}
+}
+}
+}
+while (!TerminationFlag &&
+   (!pollTimeout || (n > 0 && (flags & 
WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)));
+}
+catch (const WebSocketException& exc)
 {
+Log::error("RequestHandler::handleRequest(), WebSocketException: " + 
exc.message());
+switch (exc.code())
+{
+case WebSocket::WS_ERR_HANDSHAKE_UNSUPPORTED_VERSION:
+response.set("Sec-WebSocket-Version", 
WebSocket::WEBSOCKET_VERSION);
+// fallthrough
+case WebSocket::WS_ERR_NO_HANDSHAKE:
+case WebSocket::WS_ERR_HANDSHAKE_NO_VERSION:
+case WebSocket::WS_ERR_HANDSHAKE_NO_KEY:
+response.setStatusAndReason(HTTPResponse::HTTP_BAD_REQUEST);
+response.setContentLength(0);
+response.send();
+break;
+}
 }
+}
+
+
+/// Handle a public connection from a client.
+class ClientRequestHandler: public HTTPRequestHandler
+{
+public:
 
 void handleRequest(HTTPServerRequest& request, HTTPServerResponse& 
response) override
 {
-std::string thread_name;
-if 

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

2016-01-06 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp |5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

New commits:
commit 87d45ff3331f5a0b90a752211975c5d4eb690c8a
Author: Ashod Nakashian 
Date:   Wed Jan 6 08:56:50 2016 -0500

loolwsd: don't timeout client socket

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 03dc308..979bbb4 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -207,6 +207,9 @@ void SocketProcessor(std::shared_ptr ws,
 {
 char buffer[20]; //FIXME: Dynamic?
 
+// We should care about timeout only when we have heartbeat
+// support. For now, we can't predict when the next message
+// should arrive.
 if ((pollTimeout = ws->poll(waitTime, Socket::SELECT_READ)))
 {
 n = ws->receiveFrame(buffer, sizeof(buffer), flags);
@@ -267,7 +270,7 @@ void SocketProcessor(std::shared_ptr ws,
 }
 }
 while (!TerminationFlag &&
-   (!pollTimeout || (n > 0 && (flags & 
WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)));
+   (flags & WebSocket::FRAME_OP_BITMASK) != 
WebSocket::FRAME_OP_CLOSE);
 Log::debug() << "Finishing SocketProcessor. TerminationFlag: " << 
TerminationFlag
  << ", pollTimeout: " << pollTimeout << ", payload size: " 
<< n << Log::end;
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-01-06 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp |   61 +---
 1 file changed, 35 insertions(+), 26 deletions(-)

New commits:
commit ea1415de75156f8989e8bdcc6cfe7c53e08b3fbc
Author: Ashod Nakashian 
Date:   Tue Jan 5 22:32:58 2016 -0500

loolwsd: improved HTTP Request Handler

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 5f1ad43..259b97e 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -244,18 +244,17 @@ public:
 // Handler returns false to end.
 void SocketProcessor(std::shared_ptr ws,
  HTTPServerResponse& response,
- std::function 
handler)
+ std::function handler)
 {
+Log::info("Starting Socket Processor.");
+
 const Poco::Timespan waitTime(POLL_TIMEOUT);
 try
 {
-// Loop, receiving WebSocket messages either from the client, or from 
the child
-// process (to be forwarded to the client).
-int flags;
-int n;
+int flags = 0;
+int n = 0;
 bool pollTimeout = true;
 ws->setReceiveTimeout(0);
-
 do
 {
 char buffer[20]; //FIXME: Dynamic?
@@ -270,24 +269,27 @@ void SocketProcessor(std::shared_ptr ws,
 }
 else if ((flags & WebSocket::FRAME_OP_BITMASK) == 
WebSocket::FRAME_OP_PONG)
 {
-n = 1;
+continue;
 }
 else if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != 
WebSocket::FRAME_OP_CLOSE)
 {
 const std::string firstLine = getFirstLine(buffer, n);
 if (firstLine == "eof")
+{
+Log::info("Recieved EOF. Finishing.");
 break;
-
-StringTokenizer tokens(firstLine, " ", 
StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
+}
 
 if (firstLine.size() == 
static_cast(n))
 {
-handler(firstLine.c_str(), firstLine.size());
+handler(firstLine.c_str(), firstLine.size(), true);
 }
 else
 {
 // Check if it is a "nextmessage:" and in that case 
read the large
 // follow-up message separately, and handle that only.
+StringTokenizer tokens(firstLine, " ", 
StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
+
 int size;
 if (tokens.count() == 2 &&
 tokens[0] == "nextmessage:" && 
getTokenInteger(tokens[1], "size", size) && size > 0)
@@ -297,14 +299,20 @@ void SocketProcessor(std::shared_ptr ws,
 n = ws->receiveFrame(largeBuffer, size, flags);
 if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) 
!= WebSocket::FRAME_OP_CLOSE)
 {
-if (!handler(largeBuffer, n))
-n = 0;
+if (!handler(largeBuffer, n, false))
+{
+Log::info("Socket handler flagged for 
finishing.");
+break;
+}
 }
 }
 else
 {
-if (!handler(buffer, n))
-n = 0;
+if (!handler(buffer, n, false))
+{
+Log::info("Socket handler flagged for 
finishing.");
+break;
+}
 }
 }
 }
@@ -312,6 +320,8 @@ void SocketProcessor(std::shared_ptr ws,
 }
 while (!TerminationFlag &&
(!pollTimeout || (n > 0 && (flags & 
WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)));
+Log::debug() << "Finishing SocketProcessor. TerminationFlag: " << 
TerminationFlag
+ << ", pollTimeout: " << pollTimeout << ", payload size: " 
<< n << Log::end;
 }
 catch (const WebSocketException& exc)
 {
@@ -330,6 +340,8 @@ void SocketProcessor(std::shared_ptr ws,
 break;
 }
 }
+
+Log::info("Finished Socket Processor.");
 }
 
 
@@ -479,14 +491,15 @@ public:
 

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

2016-01-06 Thread Jan Holesovsky
 loolwsd/LOOLWSD.cpp |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

New commits:
commit 28646c1a53526b0c458e448cf7f279e9096d4e75
Author: Jan Holesovsky 
Date:   Wed Jan 6 15:55:00 2016 +0100

loolwsd: Answer the PING's with proper PONG's.

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 2669011..a4bec81 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -216,7 +216,8 @@ void SocketProcessor(std::shared_ptr ws,
 
 if ((flags & WebSocket::FRAME_OP_BITMASK) == 
WebSocket::FRAME_OP_PING)
 {
-ws->sendFrame("", 0, WebSocket::FRAME_OP_PONG);
+ws->sendFrame("PONG", 4);
+continue;
 }
 else if ((flags & WebSocket::FRAME_OP_BITMASK) == 
WebSocket::FRAME_OP_PONG)
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-01-06 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp |   19 +++
 loolwsd/LOOLWSD.hpp |3 +--
 2 files changed, 8 insertions(+), 14 deletions(-)

New commits:
commit b0cd3e5a460336ef72f3b9236ab187b4fe5459e2
Author: Ashod Nakashian 
Date:   Wed Jan 6 22:17:30 2016 -0500

loolwsd: spawn one broker and one only

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 9b5276b..81d1712 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -786,7 +786,7 @@ void LOOLWSD::displayHelp()
 helpFormatter.format(std::cout);
 }
 
-int LOOLWSD::createBroker()
+bool LOOLWSD::createBroker()
 {
 Process::Args args;
 
@@ -809,16 +809,7 @@ int LOOLWSD::createBroker()
 Log::info() << "Adding Broker #" << childIndex << " PID " << child.id() << 
Log::end;
 MasterProcessSession::_childProcesses[child.id()] = child.id();
 
-return Application::EXIT_OK;
-}
-
-void LOOLWSD::startupBroker(const signed nBrokers)
-{
-for (signed nCntr = nBrokers; nCntr > 0; --nCntr)
-{
-if (createBroker() < 0)
-break;
-}
+return true;
 }
 
 int LOOLWSD::main(const std::vector& /*args*/)
@@ -878,7 +869,11 @@ int LOOLWSD::main(const std::vector& /*args*/)
 
 NamedMutexLOOL.lock();
 
-startupBroker(1);
+if (!createBroker())
+{
+Log::error("Failed to spawn loolBroker.");
+return Application::EXIT_UNAVAILABLE;
+}
 
 #ifdef __linux
 dropCapability(CAP_SYS_CHROOT);
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index 907620a..f03faed 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -74,8 +74,7 @@ private:
 int  createComponent();
 int  createDesktop();
 
-void startupBroker(int nBroker);
-int  createBroker();
+bool createBroker();
 };
 
 #endif
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-01-06 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp  |4 +
 loolwsd/LOOLWSD.hpp  |  118 +++
 loolwsd/MasterProcessSession.cpp |   69 --
 3 files changed, 136 insertions(+), 55 deletions(-)

New commits:
commit a7556a7c1e298e40de55e915017a9fad4e0d519c
Author: Ashod Nakashian 
Date:   Thu Jan 7 00:16:47 2016 -0500

loolwsd: new Document class to manage the lifetime of a document

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 7117cb3..5afeb6d 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -151,6 +151,10 @@ using Poco::NamedMutex;
 using Poco::ProcessHandle;
 using Poco::URI;
 
+// Document management mutex.
+std::mutex Document::DocumentsMutex;
+std::map Document::UriToDocumentMap;
+
 /// Handles the filename part of the convert-to POST request payload.
 class ConvertToPartHandler : public Poco::Net::PartHandler
 {
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index f8e8f63..44ad381 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -23,8 +23,126 @@
 #include 
 #include 
 
+#include "Common.hpp"
 #include "Util.hpp"
 
+// A Document as mananged by us.
+// Contains URI, physical path, etc.
+class Document
+{
+public:
+
+static
+std::shared_ptr create(const std::string& url,
+ const std::string& jailRoot,
+ const std::string& childId)
+{
+// TODO: Sanitize the url and limit access!
+auto uriPublic = Poco::URI(url);
+uriPublic.normalize();
+
+const auto publicFilePath = uriPublic.getPath();
+
+if (publicFilePath.empty())
+throw std::runtime_error("Invalid URL.");
+
+// This lock could become a bottleneck.
+// In that case, we can use a pool and index by publicPath.
+std::unique_lock lock(DocumentsMutex);
+
+// Find the document if already open.
+auto it = UriToDocumentMap.lower_bound(publicFilePath);
+if (it != UriToDocumentMap.end())
+{
+Log::info("Document [" + it->first + "] found.");
+return it->second;
+}
+
+// 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.
+auto uriJailed = uriPublic;
+if (uriPublic.isRelative() || uriPublic.getScheme() == "file")
+{
+// chroot/jailId/user/doc
+const auto jailedDocRoot = Poco::Path(jailRoot, 
JailedDocumentRoot);
+
+// chroot/jailId/user/doc/childId
+const auto docPath = Poco::Path(jailedDocRoot, childId);
+Poco::File(docPath).createDirectories();
+
+const auto filename = 
Poco::Path(uriPublic.getPath()).getFileName();
+
+// chroot/jailId/user/doc/childId/file.ext
+const auto jailedFilePath = Poco::Path(docPath, 
filename).toString();
+
+uriJailed = Poco::URI(Poco::URI("file://"), jailedFilePath);
+
+Log::info("Public URI [" + uriPublic.toString() +
+  "] jailed to [" + uriJailed.toString() + "].");
+
+#ifdef __linux
+Log::info("Linking " + publicFilePath + " to " + jailedFilePath);
+if (!Poco::File(jailedFilePath).exists() && 
link(publicFilePath.c_str(), jailedFilePath.c_str()) == -1)
+{
+// Failed
+Log::error("link(\"" + publicFilePath + "\", \"" + 
jailedFilePath + "\") failed.");
+}
+#endif
+
+try
+{
+// Fallback to copying.
+if (!Poco::File(jailedFilePath).exists())
+{
+Log::info("Copying " + publicFilePath + " to " + 
jailedFilePath);
+Poco::File(publicFilePath).copyTo(jailedFilePath);
+}
+}
+catch (const Poco::Exception& exc)
+{
+Log::error("copyTo(\"" + publicFilePath + "\", \"" + 
jailedFilePath + "\") failed: " + exc.displayText());
+throw;
+}
+}
+else
+{
+Log::info("Public URI [" + uriPublic.toString() +
+  "] is not a file.");
+}
+
+auto document = std::shared_ptr(new Document(uriPublic, 
uriJailed, childId));
+
+Log::info("Document [" + publicFilePath + "] created.");
+it = UriToDocumentMap.emplace_hint(it, publicFilePath, document);
+return it->second;
+}
+
+Poco::URI getPublicUri() const { return _uriPublic; }
+Poco::URI getJailedUri() const { return _uriJailed; }
+std::string getChildId() const { 

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

2016-01-05 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp |6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

New commits:
commit 1bbc42351bf8b17a5a1355be0bc95570bf05cebd
Author: Ashod Nakashian 
Date:   Tue Jan 5 12:29:34 2016 -0500

loolwsd: handle browser ping frames

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index bd7dc9f..4bee0e5 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -424,7 +424,11 @@ public:
 {
 n = ws->receiveFrame(buffer, sizeof(buffer), flags);
 
-if ((flags & WebSocket::FRAME_OP_BITMASK) == 
WebSocket::FRAME_OP_PONG)
+if ((flags & WebSocket::FRAME_OP_BITMASK) == 
WebSocket::FRAME_OP_PING)
+{
+ws->sendFrame("", 0, WebSocket::FRAME_OP_PONG);
+}
+else if ((flags & WebSocket::FRAME_OP_BITMASK) == 
WebSocket::FRAME_OP_PONG)
 {
 n = 1;
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2016-01-04 Thread Ashod Nakashian
 loolwsd/LOOLWSD.cpp |   26 +++---
 1 file changed, 19 insertions(+), 7 deletions(-)

New commits:
commit 80941b0b41ca0c315a373ffee46a6af4cf8d4205
Author: Ashod Nakashian 
Date:   Mon Jan 4 16:15:02 2016 -0500

loolwsd: bccu#1394 childRoot dir should not be removed, only jails

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index a9c7756..bd7dc9f 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -323,7 +323,7 @@ public:
 Poco::Net::HTMLForm form(request, request.stream(), handler);
 if (form.has("childid") && form.has("name"))
 {
-const std::string dirPath = LOOLWSD::childRoot + 
Path::separator() + form.get("childid")
+const std::string dirPath = LOOLWSD::childRoot + 
form.get("childid")
   + LOOLSession::jailDocumentURL
   + Path::separator() + 
"insertfile";
 File(dirPath).createDirectory();
@@ -342,10 +342,12 @@ public:
 else if (tokens.count() >= 4)
 {
 // The user might request a file to download
-std::string dirPath = LOOLWSD::childRoot + "/" + tokens[1] + 
LOOLSession::jailDocumentURL + "/" + tokens[2];
+const std::string dirPath = LOOLWSD::childRoot + tokens[1]
+  + LOOLSession::jailDocumentURL
+  + Path::separator() + tokens[2];
 std::string fileName;
 URI::decode(tokens[3], fileName);
-std::string filePath = dirPath + "/" + fileName;
+const std::string filePath = dirPath + Path::separator() + 
fileName;
 Log::info("HTTP request for: " + filePath);
 File file(filePath);
 if (file.exists())
@@ -822,12 +824,15 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 // so must check options required in the parent (but not in the
 // child) separately now. Also check for options that are
 // meaningless for the parent.
-if (sysTemplate == "")
+if (sysTemplate.empty())
 throw MissingOptionException("systemplate");
-if (loTemplate == "")
+if (loTemplate.empty())
 throw MissingOptionException("lotemplate");
-if (childRoot == "")
+
+if (childRoot.empty())
 throw MissingOptionException("childroot");
+else if (childRoot[childRoot.size() - 1] != Path::separator())
+childRoot += Path::separator();
 
 if (ClientPortNumber == MASTER_PORT_NUMBER)
 throw IncompatibleOptionsException("port");
@@ -957,7 +962,14 @@ int LOOLWSD::main(const std::vector& /*args*/)
 waitpid(-1, , WUNTRACED);
 
 Log::info("Cleaning up childroot directory [" + childRoot + "].");
-Util::removeFile(childRoot, true);
+std::vector jails;
+File(childRoot).list(jails);
+for (auto& jail : jails)
+{
+const auto path = childRoot + jail;
+Log::info("Removing jail [" + path + "].");
+Util::removeFile(path, true);
+}
 
 Log::info("Process [loolwsd] finished.");
 return Application::EXIT_OK;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-12-28 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 8410ceca2faf3a413b555e5bac5ffeb18aea8a32
Author: Henry Castro 
Date:   Mon Dec 28 16:51:39 2015 -0400

loolwsd: thread renamed to wsd_queue_handler

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 09da719..c1175bf 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -245,7 +245,7 @@ public:
 
 void run() override
 {
-static const std::string thread_name = "wsd_pipe_reader";
+static const std::string thread_name = "wsd_queue_handler";
 #ifdef __linux
 if (prctl(PR_SET_NAME, reinterpret_cast(thread_name.c_str()), 0, 0, 0) != 0)
 Log::error("Cannot set thread name to " + thread_name + ".");
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-12-23 Thread Henry Castro
 loolwsd/LOOLWSD.cpp  |   18 +++---
 loolwsd/LOOLWSD.hpp  |2 ++
 loolwsd/MasterProcessSession.cpp |6 +-
 3 files changed, 22 insertions(+), 4 deletions(-)

New commits:
commit 2d375f3eba9695e2f0debefbf283553e9fd825e8
Author: Henry Castro 
Date:   Sun Dec 13 13:28:01 2015 -0500

loolwsd: FIFO

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

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index b89fb9c..8bdc377 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -101,7 +101,7 @@ DEALINGS IN THE SOFTWARE.
 #include 
 #include 
 #include 
-
+#include 
 
 #include "LOOLProtocol.hpp"
 #include "LOOLSession.hpp"
@@ -579,6 +579,7 @@ private:
 
 int LOOLWSD::portNumber = DEFAULT_CLIENT_PORT_NUMBER;
 int LOOLWSD::timeoutCounter = 0;
+int LOOLWSD::writerBroker = -1;
 Poco::UInt64 LOOLWSD::_childId = 0;
 std::string LOOLWSD::cache = LOOLWSD_CACHEDIR;
 std::string LOOLWSD::sysTemplate;
@@ -601,6 +602,7 @@ int LOOLWSD::uid = 0;
 const std::string LOOLWSD::CHILD_URI = "/loolws/child/";
 const std::string LOOLWSD::PIDLOG = "/tmp/loolwsd.pid";
 const std::string LOOLWSD::LOKIT_PIDLOG = "/tmp/lokit.pid";
+const std::string LOOLWSD::FIFO_FILE = "/tmp/loolwsdfifo";
 
 LOOLWSD::LOOLWSD()
 {
@@ -1150,7 +1152,7 @@ void LOOLWSD::desktopMain()
 }
 
 if ( WCOREDUMP(status) )
-std::cout << Util::logPrefix() << "The child produced a 
core dump." << std::endl;
+std::cout << Util::logPrefix() << "The child process [" << 
pid << "] produced a core dump." << std::endl;
 
 if ( WIFSTOPPED(status) )
 std::cout << Util::logPrefix() << "The child process was 
stopped by delivery of a signal." << std::endl;
@@ -1222,6 +1224,9 @@ void LOOLWSD::startupDesktop(int nDesktops)
 
 int LOOLWSD::main(const std::vector& /*args*/)
 {
+Poco::Environment::set("LD_BIND_NOW", "1");
+Poco::Environment::set("LOK_VIEW_CALLBACK", "1");
+
 int status;
 #ifdef __linux
 char *locale = setlocale(LC_ALL, NULL);
@@ -1233,7 +1238,7 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 
 if (access(cache.c_str(), R_OK | W_OK | X_OK) != 0)
 {
-std::cout << "Unable to access " << cache <<
+std::cout << Util::logPrefix() << "Unable to access " << cache <<
 ", please make sure it exists, and has write permission for this 
user." << std::endl;
 return Application::EXIT_UNAVAILABLE;
 }
@@ -1266,6 +1271,12 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 filePID << Process::id();
 }
 
+if (!File(FIFO_FILE).exists() && mkfifo(FIFO_FILE.c_str(), 0666) == -1)
+{
+std::cout << Util::logPrefix() << "Fail to create pipe FIFO" << 
std::endl;
+return Application::EXIT_UNAVAILABLE;
+}
+
 _namedMutexLOOL.lock();
 
 startupDesktop(1);
@@ -1362,6 +1373,7 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 // wait broker process finish
 waitpid(-1, , WUNTRACED);
 
+std::cout << Util::logPrefix() << "loolwsd finished OK!" << std::endl;
 return Application::EXIT_OK;
 }
 
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index 62e4c32..9771e4c 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -33,6 +33,7 @@ public:
 static int portNumber;
 static int timeoutCounter;
 static int _numPreSpawnedChildren;
+static int writerBroker;
 static bool doTest;
 static bool volatile isShutDown;
 static std::string cache;
@@ -53,6 +54,7 @@ public:
 static const int POLL_TIMEOUT = 100;
 static const std::string CHILD_URI;
 static const std::string PIDLOG;
+static const std::string FIFO_FILE;
 static const std::string LOKIT_PIDLOG;
 
 protected:
diff --git a/loolwsd/MasterProcessSession.cpp b/loolwsd/MasterProcessSession.cpp
index ac39c92..21f8caf 100644
--- a/loolwsd/MasterProcessSession.cpp
+++ b/loolwsd/MasterProcessSession.cpp
@@ -373,6 +373,10 @@ bool MasterProcessSession::loadDocument(const char* 
/*buffer*/, int /*length*/,
 try
 {
 URI aUri(_docURL);
+
+// request new URL session
+std::string aMessage = "request " + 
std::to_string(Thread::currentTid()) + " " + _docURL + "\r\n";
+Util::writeFIFO(LOOLWSD::writerBroker, aMessage.c_str(), 
aMessage.length());
 }
 catch(Poco::SyntaxException&)
 {
@@ -598,7 +602,7 @@ void MasterProcessSession::dispatchChild()
 
 #ifdef __linux
 Application::instance().logger().information(Util::logPrefix() + 
"Linking " + aSrcFile.toString() + " to " + aDstFile.toString());
-if (link(aSrcFile.toString().c_str(), aDstFile.toString().c_str()) == 
-1)
+if (!File(aDstFile).exists() && link(aSrcFile.toString().c_str(), 

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

2015-12-18 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |4 
 1 file changed, 4 deletions(-)

New commits:
commit 8c4421d681c9fca56faabb1a010c4394cef7fb26
Author: Henry Castro 
Date:   Fri Dec 18 16:45:30 2015 -0400

loolwsd: clean up unnecessary code

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 184ddfd..a74d867 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1360,10 +1360,6 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 // wait broker process finish
 waitpid(-1, , WUNTRACED);
 
-// remove child root
-if (LOOLWSD::_childId > 0)
-File(LOOLWSD::childRoot + Path::separator() + 
std::to_string(LOOLWSD::_childId)).remove(true);
-
 return Application::EXIT_OK;
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-12-10 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

New commits:
commit a01de999621a1bf577f0a68b2f403e1112667d45
Author: Henry Castro 
Date:   Thu Dec 10 18:15:45 2015 -0400

loolwsd: handle pong frame

pong frame is received from IE11, with payload data length = 0

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 8838a22..184ddfd 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -395,7 +395,11 @@ public:
 {
 n = ws->receiveFrame(buffer, sizeof(buffer), flags);
 
-if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != 
WebSocket::FRAME_OP_CLOSE)
+if ((flags & WebSocket::FRAME_OP_BITMASK) == 
WebSocket::FRAME_OP_PONG)
+{
+n = 1;
+}
+else if (n > 0 && (flags & 
WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)
 {
 std::string firstLine = getFirstLine(buffer, n);
 StringTokenizer tokens(firstLine, " ", 
StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-12-08 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |3 +++
 1 file changed, 3 insertions(+)

New commits:
commit 6c209cefb1f798f428bc3232b43c3d2d4f1745fa
Author: Henry Castro 
Date:   Tue Dec 8 21:30:39 2015 -0400

loolwsd: wait to finish lo_startmain thread

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 5f0e89d..8838a22 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1062,6 +1062,9 @@ void LOOLWSD::componentMain()
 
 // Destroy LibreOfficeKit
 loKit->pClass->destroy(loKit);
+
+// wait to finish lo_startmain thread
+pthread_exit(0);
 }
 catch (Exception& exc)
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-12-04 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |4 
 1 file changed, 4 insertions(+)

New commits:
commit 666e4a080f02a4eaab7355af2968c2a1a31d7618
Author: Henry Castro 
Date:   Fri Dec 4 18:06:52 2015 -0400

loolwsd: update drop capabilities

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index debb680..5f0e89d 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -982,6 +982,8 @@ void LOOLWSD::componentMain()
 
 #ifdef __linux
 dropCapability(CAP_SYS_CHROOT);
+dropCapability(CAP_MKNOD);
+dropCapability(CAP_FOWNER);
 #else
 dropCapability();
 #endif
@@ -1261,6 +1263,8 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 
 #ifdef __linux
 dropCapability(CAP_SYS_CHROOT);
+dropCapability(CAP_MKNOD);
+dropCapability(CAP_FOWNER);
 #else
 dropCapability();
 #endif
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-12-04 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |  153 ++--
 1 file changed, 77 insertions(+), 76 deletions(-)

New commits:
commit 7ea89ef99bac74de7d8f47b694d553a81318999c
Author: Henry Castro 
Date:   Fri Dec 4 15:19:31 2015 -0400

loolwsd: restore jail root child creation

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 4bfb097..9512a86 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -916,13 +916,89 @@ void LOOLWSD::componentMain()
 if (prctl(PR_SET_NAME, reinterpret_cast("libreofficekit"), 
0, 0, 0) != 0)
 std::cout << Util::logPrefix() << "Cannot set thread name :" << 
strerror(errno) << std::endl;
 
-setSignals(true);
+setSignals(false);
 #endif
 
 try
 {
 _namedMutexLOOL.lock();
 
+// Initialization
+std::unique_lock rngLock(_rngMutex);
+_rng.seed(Process::id());
+_childId = (((Poco::UInt64)_rng.next()) << 32) | _rng.next() | 1;
+rngLock.unlock();
+
+Path jailPath = Path::forDirectory(LOOLWSD::childRoot + 
Path::separator() + std::to_string(_childId));
+File(jailPath).createDirectory();
+
+Path jailLOInstallation(jailPath, LOOLWSD::loSubPath);
+jailLOInstallation.makeDirectory();
+File(jailLOInstallation).createDirectory();
+
+// Copy (link) LO installation and other necessary files into it from 
the template
+
+linkOrCopy(LOOLWSD::sysTemplate, jailPath);
+linkOrCopy(LOOLWSD::loTemplate, jailLOInstallation);
+
+// We need this because sometimes the hostname is not resolved
+std::vector networkFiles = {"/etc/host.conf", 
"/etc/hosts", "/etc/nsswitch.conf", "/etc/resolv.conf"};
+for (std::vector::iterator it = networkFiles.begin(); it 
!= networkFiles.end(); ++it)
+{
+File networkFile(*it);
+if (networkFile.exists())
+{
+networkFile.copyTo(Path(jailPath, "/etc").toString());
+}
+}
+#ifdef __linux
+// Create the urandom and random devices
+File(Path(jailPath, "/dev")).createDirectory();
+if (mknod((jailPath.toString() + "/dev/random").c_str(),
+S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH 
| S_IWOTH,
+makedev(1, 8)) != 0)
+{
+Application::instance().logger().error(Util::logPrefix() +
+"mknod(" + jailPath.toString() + "/dev/random) failed: " +
+strerror(errno));
+
+}
+if (mknod((jailPath.toString() + "/dev/urandom").c_str(),
+S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH 
| S_IWOTH,
+makedev(1, 9)) != 0)
+{
+Application::instance().logger().error(Util::logPrefix() +
+"mknod(" + jailPath.toString() + "/dev/urandom) failed: " +
+strerror(errno));
+}
+#endif
+
+Application::instance().logger().information("componentMain -> 
chroot(\"" + jailPath.toString() + "\")");
+if (chroot(jailPath.toString().c_str()) == -1)
+{
+logger().error("chroot(\"" + jailPath.toString() + "\") failed: " 
+ strerror(errno));
+exit(Application::EXIT_UNAVAILABLE);
+}
+
+if (chdir("/") == -1)
+{
+logger().error(std::string("chdir(\"/\") in jail failed: ") + 
strerror(errno));
+exit(Application::EXIT_UNAVAILABLE);
+}
+
+#ifdef __linux
+dropCapability(CAP_SYS_CHROOT);
+#else
+dropCapability();
+#endif
+
+if (std::getenv("SLEEPFORDEBUGGER"))
+{
+std::cout << "Sleeping " << std::getenv("SLEEPFORDEBUGGER") << " 
seconds, " <<
+"attach process " << Process::id() << " in debugger now." << 
std::endl;
+Thread::sleep(std::stoul(std::getenv("SLEEPFORDEBUGGER")) * 1000);
+}
+
 #ifdef __APPLE__
 LibreOfficeKit *loKit(lok_init_2(("/" + loSubPath + 
"/Frameworks").c_str(), "file:///user"));
 #else
@@ -1041,81 +1117,6 @@ void LOOLWSD::desktopMain()
 setSignals(false);
 #endif
 
-// Initialization
-std::unique_lock rngLock(_rngMutex);
-_childId = (((Poco::UInt64)_rng.next()) << 32) | _rng.next() | 1;
-rngLock.unlock();
-
-Path jailPath = Path::forDirectory(LOOLWSD::childRoot + Path::separator() 
+ std::to_string(_childId));
-File(jailPath).createDirectory();
-
-Path jailLOInstallation(jailPath, LOOLWSD::loSubPath);
-jailLOInstallation.makeDirectory();
-File(jailLOInstallation).createDirectory();
-
-// Copy (link) LO installation and other necessary files into it from the 
template
-
-linkOrCopy(LOOLWSD::sysTemplate, jailPath);
-linkOrCopy(LOOLWSD::loTemplate, jailLOInstallation);
-
-// We need this because sometimes the hostname is not resolved
-std::vector networkFiles = {"/etc/host.conf", "/etc/hosts", 

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

2015-12-03 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |4 
 1 file changed, 4 insertions(+)

New commits:
commit c71ce222a5d95ef53fce7548873818359b4f5f38
Author: Henry Castro 
Date:   Thu Dec 3 15:43:54 2015 -0400

loolwsd: remove child workspace when a child dies

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index f8882e0..0e0cc70 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1126,6 +1126,10 @@ void LOOLWSD::desktopMain()
 {
 std::cout << Util::logPrefix() << "One of our known child 
processes died :" << std::to_string(pid)  << std::endl;
 MasterProcessSession::_childProcesses.erase(pid);
+
+File aWorkSpace(LOOLSession::jailDocumentURL + 
Path::separator() + std::to_string(pid));
+if (aWorkSpace.exists())
+aWorkSpace.remove(true);
 }
 
 if ( WCOREDUMP(status) )
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-12-03 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |4 
 1 file changed, 4 insertions(+)

New commits:
commit 9933ef86758a06d75997b4550413b828f62e0cb1
Author: Henry Castro 
Date:   Thu Dec 3 17:41:12 2015 -0400

loolwsd: destroy lokit document when a child dies

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 0e0cc70..4bfb097 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -984,6 +984,10 @@ void LOOLWSD::componentMain()
 queue.put("eof");
 queueHandlerThread.join();
 
+// Destroy lokit document
+if (session->_loKitDocument)
+session->_loKitDocument->pClass->destroy(session->_loKitDocument);
+
 // Destroy LibreOfficeKit
 loKit->pClass->destroy(loKit);
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-11-25 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |   27 +++
 loolwsd/LOOLWSD.hpp |3 +++
 2 files changed, 30 insertions(+)

New commits:
commit 0417b90eeb9f05f1606a9d2d3d553db055c66bbb
Author: Henry Castro 
Date:   Wed Nov 25 22:37:08 2015 -0400

loolwsd: add signal handler

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 0ff4915..7ee8694 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -602,6 +602,27 @@ LOOLWSD::~LOOLWSD()
 {
 }
 
+void LOOLWSD::handleSignal(int aSignal)
+{
+std::cout << Util::logPrefix() << "Signal received: " << 
strsignal(aSignal) << std::endl;
+}
+
+void LOOLWSD::setSignals(bool isIgnored)
+{
+#ifdef __linux
+struct sigaction aSigAction;
+
+sigemptyset(_mask);
+aSigAction.sa_flags = 0;
+aSigAction.sa_handler = (isIgnored ? SIG_IGN : handleSignal);
+
+sigaction(SIGTERM, , NULL);
+sigaction(SIGINT, , NULL);
+sigaction(SIGQUIT, , NULL);
+sigaction(SIGHUP, , NULL);
+#endif
+}
+
 void LOOLWSD::initialize(Application& self)
 {
 ServerApplication::initialize(self);
@@ -891,6 +912,8 @@ void LOOLWSD::componentMain()
 #ifdef __linux
 if (prctl(PR_SET_NAME, reinterpret_cast("libreofficekit"), 
0, 0, 0) != 0)
 std::cout << Util::logPrefix() << "Cannot set thread name :" << 
strerror(errno) << std::endl;
+
+setSignals(true);
 #endif
 
 try
@@ -1007,6 +1030,8 @@ void LOOLWSD::desktopMain()
 #ifdef __linux
 if (prctl(PR_SET_NAME, reinterpret_cast("loolbroker"), 0, 
0, 0) != 0)
 std::cout << Util::logPrefix() << "Cannot set thread name :" << 
strerror(errno) << std::endl;
+
+setSignals(false);
 #endif
 
 // Initialization
@@ -1184,6 +1209,8 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 char *locale = setlocale(LC_ALL, NULL);
 if (locale == NULL || std::strcmp(locale, "C") == 0)
 setlocale(LC_ALL, "en_US.utf8");
+
+setSignals(false);
 #endif
 
 if (access(cache.c_str(), R_OK | W_OK | X_OK) != 0)
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index f0a3aec..2e63038 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -53,6 +53,9 @@ public:
 static const std::string LOKIT_PIDLOG;
 
 protected:
+static void setSignals(bool bIgnore);
+static void handleSignal(int nSignal);
+
 void initialize(Poco::Util::Application& self) override;
 void uninitialize() override;
 void defineOptions(Poco::Util::OptionSet& options) override;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-11-25 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |   55 +---
 loolwsd/LOOLWSD.hpp |1 
 2 files changed, 32 insertions(+), 24 deletions(-)

New commits:
commit e2e0e3a962c4347c5c0e45928af015dd911434b0
Author: Henry Castro 
Date:   Wed Nov 25 22:23:08 2015 -0400

loolwsd: call poll, to check the status of the websocket

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 2caec30..0ff4915 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -354,6 +354,7 @@ public:
 BasicTileQueue queue;
 Thread queueHandlerThread;
 QueueHandler handler(queue);
+Poco::Timespan waitTime(LOOLWSD::POLL_TIMEOUT);
 
 try
 {
@@ -383,46 +384,52 @@ public:
 // process (to be forwarded to the client).
 int flags;
 int n;
+bool pollTimeout = true;
 ws->setReceiveTimeout(0);
+
 do
 {
 char buffer[20];
-n = ws->receiveFrame(buffer, sizeof(buffer), flags);
 
-if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != 
WebSocket::FRAME_OP_CLOSE)
+if ((pollTimeout = ws->poll(waitTime, 
Socket::SELECT_READ)))
 {
-std::string firstLine = getFirstLine(buffer, n);
-StringTokenizer tokens(firstLine, " ", 
StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
+n = ws->receiveFrame(buffer, sizeof(buffer), flags);
 
-if (kind == LOOLSession::Kind::ToClient && 
firstLine.size() == static_cast(n))
-{
-queue.put(firstLine);
-}
-else
+if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != 
WebSocket::FRAME_OP_CLOSE)
 {
-// Check if it is a "nextmessage:" and in that 
case read the large
-// follow-up message separately, and handle that 
only.
-int size;
-if (tokens.count() == 2 && tokens[0] == 
"nextmessage:" && getTokenInteger(tokens[1], "size", size) && size > 0)
-{
-char largeBuffer[size];
+std::string firstLine = getFirstLine(buffer, n);
+StringTokenizer tokens(firstLine, " ", 
StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
 
-n = ws->receiveFrame(largeBuffer, size, flags);
-if (n > 0 && (flags & 
WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)
-{
-if (!session->handleInput(largeBuffer, n))
-n = 0;
-}
+if (kind == LOOLSession::Kind::ToClient && 
firstLine.size() == static_cast(n))
+{
+queue.put(firstLine);
 }
 else
 {
-if (!session->handleInput(buffer, n))
-n = 0;
+// Check if it is a "nextmessage:" and in that 
case read the large
+// follow-up message separately, and handle 
that only.
+int size;
+if (tokens.count() == 2 && tokens[0] == 
"nextmessage:" && getTokenInteger(tokens[1], "size", size) && size > 0)
+{
+char largeBuffer[size];
+
+n = ws->receiveFrame(largeBuffer, size, 
flags);
+if (n > 0 && (flags & 
WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)
+{
+if (!session->handleInput(largeBuffer, 
n))
+n = 0;
+}
+}
+else
+{
+if (!session->handleInput(buffer, n))
+n = 0;
+}
 }
 }
 }
 }
-while (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != 
WebSocket::FRAME_OP_CLOSE);
+while (!pollTimeout || (n > 0 && (flags & 
WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE));
 
 queue.clear();
 queue.put("eof");

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

2015-11-25 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |   24 ++--
 1 file changed, 10 insertions(+), 14 deletions(-)

New commits:
commit c5037c5d30e599af8ab67347381cda22f613ae0a
Author: Henry Castro 
Date:   Wed Nov 25 22:59:24 2015 -0400

loolwsd: stop http server and shut down remaining web sockets

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 1b1706c..a814de1 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1166,13 +1166,6 @@ void LOOLWSD::desktopMain()
 }
 }
 
-// Terminate child processes
-for (auto i : MasterProcessSession::_childProcesses)
-{
-logger().information(Util::logPrefix() + "Requesting child process " + 
std::to_string(i.first) + " to terminate");
-Process::requestTermination(i.first);
-}
-
 exit(Application::EXIT_OK);
 }
 
@@ -1208,6 +1201,7 @@ void LOOLWSD::startupDesktop(int nDesktops)
 
 int LOOLWSD::main(const std::vector& /*args*/)
 {
+int status;
 #ifdef __linux
 char *locale = setlocale(LC_ALL, NULL);
 if (locale == NULL || std::strcmp(locale, "C") == 0)
@@ -1292,7 +1286,6 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 
 while (!LOOLWSD::isShutDown && !LOOLWSD::doTest && 
MasterProcessSession::_childProcesses.size() > 0)
 {
-int status;
 pid_t pid = waitpid(-1, , WUNTRACED | WNOHANG);
 if (pid > 0)
 {
@@ -1335,12 +1328,15 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 if (LOOLWSD::doTest)
 inputThread.join();
 
-// Terminate child processes
-for (auto i : MasterProcessSession::_childProcesses)
-{
-logger().information(Util::logPrefix() + "Requesting child process " + 
std::to_string(i.first) + " to terminate");
-Process::requestTermination(i.first);
-}
+// stop the service, no more request
+srv.stop();
+srv2.stop();
+// close all websockets
+threadPool.joinAll();
+threadPool2.joinAll();
+
+// wait broker process finish
+waitpid(-1, , WUNTRACED);
 
 return Application::EXIT_OK;
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-11-25 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |9 ++---
 loolwsd/LOOLWSD.hpp |1 +
 2 files changed, 7 insertions(+), 3 deletions(-)

New commits:
commit 964d95f04b279233c01cc06d8dbab71af6013e15
Author: Henry Castro 
Date:   Wed Nov 25 22:49:34 2015 -0400

loolwsd: handle a graceful shutdown

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 7ee8694..1b1706c 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -429,7 +429,8 @@ public:
 }
 }
 }
-while (!pollTimeout || (n > 0 && (flags & 
WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE));
+while (!LOOLWSD::isShutDown &&
+(!pollTimeout || (n > 0 && (flags & 
WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE)));
 
 queue.clear();
 queue.put("eof");
@@ -585,6 +586,7 @@ Poco::SharedMemory LOOLWSD::_sharedForkChild("loolwsd", 
sizeof(bool), Poco::Shar
 
 int LOOLWSD::_numPreSpawnedChildren = 10;
 bool LOOLWSD::doTest = false;
+volatile bool LOOLWSD::isShutDown = false;
 #if ENABLE_DEBUG
 bool LOOLWSD::runningAsRoot = false;
 int LOOLWSD::uid = 0;
@@ -605,6 +607,7 @@ LOOLWSD::~LOOLWSD()
 void LOOLWSD::handleSignal(int aSignal)
 {
 std::cout << Util::logPrefix() << "Signal received: " << 
strsignal(aSignal) << std::endl;
+LOOLWSD::isShutDown = true;
 }
 
 void LOOLWSD::setSignals(bool isIgnored)
@@ -1145,7 +1148,7 @@ void LOOLWSD::desktopMain()
 else if (pid < 0)
 std::cout << Util::logPrefix() << "Child error: " << 
strerror(errno);
 
-if ( _sharedForkChild.begin()[0] > 0 )
+if (!LOOLWSD::isShutDown && _sharedForkChild.begin()[0] > 0 )
 {
 _namedMutexLOOL.lock();
 _sharedForkChild.begin()[0] = _sharedForkChild.begin()[0] - 1;
@@ -1287,7 +1290,7 @@ int LOOLWSD::main(const std::vector& 
/*args*/)
 waitForTerminationRequest();
 }
 
-while (!LOOLWSD::doTest && MasterProcessSession::_childProcesses.size() > 
0)
+while (!LOOLWSD::isShutDown && !LOOLWSD::doTest && 
MasterProcessSession::_childProcesses.size() > 0)
 {
 int status;
 pid_t pid = waitpid(-1, , WUNTRACED | WNOHANG);
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index 2e63038..342b36c 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -33,6 +33,7 @@ public:
 static int portNumber;
 static int timeoutCounter;
 static bool doTest;
+static bool volatile isShutDown;
 static std::string cache;
 static std::string sysTemplate;
 static std::string loTemplate;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-11-19 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

New commits:
commit 41d94bc9da0b92c435552a2e25ae17e6af4270b3
Author: Henry Castro 
Date:   Thu Nov 19 07:32:48 2015 -0400

loolwsd: clear queue before socket shutdown

This cause broke pipe exception

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 79181e5..2954842 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -423,6 +423,10 @@ public:
 }
 }
 while (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != 
WebSocket::FRAME_OP_CLOSE);
+
+queue.clear();
+queue.put("eof");
+queueHandlerThread.join();
 }
 catch (WebSocketException& exc)
 {
@@ -446,9 +450,6 @@ public:
 {
 Application::instance().logger().error(Util::logPrefix() + 
"IOException: " + exc.message());
 }
-queue.clear();
-queue.put("eof");
-queueHandlerThread.join();
 }
 };
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-11-19 Thread Miklos Vajna
 loolwsd/LOOLWSD.cpp |   26 +-
 1 file changed, 13 insertions(+), 13 deletions(-)

New commits:
commit bc38b2c265dcf48af82a1800f195d972ff3e4a06
Author: Miklos Vajna 
Date:   Thu Nov 19 11:23:45 2015 +0100

loolwsd: -Werror,-Wshadow

With this, loolwsd builds with clang.

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 31767a1..79181e5 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1004,16 +1004,16 @@ void LOOLWSD::desktopMain()
 _childId = (((Poco::UInt64)_rng.next()) << 32) | _rng.next() | 1;
 rngLock.unlock();
 
-Path jail = Path::forDirectory(LOOLWSD::childRoot + Path::separator() + 
std::to_string(_childId));
-File(jail).createDirectory();
+Path jailPath = Path::forDirectory(LOOLWSD::childRoot + Path::separator() 
+ std::to_string(_childId));
+File(jailPath).createDirectory();
 
-Path jailLOInstallation(jail, LOOLWSD::loSubPath);
+Path jailLOInstallation(jailPath, LOOLWSD::loSubPath);
 jailLOInstallation.makeDirectory();
 File(jailLOInstallation).createDirectory();
 
 // Copy (link) LO installation and other necessary files into it from the 
template
 
-linkOrCopy(LOOLWSD::sysTemplate, jail);
+linkOrCopy(LOOLWSD::sysTemplate, jailPath);
 linkOrCopy(LOOLWSD::loTemplate, jailLOInstallation);
 
 // We need this because sometimes the hostname is not resolved
@@ -1023,35 +1023,35 @@ void LOOLWSD::desktopMain()
 File networkFile(*it);
 if (networkFile.exists())
 {
-networkFile.copyTo(Path(jail, "/etc").toString());
+networkFile.copyTo(Path(jailPath, "/etc").toString());
 }
 }
 #ifdef __linux
 // Create the urandom and random devices
-File(Path(jail, "/dev")).createDirectory();
-if (mknod((jail.toString() + "/dev/random").c_str(),
+File(Path(jailPath, "/dev")).createDirectory();
+if (mknod((jailPath.toString() + "/dev/random").c_str(),
 S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | 
S_IWOTH,
 makedev(1, 8)) != 0)
 {
 Application::instance().logger().error(Util::logPrefix() +
-"mknod(" + jail.toString() + "/dev/random) failed: " +
+"mknod(" + jailPath.toString() + "/dev/random) failed: " +
 strerror(errno));
 
 }
-if (mknod((jail.toString() + "/dev/urandom").c_str(),
+if (mknod((jailPath.toString() + "/dev/urandom").c_str(),
 S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | 
S_IWOTH,
 makedev(1, 9)) != 0)
 {
 Application::instance().logger().error(Util::logPrefix() +
-"mknod(" + jail.toString() + "/dev/urandom) failed: " +
+"mknod(" + jailPath.toString() + "/dev/urandom) failed: " +
 strerror(errno));
 }
 #endif
 
-Application::instance().logger().information("desktopMain -> chroot(\"" + 
jail.toString() + "\")");
-if (chroot(jail.toString().c_str()) == -1)
+Application::instance().logger().information("desktopMain -> chroot(\"" + 
jailPath.toString() + "\")");
+if (chroot(jailPath.toString().c_str()) == -1)
 {
-logger().error("chroot(\"" + jail.toString() + "\") failed: " + 
strerror(errno));
+logger().error("chroot(\"" + jailPath.toString() + "\") failed: " + 
strerror(errno));
 exit(Application::EXIT_UNAVAILABLE);
 }
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-10-28 Thread Miklos Vajna
 loolwsd/LOOLWSD.cpp |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

New commits:
commit 1409ef11ec0f27f4c7035c94ec710a253861d1a9
Author: Miklos Vajna 
Date:   Wed Oct 28 17:29:45 2015 +0100

loolwsd: allow duplicate messages for all message types expect tile

To be on the safe side, I only allowed "uno" previously, but Mihai
confirmed that the intention was to filter out "tile" duplicates, so
filter out only that.

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index ffea9ea..3ca5c6f 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -403,8 +403,8 @@ public:
 // Also forward the "canceltiles" to the child 
process, if any
 session->handleInput(buffer, n);
 }
-// Filtering out duplicated uno commands would 
change the meaning of the message sequence.
-else if (!queue.alreadyInQueue(firstLine) || 
firstLine.find("uno") == 0)
+// Filter out duplicated tile messages.
+else if (firstLine.find("tile") != 0 || 
!queue.alreadyInQueue(firstLine))
 {
 queue.put(firstLine);
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-10-28 Thread Miklos Vajna
 loolwsd/LOOLWSD.cpp |3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

New commits:
commit b5ed22c4d9c68cb93d8ba0d7b689533cd4b38f82
Author: Miklos Vajna 
Date:   Wed Oct 28 10:24:12 2015 +0100

loolwsd: avoid filtering out "duplicated" uno commands

Problem since commit 8f48dabf28076fc448ff76ec5da1cdd59990c5b1 (loolwsd:
discard requests that are in the queue already, 2015-07-21), e.g.
"select-all, paste, select-all" doesn't have the same meaning as
"select-all, paste".

Quite possibly the condition should be inverted, and filtering out
should be done only for a few commands, like "tile"; but at least
filtering out "uno" is definitely problematic.

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 4771ec4..3e30e62 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -403,7 +403,8 @@ public:
 // Also forward the "canceltiles" to the child 
process, if any
 session->handleInput(buffer, n);
 }
-else if (!queue.alreadyInQueue(firstLine))
+// Filtering out duplicated uno commands would 
change the meaning of the message sequence.
+else if (!queue.alreadyInQueue(firstLine) || 
firstLine.find("uno") == 0)
 {
 queue.put(firstLine);
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-10-16 Thread Miklos Vajna
 loolwsd/LOOLWSD.cpp |8 
 1 file changed, 4 insertions(+), 4 deletions(-)

New commits:
commit 700b7d08b7e80826a918e8095815bf888b5f74d2
Author: Miklos Vajna 
Date:   Fri Oct 16 15:23:49 2015 +0200

loolwsd: allow frame size of 200K

I got:

WebSocketException: Insufficient buffer for payload size 113579

So double the allocated size: that seems to help.

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index ac36945..3cc510c 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -262,7 +262,7 @@ public:
 ws->setReceiveTimeout(0);
 do
 {
-char buffer[10];
+char buffer[20];
 n = ws->receiveFrame(buffer, sizeof(buffer), flags);
 
 if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != 
WebSocket::FRAME_OP_CLOSE)
@@ -316,7 +316,7 @@ public:
 }
 catch (WebSocketException& exc)
 {
-Application::instance().logger().error(Util::logPrefix() + 
"WebSocketException: " + exc.message());
+Application::instance().logger().error(Util::logPrefix() + 
"RequestHandler::handleRequest(), WebSocketException: " + exc.message());
 switch (exc.code())
 {
 case WebSocket::WS_ERR_HANDSHAKE_UNSUPPORTED_VERSION:
@@ -384,7 +384,7 @@ public:
 {
 do
 {
-char buffer[10];
+char buffer[20];
 n = _ws.receiveFrame(buffer, sizeof(buffer), flags);
 
 if (n > 0 && (flags & WebSocket::FRAME_OP_BITMASK) != 
WebSocket::FRAME_OP_CLOSE)
@@ -399,7 +399,7 @@ public:
 }
 catch (WebSocketException& exc)
 {
-Application::instance().logger().error(Util::logPrefix() + 
"WebSocketException: " + exc.message());
+Application::instance().logger().error(Util::logPrefix() + 
"TestOutput::run(), WebSocketException: " + exc.message());
 _ws.close();
 }
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-10-16 Thread Miklos Vajna
 loolwsd/LOOLWSD.cpp |   43 +--
 1 file changed, 41 insertions(+), 2 deletions(-)

New commits:
commit 9212c1c321fd76b729416500100bc9aad7b785c6
Author: Miklos Vajna 
Date:   Fri Oct 16 17:38:24 2015 +0200

loolwsd: convert-to handler skeleton

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 6b13c8b..e198203 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -67,6 +67,7 @@ DEALINGS IN THE SOFTWARE.
 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -76,7 +77,9 @@ DEALINGS IN THE SOFTWARE.
 #include 
 #include 
 #include 
+#include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -176,6 +179,24 @@ private:
 tsqueue& _queue;
 };
 
+/// Handles the filename part of the convert-to POST request payload.
+class ConvertToPartHandler : public Poco::Net::PartHandler
+{
+std::vector& _buffer;
+public:
+ConvertToPartHandler(std::vector& buffer)
+: _buffer(buffer)
+{
+}
+
+virtual void handlePart(const Poco::Net::MessageHeader& /*header*/, 
std::istream& stream) override
+{
+char c;
+while (stream.get(c))
+_buffer.push_back(c);
+}
+};
+
 class RequestHandler: public HTTPRequestHandler
 /// Handle a WebSocket connection or a simple HTTP request.
 {
@@ -199,10 +220,28 @@ public:
 
 if(!(request.find("Upgrade") != request.end() && 
Poco::icompare(request["Upgrade"], "websocket") == 0))
 {
-// The user might request a file to download
 StringTokenizer tokens(request.getURI(), "/");
-if (tokens.count() == 4)
+if (tokens.count() == 2 && tokens[1] == "convert-to")
+{
+std::vector buffer;
+ConvertToPartHandler handler(buffer);
+Poco::Net::HTMLForm form(request, request.stream(), handler);
+std::string format;
+if (form.has("format"))
+format = form.get("format");
+
+if (!format.empty() && !buffer.empty())
+{
+// TODO implement actual conversion
+}
+
+response.setStatus(HTTPResponse::HTTP_OK);
+response.setContentLength(0);
+response.send();
+}
+else if (tokens.count() == 4)
 {
+// The user might request a file to download
 std::string dirPath = LOOLWSD::childRoot + "/" + tokens[1] + 
LOOLSession::jailDocumentURL + "/" + tokens[2];
 std::string filePath = dirPath + "/" + tokens[3];
 std::cout << Util::logPrefix() << "HTTP request for: " << 
filePath << std::endl;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-10-16 Thread Miklos Vajna
 loolwsd/LOOLWSD.cpp |   35 +++
 1 file changed, 19 insertions(+), 16 deletions(-)

New commits:
commit 63bf9a132917d9089f3a847144d8ad6b01885777
Author: Miklos Vajna 
Date:   Fri Oct 16 15:47:39 2015 +0200

loolwsd: invert this condition, so it's possible to add other cases

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 3cc510c..6b13c8b 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -201,26 +201,29 @@ public:
 {
 // The user might request a file to download
 StringTokenizer tokens(request.getURI(), "/");
-if (tokens.count() != 4)
+if (tokens.count() == 4)
 {
-response.setStatus(HTTPResponse::HTTP_BAD_REQUEST);
-response.setContentLength(0);
-response.send();
-}
-std::string dirPath = LOOLWSD::childRoot + "/" + tokens[1] + 
LOOLSession::jailDocumentURL + "/" + tokens[2];
-std::string filePath = dirPath + "/" + tokens[3];
-std::cout << Util::logPrefix() << "HTTP request for: " << filePath 
<< std::endl;
-File file(filePath);
-if (file.exists())
-{
-response.set("Access-Control-Allow-Origin", "*");
-response.sendFile(filePath, "application/octet-stream");
-File dir(dirPath);
-dir.remove(true);
+std::string dirPath = LOOLWSD::childRoot + "/" + tokens[1] + 
LOOLSession::jailDocumentURL + "/" + tokens[2];
+std::string filePath = dirPath + "/" + tokens[3];
+std::cout << Util::logPrefix() << "HTTP request for: " << 
filePath << std::endl;
+File file(filePath);
+if (file.exists())
+{
+response.set("Access-Control-Allow-Origin", "*");
+response.sendFile(filePath, "application/octet-stream");
+File dir(dirPath);
+dir.remove(true);
+}
+else
+{
+response.setStatus(HTTPResponse::HTTP_NOT_FOUND);
+response.setContentLength(0);
+response.send();
+}
 }
 else
 {
-response.setStatus(HTTPResponse::HTTP_NOT_FOUND);
+response.setStatus(HTTPResponse::HTTP_BAD_REQUEST);
 response.setContentLength(0);
 response.send();
 }
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-10-13 Thread Tor Lillqvist
 loolwsd/LOOLWSD.cpp |7 +++
 1 file changed, 7 insertions(+)

New commits:
commit 7e78f3f0c611c5bb09a995bc149cc9ec0097813d
Author: Tor Lillqvist 
Date:   Tue Oct 13 20:05:42 2015 +0300

bugs.ccu#1248: If locale is C, set it to en_US.utf8

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index bb83728..ac36945 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -41,6 +41,7 @@ DEALINGS IN THE SOFTWARE.
 // number of child processes, each which handles a viewing (editing) session 
for one document.
 
 #include 
+#include 
 #include 
 #include 
 
@@ -1070,6 +1071,12 @@ void LOOLWSD::startupDesktop(int nDesktops)
 
 int LOOLWSD::main(const std::vector& args)
 {
+#ifdef __linux
+char *locale = setlocale(LC_ALL, NULL);
+if (locale == NULL || std::strcmp(locale, "C") == 0)
+setlocale(LC_ALL, "en_US.utf8");
+#endif
+
 if (access(cache.c_str(), R_OK | W_OK | X_OK) != 0)
 {
 std::cout << "Unable to access " << cache <<
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-09-11 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |   13 -
 1 file changed, 12 insertions(+), 1 deletion(-)

New commits:
commit 8a10a16855534c1d41a138ea66e881cf3a16bbc1
Author: Henry Castro 
Date:   Fri Sep 11 16:31:43 2015 -0400

loolwsd: restore interactive testing

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 0b12474..e12cbf4 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1114,7 +1114,15 @@ int LOOLWSD::main(const std::vector& args)
 
 _namedMutexLOOL.unlock();
 
-while (MasterProcessSession::_childProcesses.size() > 0)
+TestInput input(*this, svs, srv);
+Thread inputThread;
+if (LOOLWSD::doTest)
+{
+inputThread.start(input);
+waitForTerminationRequest();
+}
+
+while (!LOOLWSD::doTest && MasterProcessSession::_childProcesses.size() > 
0)
 {
 int status;
 pid_t pid = waitpid(-1, , WUNTRACED | WNOHANG);
@@ -1156,6 +1164,9 @@ int LOOLWSD::main(const std::vector& args)
 }
 }
 
+if (LOOLWSD::doTest)
+inputThread.join();
+
 // Terminate child processes
 for (auto i : MasterProcessSession::_childProcesses)
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-09-04 Thread Mihai Varga
 loolwsd/LOOLWSD.cpp |6 ++
 1 file changed, 6 insertions(+)

New commits:
commit 515e6f7feaf7587300bbb399b19aba791c37f503
Author: Mihai Varga 
Date:   Fri Sep 4 18:43:47 2015 +0300

loolwsd: copy /etc/resolv.conf in the jail

Because sometimes the hostname is not resolved

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 798428c..33fa261 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -894,6 +894,12 @@ void LOOLWSD::desktopMain()
 linkOrCopy(LOOLWSD::sysTemplate, jail);
 linkOrCopy(LOOLWSD::loTemplate, jailLOInstallation);
 
+// We need this because sometimes the hostname is not resolved
+File resolv("/etc/resolv.conf");
+if (resolv.exists())
+{
+resolv.copyTo(Path(jail, "/etc").toString());
+}
 #ifdef __linux
 // Create the urandom and random devices
 File(Path(jail, "/dev")).createDirectory();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-08-08 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |   27 +++
 1 file changed, 27 insertions(+)

New commits:
commit 54b1e1b6120af3c24316c5ac28424456a46bdceb
Author: Henry Castro hcas...@collabora.com
Date:   Sat Aug 8 07:55:54 2015 -0400

loolwsd: set thread name to debug socket

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 3d4869e..6988e11 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -48,6 +48,7 @@ DEALINGS IN THE SOFTWARE.
 #include sys/capability.h
 #include sys/types.h
 #include sys/wait.h
+#include sys/prctl.h
 #endif
 
 #include ftw.h
@@ -154,6 +155,11 @@ public:
 
 void run() override
 {
+#ifdef __linux
+if (prctl(PR_SET_NAME, reinterpret_castunsigned 
long(queue_handler), 0, 0, 0) != 0)
+std::cout  Util::logPrefix()  Cannot set thread name :  
strerror(errno)  std::endl;
+#endif
+
 while (true)
 {
 std::string input = _queue.get();
@@ -179,6 +185,17 @@ public:
 
 void handleRequest(HTTPServerRequest request, HTTPServerResponse 
response) override
 {
+#ifdef __linux
+std::string thread_name;
+if (request.serverAddress().port() == LOOLWSD::MASTER_PORT_NUMBER)
+thread_name = prision_socket;
+else
+thread_name = client_socket;
+
+if (prctl(PR_SET_NAME, reinterpret_castunsigned 
long(thread_name.c_str()), 0, 0, 0) != 0)
+std::cout  Util::logPrefix()  Cannot set thread name :  
strerror(errno)  std::endl;
+#endif
+
 if(!(request.find(Upgrade) != request.end()  
Poco::icompare(request[Upgrade], websocket) == 0))
 {
 response.setStatusAndReason(HTTPResponse::HTTP_BAD_REQUEST);
@@ -728,6 +745,11 @@ namespace
 // Writer, Impress or Calc
 void LOOLWSD::componentMain()
 {
+#ifdef __linux
+if (prctl(PR_SET_NAME, reinterpret_castunsigned long(libreofficekit), 
0, 0, 0) != 0)
+std::cout  Util::logPrefix()  Cannot set thread name :  
strerror(errno)  std::endl;
+#endif
+
 try
 {
 _namedMutexLOOL.lock();
@@ -847,6 +869,11 @@ void LOOLWSD::startupComponent(int nComponents)
 
 void LOOLWSD::desktopMain()
 {
+#ifdef __linux
+if (prctl(PR_SET_NAME, reinterpret_castunsigned long(loolbroker), 0, 
0, 0) != 0)
+std::cout  Util::logPrefix()  Cannot set thread name :  
strerror(errno)  std::endl;
+#endif
+
 // Initialization
 std::unique_lockstd::mutex rngLock(_rngMutex);
 _childId = (((Poco::UInt64)_rng.next())  32) | _rng.next() | 1;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-08-08 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |3 +++
 1 file changed, 3 insertions(+)

New commits:
commit 7aeca2f92b23cf3c247eaec260a7885c3912ab17
Author: Henry Castro hcas...@collabora.com
Date:   Sat Aug 8 08:20:16 2015 -0400

loolwsd: destroy LOKit when child finished

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 6988e11..798428c 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -825,6 +825,9 @@ void LOOLWSD::componentMain()
 queue.clear();
 queue.put(eof);
 queueHandlerThread.join();
+
+// Destroy LibreOfficeKit
+loKit-pClass-destroy(loKit);
 }
 catch (Exception exc)
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-07-24 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |   14 ++
 loolwsd/LOOLWSD.hpp |4 +++-
 2 files changed, 17 insertions(+), 1 deletion(-)

New commits:
commit 6dafcc753f64fc70468b4336166b7893057ab45f
Author: Henry Castro hcas...@collabora.com
Date:   Fri Jul 24 14:10:24 2015 -0400

loolwsd: process sleep for amount of time ...

specified by MAINTENANCE_INTERVAL

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 4bccf72..7684d82 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -413,6 +413,7 @@ private:
 };
 
 int LOOLWSD::portNumber = DEFAULT_CLIENT_PORT_NUMBER;
+int LOOLWSD::timeoutCounter = 0;
 std::string LOOLWSD::cache = LOOLWSD_CACHEDIR;
 std::string LOOLWSD::sysTemplate;
 std::string LOOLWSD::loTemplate;
@@ -954,6 +955,13 @@ void LOOLWSD::desktopMain()
 if (createComponent()  0 )
 break;
 }
+
+++timeoutCounter;
+if (timeoutCounter == INTERVAL_PROBES)
+{
+timeoutCounter = 0;
+sleep(MAINTENANCE_INTERVAL);
+}
 }
 
 // Terminate child processes
@@ -1098,6 +1106,12 @@ int LOOLWSD::main(const std::vectorstd::string args)
 else if (pid  0)
 std::cout  Util::logPrefix()  Child error:   
strerror(errno);
 
+++timeoutCounter;
+if (timeoutCounter == INTERVAL_PROBES)
+{
+timeoutCounter = 0;
+sleep(MAINTENANCE_INTERVAL);
+}
 }
 
 // Terminate child processes
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index 099de04..2824409 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -31,6 +31,7 @@ public:
 // An Application is a singleton anyway, so just keep these as
 // statics
 static int portNumber;
+static int timeoutCounter;
 static std::string cache;
 static std::string sysTemplate;
 static std::string loTemplate;
@@ -41,7 +42,8 @@ public:
 
 static const int DEFAULT_CLIENT_PORT_NUMBER = 9980;
 static const int MASTER_PORT_NUMBER = 9981;
-static const int FILE_PORT_NUMBER = 9979;
+static const int INTERVAL_PROBES = 10;
+static const int MAINTENANCE_INTERVAL = 100;
 static const std::string CHILD_URI;
 static const std::string PIDLOG;
 
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-07-19 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |9 +
 loolwsd/LOOLWSD.hpp |1 +
 2 files changed, 10 insertions(+)

New commits:
commit de3d97d5a4f4a711808c98e067af8a01b4956e78
Author: Henry Castro hcas...@collabora.com
Date:   Sun Jul 19 16:49:11 2015 -0400

loolwsd: create PID log file.

The PID log file is used by external utilities
to report processes, threads, etc.

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index e38a971..0670876 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -92,6 +92,7 @@ DEALINGS IN THE SOFTWARE.
 #include Poco/Net/Net.h
 #include Poco/ThreadLocal.h
 #include Poco/NamedMutex.h
+#include Poco/FileStream.h
 
 
 #include LOOLProtocol.hpp
@@ -429,6 +430,7 @@ bool LOOLWSD::runningAsRoot = false;
 int LOOLWSD::uid = 0;
 #endif
 const std::string LOOLWSD::CHILD_URI = /loolws/child/;
+const std::string LOOLWSD::PIDLOG = /tmp/loolwsd.pid;
 
 LOOLWSD::LOOLWSD() :
 _doTest(false),
@@ -1024,6 +1026,13 @@ int LOOLWSD::main(const std::vectorstd::string args)
 if (_doTest)
 _numPreSpawnedChildren = 1;
 
+// log pid information
+{
+Poco::FileOutputStream filePID(LOOLWSD::PIDLOG);
+if (filePID.good())
+filePID  Process::id();
+}
+
 std::unique_lockstd::mutex rngLock(_rngMutex);
 _childId = (((Poco::UInt64)_rng.next())  32) | _rng.next() | 1;
 rngLock.unlock();
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index 86896a8..099de04 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -43,6 +43,7 @@ public:
 static const int MASTER_PORT_NUMBER = 9981;
 static const int FILE_PORT_NUMBER = 9979;
 static const std::string CHILD_URI;
+static const std::string PIDLOG;
 
 protected:
 void initialize(Poco::Util::Application self) override;
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-07-18 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |   10 +-
 loolwsd/LOOLWSD.hpp |2 ++
 2 files changed, 7 insertions(+), 5 deletions(-)

New commits:
commit 66756a77a91d161961407fc09fe30d610823c810
Author: Henry Castro hcas...@collabora.com
Date:   Sat Jul 18 12:35:16 2015 -0400

loolwsd: change named mutex to private static.

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 9af4aad..e38a971 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -420,7 +420,7 @@ std::string LOOLWSD::loSubPath = lo;
 std::string LOOLWSD::jail;
 std::mutex LOOLWSD::_rngMutex;
 Random LOOLWSD::_rng;
-static NamedMutex namedMutexLOOL(loolwsd);
+Poco::NamedMutex LOOLWSD::_namedMutexLOOL(loolwsd);
 Poco::SharedMemory LOOLWSD::_sharedForkChild(loolwsd, sizeof(bool), 
Poco::SharedMemory::AM_WRITE);
 
 int LOOLWSD::_numPreSpawnedChildren = 10;
@@ -726,7 +726,7 @@ void LOOLWSD::componentMain()
 {
 try
 {
-namedMutexLOOL.lock();
+_namedMutexLOOL.lock();
 
 #ifdef __APPLE__
 LibreOfficeKit *loKit(lok_init_2((/ + loSubPath + 
/Frameworks).c_str(), file:///user));
@@ -740,7 +740,7 @@ void LOOLWSD::componentMain()
 exit(Application::EXIT_UNAVAILABLE);
 }
 
-namedMutexLOOL.unlock();
+_namedMutexLOOL.unlock();
 
 // Open websocket connection between the child process and the
 // parent. The parent forwards us requests that it can't handle.
@@ -1028,7 +1028,7 @@ int LOOLWSD::main(const std::vectorstd::string args)
 _childId = (((Poco::UInt64)_rng.next())  32) | _rng.next() | 1;
 rngLock.unlock();
 
-namedMutexLOOL.lock();
+_namedMutexLOOL.lock();
 
 startupDesktop(1);
 
@@ -1053,7 +1053,7 @@ int LOOLWSD::main(const std::vectorstd::string args)
 
 srv2.start();
 
-namedMutexLOOL.unlock();
+_namedMutexLOOL.unlock();
 
 while (MasterProcessSession::_childProcesses.size()  0)
 {
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index befed88..86896a8 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -20,6 +20,7 @@
 #include Poco/Path.h
 #include Poco/Util/ServerApplication.h
 #include Poco/SharedMemory.h
+#include Poco/NamedMutex.h
 
 class LOOLWSD: public Poco::Util::ServerApplication
 {
@@ -65,6 +66,7 @@ private:
 static int _numPreSpawnedChildren;
 static std::mutex _rngMutex;
 static Poco::Random _rng;
+static Poco::NamedMutex _namedMutexLOOL;
 
 #if ENABLE_DEBUG
 public:
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-07-17 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

New commits:
commit 161e5534ec3669e50662687769ba02aba6cfaf70
Author: Henry Castro hcas...@collabora.com
Date:   Fri Jul 17 21:54:26 2015 -0400

loolwsd: mutex lock when loKit initialization.

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index ec7288f..9af4aad 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -726,9 +726,7 @@ void LOOLWSD::componentMain()
 {
 try
 {
-
-// initialisation
-//_childId = Process::id();
+namedMutexLOOL.lock();
 
 #ifdef __APPLE__
 LibreOfficeKit *loKit(lok_init_2((/ + loSubPath + 
/Frameworks).c_str(), file:///user));
@@ -742,8 +740,6 @@ void LOOLWSD::componentMain()
 exit(Application::EXIT_UNAVAILABLE);
 }
 
-// wait until desktop sockets setup
-namedMutexLOOL.lock();
 namedMutexLOOL.unlock();
 
 // Open websocket connection between the child process and the
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-07-17 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |   64 +++-
 loolwsd/LOOLWSD.hpp |1 
 2 files changed, 29 insertions(+), 36 deletions(-)

New commits:
commit 63a33b39f69b674ca835fdef7a1f06d6f6e81928
Author: Henry Castro hcas...@collabora.com
Date:   Fri Jul 17 17:55:27 2015 -0400

loolwsd: moved server socket to main function.

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 76d4a73..ec7288f 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -998,9 +998,36 @@ void LOOLWSD::startupDesktop(int nDesktops)
 }
 }
 
-
-void LOOLWSD::loolMain()
+int LOOLWSD::main(const std::vectorstd::string args)
 {
+if (access(cache.c_str(), R_OK | W_OK | X_OK) != 0)
+{
+std::cout  Unable to access   cache 
+, please make sure it exists, and has write permission for this 
user.  std::endl;
+return Application::EXIT_UNAVAILABLE;
+}
+
+// We use the same option set for both parent and child loolwsd,
+// so must check options required in the parent (but not in the
+// child) separately now. Also check for options that are
+// meaningless for the parent.
+if (sysTemplate == )
+throw MissingOptionException(systemplate);
+if (loTemplate == )
+throw MissingOptionException(lotemplate);
+if (childRoot == )
+throw MissingOptionException(childroot);
+
+if (_childId != 0)
+throw IncompatibleOptionsException(child);
+if (jail != )
+throw IncompatibleOptionsException(jail);
+if (portNumber == MASTER_PORT_NUMBER)
+throw IncompatibleOptionsException(port);
+
+if (_doTest)
+_numPreSpawnedChildren = 1;
+
 std::unique_lockstd::mutex rngLock(_rngMutex);
 _childId = (((Poco::UInt64)_rng.next())  32) | _rng.next() | 1;
 rngLock.unlock();
@@ -1074,39 +1101,6 @@ void LOOLWSD::loolMain()
 logger().information(Util::logPrefix() + Requesting child process  + 
std::to_string(i.first) +  to terminate);
 Process::requestTermination(i.first);
 }
-}
-
-int LOOLWSD::main(const std::vectorstd::string args)
-{
-if (access(cache.c_str(), R_OK | W_OK | X_OK) != 0)
-{
-std::cout  Unable to access   cache 
-, please make sure it exists, and has write permission for this 
user.  std::endl;
-return Application::EXIT_UNAVAILABLE;
-}
-
-// We use the same option set for both parent and child loolwsd,
-// so must check options required in the parent (but not in the
-// child) separately now. Also check for options that are
-// meaningless for the parent.
-if (sysTemplate == )
-throw MissingOptionException(systemplate);
-if (loTemplate == )
-throw MissingOptionException(lotemplate);
-if (childRoot == )
-throw MissingOptionException(childroot);
-
-if (_childId != 0)
-throw IncompatibleOptionsException(child);
-if (jail != )
-throw IncompatibleOptionsException(jail);
-if (portNumber == MASTER_PORT_NUMBER)
-throw IncompatibleOptionsException(port);
-
-if (_doTest)
-_numPreSpawnedChildren = 1;
-
-loolMain();
 
 return Application::EXIT_OK;
 }
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index 51e05ad..befed88 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -55,7 +55,6 @@ private:
 bool childMode() const;
 void componentMain();
 void desktopMain();
-void loolMain();
 void startupComponent(int nComponents);
 void startupDesktop(int nDesktop);
 int  createComponent();
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-07-16 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |   41 +
 1 file changed, 29 insertions(+), 12 deletions(-)

New commits:
commit 061a2bfc3dd2057abdc3b517189d3ee012b9bf46
Author: Henry Castro hcas...@collabora.com
Date:   Thu Jul 16 18:05:28 2015 -0400

loolwsd: rework child monitor status.

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index f6b8457..e5be693 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1018,25 +1018,42 @@ void LOOLWSD::desktopMain()
 
 namedMutexLOOL.unlock();
 
+/* Pause for a second */
+sleep(1);
+
 while (MasterProcessSession::_childProcesses.size()  0)
 {
 int status;
 pid_t pid = waitpid(-1, status, WUNTRACED | WNOHANG);
-if (pid  0)
+if (pid  0)
 {
-if (errno == ECHILD)
+if ( MasterProcessSession::_childProcesses.find(pid) != 
MasterProcessSession::_childProcesses.end() )
 {
-// We have spawned children, and we think that we still have 
them running,
-// but we don't, huh? Something badly messed up, or just a 
timing glitch,
-// like we are at the moment in the process of spawning new 
children?
-// Sleep or return from the function (i.e. finish the 
Undertaker thread)?
-std::cout  Util::logPrefix()  No child processes even if 
we think there should be some!?  std::endl;
- }
-}
+if ((WIFEXITED(status) || WIFSIGNALED(status) || 
WTERMSIG(status) ) )
+{
+std::cout  Util::logPrefix()  One of our known child 
processes died :  std::to_string(pid)   std::endl;
+MasterProcessSession::_childProcesses.erase(pid);
+}
+
+if ( WCOREDUMP(status) )
+std::cout  Util::logPrefix()  The child produced a 
core dump.  std::endl;
+
+if ( WIFSTOPPED(status) )
+std::cout  Util::logPrefix()  The child process was 
stopped by delivery of a signal.  std::endl;
 
-if ((WIFEXITED(status) || WIFSIGNALED(status) || WTERMSIG(status) ) 
-MasterProcessSession::_childProcesses.find(pid) != 
MasterProcessSession::_childProcesses.end())
-std::cout  Util::logPrefix()  One of our known child 
processes died  std::endl;
+if ( WSTOPSIG(status) )
+std::cout  Util::logPrefix()  The child process was 
stopped.  std::endl;
+
+if ( WIFCONTINUED(status) )
+std::cout  Util::logPrefix()  The child process was 
resumed.  std::endl;
+}
+else
+{
+std::cout  Util::logPrefix()  None of our known child 
processes died :  std::to_string(pid)   std::endl;
+}
+}
+else if (pid  0)
+std::cout  Util::logPrefix()  Child error:   
strerror(errno);
 
 if (MasterProcessSession::getAvailableChildSessions() == 0  
MasterProcessSession::getPendingPreSpawnedChildren() == 0 )
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-07-15 Thread Henry Castro
 loolwsd/LOOLWSD.cpp |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

New commits:
commit 3f3b9f767581ac629c941f4c15f4da9eaae650ed
Author: Henry Castro hcas...@collabora.com
Date:   Wed Jul 15 09:15:12 2015 -0400

loolwsd: remove WSTOPSIG(status).

No child returns status process stop. This cause problems
when we attach one child to debug.

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 61fe7a6..77be226 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1052,7 +1052,7 @@ void LOOLWSD::desktopMain()
 MasterProcessSession::_childProcesses.find(pid) != 
MasterProcessSession::_childProcesses.end())
 std::cout  Util::logPrefix()  One of our known child 
processes died  std::endl;
 
-if (WSTOPSIG(status)  
MasterProcessSession::getAvailableChildSessions() == 0  
MasterProcessSession::getPendingPreSpawnedChildren() == 0 )
+if (MasterProcessSession::getAvailableChildSessions() == 0  
MasterProcessSession::getPendingPreSpawnedChildren() == 0 )
 {
 std::cout  Util::logPrefix()  No availabe child session, fork 
new one  std::endl;
 if (createComponent()  0 )
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


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

2015-05-22 Thread Tor Lillqvist
 loolwsd/LOOLWSD.cpp |   19 ---
 1 file changed, 16 insertions(+), 3 deletions(-)

New commits:
commit 8612aab7c4566d6eaefa6be14f1785ebed3538ab
Author: Tor Lillqvist t...@collabora.com
Date:   Fri May 22 10:57:17 2015 +0100

Make this build on OS X

Note that I said build, not work.

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index f2e7252..fe17cda 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -41,10 +41,10 @@ DEALINGS IN THE SOFTWARE.
 // number of child processes, each which handles a viewing (editing) session 
for one document.
 
 #include errno.h
+#include pwd.h
 #include unistd.h
 
 #ifdef __linux
-#include pwd.h
 #include sys/capability.h
 #include sys/types.h
 #include sys/wait.h
@@ -529,7 +529,11 @@ void LOOLWSD::displayHelp()
 
 namespace
 {
-void dropCapability(cap_value_t capability)
+void dropCapability(
+#ifdef __linux
+cap_value_t capability
+#endif
+)
 {
 #ifdef __linux
 cap_t caps;
@@ -596,8 +600,9 @@ int LOOLWSD::childMain()
 {
 std::cout  Util::logPrefix()  Child here! id=  _childId  
std::endl;
 
+#ifdef __linux
 dropCapability(CAP_FOWNER);
-
+#endif
 // We use the same option set for both parent and child loolwsd,
 // so must check options required in the child (but not in the
 // parent) separately now. And also for options that are
@@ -618,7 +623,11 @@ int LOOLWSD::childMain()
 exit(1);
 }
 
+#ifdef __linux
 dropCapability(CAP_SYS_CHROOT);
+#else
+dropCapability();
+#endif
 
 if (chdir(/) == -1)
 {
@@ -690,7 +699,11 @@ int LOOLWSD::main(const std::vectorstd::string args)
 if (childMode())
 return childMain();
 
+#ifdef __linux
 dropCapability(CAP_SYS_CHROOT);
+#else
+dropCapability();
+#endif
 
 if (access(LOOLWSD_CACHEDIR, R_OK | W_OK | X_OK) != 0)
 {
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


<    1   2