config_parser: Split up sections
We can't always combine sections together in network files as sections
like
[Address]
Address=::1/128
Peer=fe80::1
[Address]
Address=::2/128
Peer=fe80::2
Require that they are grouped accordingly. Rewrite the storage logic of
the config parser to support this logical organization.
Change-Id: I34ae1523202f8770fe3dcac010fb6226dd28b9ec
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/util.cpp b/src/util.cpp
index 26d9b47..724eae6 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -366,8 +366,8 @@
bool getIPv6AcceptRA(const config::Parser& config)
{
- const auto& values = config.getValues("Network", "IPv6AcceptRA");
- if (values.empty())
+ auto value = config.getMap().getLastValueString("Network", "IPv6AcceptRA");
+ if (value == nullptr)
{
auto msg = fmt::format(
"Unable to get the value for Network[IPv6AcceptRA] from {}",
@@ -376,23 +376,23 @@
entry("FILE=%s", config.getFilename().c_str()));
return false;
}
- auto ret = config::parseBool(values.back());
+ auto ret = config::parseBool(*value);
if (!ret.has_value())
{
auto msg = fmt::format(
"Failed to parse section Network[IPv6AcceptRA] from {}: `{}`",
- config.getFilename().native(), values.back());
+ config.getFilename().native(), *value);
log<level::NOTICE>(msg.c_str(),
entry("FILE=%s", config.getFilename().c_str()),
- entry("VALUE=%s", values.back().c_str()));
+ entry("VALUE=%s", value->c_str()));
}
return ret.value_or(false);
}
EthernetInterfaceIntf::DHCPConf getDHCPValue(const config::Parser& config)
{
- const auto& values = config.getValues("Network", "DHCP");
- if (values.empty())
+ const auto value = config.getMap().getLastValueString("Network", "DHCP");
+ if (value == nullptr)
{
auto msg =
fmt::format("Unable to get the value for Network[DHCP] from {}",
@@ -401,22 +401,22 @@
entry("FILE=%s", config.getFilename().c_str()));
return EthernetInterfaceIntf::DHCPConf::none;
}
- if (config::icaseeq(values.back(), "ipv4"))
+ if (config::icaseeq(*value, "ipv4"))
{
return EthernetInterfaceIntf::DHCPConf::v4;
}
- if (config::icaseeq(values.back(), "ipv6"))
+ if (config::icaseeq(*value, "ipv6"))
{
return EthernetInterfaceIntf::DHCPConf::v6;
}
- auto ret = config::parseBool(values.back());
+ auto ret = config::parseBool(*value);
if (!ret.has_value())
{
auto str = fmt::format("Unable to parse Network[DHCP] from {}: `{}`",
- config.getFilename().native(), values.back());
+ config.getFilename().native(), *value);
log<level::NOTICE>(str.c_str(),
entry("FILE=%s", config.getFilename().c_str()),
- entry("VALUE=%s", values.back().c_str()));
+ entry("VALUE=%s", value->c_str()));
}
return ret.value_or(false) ? EthernetInterfaceIntf::DHCPConf::both
: EthernetInterfaceIntf::DHCPConf::none;