From: Francis Dupont Date: Mon, 22 Oct 2018 22:01:41 +0000 (+0200) Subject: [65-libyang-config-adaptor] Changed preProcess type X-Git-Tag: 65-libyang-config-translator_base~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=be3423b7bc1b10e86ad23e6a75ebc37cc08749d7;p=thirdparty%2Fkea.git [65-libyang-config-adaptor] Changed preProcess type --- diff --git a/src/lib/yang/adaptor_config.cc b/src/lib/yang/adaptor_config.cc index 25058ea1e9..a52a93fd5c 100644 --- a/src/lib/yang/adaptor_config.cc +++ b/src/lib/yang/adaptor_config.cc @@ -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(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(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(dhcp); + preProcess(mutable_dhcp, "subnet6", "dhcp6"); } }; // end of namespace isc::yang }; // end of namespace isc + diff --git a/src/lib/yang/adaptor_config.h b/src/lib/yang/adaptor_config.h index c4ca8ec5d1..401c433bd3 100644 --- a/src/lib/yang/adaptor_config.h +++ b/src/lib/yang/adaptor_config.h @@ -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); };