loolwsd/Connect.cpp | 45 ++++++++++++++++++++++++++------------- loolwsd/LOOLWSD.cpp | 27 +++++++++++------------ loolwsd/LOOLWSD.hpp | 4 --- loolwsd/MasterProcessSession.hpp | 4 +-- 4 files changed, 46 insertions(+), 34 deletions(-)
New commits: commit 418fc3f2032807a62903610a13a0033097fc9edb Author: Tor Lillqvist <t...@collabora.com> Date: Tue Mar 22 20:06:44 2016 +0200 Use SSL here, too diff --git a/loolwsd/Connect.cpp b/loolwsd/Connect.cpp index e0f82ea..d53ae43 100644 --- a/loolwsd/Connect.cpp +++ b/loolwsd/Connect.cpp @@ -12,25 +12,28 @@ #include <fstream> #include <iostream> -#include <Poco/Net/HTTPClientSession.h> +#include <Poco/Net/AcceptCertificateHandler.h> +#include <Poco/Net/Context.h> +#include <Poco/Net/HTTPSClientSession.h> #include <Poco/Net/HTTPRequest.h> #include <Poco/Net/HTTPResponse.h> +#include <Poco/Net/InvalidCertificateHandler.h> #include <Poco/Net/NetException.h> +#include <Poco/Net/PrivateKeyPassphraseHandler.h> #include <Poco/Net/SocketStream.h> +#include <Poco/Net/SSLManager.h> #include <Poco/Net/StreamSocket.h> #include <Poco/Net/TCPServer.h> #include <Poco/Net/TCPServerConnection.h> #include <Poco/Net/TCPServerConnectionFactory.h> #include <Poco/Net/WebSocket.h> #include <Poco/Process.h> +#include <Poco/SharedPtr.h> #include <Poco/StringTokenizer.h> #include <Poco/TemporaryFile.h> #include <Poco/Thread.h> #include <Poco/URI.h> #include <Poco/Util/Application.h> -#include <Poco/Util/HelpFormatter.h> -#include <Poco/Util/Option.h> -#include <Poco/Util/OptionSet.h> #include "Common.hpp" #include "LOOLProtocol.hpp" @@ -38,25 +41,26 @@ using namespace LOOLProtocol; -using Poco::Net::HTTPClientSession; +using Poco::Net::AcceptCertificateHandler; +using Poco::Net::Context; +using Poco::Net::HTTPSClientSession; using Poco::Net::HTTPRequest; using Poco::Net::HTTPResponse; +using Poco::Net::InvalidCertificateHandler; using Poco::Net::Socket; -using Poco::Net::SocketOutputStream; +using Poco::Net::SSLManager; using Poco::Net::StreamSocket; using Poco::Net::TCPServer; using Poco::Net::TCPServerConnection; using Poco::Net::WebSocket; using Poco::Net::WebSocketException; using Poco::Runnable; +using Poco::SharedPtr; using Poco::StringTokenizer; using Poco::TemporaryFile; using Poco::Thread; using Poco::URI; using Poco::Util::Application; -using Poco::Util::HelpFormatter; -using Poco::Util::Option; -using Poco::Util::OptionSet; class Output: public Runnable { @@ -113,7 +117,7 @@ class Connect: public Poco::Util::Application { public: Connect() : - _uri("http://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER) + "/ws") + _uri("https://127.0.0.1:" + std::to_string(DEFAULT_CLIENT_PORT_NUMBER) + "/ws") { } @@ -124,11 +128,24 @@ public: protected: int main(const std::vector<std::string>& args) override { - if (args.size() > 0) - _uri = URI(args[0]); + if (args.size() < 1) + { + Log::error("Usage: connect documentURI [serverURI]"); + return Application::EXIT_USAGE; + } + + if (args.size() > 1) + _uri = URI(args[1]); + + Poco::Net::initializeSSL(); + + SharedPtr<InvalidCertificateHandler> invalidCertHandler = new AcceptCertificateHandler(false); + Context::Params sslParams; + Context::Ptr sslContext = new Poco::Net::Context(Poco::Net::Context::CLIENT_USE, sslParams); + SSLManager::instance().initializeClient(0, invalidCertHandler, sslContext); - HTTPClientSession cs(_uri.getHost(), _uri.getPort()); - HTTPRequest request(HTTPRequest::HTTP_GET, "/ws"); + HTTPSClientSession cs(_uri.getHost(), _uri.getPort()); + HTTPRequest request(HTTPRequest::HTTP_GET, args[0]); HTTPResponse response; WebSocket ws(cs, request, response); commit 0677c4abc99023e3f0c6679d83823d5c293eedcb Author: Tor Lillqvist <t...@collabora.com> Date: Tue Mar 22 18:47:05 2016 +0200 No need for the DocumentBroker map to be in the LOOLWSD class It can be a simple static variable in LOOLWSD.cpp. It is not used anywhere else. diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index dfcad92..430f406 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -171,8 +171,8 @@ using Poco::XML::InputSource; using Poco::XML::Node; using Poco::XML::NodeList; -std::map<std::string, std::shared_ptr<DocumentBroker>> LOOLWSD::DocBrokers; -std::mutex LOOLWSD::DocBrokersMutex; +static std::map<std::string, std::shared_ptr<DocumentBroker>> docBrokers; +static std::mutex docBrokersMutex; /// Handles the filename part of the convert-to POST request payload. class ConvertToPartHandler : public PartHandler @@ -371,10 +371,10 @@ private: // This lock could become a bottleneck. // In that case, we can use a pool and index by publicPath. - std::unique_lock<std::mutex> lock(LOOLWSD::DocBrokersMutex); + std::unique_lock<std::mutex> lock(docBrokersMutex); Log::debug("New DocumentBroker for docKey [" + docKey + "]."); - LOOLWSD::DocBrokers.emplace(docKey, docBroker); + docBrokers.emplace(docKey, docBroker); // Load the document. std::shared_ptr<WebSocket> ws; @@ -410,7 +410,7 @@ private: if (docBroker->decSessions() == 0) { Log::debug("Removing DocumentBroker for docKey [" + docKey + "]."); - LOOLWSD::DocBrokers.erase(docKey); + docBrokers.erase(docKey); } } @@ -551,11 +551,11 @@ private: // This lock could become a bottleneck. // In that case, we can use a pool and index by publicPath. - std::unique_lock<std::mutex> lock(LOOLWSD::DocBrokersMutex); + std::unique_lock<std::mutex> lock(docBrokersMutex); // Lookup this document. - auto it = LOOLWSD::DocBrokers.find(docKey); - if (it != LOOLWSD::DocBrokers.end()) + auto it = docBrokers.find(docKey); + if (it != docBrokers.end()) { // Get the DocumentBroker from the Cache. Log::debug("Found DocumentBroker for docKey [" + docKey + "]."); @@ -566,7 +566,7 @@ private: { // Set one we just created. Log::debug("New DocumentBroker for docKey [" + docKey + "]."); - LOOLWSD::DocBrokers.emplace(docKey, docBroker); + docBrokers.emplace(docKey, docBroker); } auto ws = std::make_shared<WebSocket>(request, response); @@ -633,7 +633,7 @@ private: if (docBroker->decSessions() == 0) { Log::debug("Removing DocumentBroker for docKey [" + docKey + "]."); - LOOLWSD::DocBrokers.erase(docKey); + docBrokers.erase(docKey); } } @@ -764,11 +764,11 @@ public: { // This lock could become a bottleneck. // In that case, we can use a pool and index by publicPath. - std::unique_lock<std::mutex> lock(LOOLWSD::DocBrokersMutex); + std::unique_lock<std::mutex> lock(docBrokersMutex); // Lookup this document. - auto it = LOOLWSD::DocBrokers.find(docKey); - if (it != LOOLWSD::DocBrokers.end()) + auto it = docBrokers.find(docKey); + if (it != docBrokers.end()) { // Get the DocumentBroker from the Cache. docBroker = it->second; diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp index 5504888..61ce73e 100644 --- a/loolwsd/LOOLWSD.hpp +++ b/loolwsd/LOOLWSD.hpp @@ -52,10 +52,6 @@ public: static const std::string FIFO_LOOLWSD; static const std::string LOKIT_PIDLOG; - // All DocumentBrokers by their DocKey (the URI path without host, port, or query). - static std::map<std::string, std::shared_ptr<DocumentBroker>> DocBrokers; - static std::mutex DocBrokersMutex; - static std::string GenSessionId() { commit 6b505e561fe410947a55469db7e2127010cc2de6 Author: Tor Lillqvist <t...@collabora.com> Date: Tue Mar 22 18:45:22 2016 +0200 Bin unneeded #include diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 9d23a12..dfcad92 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -67,7 +67,6 @@ DEALINGS IN THE SOFTWARE. #include <Poco/Exception.h> #include <Poco/File.h> #include <Poco/FileStream.h> -#include <Poco/Mutex.h> #include <Poco/Net/ConsoleCertificateHandler.h> #include <Poco/Net/Context.h> #include <Poco/Net/HTMLForm.h> commit 744c4143c2d6b5f57ba6e8b3b4df64a68ebfc4ed Author: Tor Lillqvist <t...@collabora.com> Date: Tue Mar 22 18:41:14 2016 +0200 Indentation nit-pick diff --git a/loolwsd/MasterProcessSession.hpp b/loolwsd/MasterProcessSession.hpp index 87607fb..f102760 100644 --- a/loolwsd/MasterProcessSession.hpp +++ b/loolwsd/MasterProcessSession.hpp @@ -18,7 +18,7 @@ class MasterProcessSession final : public LOOLSession, public std::enable_shared_from_this<MasterProcessSession> { -public: + public: MasterProcessSession(const std::string& id, const Kind kind, std::shared_ptr<Poco::Net::WebSocket> ws, @@ -59,7 +59,7 @@ public: virtual void sendFontRendering(const char *buffer, int length, Poco::StringTokenizer& tokens) override; -private: + private: void dispatchChild(); void forwardToPeer(const char *buffer, int length); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits