]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[65-libyang-config-adaptor] Changed preProcess type
authorFrancis Dupont <fdupont@isc.org>
Mon, 22 Oct 2018 22:01:41 +0000 (00:01 +0200)
committerTomek Mrugalski <tomasz@isc.org>
Tue, 23 Oct 2018 08:47:29 +0000 (10:47 +0200)
src/lib/yang/adaptor_config.cc
src/lib/yang/adaptor_config.h

index 25058ea1e9fdb1259cb271927bfc284110057a47..a52a93fd5c2344d15232383de0df26440cc626e8 100644 (file)
@@ -402,9 +402,11 @@ AdaptorConfig::relaySuppliedOptions(ConstElementPtr dhcp) {
 }
 
 void
-AdaptorConfig::preProcess(ConstElementPtr dhcp, const string& subsel,
+AdaptorConfig::preProcess(ElementPtr dhcp, const string& subsel,
                           const string& space) {
-    ElementPtr mutable_dhcp = boost::const_pointer_cast<Element>(dhcp);
+    if (!dhcp) {
+        isc_throw(BadValue, "preProcess: null DHCP config");
+    }
     bool have_ids = true;
     SubnetIDSet set;
     ConstElementPtr subnets = dhcp->get(subsel);
@@ -414,7 +416,7 @@ AdaptorConfig::preProcess(ConstElementPtr dhcp, const string& subsel,
                 have_ids = false;
             }
         } else {
-            mutable_dhcp->remove(subsel);
+            dhcp->remove(subsel);
         }
     }
     ConstElementPtr networks = dhcp->get("shared-networks");
@@ -424,7 +426,7 @@ AdaptorConfig::preProcess(ConstElementPtr dhcp, const string& subsel,
                 have_ids = false;
             }
         } else {
-            mutable_dhcp->remove("shared-networks");
+            dhcp->remove("shared-networks");
         }
     }
 
@@ -441,7 +443,7 @@ AdaptorConfig::preProcess(ConstElementPtr dhcp, const string& subsel,
         if (defs->size() > 0) {
             optionDefList(defs, space, codes);
         } else {
-            mutable_dhcp->remove("option-def");
+            dhcp->remove("option-def");
         }
     }
     ConstElementPtr options = dhcp->get("option-data");
@@ -449,7 +451,7 @@ AdaptorConfig::preProcess(ConstElementPtr dhcp, const string& subsel,
         if (options->size() > 0) {
             optionDataList(options, space, codes);
         } else {
-            mutable_dhcp->remove("option-data");
+            dhcp->remove("option-data");
         }
     }
     ConstElementPtr classes = dhcp->get("client-classes");
@@ -457,7 +459,7 @@ AdaptorConfig::preProcess(ConstElementPtr dhcp, const string& subsel,
         if (classes->size() > 0) {
             optionClasses(classes, space, codes);
         } else {
-            mutable_dhcp->remove("client-classes");
+            dhcp->remove("client-classes");
         }
     }
     ConstElementPtr hosts = dhcp->get("reservations");
@@ -465,7 +467,7 @@ AdaptorConfig::preProcess(ConstElementPtr dhcp, const string& subsel,
         if (hosts->size() > 0) {
             optionHosts(hosts, space, codes);
         } else {
-            mutable_dhcp->remove("reservations");
+            dhcp->remove("reservations");
         }
     }
     optionSubnets(subnets, space, codes);
@@ -502,7 +504,8 @@ AdaptorConfig::preProcess4(ConstElementPtr config) {
     if (!dhcp) {
         return;
     }
-    preProcess(dhcp, "subnet4", "dhcp4");
+    ElementPtr mutable_dhcp = boost::const_pointer_cast<Element>(dhcp);
+    preProcess(mutable_dhcp, "subnet4", "dhcp4");
 }
 
 void
@@ -517,8 +520,10 @@ AdaptorConfig::preProcess6(ConstElementPtr config) {
     if (!dhcp) {
         return;
     }
-    preProcess(dhcp, "subnet6", "dhcp6");
+    ElementPtr mutable_dhcp = boost::const_pointer_cast<Element>(dhcp);
+    preProcess(mutable_dhcp, "subnet6", "dhcp6");
 }
 
 }; // end of namespace isc::yang
 }; // end of namespace isc
+
index c4ca8ec5d1f48eeb3c852cd8d100b02bbed38a8c..401c433bd3b96375764b1d26ac25cf7599a10168 100644 (file)
@@ -34,7 +34,9 @@ public:
 
     /// @brief Pre process a DHCPv4 configuration.
     ///
-    /// Assign subnet IDs, check and set default in options.
+    /// Assign subnet IDs, check and set default in options, etc.
+    /// Note even the parameter is a ConstElementPtr and is not modified
+    /// sub-structures can be so if you need a copy do a deep one.
     ///
     /// @param config The configuration.
     /// @throw MissingKey when a required key is missing.
@@ -44,7 +46,9 @@ public:
 
     /// @brief Pre process a DHCPv6 configuration.
     ///
-    /// Assign subnet IDs, check and set default in options.
+    /// Assign subnet IDs, check and set default in options, etc.
+    /// Note even the parameter is a ConstElementPtr and is not modified
+    /// sub-structures can be so if you need a copy do a deep one.
     ///
     /// @param config The configuration.
     /// @throw MissingKey when a required key is missing.
@@ -257,7 +261,7 @@ protected:
     /// @param subsel The subnet list name.
     /// @param space The default option space name.
     /// @throw MissingKey when a required key is missing.
-    static void preProcess(isc::data::ConstElementPtr dhcp,
+    static void preProcess(isc::data::ElementPtr dhcp,
                            const std::string& subsel,
                            const std::string& space);
 };