]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[5039] Element::getMutableMap implemented
authorTomek Mrugalski <tomasz@isc.org>
Thu, 22 Dec 2016 15:36:28 +0000 (16:36 +0100)
committerTomek Mrugalski <tomasz@isc.org>
Thu, 22 Dec 2016 15:36:28 +0000 (16:36 +0100)
src/bin/dhcp4/json_config_parser.cc
src/bin/dhcp6/json_config_parser.cc
src/lib/cc/data.cc
src/lib/cc/data.h

index 6a4c35234296bb9c844fe950cbd0a02eb595c584..2109c7b8f261540e841d6e8af6941ac86198a22b 100644 (file)
@@ -567,10 +567,7 @@ configureDhcp4Server(Dhcpv4Srv&, isc::data::ConstElementPtr config_set) {
         // This is a way to convert ConstElementPtr to ElementPtr.
         // We need a config that can be edited, because we will insert
         // default values and will insert derived values as well.
-        std::map<std::string, ConstElementPtr> values;
-        config_set->getValue(values);
-        ElementPtr mutable_cfg(new MapElement());
-        mutable_cfg->setValue(values);
+        ElementPtr mutable_cfg = Element::getMutableMap(config_set);
 
         // Set all default values if not specified by the user.
         SimpleParser4::setAllDefaults(mutable_cfg);
index ee9ea6a98ef358cdb4d610ff5eb4611836dc1afa..9a6c8483ebc1ef00f2e6ab3ffefcd25d06437323 100644 (file)
@@ -840,10 +840,7 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {
         // This is a way to convert ConstElementPtr to ElementPtr.
         // We need a config that can be edited, because we will insert
         // default values and will insert derived values as well.
-        std::map<std::string, ConstElementPtr> values;
-        config_set->getValue(values);
-        ElementPtr mutable_cfg(new MapElement());
-        mutable_cfg->setValue(values);
+        ElementPtr mutable_cfg = Element::getMutableMap(config_set);
 
         SimpleParser6::setAllDefaults(mutable_cfg);
 
@@ -881,9 +878,7 @@ configureDhcp6Server(Dhcpv6Srv&, isc::data::ConstElementPtr config_set) {
                 subnet_parser = parser;
             } else if (config_pair.first == "lease-database") {
                 leases_parser = parser;
-            } /* else if (config_pair.first == "option-data") {
-                option_parser = parser;
-            } */ else if (config_pair.first == "hooks-libraries") {
+            } else if (config_pair.first == "hooks-libraries") {
                 // Executing the commit will alter currently loaded hooks
                 // libraries. Check if the supplied libraries are valid,
                 // but defer the commit until after everything else has
index 89042b9e2eef4c3c990e1372b8d42169e5b538f0..6430fb6dee1a07bd49c754f857a134630c39c3f4 100644 (file)
@@ -1079,5 +1079,14 @@ void Element::preprocess(std::istream& in, std::stringstream& out) {
     }
 }
 
+ElementPtr Element::getMutableMap(ConstElementPtr& const_map) {
+    std::map<std::string, ConstElementPtr> values;
+    const_map->getValue(values);
+    ElementPtr mutable_map(new MapElement());
+    mutable_map->setValue(values);
+
+    return (mutable_map);
+}
+
 }
 }
index f1a08fca404227852c4267739c41f31ac6500519..c4b985689cabdddb9ece24b8b0a7fd79b2d2a8e7 100644 (file)
@@ -523,6 +523,12 @@ public:
     /// \return ElementPtr with the data that is parsed.
     static ElementPtr fromWire(const std::string& s);
     //@}
+
+    /// @brief Creates mutable map based on const map
+    ///
+    /// @param const_map const map to be used as a donor
+    /// @return mutable map
+    static ElementPtr getMutableMap(ConstElementPtr& const_map);
 };
 
 /// Notes: IntElement type is changed to int64_t.