blob: cbd5275773cb328763831d6ed989b34b04521225 [file] [log] [blame]
Alexander Afanasyeve5a19b82017-01-30 22:30:46 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2013-2017 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_SECURITY_V2_VALIDATOR_CONFIG_FILTER_HPP
23#define NDN_SECURITY_V2_VALIDATOR_CONFIG_FILTER_HPP
24
25#include "common.hpp"
26#include "name-relation.hpp"
27#include "../../../interest.hpp"
28#include "../../../data.hpp"
29#include "../../../util/regex.hpp"
30
31namespace ndn {
32namespace security {
33namespace v2 {
34namespace validator_config {
35
36/**
37 * @brief Filter is one of the classes used by ValidatorConfig.
38 *
39 * The ValidatorConfig class consists of a set of rules.
40 * The Filter class is a part of a rule and is used to match packet.
41 * Matched packets will be checked against the checkers defined in the rule.
42 */
43class Filter : noncopyable
44{
45public:
46 virtual
47 ~Filter() = default;
48
49 bool
50 match(uint32_t pktType, const Name& pktName);
51
52public:
53 /**
54 * @brief Create a filter from the configuration section
55 *
56 * @param configSection The section containing the definition of filter.
57 * @param configFilename The configuration file name.
58 * @return a filter created from configuration
59 */
60 static unique_ptr<Filter>
61 create(const ConfigSection& configSection, const std::string& configFilename);
62
63private:
64 static unique_ptr<Filter>
65 createNameFilter(const ConfigSection& configSection, const std::string& configFilename);
66
67private:
68 virtual bool
69 matchName(const Name& pktName) = 0;
70};
71
72/**
73 * @brief Check that name is in relation to the packet name
74 *
75 * The following configuration
76 * @code
77 * filter
78 * {
79 * type name
80 * name /example
81 * relation is-prefix-of
82 * }
83 * @endcode
84 *
85 * creates
86 * @code
87 * RelationNameFilter("/example", RelationNameFilter::RELATION_IS_PREFIX_OF);
88 * @endcode
89 */
90class RelationNameFilter : public Filter
91{
92public:
93 RelationNameFilter(const Name& name, NameRelation relation);
94
95private:
96 bool
97 matchName(const Name& pktName) override;
98
99private:
100 Name m_name;
101 NameRelation m_relation;
102};
103
104/**
105 * @brief Filter to check that packet name matches the specified regular expression
106 *
107 * The following configuration
108 * @code
109 * filter
110 * {
111 * type name
112 * regex ^[^<KEY>]*<KEY><>*<ksk-.*>$
113 * }
114 * @endcode
115 *
116 * creates
117 * @code
118 * RegexNameFilter("^[^<KEY>]*<KEY><>*<ksk-.*>$");
119 * @endcode
120 *
121 * @sa Regex
122 */
123class RegexNameFilter : public Filter
124{
125public:
126 explicit
127 RegexNameFilter(const Regex& regex);
128
129private:
130 bool
131 matchName(const Name& pktName) override;
132
133private:
134 Regex m_regex;
135};
136
137} // namespace validator_config
138} // namespace v2
139} // namespace security
140} // namespace ndn
141
142#endif // NDN_SECURITY_V2_VALIDATOR_CONFIG_FILTER_HPP