29 #include <boost/algorithm/string.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(
"Expect <filter.type>"));
84 std::string type = propertyIt->second.data();
86 if (boost::iequals(type,
"name"))
87 return createNameFilter(configSection, configFilename);
89 BOOST_THROW_EXCEPTION(
Error(
"Unsupported filter.type: " + type));
93 Filter::createNameFilter(
const ConfigSection& configSection,
const std::string& configFilename)
95 auto propertyIt = configSection.begin();
98 if (propertyIt == configSection.end()) {
99 BOOST_THROW_EXCEPTION(
Error(
"Expect more properties for filter(name)"));
102 if (boost::iequals(propertyIt->first,
"name")) {
106 name =
Name(propertyIt->second.data());
109 BOOST_THROW_EXCEPTION(
Error(
"Wrong filter.name: " + propertyIt->second.data()));
115 if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first,
"relation")) {
116 BOOST_THROW_EXCEPTION(
Error(
"Expect <filter.relation>"));
122 if (propertyIt != configSection.end())
123 BOOST_THROW_EXCEPTION(
Error(
"Expect the end of filter"));
125 return make_unique<RelationNameFilter>(name, relation);
127 else if (boost::iequals(propertyIt->first,
"regex")) {
128 std::string regexString = propertyIt->second.data();
131 if (propertyIt != configSection.end())
132 BOOST_THROW_EXCEPTION(
Error(
"Expect the end of filter"));
135 return make_unique<RegexNameFilter>(regexString);
138 BOOST_THROW_EXCEPTION(
Error(
"Wrong filter.regex: " + regexString));
142 BOOST_THROW_EXCEPTION(
Error(
"Wrong filter(name) properties"));
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.