All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
rule.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
8 #ifndef NDN_SECURITY_CONF_RULE_HPP
9 #define NDN_SECURITY_CONF_RULE_HPP
10 
11 #include "filter.hpp"
12 #include "checker.hpp"
13 
14 
15 namespace ndn {
16 namespace security {
17 namespace conf {
18 
19 template<class Packet>
20 class Rule
21 {
22 public:
23  Rule(const std::string& id)
24  : m_id(id)
25  {
26  }
27 
28  virtual
30  {
31  }
32 
33  const std::string&
35  {
36  return m_id;
37  }
38 
39  void
40  addFilter(const shared_ptr<Filter>& filter)
41  {
42  m_filters.push_back(filter);
43  }
44 
45  void
46  addChecker(const shared_ptr<Checker>& checker)
47  {
48  m_checkers.push_back(checker);
49  }
50 
51  bool
52  match(const Packet& packet)
53  {
54  if (m_filters.empty())
55  return true;
56 
57  for (FilterList::iterator it = m_filters.begin();
58  it != m_filters.end(); it++)
59  {
60  if (!(*it)->match(packet))
61  return false;
62  }
63 
64  return true;
65  }
66 
77  template<class ValidatedCallback, class ValidationFailureCallback>
78  int8_t
79  check(const Packet& packet,
80  const ValidatedCallback& onValidated,
81  const ValidationFailureCallback& onValidationFailed)
82  {
83  for (CheckerList::iterator it = m_checkers.begin();
84  it != m_checkers.end(); it++)
85  {
86  int8_t result = (*it)->check(packet, onValidated, onValidationFailed);
87  if (result >= 0)
88  return result;
89  }
90  return -1;
91  }
92 
93 private:
94  typedef std::vector<shared_ptr<Filter> > FilterList;
95  typedef std::vector<shared_ptr<Checker> > CheckerList;
96 
97  std::string m_id;
98  FilterList m_filters;
99  CheckerList m_checkers;
100 };
101 
102 } // namespace conf
103 } // namespace security
104 } // namespace ndn
105 
106 #endif // NDN_SECURITY_CONF_RULE_HPP
const std::string & getId()
Definition: rule.hpp:34
bool match(const Packet &packet)
Definition: rule.hpp:52
void addFilter(const shared_ptr< Filter > &filter)
Definition: rule.hpp:40
Rule(const std::string &id)
Definition: rule.hpp:23
void addChecker(const shared_ptr< Checker > &checker)
Definition: rule.hpp:46
int8_t check(const Packet &packet, const ValidatedCallback &onValidated, const ValidationFailureCallback &onValidationFailed)
check if packet satisfies certain condition
Definition: rule.hpp:79