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

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


 loolwsd/LOOLWSD.cpp |   20 ++++++++++++++++++--
 loolwsd/LOOLWSD.hpp |   33 ++++++++++++++++++++++++++++++++-
 2 files changed, 50 insertions(+), 3 deletions(-)

New commits:
commit 8798943f08f9faa33468e9415e396ec77c779a6e
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sat Jun 25 12:31:22 2016 -0400

    bccu#1909 - loolwsd command line options vs. config file and package upgrades
    
    Support overriding config settings via the command-line.
    
    By using --o:name=value (or --override:name=value) the
    setting called 'name' can be replaced by 'value'.
    
    Ex. --o:per_document.max_concurrency=12
    
    The above will override the max_concurrency to 12,
    regardless of what the XML has set.
    
    Change-Id: If7ffa5dcdc9ce2a8d1a89c8203b8ba870cb624ac
    Reviewed-on: https://gerrit.libreoffice.org/26668
    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 6766b98..8ce6303 100644
--- a/loolwsd/LOOLWSD.cpp
+++ b/loolwsd/LOOLWSD.cpp
@@ -1260,6 +1260,10 @@ void LOOLWSD::initialize(Application& self)
         loadConfiguration(configPath, PRIO_DEFAULT);
     }
 
+    // Override any settings passed on the command-line.
+    AutoPtr<AppConfigMap> pOverrideConfig(new AppConfigMap(_overrideSettings));
+    conf.addWriteable(pOverrideConfig, PRIO_APPLICATION); // Highest priority
+
     // This overrides whatever is in the config file,
     // which forces admins to set this flag on the command-line.
     config().setBool("storage.filesystem[@allow]", AllowLocalStorage);
@@ -1316,10 +1320,10 @@ void LOOLWSD::initialize(Application& self)
     if (NumPreSpawnedChildren == 0)
     {
         // Default to 1 child.
-        NumPreSpawnedChildren = config().getUInt("num_prespawn_children", 1);
+        NumPreSpawnedChildren = getUIntConfigValue(conf, "num_prespawn_children", 1);
     }
 
-    const auto maxConcurrency = config().getInt("per_document.max_concurrency", 4);
+    const auto maxConcurrency = getUIntConfigValue(conf, "per_document.max_concurrency", 4);
     if (maxConcurrency > 0)
     {
         setenv("MAX_CONCURRENCY", std::to_string(maxConcurrency).c_str(), 1);
@@ -1438,6 +1442,11 @@ void LOOLWSD::defineOptions(OptionSet& optionSet)
                         .required(false)
                         .repeatable(false));
 
+    optionSet.addOption(Option("override", "o", "Override any setting by providing fullxmlpath=value.")
+                        .required(false)
+                        .repeatable(true)
+                        .argument("xmlpath"));
+
 #if ENABLE_DEBUG
     optionSet.addOption(Option("unitlib", "", "Unit testing library path.")
                         .required(false)
@@ -1494,6 +1503,13 @@ void LOOLWSD::handleOption(const std::string& optionName,
         NoCapsForKit = true;
     else if (optionName == "careerspan")
         careerSpanSeconds = std::stoi(value);
+    else if (optionName == "override")
+    {
+        std::string optName;
+        std::string optValue;
+        LOOLProtocol::parseNameValuePair(value, optName, optValue);
+        _overrideSettings[optName] = optValue;
+    }
 
     static const char* clientPort = getenv("LOOL_TEST_CLIENT_PORT");
     if (clientPort)
diff --git a/loolwsd/LOOLWSD.hpp b/loolwsd/LOOLWSD.hpp
index 8de18e4..248b240 100644
--- a/loolwsd/LOOLWSD.hpp
+++ b/loolwsd/LOOLWSD.hpp
@@ -66,10 +66,37 @@ private:
     void displayHelp();
     Poco::Process::PID createForKit();
 
+    static
+    bool getSafeUIntConfig(Poco::Util::LayeredConfiguration& config, const std::string& name, unsigned int& value)
+    {
+        try
+        {
+            value = config.getUInt(name);
+            return true;
+        }
+        catch (Poco::SyntaxException)
+        {
+        }
+
+        return false;
+    }
+
+    static
+    unsigned int getUIntConfigValue(Poco::Util::LayeredConfiguration& config, const std::string& name, const unsigned int def)
+    {
+        unsigned int value = def;
+        if (getSafeUIntConfig(config, name, value) ||
+            getSafeUIntConfig(config, name + "[@default]", value))
+        {
+            return value;
+        }
+
+        return def;
+    }
+
     /// Reads and processes path entries with the given property
     /// from the configuration.
     /// Converts relative paths to absolute.
-    //TODO: Move to a better namespace.
     std::string getPathFromConfig(const std::string& property) const
     {
         auto path = config().getString(property);
@@ -88,6 +115,10 @@ private:
 
         return path;
     }
+
+private:
+    /// Settings passed from the command-line to override those in the config file.
+    std::map<std::string, std::string> _overrideSettings;
 };
 
 #endif


More information about the Libreoffice-commits mailing list