27 #include <boost/algorithm/string/predicate.hpp> 32 namespace validator_config {
36 const shared_ptr<ValidationState>& state)
53 , m_relation(relation)
59 const shared_ptr<ValidationState>& state)
65 std::ostringstream os;
66 os <<
"KeyLocator check failed: name relation " << m_name <<
" " << m_relation
67 <<
" for packet " << pktName <<
" is invalid" 68 <<
" (KeyLocator=" << klName <<
", identity=" << identity <<
")";
82 bool result = m_regex.
match(klName);
84 std::ostringstream os;
85 os <<
"KeyLocator check failed: regex " << m_regex <<
" for packet " << pktName <<
" is invalid" 86 <<
" (KeyLocator=" << klName <<
")";
93 const std::string& klNameExpr,
const std::string klNameExpand,
95 : m_hyperPRegex(pktNameExpr, pktNameExpand)
96 , m_hyperKRegex(klNameExpr, klNameExpand)
97 , m_hyperRelation(hyperRelation)
103 const shared_ptr<ValidationState>& state)
105 if (!m_hyperPRegex.
match(pktName) || !m_hyperKRegex.
match(klName)) {
106 std::ostringstream os;
107 os <<
"Packet " << pktName <<
" (" <<
"KeyLocator=" << klName <<
") does not match " 108 <<
"the hyper relation rule pkt=" << m_hyperPRegex <<
", key=" << m_hyperKRegex;
115 std::ostringstream os;
116 os <<
"KeyLocator check failed: hyper relation " << m_hyperRelation
117 <<
" pkt=" << m_hyperPRegex <<
", key=" << m_hyperKRegex
118 <<
" of packet " << pktName <<
" (KeyLocator=" << klName <<
") is invalid";
127 auto propertyIt = configSection.begin();
130 if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first,
"type")) {
134 std::string type = propertyIt->second.data();
135 if (boost::iequals(type,
"customized")) {
136 return createCustomizedChecker(configSection, configFilename);
138 else if (boost::iequals(type,
"hierarchical")) {
139 return createHierarchicalChecker(configSection, configFilename);
147 Checker::createCustomizedChecker(
const ConfigSection& configSection,
148 const std::string& configFilename)
150 auto propertyIt = configSection.begin();
155 if (propertyIt != configSection.end() && boost::iequals(propertyIt->first,
"sig-type")) {
161 if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first,
"key-locator")) {
165 auto checker = createKeyLocatorChecker(propertyIt->second, configFilename);
168 if (propertyIt != configSection.end()) {
175 Checker::createHierarchicalChecker(
const ConfigSection& configSection,
176 const std::string& configFilename)
178 auto propertyIt = configSection.begin();
183 if (propertyIt != configSection.end() && boost::iequals(propertyIt->first,
"sig-type")) {
188 if (propertyIt != configSection.end()) {
191 return make_unique<HyperRelationChecker>(
"^(<>*)$",
"\\1",
192 "^(<>*)<KEY><>$",
"\\1",
197 Checker::createKeyLocatorChecker(
const ConfigSection& configSection,
198 const std::string& configFilename)
200 auto propertyIt = configSection.begin();
203 if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first,
"type"))
206 std::string type = propertyIt->second.data();
207 if (boost::iequals(type,
"name"))
208 return createKeyLocatorNameChecker(configSection, configFilename);
210 NDN_THROW(
Error(
"Unrecognized <checker.key-locator.type>: " + type));
214 Checker::createKeyLocatorNameChecker(
const ConfigSection& configSection,
215 const std::string& configFilename)
217 auto propertyIt = configSection.begin();
220 if (propertyIt == configSection.end())
223 if (boost::iequals(propertyIt->first,
"name")) {
226 name =
Name(propertyIt->second.data());
233 if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first,
"relation")) {
237 std::string relationString = propertyIt->second.data();
242 if (propertyIt != configSection.end()) {
245 return make_unique<NameRelationChecker>(name, relation);
247 else if (boost::iequals(propertyIt->first,
"regex")) {
248 std::string regexString = propertyIt->second.data();
251 if (propertyIt != configSection.end()) {
256 return make_unique<RegexChecker>(
Regex(regexString));
262 else if (boost::iequals(propertyIt->first,
"hyper-relation")) {
264 auto hPropertyIt = hSection.begin();
267 if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first,
"k-regex")) {
268 NDN_THROW(
Error(
"Expecting <checker.key-locator.hyper-relation.k-regex>"));
271 std::string kRegex = hPropertyIt->second.data();
275 if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first,
"k-expand")) {
276 NDN_THROW(
Error(
"Expecting <checker.key-locator.hyper-relation.k-expand>"));
279 std::string kExpand = hPropertyIt->second.data();
283 if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first,
"h-relation")) {
284 NDN_THROW(
Error(
"Expecting <checker.key-locator.hyper-relation.h-relation>"));
287 std::string hRelation = hPropertyIt->second.data();
291 if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first,
"p-regex")) {
292 NDN_THROW(
Error(
"Expecting <checker.key-locator.hyper-relation.p-regex>"));
295 std::string pRegex = hPropertyIt->second.data();
299 if (hPropertyIt == hSection.end() || !boost::iequals(hPropertyIt->first,
"p-expand")) {
300 NDN_THROW(
Error(
"Expecting <checker.key-locator.hyper-relation.p-expand>"));
303 std::string pExpand = hPropertyIt->second.data();
306 if (hPropertyIt != hSection.end()) {
307 NDN_THROW(
Error(
"Expecting end of <checker.key-locator.hyper-relation>"));
312 return make_unique<HyperRelationChecker>(pRegex, pExpand, kRegex, kExpand, relation);
319 NDN_THROW(
Error(
"Unrecognized <checker.key-locator>: " + propertyIt->first));
#define NDN_THROW_NESTED(e)
NameRelationChecker(const Name &name, const NameRelation &relation)
bool checkNames(const Name &pktName, const Name &klName, const shared_ptr< ValidationState > &state) override
const size_t MIN_SIZE
minimal number of components for Signed Interest
RegexChecker(const Regex ®ex)
bool checkNameRelation(NameRelation relation, const Name &name1, const Name &name2)
check whether name1 and name2 satisfies relation
bool checkNames(const Name &pktName, const Name &klName, const shared_ptr< ValidationState > &state) override
NameRelation getNameRelationFromString(const std::string &relationString)
convert relationString to NameRelation
size_t size() const
Get number of components.
Represents an absolute name.
boost::property_tree::ptree ConfigSection
virtual Name expand(const std::string &expand="")
bool checkNames(const Name &pktName, const Name &klName, const shared_ptr< ValidationState > &state) override
bool match(const Name &name)
PartialName getPrefix(ssize_t nComponents) const
Extract a prefix of the name.
HyperRelationChecker(const std::string &pktNameExpr, const std::string pktNameExpand, const std::string &klNameExpr, const std::string klNameExpand, const NameRelation &hyperRelation)
bool check(uint32_t pktType, const Name &pktName, const Name &klName, const shared_ptr< ValidationState > &state)
Check if packet name ane KeyLocator satisfy the checker's conditions.
virtual bool checkNames(const Name &pktName, const Name &klName, const shared_ptr< ValidationState > &state)=0
Name extractIdentityFromKeyName(const Name &keyName)
Extract identity namespace from the key name keyName.
static unique_ptr< Checker > create(const ConfigSection &configSection, const std::string &configFilename)
create a checker from configuration section