24 #ifndef NDN_SECURITY_CONF_FILTER_HPP 25 #define NDN_SECURITY_CONF_FILTER_HPP 27 #include "../../common.hpp" 28 #include "../../data.hpp" 29 #include "../../interest.hpp" 30 #include "../../util/regex.hpp" 31 #include "../security-common.hpp" 32 #include <boost/algorithm/string.hpp> 85 RELATION_IS_STRICT_PREFIX_OF
90 , m_relation(relation)
106 return (name == m_name);
107 case RELATION_IS_PREFIX_OF:
108 return m_name.isPrefixOf(name);
109 case RELATION_IS_STRICT_PREFIX_OF:
110 return (m_name.isPrefixOf(name) && m_name.size() < name.
size());
139 return m_regex.match(name);
149 static shared_ptr<Filter>
152 ConfigSection::const_iterator propertyIt = configSection.begin();
154 if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first,
"type"))
155 BOOST_THROW_EXCEPTION(
Error(
"Expect <filter.type>!"));
157 std::string type = propertyIt->second.data();
159 if (boost::iequals(type,
"name"))
160 return createNameFilter(configSection);
162 BOOST_THROW_EXCEPTION(
Error(
"Unsupported filter.type: " + type));
165 static shared_ptr<Filter>
168 ConfigSection::const_iterator propertyIt = configSection.begin();
171 if (propertyIt == configSection.end())
172 BOOST_THROW_EXCEPTION(
Error(
"Expect more properties for filter(name)"));
174 if (boost::iequals(propertyIt->first,
"name"))
180 name =
Name(propertyIt->second.data());
184 BOOST_THROW_EXCEPTION(
Error(
"Wrong filter.name: " + propertyIt->second.data()));
190 if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first,
"relation"))
191 BOOST_THROW_EXCEPTION(
Error(
"Expect <filter.relation>!"));
193 std::string relationString = propertyIt->second.data();
197 if (boost::iequals(relationString,
"equal"))
199 else if (boost::iequals(relationString,
"is-prefix-of"))
201 else if (boost::iequals(relationString,
"is-strict-prefix-of"))
204 BOOST_THROW_EXCEPTION(
Error(
"Unsupported relation: " + relationString));
207 if (propertyIt != configSection.end())
208 BOOST_THROW_EXCEPTION(
Error(
"Expect the end of filter!"));
210 return make_shared<RelationNameFilter>(name, relation);
212 else if (boost::iequals(propertyIt->first,
"regex"))
214 std::string regexString = propertyIt->second.data();
217 if (propertyIt != configSection.end())
218 BOOST_THROW_EXCEPTION(
Error(
"Expect the end of filter!"));
226 BOOST_THROW_EXCEPTION(
Error(
"Wrong filter.regex: " + regexString));
230 BOOST_THROW_EXCEPTION(
Error(
"Wrong filter(name) properties"));
238 #endif // NDN_SECURITY_CONF_FILTER_HPP
PartialName getPrefix(ssize_t nComponents) const
Extract a prefix (PartialName) of the name, containing first nComponents components.
Copyright (c) 2011-2015 Regents of the University of California.
virtual bool matchName(const Name &name)
const Name & getName() const
Get name of the Data packet.
RegexNameFilter(const Regex ®ex)
represents an Interest packet
Copyright (c) 2013-2016 Regents of the University of California.
Error that can be thrown from Name.
bool match(const Interest &interest)
virtual bool matchName(const Name &name)=0
const size_t MIN_LENGTH
minimal number of components for Command Interest
virtual bool matchName(const Name &name)
bool match(const Data &data)
Name abstraction to represent an absolute name.
Filter is one of the classes used by ValidatorConfig.
virtual ~RegexNameFilter()
size_t size() const
Get the number of components.
boost::property_tree::ptree ConfigSection
RelationNameFilter(const Name &name, Relation relation)
static shared_ptr< Filter > create(const ConfigSection &configSection)
virtual ~RelationNameFilter()
const Name & getName() const