25 #include <boost/algorithm/string/predicate.hpp> 32 namespace validator_config {
57 BOOST_THROW_EXCEPTION(
Error(
"Invalid packet type supplied (" +
67 retval |= filter->match(pktType, pktName);
77 const shared_ptr<ValidationState>& state)
const 79 NDN_LOG_TRACE(
"Trying to check " << pktName <<
" with keyLocator " << klName);
82 BOOST_THROW_EXCEPTION(
Error(
"Invalid packet type supplied (" +
86 bool hasPendingResult =
false;
88 bool result = checker->check(pktType, pktName, klName, state);
92 hasPendingResult =
true;
95 return hasPendingResult;
101 auto propertyIt = configSection.begin();
104 if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first,
"id")) {
105 BOOST_THROW_EXCEPTION(
Error(
"Expecting <rule.id>"));
108 std::string ruleId = propertyIt->second.data();
112 if (propertyIt == configSection.end() || !boost::iequals(propertyIt->first,
"for")) {
113 BOOST_THROW_EXCEPTION(
Error(
"Expecting <rule.for> in rule: " + ruleId));
116 std::string usage = propertyIt->second.data();
119 bool isForData =
false;
120 if (boost::iequals(usage,
"data")) {
123 else if (boost::iequals(usage,
"interest")) {
127 BOOST_THROW_EXCEPTION(
Error(
"Unrecognized <rule.for>: " + usage +
" in rule: " + ruleId));
133 for (; propertyIt != configSection.end(); propertyIt++) {
134 if (!boost::iequals(propertyIt->first,
"filter")) {
135 if (boost::iequals(propertyIt->first,
"checker")) {
138 BOOST_THROW_EXCEPTION(
Error(
"Expecting <rule.filter> in rule: " + ruleId));
141 rule->addFilter(
Filter::create(propertyIt->second, configFilename));
145 bool hasCheckers =
false;
146 for (; propertyIt != configSection.end(); propertyIt++) {
147 if (!boost::iequals(propertyIt->first,
"checker")) {
148 BOOST_THROW_EXCEPTION(
Error(
"Expecting <rule.checker> in rule: " + ruleId));
155 if (propertyIt != configSection.end()) {
156 BOOST_THROW_EXCEPTION(
Error(
"Expecting end of <rule>: " + ruleId));
160 BOOST_THROW_EXCEPTION(
Error(
"No <rule.checker> is specified in rule: " + ruleId));
Rule(const std::string &id, uint32_t pktType)
Copyright (c) 2011-2015 Regents of the University of California.
static unique_ptr< Rule > create(const ConfigSection &configSection, const std::string &configFilename)
create a rule from configuration section
bool check(uint32_t pktType, const Name &pktName, const Name &klName, const shared_ptr< ValidationState > &state) const
check if packet satisfies rule's condition
std::vector< unique_ptr< Checker > > m_checkers
void addFilter(unique_ptr< Filter > filter)
Represents an absolute name.
#define NDN_LOG_TRACE(expression)
static unique_ptr< Filter > create(const ConfigSection &configSection, const std::string &configFilename)
Create a filter from the configuration section.
boost::property_tree::ptree ConfigSection
void addChecker(unique_ptr< Checker > checker)
#define NDN_LOG_INIT(name)
declare a log module
std::string to_string(const V &v)
std::vector< unique_ptr< Filter > > m_filters
bool match(uint32_t pktType, const Name &pktName) const
check if the packet name matches rule's filter
static unique_ptr< Checker > create(const ConfigSection &configSection, const std::string &configFilename)
create a checker from configuration section