blob: 921faa2a4a919b603ec10ddf7adfb70c5544eddc [file] [log] [blame]
Yingdi Yu7d773322015-03-22 21:32:48 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014, Regents of the University of California
4 *
5 * This file is part of NSL (NDN Signature Logger).
6 * See AUTHORS.md for complete list of NSL authors and contributors.
7 *
8 * NSL is free software: you can redistribute it and/or modify it under the terms
9 * of the GNU General Public License as published by the Free Software Foundation,
10 * either version 3 of the License, or (at your option) any later version.
11 *
12 * NSL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along with
17 * NSL, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of nsl authors and contributors.
20 */
21
22#ifndef NSL_CONF_KEY_LOCATOR_CHECKER_HPP
23#define NSL_CONF_KEY_LOCATOR_CHECKER_HPP
24
25#include "common.hpp"
26#include "config.hpp"
27#include <ndn-cxx/util/regex.hpp>
28
29namespace nsl {
30namespace conf {
31
32class KeyLocatorCheckerFactory;
33
34/**
35 * @brief KeyLocatorChecker is one of the classes used by ValidatorConfig.
36 *
37 * The ValidatorConfig class consists of a set of rules.
38 * The KeyLocatorChecker class is part of a rule and is used to check if the KeyLocator field of a
39 * packet satisfy the requirements.
40 */
41
42
43class KeyLocatorChecker
44{
45public:
46 enum Relation {
47 RELATION_EQUAL,
48 RELATION_IS_PREFIX_OF,
49 RELATION_IS_STRICT_PREFIX_OF
50 };
51
52 virtual
53 ~KeyLocatorChecker();
54
55 bool
56 check(const Data& data, const KeyLocator& keyLocator, std::string& failInfo);
57
58protected:
59 virtual bool
60 check(const Name& packetName, const KeyLocator& keyLocator, std::string& failInfo) = 0;
61
62 bool
63 checkRelation(const Relation& relation, const Name& name1, const Name& name2);
64};
65
66class RelationKeyLocatorNameChecker : public KeyLocatorChecker
67{
68public:
69 RelationKeyLocatorNameChecker(const Name& name, const KeyLocatorChecker::Relation& relation);
70
71protected:
72 virtual bool
73 check(const Name& packetName, const KeyLocator& keyLocator, std::string& failInfo);
74
75private:
76 Name m_name;
77 KeyLocatorChecker::Relation m_relation;
78};
79
80class RegexKeyLocatorNameChecker : public KeyLocatorChecker
81{
82public:
83 explicit
84 RegexKeyLocatorNameChecker(const ndn::Regex& regex);
85
86protected:
87 virtual bool
88 check(const Name& packetName, const KeyLocator& keyLocator, std::string& failInfo);
89
90private:
91 ndn::Regex m_regex;
92};
93
94class HyperKeyLocatorNameChecker : public KeyLocatorChecker
95{
96public:
97 HyperKeyLocatorNameChecker(const std::string& pExpr, const std::string pExpand,
98 const std::string& kExpr, const std::string kExpand,
99 const Relation& hyperRelation);
100
101protected:
102 virtual bool
103 check(const Name& packetName, const KeyLocator& keyLocator, std::string& failInfo);
104
105private:
106 shared_ptr<ndn::Regex> m_hyperPRegex;
107 shared_ptr<ndn::Regex> m_hyperKRegex;
108 Relation m_hyperRelation;
109};
110
111
112class KeyLocatorCheckerFactory
113{
114public:
115 static shared_ptr<KeyLocatorChecker>
116 create(const ConfigSection& configSection);
117
118private:
119 static shared_ptr<KeyLocatorChecker>
120 createKeyLocatorNameChecker(const ConfigSection& configSection);
121};
122
123
124} // namespace conf
125} // namespace nsl
126
127#endif // NSL_CONF_KEY_LOCATOR_CHECKER_HPP