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

Ashod Nakashian ashod.nakashian at collabora.co.uk
Sun Jun 26 00:27:40 UTC 2016


 loolwsd/LOOLWSD.cpp |   48 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 46 insertions(+), 2 deletions(-)

New commits:
commit 7d4d7f47ac7f4fa0d9d18766b159f06d2f238d53
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sat Jun 25 08:20:56 2016 -0400

    bccu#1909 - loolwsd command line options vs. config file and package upgrades
    
    Default config entries and values are now set before loading
    the config file from disk. This ensures that an upgrade
    to the server with new config entries will not break the
    server when the XML is not upgrade, rather, the server
    will fallback to the defaults when it fails to find the
    entry in the XML.
    
    This, of course, requires adding new entries to the
    default entries every time config entries are changed.
    
    Change-Id: Iac849dc41fc7410a3c9093b0d6e91d96182b86fd
    Reviewed-on: https://gerrit.libreoffice.org/26667
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp
index 490176a..6766b98 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -77,6 +77,7 @@
 #include <Poco/ThreadPool.h>
 #include <Poco/URI.h>
 #include <Poco/Util/HelpFormatter.h>
+#include <Poco/Util/MapConfiguration.h>
 #include <Poco/Util/Option.h>
 #include <Poco/Util/OptionException.h>
 #include <Poco/Util/OptionSet.h>
@@ -1185,6 +1186,18 @@ static std::string UnitTestLibrary;
 
 unsigned int LOOLWSD::NumPreSpawnedChildren = 0;
 
+class AppConfigMap : public Poco::Util::MapConfiguration
+{
+public:
+    AppConfigMap(const std::map<std::string, std::string>& map)
+    {
+        for (const auto& pair : map)
+        {
+            setRaw(pair.first, pair.second);
+        }
+    }
+};
+
 LOOLWSD::LOOLWSD()
 {
 }
@@ -1208,12 +1221,43 @@ void LOOLWSD::initialize(Application& self)
         throw std::runtime_error("Failed to load wsd unit test library.");
     }
 
+    auto& conf = config();
+
+    // Add default values of new entries here.
+    static const std::map<std::string, std::string> DefAppConfig = {
+        { "tile_cache_path", "/usr/local/var/cache/loolwsd" },
+        { "sys_template_path", "systemplate" },
+        { "lo_template_path", "/opt/collaboraoffice5.0" },
+        { "child_root_path", "jails" },
+        { "lo_jail_subpath", "lo" },
+        { "server_name", "" },
+        { "file_server_root_path", "../loleaflet/../" },
+        { "num_prespawn_children", "1" },
+        { "per_document.max_concurrency", "4" },
+        { "loleaflet_html", "loleaflet.html" },
+        { "logging.color", "true" },
+        { "logging.level", "trace" },
+        { "ssl.cert_file_path", "/etc/loolwsd/cert.pem" },
+        { "ssl.key_file_path", "/etc/loolwsd/key.pem" },
+        { "ssl.ca_file_path", "/etc/loolwsd/ca-chain.cert.pem" },
+        { "storage.filesystem[@allow]", "false" },
+        { "storage.wopi[@allow]", "true" },
+        { "storage.wopi.host[0][@allow]", "true" },
+        { "storage.wopi.host[0]", "localhost" },
+        { "storage.wopi.max_file_size", "0" },
+        { "storage.webdav[@allow]", "false" },
+    };
+
+    // Set default values, in case they are missing from the config file.
+    AutoPtr<AppConfigMap> pDefConfig(new AppConfigMap(DefAppConfig));
+    conf.addWriteable(pDefConfig, PRIO_SYSTEM); // Lowest priority
+
     // Load default configuration files, if present.
-    if (loadConfiguration() == 0)
+    if (loadConfiguration(PRIO_DEFAULT) == 0)
     {
         // Fallback to the default path.
         const std::string configPath = LOOLWSD_CONFIGDIR "/loolwsd.xml";
-        loadConfiguration(configPath);
+        loadConfiguration(configPath, PRIO_DEFAULT);
     }
 
     // This overrides whatever is in the config file,


More information about the Libreoffice-commits mailing list