[Libreoffice-commits] online.git: loleaflet/welcome wsd/FileServer.cpp

Jan Holesovsky (via logerrit) logerrit at kemper.freedesktop.org
Thu Apr 16 09:34:58 UTC 2020


 wsd/FileServer.cpp |   46 ++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 42 insertions(+), 4 deletions(-)

New commits:
commit e228e4138944553b34b4afcca55ed1ff6556f2b9
Author:     Jan Holesovsky <kendy at collabora.com>
AuthorDate: Wed Apr 15 15:37:49 2020 +0200
Commit:     Jan Holesovsky <kendy at collabora.com>
CommitDate: Thu Apr 16 11:34:41 2020 +0200

    Welcome: Handle language versions of the welcome files.
    
    If eg. welcome-cs-CZ.html is not available, try welcome-cs.html and
    fallback to welcome.html (which should be the en-US version).
    
    Change-Id: I5df6a6d6da97fb3c111a709a63a54ee86248f73d
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/92274
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/loleaflet/welcome/welcome-en-US.html b/loleaflet/welcome/welcome.html
similarity index 100%
rename from loleaflet/welcome/welcome-en-US.html
rename to loleaflet/welcome/welcome.html
diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp
index e5e08e92a..027655dc9 100644
--- a/wsd/FileServer.cpp
+++ b/wsd/FileServer.cpp
@@ -56,6 +56,10 @@ using Poco::Util::Application;
 
 std::map<std::string, std::pair<std::string, std::string>> FileServerRequestHandler::FileHash;
 
+/// Place from where we serve the welcome-<lang>.html; defaults to
+/// welcome.html if no lang matches.
+#define WELCOME_ENDPOINT "/loleaflet/dist/welcome"
+
 namespace {
 
 int functionConversation(int /*num_msg*/, const struct pam_message** /*msg*/,
@@ -283,8 +287,11 @@ void FileServerRequestHandler::handleRequest(const HTTPRequest& request, Poco::M
 
         std::vector<std::string> requestSegments;
         requestUri.getPathSegments(requestSegments);
-        const std::string relPath = getRequestPathname(request);
-        const std::string endPoint = requestSegments[requestSegments.size() - 1];
+        if (requestSegments.size() < 1)
+            throw Poco::FileNotFoundException("Invalid URI request: [" + requestUri.toString() + "].");
+
+        std::string relPath = getRequestPathname(request);
+        std::string endPoint = requestSegments[requestSegments.size() - 1];
         const auto& config = Application::instance().config();
 
         if (request.getMethod() == HTTPRequest::HTTP_POST && endPoint == "logging.html")
@@ -301,8 +308,39 @@ void FileServerRequestHandler::handleRequest(const HTTPRequest& request, Poco::M
             }
         }
 
+        // handling of the language in welcome-*.html - shorten the langtag as
+        // necessary, if we don't have the particular language version
+        if (Util::startsWith(relPath, WELCOME_ENDPOINT "/"))
+        {
+            bool found = true;
+            while (FileHash.find(relPath) == FileHash.end())
+            {
+                size_t dot = relPath.find_last_of('.');
+                if (dot == std::string::npos)
+                {
+                    found = false;
+                    break;
+                }
+
+                size_t dash = relPath.find_last_of("-_", dot);
+                if (dash == std::string::npos)
+                {
+                    found = false;
+                    break;
+                }
+
+                relPath = relPath.substr(0, dash) + relPath.substr(dot);
+                LOG_TRC("Shortening welcome file request to: " << relPath);
+            }
+
+            if (!found)
+                throw Poco::FileNotFoundException("Invalid URI welcome file request: [" + requestUri.toString() + "].");
+
+            endPoint = relPath.substr(sizeof(WELCOME_ENDPOINT));
+        }
+
         // Is this a file we read at startup - if not; its not for serving.
-        if (requestSegments.size() < 1 || FileHash.find(relPath) == FileHash.end())
+        if (FileHash.find(relPath) == FileHash.end())
             throw Poco::FileNotFoundException("Invalid URI request: [" + requestUri.toString() + "].");
 
         const std::string loleafletHtml = config.getString("loleaflet_html", "loleaflet.html");
@@ -562,7 +600,7 @@ void FileServerRequestHandler::initialize()
     if (!LOOLWSD::WelcomeFilesRoot.empty())
     {
         try {
-            readDirToHash(LOOLWSD::WelcomeFilesRoot, "", "/loleaflet/dist/welcome");
+            readDirToHash(LOOLWSD::WelcomeFilesRoot, "", WELCOME_ENDPOINT);
         } catch (...) {
             LOG_ERR("Failed to read from directory " << LOOLWSD::WelcomeFilesRoot);
         }


More information about the Libreoffice-commits mailing list