Kea  2.3.5-git
eval_context.h
Go to the documentation of this file.
1 // Copyright (C) 2015-2022 Internet Systems Consortium, Inc. ("ISC")
2 //
3 // This Source Code Form is subject to the terms of the Mozilla Public
4 // License, v. 2.0. If a copy of the MPL was not distributed with this
5 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 
7 #ifndef EVAL_CONTEXT_H
8 #define EVAL_CONTEXT_H
9 #include <string>
10 #include <map>
11 #include <eval/parser.h>
12 #include <eval/eval_context_decl.h>
13 #include <exceptions/exceptions.h>
14 
15 // Tell Flex the lexer's prototype ...
16 #define YY_DECL \
17  isc::eval::EvalParser::symbol_type evallex (EvalContext& driver)
18 
19 // ... and declare it for the parser's sake.
21 
22 namespace isc {
23 namespace eval {
24 
27 public:
28  EvalParseError(const char* file, size_t line, const char* what) :
29  isc::Exception(file, line, what) { };
30 };
31 
32 
34 class EvalContext {
35 public:
36 
38  typedef enum {
40  PARSER_STRING
41  } ParserType;
42 
44  typedef std::function<bool(const ClientClass&)> CheckDefined;
45 
54  EvalContext(const Option::Universe& option_universe,
55  CheckDefined check_defined = acceptAll);
56 
58  virtual ~EvalContext();
59 
64  static bool acceptAll(const ClientClass& client_class);
65 
68 
72  void scanStringBegin(ParserType type);
73 
75  void scanStringEnd();
76 
82  bool parseString(const std::string& str, ParserType type = PARSER_BOOL);
83 
86  std::string file_;
87 
89  std::string string_;
90 
95  static void error(const isc::eval::location& loc, const std::string& what);
96 
101  static void error(const std::string& what);
102 
106  static void fatal(const std::string& what);
107 
115  uint16_t convertOptionCode(const std::string& option_code,
116  const isc::eval::location& loc);
117 
124  uint16_t convertOptionName(const std::string& option_name,
125  const isc::eval::location& loc);
126 
135  static uint32_t convertUint32(const std::string& number,
136  const isc::eval::location& loc);
137 
144  static int32_t convertInt32(const std::string& number,
145  const isc::eval::location& loc);
146 
155  static uint16_t convertUint16(const std::string& number,
156  const isc::eval::location& loc);
157 
164  static int16_t convertInt16(const std::string& number,
165  const isc::eval::location& loc);
166 
173  static uint8_t convertUint8(const std::string& number,
174  const isc::eval::location& loc);
175 
182  static int8_t convertInt8(const std::string& number,
183  const isc::eval::location& loc);
184 
192  int8_t convertNestLevelNumber(const std::string& nest_level,
193  const isc::eval::location& loc);
194 
203  static std::string fromUint32(const uint32_t integer);
204 
213  static std::string fromUint16(const uint16_t integer);
214 
219  return (option_universe_);
220  }
221 
226  bool isClientClassDefined(const ClientClass& client_class);
227 
228 private:
230  bool trace_scanning_;
231 
233  bool trace_parsing_;
234 
239  Option::Universe option_universe_;
240 
242  CheckDefined check_defined_;
243 
244 };
245 
246 } // end of isc::eval namespace
247 } // end of isc namespace
248 
249 #endif
Forward declaration of the EvalContext class.
Option::Universe getUniverse()
Returns the universe (v4 or v6)
Definition: eval_context.h:218
Evaluation error exception raised when trying to parse an exceptions.
Definition: eval_context.h:26
isc::dhcp::Expression expression
Parsed expression (output tokens are stored here)
Definition: eval_context.h:67
Universe
defines option universe DHCPv4 or DHCPv6
Definition: option.h:83
EvalParseError(const char *file, size_t line, const char *what)
Definition: eval_context.h:28
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
expression is expected to evaluate to bool
Definition: eval_context.h:39
bool isClientClassDefined(ClientClassDictionaryPtr &class_dictionary, bool &depend_on_known, const ClientClass &client_class)
Check if a client class name is already defined, i.e.
std::string string_
The string being parsed.
Definition: eval_context.h:89
Define the isc::eval::parser class.
Evaluation context, an interface to the expression evaluation.
Definition: eval_context.h:34
std::string file_
The name of the file being parsed.
Definition: eval_context.h:86
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-lfc.
std::vector< TokenPtr > Expression
This is a structure that holds an expression converted to RPN.
Definition: token.h:28
#define YY_DECL
Definition: eval_context.h:16
ParserType
Specifies what type of expression the parser is expected to see.
Definition: eval_context.h:38
std::string ClientClass
Defines a single class name.
Definition: classify.h:42
std::function< bool(const ClientClass &)> CheckDefined
Type of the check defined function.
Definition: eval_context.h:44