filter.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2023 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
22 #ifndef NDN_CXX_SECURITY_VALIDATOR_CONFIG_FILTER_HPP
23 #define NDN_CXX_SECURITY_VALIDATOR_CONFIG_FILTER_HPP
24 
25 #include "ndn-cxx/data.hpp"
26 #include "ndn-cxx/interest.hpp"
29 #include "ndn-cxx/util/regex.hpp"
30 
31 namespace ndn::security {
32 
33 class ValidationState;
34 
35 namespace validator_config {
36 
44 class Filter : noncopyable
45 {
46 public:
47  virtual
48  ~Filter() = default;
49 
50  bool
51  match(uint32_t pktType, const Name& pktName, const shared_ptr<ValidationState>& state);
52 
53 public:
61  static unique_ptr<Filter>
62  create(const ConfigSection& configSection, const std::string& configFilename);
63 
64 private:
65  static unique_ptr<Filter>
66  createNameFilter(const ConfigSection& configSection, const std::string& configFilename);
67 
68 private:
69  virtual bool
70  matchName(const Name& pktName) = 0;
71 };
72 
91 class RelationNameFilter : public Filter
92 {
93 public:
94  RelationNameFilter(const Name& name, NameRelation relation);
95 
96 private:
97  bool
98  matchName(const Name& pktName) override;
99 
100 private:
101  Name m_name;
102  NameRelation m_relation;
103 };
104 
124 class RegexNameFilter : public Filter
125 {
126 public:
127  explicit
128  RegexNameFilter(const Regex& regex);
129 
130 private:
131  bool
132  matchName(const Name& pktName) override;
133 
134 private:
135  Regex m_regex;
136 };
137 
138 } // namespace validator_config
139 } // namespace ndn::security
140 
141 #endif // NDN_CXX_SECURITY_VALIDATOR_CONFIG_FILTER_HPP
Represents an absolute name.
Definition: name.hpp:45
Filter is one of the classes used by ValidatorConfig.
Definition: filter.hpp:45
static unique_ptr< Filter > create(const ConfigSection &configSection, const std::string &configFilename)
Create a filter from the configuration section.
Definition: filter.cpp:88
bool match(uint32_t pktType, const Name &pktName, const shared_ptr< ValidationState > &state)
Definition: filter.cpp:35
Filter to check that packet name matches the specified regular expression.
Definition: filter.hpp:125
Check that name is in relation to the packet name.
Definition: filter.hpp:92
RelationNameFilter(const Name &name, NameRelation relation)
Definition: filter.cpp:64
boost::property_tree::ptree ConfigSection
Definition: common.hpp:33
Contains the ndn-cxx security framework.