[Libreoffice-commits] online.git: loleaflet/debug loleaflet/dist loleaflet/src loolwsd/FileServer.hpp loolwsd/LOOLWSD.cpp loolwsd/test

Pranav Kant pranavk at collabora.com
Wed Jun 8 14:06:39 UTC 2016


 loleaflet/debug/document/admin.html          |    2 +-
 loleaflet/debug/document/adminAnalytics.html |    2 +-
 loleaflet/debug/document/adminSettings.html  |    2 +-
 loleaflet/dist/admin/admin.html              |    4 ++--
 loleaflet/dist/admin/adminAnalytics.html     |    4 ++--
 loleaflet/dist/admin/adminSettings.html      |    4 ++--
 loleaflet/src/core/Socket.js                 |    2 +-
 loolwsd/FileServer.hpp                       |    2 +-
 loolwsd/LOOLWSD.cpp                          |   15 +++++++++++----
 loolwsd/test/UnitAdmin.cpp                   |    8 ++++----
 loolwsd/test/helpers.hpp                     |    2 +-
 loolwsd/test/httpwstest.cpp                  |    6 +++---
 12 files changed, 30 insertions(+), 23 deletions(-)

New commits:
commit 8cc367638f7a0e5da56905510dda76075401cb4e
Author: Pranav Kant <pranavk at collabora.com>
Date:   Wed Jun 8 15:51:29 2016 +0530

    bccu#1871: Add url prefix to websocket urls
    
    Normal websocket connections are now :
    /lool/ws/filename
    
    Admin websocket is now :
    /lool/adminws/
    
    Change-Id: If39382cb852d89ed0394adbd7fe168fe4767a075
    Reviewed-on: https://gerrit.libreoffice.org/26029
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Reviewed-by: Andras Timar <andras.timar at collabora.com>
    Tested-by: Andras Timar <andras.timar at collabora.com>

diff --git a/loleaflet/debug/document/admin.html b/loleaflet/debug/document/admin.html
index 98bc593..891dab8 100644
--- a/loleaflet/debug/document/admin.html
+++ b/loleaflet/debug/document/admin.html
@@ -37,7 +37,7 @@
     <script>vex.defaultOptions.className = 'vex-theme-plain';</script>
     <script>
 
-	var host = 'wss://' + window.location.host + '/adminws/';
+	var host = 'wss://' + window.location.host + '/lool/adminws/';
 	new AdminSocketOverview(host);
 
     </script>
diff --git a/loleaflet/debug/document/adminAnalytics.html b/loleaflet/debug/document/adminAnalytics.html
index 13c124c..1841c56 100644
--- a/loleaflet/debug/document/adminAnalytics.html
+++ b/loleaflet/debug/document/adminAnalytics.html
@@ -38,7 +38,7 @@
     <script src="../../dist/admin/admin-src.js"></script>
     <script>
 
-	host = 'wss://' + window.location.host + '/adminws/';
+	host = 'wss://' + window.location.host + '/lool/adminws/';
 	new AdminSocketAnalytics(host);
 
     </script>
diff --git a/loleaflet/debug/document/adminSettings.html b/loleaflet/debug/document/adminSettings.html
index a86b137..5cd3bbc 100644
--- a/loleaflet/debug/document/adminSettings.html
+++ b/loleaflet/debug/document/adminSettings.html
@@ -37,7 +37,7 @@
     <script src="../../dist/admin/admin-src.js"></script>
     <script>
 
-	host = 'wss://' + window.location.host + '/adminws/';
+	host = 'wss://' + window.location.host + '/lool/adminws/';
 	new AdminSocketSettings(host);
 
     </script>
diff --git a/loleaflet/dist/admin/admin.html b/loleaflet/dist/admin/admin.html
index ef4a209..a3369fc 100644
--- a/loleaflet/dist/admin/admin.html
+++ b/loleaflet/dist/admin/admin.html
@@ -44,10 +44,10 @@
     <script>
 
         if (window.location.protocol == "https:") {
-	    host = 'wss://' + window.location.host + '/adminws/'
+	    host = 'wss://' + window.location.host + '/lool/adminws/'
         }
         else {
-	    host = 'ws://' + window.location.host + '/adminws/'
+	    host = 'ws://' + window.location.host + '/lool/adminws/'
         }
 	new AdminSocketOverview(host);
 
diff --git a/loleaflet/dist/admin/adminAnalytics.html b/loleaflet/dist/admin/adminAnalytics.html
index 23ad622..bef4e00 100644
--- a/loleaflet/dist/admin/adminAnalytics.html
+++ b/loleaflet/dist/admin/adminAnalytics.html
@@ -46,10 +46,10 @@
     <script>
 
         if (window.location.protocol == "https:") {
-           host = 'wss://' + window.location.host + '/adminws/'
+           host = 'wss://' + window.location.host + '/lool/adminws/'
         }
         else {
-           host = 'ws://' + window.location.host + '/adminws/'
+           host = 'ws://' + window.location.host + '/lool/adminws/'
         }
 	new AdminSocketAnalytics(host);
 
diff --git a/loleaflet/dist/admin/adminSettings.html b/loleaflet/dist/admin/adminSettings.html
index 351d4c0..54d5f31 100644
--- a/loleaflet/dist/admin/adminSettings.html
+++ b/loleaflet/dist/admin/adminSettings.html
@@ -45,10 +45,10 @@
     <script>
 
         if (window.location.protocol == "https:") {
-           host = 'wss://' + window.location.host + '/adminws/'
+           host = 'wss://' + window.location.host + '/lool/adminws/'
         }
         else {
-           host = 'ws://' + window.location.host + '/adminws/'
+           host = 'ws://' + window.location.host + '/lool/adminws/'
         }
 	new AdminSocketSettings(host);
 
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index bbd68e2..49092c8 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -9,7 +9,7 @@ L.Socket = L.Class.extend({
 	initialize: function (map) {
 		this._map = map;
 		try {
-			this.socket = new WebSocket(map.options.server + '/' + map.options.doc);
+			this.socket = new WebSocket(map.options.server + '/lool/ws/' + map.options.doc);
 		} catch (e) {
 			this.fire('error', {msg: _('Oops, there is a problem connecting to LibreOffice Online : ' + e), cmd: 'socket', kind: 'failed', id: 3});
 			return null;
diff --git a/loolwsd/FileServer.hpp b/loolwsd/FileServer.hpp
index f7462b2..2d23a74 100644
--- a/loolwsd/FileServer.hpp
+++ b/loolwsd/FileServer.hpp
@@ -99,7 +99,7 @@ public:
             JWTAuth authAgent(sslKeyPath, "admin", "admin", "admin");
             const std::string jwtToken = authAgent.getAccessToken();
             Poco::Net::HTTPCookie cookie("jwt", jwtToken);
-            cookie.setPath("/adminws/");
+            cookie.setPath("/lool/adminws/");
             cookie.setSecure(true);
             cookie.setHttpOnly(true);
             response.addCookie(cookie);
diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index cd89457..c5d8743 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -527,9 +527,12 @@ private:
         // Remove the leading '/' in the GET URL.
         std::string uri = request.getURI();
         if (uri.size() > 0 && uri[0] == '/')
-        {
             uri.erase(0, 1);
-        }
+
+        // Remove leading 'lool/ws/' from GET URL
+        if (uri.size() > 0 && uri.compare(0, 8, "lool/ws/") == 0)
+            uri.erase(0, 8);
+
 
         const auto uriPublic = DocumentBroker::sanitizeURI(uri);
         const auto docKey = DocumentBroker::getDocKey(uriPublic);
@@ -802,6 +805,10 @@ public:
     {
         const auto id = LOOLWSD::GenSessionId();
 
+        Poco::URI requestUri(request.getURI());
+        std::vector<std::string> reqPathSegs;
+        requestUri.getPathSegments(reqPathSegs);
+
         Util::setThreadName("client_ws_" + id);
 
         Log::debug("Thread started.");
@@ -818,7 +825,7 @@ public:
             {
                 responded = handlePostRequest(request, response, id);
             }
-            else
+            else if (reqPathSegs.size() > 2 && reqPathSegs[0] == "lool" && reqPathSegs[1] == "ws")
             {
                 auto ws = std::make_shared<WebSocket>(request, response);
                 try
@@ -1109,7 +1116,7 @@ public:
             requestHandler = _fileServer.createRequestHandler();
         }
         // Admin WebSocket Connections
-        else if (reqPathSegs.size() >= 1 && reqPathSegs[0] == "adminws")
+        else if (reqPathSegs.size() >= 2 && reqPathSegs[0] == "lool" && reqPathSegs[1] == "adminws")
         {
             requestHandler = Admin::createRequestHandler();
         }
diff --git a/loolwsd/test/UnitAdmin.cpp b/loolwsd/test/UnitAdmin.cpp
index 8a7ea37..6bfe261 100644
--- a/loolwsd/test/UnitAdmin.cpp
+++ b/loolwsd/test/UnitAdmin.cpp
@@ -112,7 +112,7 @@ private:
         bool httpOnly = cookies[0].getHttpOnly();
         std::string value = cookies[0].getValue();
         TestResult res = TestResult::TEST_FAILED;
-        if (cookiePath.find_first_of("/adminws/") == 0 &&
+        if (cookiePath.find_first_of("/lool/adminws/") == 0 &&
             secure &&
             httpOnly &&
             value != "")
@@ -155,7 +155,7 @@ private:
     TestResult testWebSocketWithCookie()
     {
         HTTPResponse response;
-        HTTPRequest request(HTTPRequest::HTTP_GET, "/adminws/");
+        HTTPRequest request(HTTPRequest::HTTP_GET, "/lool/adminws/");
         std::unique_ptr<HTTPClientSession> session(helpers::createSession(_uri));
 
         // set cookie
@@ -191,7 +191,7 @@ private:
         _adminWs->sendFrame(subscribeMessage.data(), subscribeMessage.size());
 
         const std::string documentPath1 = Util::getTempFilePath(TDOC, "hello.odt");
-        const std::string documentURL1 = "file://" + Poco::Path(documentPath1).makeAbsolute().toString();
+        const std::string documentURL1 = std::string("lool/ws/") + "file://" + Poco::Path(documentPath1).makeAbsolute().toString();
         HTTPRequest request1(HTTPRequest::HTTP_GET, documentURL1);
         HTTPResponse response1;
         const Poco::URI docUri1(helpers::getTestServerURI());
@@ -261,7 +261,7 @@ private:
 
         // Open another document (different)
         const std::string documentPath2 = Util::getTempFilePath(TDOC, "insert-delete.odp");
-        const std::string documentURL2 = "file://" + Poco::Path(documentPath2).makeAbsolute().toString();
+        const std::string documentURL2 = std::string("lool/ws/") + "file://" + Poco::Path(documentPath2).makeAbsolute().toString();
         HTTPRequest request2(HTTPRequest::HTTP_GET, documentURL2);
         HTTPResponse response2;
         const Poco::URI docUri2(helpers::getTestServerURI());
diff --git a/loolwsd/test/helpers.hpp b/loolwsd/test/helpers.hpp
index b6c39c2..eec98ac 100644
--- a/loolwsd/test/helpers.hpp
+++ b/loolwsd/test/helpers.hpp
@@ -52,7 +52,7 @@ inline
 void getDocumentPathAndURL(const char* document, std::string& documentPath, std::string& documentURL)
 {
     documentPath = Util::getTempFilePath(TDOC, document);
-    documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString();
+    documentURL = "lool/ws/file://" + Poco::Path(documentPath).makeAbsolute().toString();
 
     std::cerr << "Test file: " << documentPath << std::endl;
 }
diff --git a/loolwsd/test/httpwstest.cpp b/loolwsd/test/httpwstest.cpp
index 0572fbb..b723b3c 100644
--- a/loolwsd/test/httpwstest.cpp
+++ b/loolwsd/test/httpwstest.cpp
@@ -179,7 +179,7 @@ void HTTPWSTest::testBadRequest()
     try
     {
         // Load a document and get its status.
-        const std::string documentURL = "file:///fake.doc";
+        const std::string documentURL = "lool/ws/file:///fake.doc";
 
         Poco::Net::HTTPResponse response;
         Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
@@ -801,7 +801,7 @@ void HTTPWSTest::testPasswordProtectedDocumentWithCorrectPassword()
     try
     {
         const std::string documentPath = Util::getTempFilePath(TDOC, "password-protected.ods");
-        const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString();
+        const std::string documentURL = "lool/ws/file://" + Poco::Path(documentPath).makeAbsolute().toString();
 
         Poco::Net::HTTPRequest request(Poco::Net::HTTPRequest::HTTP_GET, documentURL);
         Poco::Net::WebSocket socket = *connectLOKit(_uri, request, _response);
@@ -921,7 +921,7 @@ void HTTPWSTest::testInsertDelete()
 void HTTPWSTest::testEditLock()
 {
     const std::string documentPath = Util::getTempFilePath(TDOC, "hello.odt");
-    const std::string documentURL = "file://" + Poco::Path(documentPath).makeAbsolute().toString();
+    const std::string documentURL = "lool/ws/file://" + Poco::Path(documentPath).makeAbsolute().toString();
 
     // This test doesn't really need to be multithreaded.
     // But it's done this way as an experiment and to serve


More information about the Libreoffice-commits mailing list