50 NetworkPredicateBase::parseList(std::set<std::string>& set,
51 const boost::property_tree::ptree& list,
52 const std::string& section)
56 for (
const auto& item : list) {
57 if (item.first ==
"*") {
59 set.insert(item.first);
62 if (!isRuleSupported(item.first)) {
64 "' in section '" + section +
"'"));
67 auto value = item.second.get_value<std::string>();
68 if (!isRuleValid(item.first, value)) {
69 NDN_THROW(ConfigFile::Error(
"Malformed " + item.first +
" '" + value +
70 "' in section '" + section +
"'"));
78 NetworkPredicateBase::parseList(std::set<std::string>& set,
79 std::initializer_list<std::pair<std::string, std::string>> list)
83 for (
const auto& item : list) {
84 if (item.first ==
"*") {
86 set.insert(item.first);
89 if (!isRuleSupported(item.first)) {
90 NDN_THROW(std::runtime_error(
"Unrecognized rule '" + item.first +
"'"));
93 if (!isRuleValid(item.first, item.second)) {
94 NDN_THROW(std::runtime_error(
"Malformed " + item.first +
" '" + item.second +
"'"));
96 set.insert(item.second);
115 std::initializer_list<std::pair<std::string, std::string>> blacklist)
122 NetworkInterfacePredicate::isRuleSupported(
const std::string& key)
124 return key ==
"ifname" || key ==
"ether" || key ==
"subnet";
128 NetworkInterfacePredicate::isRuleValid(
const std::string& key,
const std::string& value)
130 if (key ==
"ifname") {
132 return !value.empty();
134 else if (key ==
"ether") {
138 else if (key ==
"subnet") {
143 NDN_THROW(std::logic_error(
"Only supported rules are expected"));
148 IpAddressPredicate::isRuleSupported(
const std::string& key)
150 return key ==
"subnet";
154 IpAddressPredicate::isRuleValid(
const std::string& key,
const std::string& value)
156 if (key ==
"subnet") {
161 NDN_THROW(std::logic_error(
"Only supported rules are expected"));
177 return ::fnmatch(pattern.data(), ifname.data(), 0) == 0;
184 if (rule.find(
'/') != std::string::npos) {
185 Network n = boost::lexical_cast<Network>(rule);
193 return rule ==
"*" ||
209 if (rule.find(
'/') != std::string::npos) {
210 Network n = boost::lexical_cast<Network>(rule);