[Libreoffice-commits] online.git: 3 commits - common/Util.cpp common/Util.hpp loleaflet/html loleaflet/src wsd/Admin.cpp wsd/ClientSession.cpp wsd/DocumentBroker.cpp wsd/LOOLWSD.cpp wsd/LOOLWSD.hpp

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri May 17 12:29:01 UTC 2019


 common/Util.cpp                  |   10 ++++++++++
 common/Util.hpp                  |    3 +++
 loleaflet/html/loleaflet.html.m4 |    1 +
 loleaflet/src/core/Socket.js     |   12 ++++++++++--
 wsd/Admin.cpp                    |    7 +------
 wsd/ClientSession.cpp            |    8 +-------
 wsd/DocumentBroker.cpp           |    3 +++
 wsd/LOOLWSD.cpp                  |   39 +++++++++++++++++++++++++++++++++------
 wsd/LOOLWSD.hpp                  |    3 +++
 9 files changed, 65 insertions(+), 21 deletions(-)

New commits:
commit d8bcc1cf9cde6c792d4509a6be7af9e577a9b7b7
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Fri May 17 13:22:02 2019 +0100
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Fri May 17 13:24:32 2019 +0100

    debug: cleanup ID display as a simple link.
    
    And cleanup debug printout in 'make run' too.
    
    Change-Id: I7a399eb00f15e43ceb230f66a2b17d437c5c79b0

diff --git a/loleaflet/html/loleaflet.html.m4 b/loleaflet/html/loleaflet.html.m4
index f88b2374d..583851954 100644
--- a/loleaflet/html/loleaflet.html.m4
+++ b/loleaflet/html/loleaflet.html.m4
@@ -181,10 +181,9 @@ ifelse(MOBILEAPP,[true],
       <p id="product-string"></p>
       <h3>LOOLWSD</h3>
       <div id="loolwsd-version"></div>
+      <div id="loolwsd-id"></div>
       <h3>LOKit</h3>
       <div id="lokit-version"></div>
-      <h3>Id</h3>
-      <div id="loolwsd-id"></div>
     </div>
 
     <script defer>
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index be638b860..fa7a78d48 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -250,7 +250,10 @@ L.Socket = L.Class.extend({
 				$('#loolwsd-version').text(loolwsdVersionObj.Version);
 			}
 
-			$('#loolwsd-id').html('<p>' + this.getWebSocketBaseURI(this._map) + '</p><p>' + loolwsdVersionObj.Id + '</p>');
+			var idUri = this._map.options.server + this._map.options.serviceRoot + '/hosting/discovery';
+			idUri = idUri.replace(/^ws:/, 'http:');
+			idUri = idUri.replace(/^wss:/, 'https:');
+			$('#loolwsd-id').html('<a href="' + idUri + '">' + loolwsdVersionObj.Id + '</a>');
 
 			// TODO: For now we expect perfect match in protocol versions
 			if (loolwsdVersionObj.Protocol !== this.ProtocolVersionNumber) {
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 3097120d7..79a908fb4 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -645,6 +645,17 @@ inline std::string getLaunchURI(const std::string &document)
     return oss.str();
 }
 
+inline std::string getServiceURI(const std::string &sub)
+{
+    std::ostringstream oss;
+
+    oss << getLaunchBase("");
+    oss << LOOLWSD::ServiceRoot;
+    oss << sub;
+
+    return oss.str();
+}
+
 inline std::string getAdminURI(const Poco::Util::LayeredConfiguration &config)
 {
     std::string user = config.getString("admin_console.username", "");
@@ -1152,13 +1163,16 @@ void LOOLWSD::initialize(Application& self)
     std::cerr << "\nLaunch one of these in your browser:\n\n"
               << "    Writer:  " << getLaunchURI(LOOLWSD_TEST_DOCUMENT_RELATIVE_PATH_WRITER) << '\n'
               << "    Calc:    " << getLaunchURI(LOOLWSD_TEST_DOCUMENT_RELATIVE_PATH_CALC) << '\n'
-              << "    Impress: " << getLaunchURI(LOOLWSD_TEST_DOCUMENT_RELATIVE_PATH_IMPRESS) << '\n'
-              << std::endl;
+              << "    Impress: " << getLaunchURI(LOOLWSD_TEST_DOCUMENT_RELATIVE_PATH_IMPRESS) << std::endl;
 
     const std::string adminURI = getAdminURI(config());
     if (!adminURI.empty())
-        std::cerr << "\nOr for the Admin Console:\n\n"
-                  << adminURI << '\n' << std::endl;
+        std::cerr << "\nOr for the admin, capabilities & discovery:\n\n"
+                  << adminURI << "\n"
+                  << getServiceURI("/hosting/capabilities") << "\n"
+                  << getServiceURI("/hosting/discovery") << "\n";
+
+    std::cerr << std::endl;
 #endif
 
 #endif
@@ -2260,7 +2274,7 @@ private:
         auto socket = _socket.lock();
         socket->send(oss.str());
         socket->shutdown();
-        LOG_INF("Sent cpabilities.json successfully.");
+        LOG_INF("Sent capabilities.json successfully.");
     }
 
     void handleRobotsTxtRequest(const Poco::Net::HTTPRequest& request)
commit 289894c66ce3fabaf03db3d6b8b2bd4553f1284c
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Thu May 16 21:12:20 2019 +0100
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Fri May 17 13:24:32 2019 +0100

    debug: show WebSocketURI & a unique host id in help -> about.
    
    Rather useful for debugging clustering issues.
    
    Change-Id: I6d5f224bf8a3e4034c419137c8ad2b17fdf265ed

diff --git a/common/Util.cpp b/common/Util.cpp
index 5379fbb0d..9acd82735 100644
--- a/common/Util.cpp
+++ b/common/Util.cpp
@@ -42,6 +42,7 @@
 #include <thread>
 
 #include <Poco/Base64Encoder.h>
+#include <Poco/HexBinaryEncoder.h>
 #include <Poco/ConsoleChannel.h>
 #include <Poco/Exception.h>
 #include <Poco/Format.h>
@@ -98,6 +99,15 @@ namespace Util
             return v;
         }
 
+        /// Generate a string of random characters.
+        std::string getHexString(const size_t length)
+        {
+            std::stringstream ss;
+            Poco::HexBinaryEncoder hex(ss);
+            hex.write(getBytes(length).data(), length);
+            return ss.str().substr(0, length);
+        }
+
         /// Generates a random string in Base64.
         /// Note: May contain '/' characters.
         std::string getB64String(const size_t length)
diff --git a/common/Util.hpp b/common/Util.hpp
index ab4ba2176..d493cdf74 100644
--- a/common/Util.hpp
+++ b/common/Util.hpp
@@ -46,6 +46,9 @@ namespace Util
         /// Generate an array of random characters.
         std::vector<char> getBytes(const size_t length);
 
+        /// Generate a string of random characters.
+        std::string getHexString(const size_t length);
+
         /// Generates a random string suitable for
         /// file/directory names.
         std::string getFilename(const size_t length);
diff --git a/loleaflet/html/loleaflet.html.m4 b/loleaflet/html/loleaflet.html.m4
index 4acb7f875..f88b2374d 100644
--- a/loleaflet/html/loleaflet.html.m4
+++ b/loleaflet/html/loleaflet.html.m4
@@ -183,6 +183,8 @@ ifelse(MOBILEAPP,[true],
       <div id="loolwsd-version"></div>
       <h3>LOKit</h3>
       <div id="lokit-version"></div>
+      <h3>Id</h3>
+      <div id="loolwsd-id"></div>
     </div>
 
     <script defer>
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 01d5c5675..be638b860 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -23,6 +23,10 @@ L.Socket = L.Class.extend({
 		this._msgQueue = [];
 	},
 
+	getWebSocketBaseURI: function(map) {
+		return map.options.server + map.options.serviceRoot + '/lool/' + encodeURIComponent(map.options.doc + '?' + $.param(map.options.docParams)) + '/ws';
+	},
+
 	connect: function(socket) {
 		var map = this._map;
 		if (map.options.permission) {
@@ -42,8 +46,7 @@ L.Socket = L.Class.extend({
 			}
 
 			try {
-				var websocketURI = map.options.server + map.options.serviceRoot + '/lool/' + encodeURIComponent(map.options.doc + '?' + $.param(map.options.docParams)) + '/ws' + wopiSrc;
-				this.socket = new WebSocket(websocketURI);
+				this.socket = new WebSocket(this.getWebSocketBaseURI(map) + wopiSrc);
 			} catch (e) {
 				// On IE 11 there is a limitation on the number of WebSockets open to a single domain (6 by default and can go to 128).
 				// Detect this and hint the user.
@@ -247,6 +250,8 @@ L.Socket = L.Class.extend({
 				$('#loolwsd-version').text(loolwsdVersionObj.Version);
 			}
 
+			$('#loolwsd-id').html('<p>' + this.getWebSocketBaseURI(this._map) + '</p><p>' + loolwsdVersionObj.Id + '</p>');
+
 			// TODO: For now we expect perfect match in protocol versions
 			if (loolwsdVersionObj.Protocol !== this.ProtocolVersionNumber) {
 				this._map.fire('error', {msg: _('Unsupported server version.')});
diff --git a/wsd/Admin.cpp b/wsd/Admin.cpp
index 650429af4..ea3d5b5be 100644
--- a/wsd/Admin.cpp
+++ b/wsd/Admin.cpp
@@ -122,12 +122,7 @@ void AdminSocketHandler::handleMessage(bool /* fin */, WSOpCode /* code */,
     else if (tokens[0] == "version")
     {
         // Send LOOL version information
-        std::string version, hash;
-        Util::getVersionInfo(version, hash);
-        std::string versionStr =
-            "{ \"Version\":  \"" + version + "\", " +
-            "\"Hash\":  \"" + hash  + "\" }";
-        sendTextFrame("loolserver " + versionStr);
+        sendTextFrame("loolserver " + LOOLWSD::getVersionJSON());
         // Send LOKit version information
         sendTextFrame("lokitversion " + LOOLWSD::LOKitVersion);
     }
diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index 2146cedfe..596c1c757 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -112,13 +112,7 @@ bool ClientSession::_handleInput(const char *buffer, int length)
         }
 
         // Send LOOL version information
-        std::string version, hash;
-        Util::getVersionInfo(version, hash);
-        std::string versionStr =
-            "{ \"Version\":  \"" + version + "\", " +
-            "\"Hash\":     \"" + hash + "\", " +
-            "\"Protocol\": \"" + GetProtocolVersion() + "\" }";
-        sendTextFrame("loolserver " + versionStr);
+        sendTextFrame("loolserver " + LOOLWSD::getVersionJSON());
         // Send LOKit version information
         sendTextFrame("lokitversion " + LOOLWSD::LOKitVersion);
 
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index a622607d5..3097120d7 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -685,6 +685,7 @@ std::string LOOLWSD::ServerName;
 std::string LOOLWSD::FileServerRoot;
 std::string LOOLWSD::ServiceRoot;
 std::string LOOLWSD::LOKitVersion;
+std::string LOOLWSD::HostIdentifier;
 std::string LOOLWSD::ConfigFile = LOOLWSD_CONFIGDIR "/loolwsd.xml";
 std::string LOOLWSD::ConfigDir = LOOLWSD_CONFIGDIR "/conf.d";
 std::string LOOLWSD::LogLevel = "trace";
@@ -3062,6 +3063,17 @@ private:
     }
 };
 
+std::string LOOLWSD::getVersionJSON()
+{
+    std::string version, hash;
+    Util::getVersionInfo(version, hash);
+    return
+        "{ \"Version\":  \"" + version + "\", "
+        "\"Hash\":     \"" + hash + "\", "
+        "\"Protocol\": \"" + GetProtocolVersion() + "\", "
+        "\"Id\":  \"" + HostIdentifier + "\" }";
+}
+
 static LOOLWSDServer srv;
 
 #if !MOBILEAPP
@@ -3092,11 +3104,12 @@ int LOOLWSD::innerMain()
     Environment::set("LD_BIND_NOW", "1");
 
 #if !MOBILEAPP
+    HostIdentifier = Util::rng::getHexString(8);
     if (DisplayVersion)
     {
         std::string version, hash;
         Util::getVersionInfo(version, hash);
-        LOG_INF("Loolwsd version details: " << version << " - " << hash);
+        LOG_INF("Loolwsd version details: " << version << " - " << hash << " - id " << HostIdentifier);
     }
 #endif
 #endif
diff --git a/wsd/LOOLWSD.hpp b/wsd/LOOLWSD.hpp
index f4c2db405..53fe4deb2 100644
--- a/wsd/LOOLWSD.hpp
+++ b/wsd/LOOLWSD.hpp
@@ -62,6 +62,7 @@ public:
     static std::string FileServerRoot;
     static std::string ServiceRoot; ///< There are installations that need prefixing every page with some path.
     static std::string LOKitVersion;
+    static std::string HostIdentifier; ///< A unique random hash that identifies this server
     static std::string LogLevel;
     static bool AnonymizeFilenames;
     static bool AnonymizeUsernames;
@@ -158,6 +159,8 @@ public:
     /// get correct server URL with protocol + port number for this running server
     static std::string getServerURL();
 
+    static std::string getVersionJSON();
+
     int innerMain();
 
 protected:
commit 1955287013092474e09e54b525cb753250273125
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Thu May 16 20:38:36 2019 +0100
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Fri May 17 13:24:32 2019 +0100

    debug: dump content of paste messages.
    
    Problematic not to be able to see the content, helps hunt weirdness
    in eg. pasted RTF.
    
    Change-Id: I301bfe040a2424b6ca84ab94b8eee865439fb680

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index e3b42e8c3..be53dcfd7 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1696,6 +1696,9 @@ bool DocumentBroker::forwardToChild(const std::string& viewId, const std::string
 
     LOG_TRC("Forwarding payload to child [" << viewId << "]: " << getAbbreviatedMessage(message));
 
+    if (Log::traceEnabled() && Util::startsWith(message, "paste "))
+        LOG_TRC("Logging paste payload (" << message.size() << " bytes) '" << message << "' end paste");
+
     std::string msg = "child-" + viewId + ' ' + message;
 
     const auto it = _sessions.find(viewId);


More information about the Libreoffice-commits mailing list