Commit c604855f authored by Tomek Mrugalski's avatar Tomek Mrugalski 🛰

[#65,!88] Remaining changes after review:

 - Remaining methods renamed
 - comments expanded
 - size() > 0 replaced with !empty() checks.
parent c7965980
......@@ -104,13 +104,15 @@ AdaptorConfig::sharedNetworksAssignID(ConstElementPtr networks,
for (ConstElementPtr network : networks->listValue()) {
ConstElementPtr subnets = network->get(subsel);
if (subnets && (subnets->size() > 0)) {
if (!subnets || subnets->empty()) {
continue;
}
for (size_t i = 0; i < subnets->size(); ++i) {
ElementPtr subnet = subnets->getNonConst(i);
assignID(subnet, set, next);
}
}
}
}
void
......@@ -154,7 +156,7 @@ AdaptorConfig::sanitizePoolsInSharedNetworks(ConstElementPtr networks,
}
void
AdaptorConfig::optionDefList(ConstElementPtr defs,
AdaptorConfig::sanitizeOptionDefList(ConstElementPtr defs,
const string& space,
OptionCodes& codes) {
if (!defs || defs->empty()) {
......@@ -174,7 +176,8 @@ AdaptorConfig::optionDefList(ConstElementPtr defs,
}
void
AdaptorConfig::optionDataList(ConstElementPtr options,const string& space,
AdaptorConfig::sanitizeOptionDataList(ConstElementPtr options,
const string& space,
const OptionCodes& codes) {
if (!options || options->empty()) {
// nothing to do here.
......@@ -191,30 +194,39 @@ AdaptorConfig::optionDataList(ConstElementPtr options,const string& space,
}
void
AdaptorConfig::optionClasses(ConstElementPtr classes, const string& space,
AdaptorConfig::sanitizeOptionClasses(ConstElementPtr classes,
const string& space,
OptionCodes& codes) {
if (!classes || classes->empty()) {
// nothing to do here.
return;
}
// For every client class defined...
for (size_t i = 0; i < classes->size(); ++i) {
ElementPtr cclass = classes->getNonConst(i);
if (space == DHCP4_SPACE) {
ConstElementPtr options = cclass->get("option-def");
if (options) {
if (options->size() > 0) {
optionDefList(options, space, codes);
if (!options->empty()) {
// If present, sanitize it.
sanitizeOptionDefList(options, space, codes);
} else {
// If empty, remove it.
cclass->remove("option-def");
}
}
}
// also sanitize option data.
ConstElementPtr options = cclass->get("option-data");
if (options) {
if (options->size() > 0) {
optionDataList(options, space, codes);
if (!options->empty()) {
// If present, sanitize it.
sanitizeOptionDataList(options, space, codes);
} else {
// If empty, remove it.
cclass->remove("option-data");
}
}
......@@ -222,7 +234,7 @@ AdaptorConfig::optionClasses(ConstElementPtr classes, const string& space,
}
void
AdaptorConfig::optionPools(ConstElementPtr pools, const string& space,
AdaptorConfig::sanitizeOptionPools(ConstElementPtr pools, const string& space,
const OptionCodes& codes) {
if (!pools || pools->empty()) {
// nothing to do here.
......@@ -233,8 +245,8 @@ AdaptorConfig::optionPools(ConstElementPtr pools, const string& space,
ElementPtr pool = pools->getNonConst(i);
ConstElementPtr options = pool->get("option-data");
if (options) {
if (options->size() > 0) {
optionDataList(options, space, codes);
if (!options->empty()) {
sanitizeOptionDataList(options, space, codes);
} else {
pool->remove("option-data");
}
......@@ -243,7 +255,7 @@ AdaptorConfig::optionPools(ConstElementPtr pools, const string& space,
}
void
AdaptorConfig::optionHosts(ConstElementPtr hosts, const string& space,
AdaptorConfig::sanitizeOptionHosts(ConstElementPtr hosts, const string& space,
const OptionCodes& codes) {
if (!hosts || hosts->empty()) {
// nothing to do here.
......@@ -254,8 +266,8 @@ AdaptorConfig::optionHosts(ConstElementPtr hosts, const string& space,
ElementPtr host = hosts->getNonConst(i);
ConstElementPtr options = host->get("option-data");
if (options) {
if (options->size() > 0) {
optionDataList(options, space, codes);
if (!options->empty()) {
sanitizeOptionDataList(options, space, codes);
} else {
host->remove("option-data");
}
......@@ -264,7 +276,8 @@ AdaptorConfig::optionHosts(ConstElementPtr hosts, const string& space,
}
void
AdaptorConfig::optionSubnets(ConstElementPtr subnets, const string& space,
AdaptorConfig::sanitizeOptionSubnets(ConstElementPtr subnets,
const string& space,
const OptionCodes& codes) {
if (!subnets || subnets->empty()) {
// nothing to do here.
......@@ -277,8 +290,8 @@ AdaptorConfig::optionSubnets(ConstElementPtr subnets, const string& space,
// Let's try to sanitize option-data first.
ConstElementPtr options = subnet->get("option-data");
if (options) {
if (options->size() > 0) {
optionDataList(options, space, codes);
if (!options->empty()) {
sanitizeOptionDataList(options, space, codes);
} else {
subnet->remove("option-data");
}
......@@ -287,8 +300,8 @@ AdaptorConfig::optionSubnets(ConstElementPtr subnets, const string& space,
// Then try to sanitize pools.
ConstElementPtr pools = subnet->get("pools");
if (pools) {
if (pools->size() > 0) {
optionPools(pools, space, codes);
if (!pools->empty()) {
sanitizeOptionPools(pools, space, codes);
} else {
subnet->remove("pools");
}
......@@ -298,8 +311,8 @@ AdaptorConfig::optionSubnets(ConstElementPtr subnets, const string& space,
if (space == DHCP6_SPACE) {
ConstElementPtr pools = subnet->get("pd-pools");
if (pools) {
if (pools->size() > 0) {
optionPools(pools, space, codes);
if (!pools->empty()) {
sanitizeOptionPools(pools, space, codes);
} else {
subnet->remove("pd-pools");
}
......@@ -309,8 +322,8 @@ AdaptorConfig::optionSubnets(ConstElementPtr subnets, const string& space,
// Finally, sanitize host reservations.
ConstElementPtr hosts = subnet->get("reservations");
if (hosts) {
if (hosts->size() > 0) {
optionHosts(hosts, space, codes);
if (!hosts->empty()) {
sanitizeOptionHosts(hosts, space, codes);
} else {
subnet->remove("reservations");
}
......@@ -319,7 +332,7 @@ AdaptorConfig::optionSubnets(ConstElementPtr subnets, const string& space,
}
void
AdaptorConfig::optionSharedNetworks(ConstElementPtr networks,
AdaptorConfig::sanitizeOptionSharedNetworks(ConstElementPtr networks,
const string& space,
const OptionCodes& codes) {
if (!networks || networks->empty()) {
......@@ -334,8 +347,8 @@ AdaptorConfig::optionSharedNetworks(ConstElementPtr networks,
// try to sanitize shared network options first.
ConstElementPtr options = network->get("option-data");
if (options) {
if (options->size() > 0) {
optionDataList(options, space, codes);
if (!options->empty()) {
sanitizeOptionDataList(options, space, codes);
} else {
network->remove("option-data");
}
......@@ -350,8 +363,8 @@ AdaptorConfig::optionSharedNetworks(ConstElementPtr networks,
// Now try to sanitize subnets.
ConstElementPtr subnets = network->get(subnet);
if (subnets) {
if (subnets->size() > 0) {
optionSubnets(subnets, space, codes);
if (!subnets->empty()) {
sanitizeOptionSubnets(subnets, space, codes);
} else {
network->remove(subnet);
}
......@@ -360,7 +373,7 @@ AdaptorConfig::optionSharedNetworks(ConstElementPtr networks,
}
void
AdaptorConfig::requireClassesPools(ConstElementPtr pools) {
AdaptorConfig::sanitizeRequireClassesPools(ConstElementPtr pools) {
if (!pools || pools->empty()) {
// nothing to do here.
return;
......@@ -376,7 +389,7 @@ AdaptorConfig::requireClassesPools(ConstElementPtr pools) {
}
void
AdaptorConfig::requireClassesSubnets(ConstElementPtr subnets) {
AdaptorConfig::sanitizeRequireClassesSubnets(ConstElementPtr subnets) {
if (!subnets || subnets->empty()) {
// nothing to do here.
return;
......@@ -384,10 +397,10 @@ AdaptorConfig::requireClassesSubnets(ConstElementPtr subnets) {
for (size_t i = 0; i < subnets->size(); ++i) {
ElementPtr subnet = subnets->getNonConst(i);
requireClassesPools(subnet->get("pools"));
requireClassesPools(subnet->get("pd-pools"));
sanitizeRequireClassesPools(subnet->get("pools"));
sanitizeRequireClassesPools(subnet->get("pd-pools"));
ConstElementPtr requires = subnet->get("require-client-classes");
if (requires && (requires->size() == 0)) {
if (requires && requires->empty()) {
subnet->remove("require-client-classes");
}
}
......@@ -403,16 +416,16 @@ AdaptorConfig::requireClassesSharedNetworks(ConstElementPtr networks,
for (size_t i = 0; i < networks->size(); ++i) {
ElementPtr network = networks->getNonConst(i);
requireClassesSubnets(network->get(subsel));
sanitizeRequireClassesSubnets(network->get(subsel));
ConstElementPtr requires = network->get("require-client-classes");
if (requires && (requires->size() == 0)) {
if (requires && requires->empty()) {
network->remove("require-client-classes");
}
}
}
void
AdaptorConfig::hostList(ConstElementPtr hosts) {
AdaptorConfig::sanitizeHostList(ConstElementPtr hosts) {
if (!hosts || hosts->empty()) {
// nothing to do here.
......@@ -426,7 +439,7 @@ AdaptorConfig::hostList(ConstElementPtr hosts) {
}
void
AdaptorConfig::hostSubnets(ConstElementPtr subnets) {
AdaptorConfig::sanitizeHostSubnets(ConstElementPtr subnets) {
if (!subnets || subnets->empty()) {
// nothing to do here.
......@@ -434,12 +447,12 @@ AdaptorConfig::hostSubnets(ConstElementPtr subnets) {
}
for (ConstElementPtr subnet : subnets->listValue()) {
hostList(subnet->get("reservations"));
sanitizeHostList(subnet->get("reservations"));
}
}
void
AdaptorConfig::hostSharedNetworks(ConstElementPtr networks,
AdaptorConfig::SanitizeHostsInSharedNetworks(ConstElementPtr networks,
const string& space) {
if (!networks || networks->empty()) {
// nothing to do here.
......@@ -448,15 +461,15 @@ AdaptorConfig::hostSharedNetworks(ConstElementPtr networks,
for (ConstElementPtr network : networks->listValue()) {
if (space == DHCP4_SPACE) {
hostSubnets(network->get("subnet4"));
sanitizeHostSubnets(network->get("subnet4"));
} else {
hostSubnets(network->get("subnet6"));
sanitizeHostSubnets(network->get("subnet6"));
}
}
}
void
AdaptorConfig::relaySubnets(ConstElementPtr subnets) {
AdaptorConfig::sanitizeRelaySubnets(ConstElementPtr subnets) {
if (!subnets || subnets->empty()) {
// nothing to do here.
return;
......@@ -469,7 +482,7 @@ AdaptorConfig::relaySubnets(ConstElementPtr subnets) {
}
void
AdaptorConfig::relaySharedNetworks(ConstElementPtr networks,
AdaptorConfig::sanitizeRelayInSharedNetworks(ConstElementPtr networks,
const string& subsel) {
if (!networks || networks->empty()) {
// nothing to do here.
......@@ -479,12 +492,12 @@ AdaptorConfig::relaySharedNetworks(ConstElementPtr networks,
for (size_t i = 0; i < networks->size(); ++i) {
ElementPtr network = networks->getNonConst(i);
updateRelay(network);
relaySubnets(network->get(subsel));
sanitizeRelaySubnets(network->get(subsel));
}
}
void
AdaptorConfig::updateDatabase(ConstElementPtr dhcp) {
AdaptorConfig::sanitizeDatabase(ConstElementPtr dhcp) {
ConstElementPtr database = dhcp->get("hosts-database");
if (!database) {
return;
......@@ -498,7 +511,7 @@ AdaptorConfig::updateDatabase(ConstElementPtr dhcp) {
}
void
AdaptorConfig::relaySuppliedOptions(ConstElementPtr dhcp) {
AdaptorConfig::sanitizeRelaySuppliedOptions(ConstElementPtr dhcp) {
ConstElementPtr options = dhcp->get("relay-supplied-options");
if (!options || options->empty()) {
return;
......@@ -517,7 +530,7 @@ AdaptorConfig::preProcess(ElementPtr dhcp, const string& subsel,
SubnetIDSet set;
ConstElementPtr subnets = dhcp->get(subsel);
if (subnets) {
if (subnets->size() > 0) {
if (!subnets->empty()) {
if (!subnetsCollectID(subnets, set)) {
have_ids = false;
}
......@@ -527,7 +540,7 @@ AdaptorConfig::preProcess(ElementPtr dhcp, const string& subsel,
}
ConstElementPtr networks = dhcp->get("shared-networks");
if (networks) {
if (networks->size() > 0) {
if (!networks->empty()) {
if (!sharedNetworksCollectID(networks, set, subsel)) {
have_ids = false;
}
......@@ -546,55 +559,55 @@ AdaptorConfig::preProcess(ElementPtr dhcp, const string& subsel,
initCodes(codes, space);;
ConstElementPtr defs = dhcp->get("option-def");
if (defs) {
if (defs->size() > 0) {
optionDefList(defs, space, codes);
if (!defs->empty()) {
sanitizeOptionDefList(defs, space, codes);
} else {
dhcp->remove("option-def");
}
}
ConstElementPtr options = dhcp->get("option-data");
if (options) {
if (options->size() > 0) {
optionDataList(options, space, codes);
if (!options->empty()) {
sanitizeOptionDataList(options, space, codes);
} else {
dhcp->remove("option-data");
}
}
ConstElementPtr classes = dhcp->get("client-classes");
if (classes) {
if (classes->size() > 0) {
optionClasses(classes, space, codes);
if (!classes->empty()) {
sanitizeOptionClasses(classes, space, codes);
} else {
dhcp->remove("client-classes");
}
}
ConstElementPtr hosts = dhcp->get("reservations");
if (hosts) {
if (hosts->size() > 0) {
optionHosts(hosts, space, codes);
if (!hosts->empty()) {
sanitizeOptionHosts(hosts, space, codes);
} else {
dhcp->remove("reservations");
}
}
optionSubnets(subnets, space, codes);
optionSharedNetworks(networks, space, codes);
sanitizeOptionSubnets(subnets, space, codes);
sanitizeOptionSharedNetworks(networks, space, codes);
sanitizePoolsInSubnets(subnets);
sanitizePoolsInSharedNetworks(networks, subsel);
hostSubnets(subnets);
hostSharedNetworks(networks, space);
sanitizeHostSubnets(subnets);
SanitizeHostsInSharedNetworks(networks, space);
relaySubnets(subnets);
relaySharedNetworks(networks, subsel);
sanitizeRelaySubnets(subnets);
sanitizeRelayInSharedNetworks(networks, subsel);
requireClassesSubnets(subnets);
sanitizeRequireClassesSubnets(subnets);
requireClassesSharedNetworks(networks, subsel);
updateDatabase(dhcp);
sanitizeDatabase(dhcp);
if (space == DHCP6_SPACE) {
relaySuppliedOptions(dhcp);
sanitizeRelaySuppliedOptions(dhcp);
}
}
......
......@@ -134,10 +134,13 @@ protected:
/// @brief Collect option definitions from an option definition list.
///
/// Collects options definitions, but also sets missing option space
/// with default.
///
/// @param defs The option definition list.
/// @param space The default space name.
/// @param space The default space name (missing will be filled with this)
/// @param codes Option definitions.
static void optionDefList(isc::data::ConstElementPtr defs,
static void sanitizeOptionDefList(isc::data::ConstElementPtr defs,
const std::string& space,
OptionCodes& codes);
......@@ -146,7 +149,7 @@ protected:
/// @param options The option data list.
/// @param space The default space name.
/// @param codes Option definitions.
static void optionDataList(isc::data::ConstElementPtr options,
static void sanitizeOptionDataList(isc::data::ConstElementPtr options,
const std::string& space,
const OptionCodes& codes);
......@@ -156,7 +159,7 @@ protected:
/// @param classes The client class list.
/// @param space The default space name.
/// @param codes Option definitions.
static void optionClasses(isc::data::ConstElementPtr classes,
static void sanitizeOptionClasses(isc::data::ConstElementPtr classes,
const std::string& space,
OptionCodes& codes);
......@@ -165,7 +168,7 @@ protected:
/// @param pools The pool list.
/// @param space The default space name.
/// @param codes Option definitions.
static void optionPools(isc::data::ConstElementPtr pools,
static void sanitizeOptionPools(isc::data::ConstElementPtr pools,
const std::string& space,
const OptionCodes& codes);
......@@ -174,7 +177,7 @@ protected:
/// @param hosts The host reservation list.
/// @param space The default space name.
/// @param codes Option definitions.
static void optionHosts(isc::data::ConstElementPtr hosts,
static void sanitizeOptionHosts(isc::data::ConstElementPtr hosts,
const std::string& space,
const OptionCodes& codes);
......@@ -183,7 +186,7 @@ protected:
/// @param subnets The subnet list.
/// @param space The default space name.
/// @param codes Option definitions.
static void optionSubnets(isc::data::ConstElementPtr subnets,
static void sanitizeOptionSubnets(isc::data::ConstElementPtr subnets,
const std::string& space,
const OptionCodes& codes);
......@@ -192,7 +195,7 @@ protected:
/// @param networks The shared network list.
/// @param space The default space name.
/// @param codes Option definitions.
static void optionSharedNetworks(isc::data::ConstElementPtr networks,
static void sanitizeOptionSharedNetworks(isc::data::ConstElementPtr networks,
const std::string& space,
const OptionCodes& codes);
......@@ -201,14 +204,14 @@ protected:
/// Remove empty require client class list.
///
/// @param pools The pool list.
static void requireClassesPools(isc::data::ConstElementPtr pools);
static void sanitizeRequireClassesPools(isc::data::ConstElementPtr pools);
/// @brief Process require client classes in a subnet list.
///
/// Remove empty require client class lists.
///
/// @param subnets The subnet list.
static void requireClassesSubnets(isc::data::ConstElementPtr subnets);
static void sanitizeRequireClassesSubnets(isc::data::ConstElementPtr subnets);
/// @brief Process require client classes in a shared network list.
///
......@@ -224,14 +227,14 @@ protected:
/// Quote when needed flex-id identifiers.
///
/// @param hosts The host reservation list.
static void hostList(isc::data::ConstElementPtr hosts);
static void sanitizeHostList(isc::data::ConstElementPtr hosts);
/// @brief Process host reservations in a subnet list.
///
/// Quote when needed flex-id identifiers.
///
/// @param subnets The subnet list.
static void hostSubnets(isc::data::ConstElementPtr subnets);
static void sanitizeHostSubnets(isc::data::ConstElementPtr subnets);
/// @brief Process host reservations in a shared network list.
///
......@@ -239,23 +242,23 @@ protected:
///
/// @param networks The shared network list.
/// @param space The default space name.
static void hostSharedNetworks(isc::data::ConstElementPtr networks,
static void SanitizeHostsInSharedNetworks(isc::data::ConstElementPtr networks,
const std::string& space);
/// @brief updateRelay in a subnet list.
/// @brief Sanitizes relay information in subnets in a subnet list.
///
/// Force the use of ip-addresses when it finds an ip-address entry.
///
/// @param subnets The subnet list.
static void relaySubnets(isc::data::ConstElementPtr subnets);
static void sanitizeRelaySubnets(isc::data::ConstElementPtr subnets);
/// @brief updateRelay in a shared network list.
/// @brief Sanitizes relay information in a shared network list.
///
/// Force the use of ip-addresses when it finds an ip-address entry.
///
/// @param networks The shared network list.
/// @param subsel The subnet list name.
static void relaySharedNetworks(isc::data::ConstElementPtr networks,
static void sanitizeRelayInSharedNetworks(isc::data::ConstElementPtr networks,
const std::string& subsel);
/// @brief Update (hosts) database.
......@@ -263,14 +266,14 @@ protected:
/// Force the use of hosts-databases vs. hosts-database.
///
/// @param dhcp The DHCP server.
static void updateDatabase(isc::data::ConstElementPtr dhcp);
static void sanitizeDatabase(isc::data::ConstElementPtr dhcp);
/// @brief Update relay supplied options.
///
/// Remove empty relay supplied option list.
///
/// @param dhcp The DHCPv6 server.
static void relaySuppliedOptions(isc::data::ConstElementPtr dhcp);
static void sanitizeRelaySuppliedOptions(isc::data::ConstElementPtr dhcp);
/// @brief Pre process a configuration.
///
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment