8 #ifndef NDN_SECURITY_CONF_FILTER_HPP
9 #define NDN_SECURITY_CONF_FILTER_HPP
11 #include "../../common.hpp"
12 #include "../../data.hpp"
13 #include "../../interest.hpp"
14 #include "../../util/regex.hpp"
15 #include <boost/algorithm/string.hpp>
50 , m_relation(relation)
72 return match(signedName);
82 return (name == m_name);
86 return (m_name.
isPrefixOf(name) && m_name != name);
124 return m_regex.
match(signedName);
134 static shared_ptr<Filter>
137 ConfigSection::const_iterator propertyIt = configSection.begin();
139 if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first,
"type"))
140 throw Error(
"Expect <filter.type>!");
142 std::string type = propertyIt->second.data();
144 if (boost::iequals(type,
"name"))
145 return createNameFilter(configSection);
147 throw Error(
"Unsupported filter.type: " + type);
150 static shared_ptr<Filter>
153 ConfigSection::const_iterator propertyIt = configSection.begin();
156 if (propertyIt == configSection.end())
157 throw Error(
"Expect more properties for filter(name)");
159 if (boost::iequals(propertyIt->first,
"name"))
165 name =
Name(propertyIt->second.data());
169 throw Error(
"Wrong filter.name: " + propertyIt->second.data());
175 if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first,
"relation"))
176 throw Error(
"Expect <filter.relation>!");
178 std::string relationString = propertyIt->second.data();
182 if (boost::iequals(relationString,
"equal"))
184 else if (boost::iequals(relationString,
"is-prefix-of"))
186 else if (boost::iequals(relationString,
"is-strict-prefix-of"))
189 throw Error(
"Unsupported relation: " + relationString);
192 if (propertyIt != configSection.end())
193 throw Error(
"Expect the end of filter!");
195 return make_shared<RelationNameFilter>(boost::cref(name),
196 boost::cref(relation));
198 else if (boost::iequals(propertyIt->first,
"regex"))
200 std::string regexString = propertyIt->second.data();
203 if (propertyIt != configSection.end())
204 throw Error(
"Expect the end of filter!");
208 return shared_ptr<RegexNameFilter>(
new RegexNameFilter(regexString));
210 catch (Regex::Error& e)
212 throw Error(
"Wrong filter.regex: " + regexString);
216 throw Error(
"Wrong filter(name) properties");
224 #endif // NDN_SECURITY_CONF_FILTER_HPP
const Name & getName() const
Name getPrefix(int nComponents) const
Return a new Name with the first nComponents components of this Name.
RegexNameFilter(const Regex ®ex)
virtual bool match(const Data &data)=0
An Interest holds a Name and other fields for an interest.
const Name & getName() const
Error that can be thrown from Name.
virtual bool match(const Data &data)
size_t size() const
Get the number of components.
virtual bool match(const Interest &interest)
A Name holds an array of Name::Component and represents an NDN name.
virtual ~RegexNameFilter()
boost::property_tree::ptree ConfigSection
RelationNameFilter(const Name &name, Relation relation)
bool match(const Name &name)
virtual bool match(const Interest &interest)
bool isPrefixOf(const Name &name) const
Check if the N components of this name are the same as the first N components of the given name...
static shared_ptr< Filter > create(const ConfigSection &configSection)
virtual bool match(const Data &data)
virtual ~RelationNameFilter()