29 #include <boost/algorithm/string/predicate.hpp> 34 namespace validator_config {
48 return matchName(pktName);
54 , m_relation(relation)
59 RelationNameFilter::matchName(
const Name& name)
70 RegexNameFilter::matchName(
const Name& name)
72 return m_regex.
match(name);
78 auto propertyIt = configSection.begin();
80 if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first,
"type")) {
81 BOOST_THROW_EXCEPTION(
Error(
"Expecting <filter.type>"));
84 std::string type = propertyIt->second.data();
85 if (boost::iequals(type,
"name"))
86 return createNameFilter(configSection, configFilename);
88 BOOST_THROW_EXCEPTION(
Error(
"Unrecognized <filter.type>: " + type));
92 Filter::createNameFilter(
const ConfigSection& configSection,
const std::string& configFilename)
94 auto propertyIt = configSection.begin();
97 if (propertyIt == configSection.end())
98 BOOST_THROW_EXCEPTION(
Error(
"Unexpected end of <filter>"));
100 if (boost::iequals(propertyIt->first,
"name")) {
104 name =
Name(propertyIt->second.data());
107 BOOST_THROW_EXCEPTION(
Error(
"Invalid <filter.name>: " + propertyIt->second.data()));
113 if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first,
"relation")) {
114 BOOST_THROW_EXCEPTION(
Error(
"Expecting <filter.relation>"));
120 if (propertyIt != configSection.end())
121 BOOST_THROW_EXCEPTION(
Error(
"Expecting end of <filter>"));
123 return make_unique<RelationNameFilter>(name, relation);
125 else if (boost::iequals(propertyIt->first,
"regex")) {
126 std::string regexString = propertyIt->second.data();
129 if (propertyIt != configSection.end())
130 BOOST_THROW_EXCEPTION(
Error(
"Expecting end of <filter>"));
133 return make_unique<RegexNameFilter>(
Regex(regexString));
136 BOOST_THROW_EXCEPTION(
Error(
"Invalid <filter.regex>: " + regexString));
140 BOOST_THROW_EXCEPTION(
Error(
"Unrecognized <filter> property: " + propertyIt->first));
Copyright (c) 2013-2017 Regents of the University of California.
const size_t MIN_SIZE
minimal number of components for Signed Interest
bool match(uint32_t pktType, const Name &pktName)
bool checkNameRelation(NameRelation relation, const Name &name1, const Name &name2)
check whether name1 and name2 satisfies relation
NameRelation getNameRelationFromString(const std::string &relationString)
convert relationString to NameRelation
RelationNameFilter(const Name &name, NameRelation relation)
size_t size() const
Get number of components.
RegexNameFilter(const Regex ®ex)
Represents an absolute name.
static unique_ptr< Filter > create(const ConfigSection &configSection, const std::string &configFilename)
Create a filter from the configuration section.
boost::property_tree::ptree ConfigSection
bool match(const Name &name)
PartialName getPrefix(ssize_t nComponents) const
Extract a prefix of the name.