Kea  1.9.9-git
eval_context.h
Go to the documentation of this file.
1 // Copyright (C) 2015-2021 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 {
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
EvalContext(const Option::Universe &option_universe, CheckDefined check_defined=acceptAll)
Default constructor.
Definition: eval_context.cc:21
Forward declaration of the EvalContext class.
static uint32_t convertUint32(const std::string &number, const isc::eval::location &loc)
Attempts to convert string to unsigned 32bit integer.
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:82
static uint16_t convertUint16(const std::string &number, const isc::eval::location &loc)
Attempts to convert string to unsigned 16bit integer.
static void error(const isc::eval::location &loc, const std::string &what)
Error handler.
Definition: eval_context.cc:55
EvalParseError(const char *file, size_t line, const char *what)
Definition: eval_context.h:28
void scanStringBegin(ParserType type)
Method called before scanning starts on a string.
static int16_t convertInt16(const std::string &number, const isc::eval::location &loc)
Attempts to convert string to signed 16bit integer.
expression is expected to evaluate to bool
Definition: eval_context.h:39
std::string string_
The string being parsed.
Definition: eval_context.h:89
Define the isc::eval::parser class.
static int32_t convertInt32(const std::string &number, const isc::eval::location &loc)
Attempts to convert string to signed 32bit integer.
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
static std::string fromUint32(const uint32_t integer)
Converts unsigned 32bit integer to string representation.
static uint8_t convertUint8(const std::string &number, const isc::eval::location &loc)
Attempts to convert string to unsigned 8bit integer.
uint16_t convertOptionName(const std::string &option_name, const isc::eval::location &loc)
Option name conversion.
Definition: eval_context.cc:89
uint16_t convertOptionCode(const std::string &option_code, const isc::eval::location &loc)
Option code conversion.
Definition: eval_context.cc:65
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
static void fatal(const std::string &what)
Fatal error handler.
This is a base class for exceptions thrown from the DNS library module.
Defines the logger used by the top-level component of kea-dhcp-ddns.
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
void scanStringEnd()
Method called after the last tokens are scanned from a string.
static std::string fromUint16(const uint16_t integer)
Converts unsigned 16bit integer to string representation.
expression is expected to evaluate to string
Definition: eval_context.h:40
ParserType
Specifies what type of expression the parser is expected to see.
Definition: eval_context.h:38
int8_t convertNestLevelNumber(const std::string &nest_level, const isc::eval::location &loc)
Nest level conversion.
std::string ClientClass
Defines a single class name.
Definition: classify.h:37
static int8_t convertInt8(const std::string &number, const isc::eval::location &loc)
Attempts to convert string to signed 8bit integer.
std::function< bool(const ClientClass &)> CheckDefined
Type of the check defined function.
Definition: eval_context.h:44
virtual ~EvalContext()
destructor
Definition: eval_context.cc:28
bool isClientClassDefined(const ClientClass &client_class)
Check if a client class is already defined.
bool parseString(const std::string &str, ParserType type=PARSER_BOOL)
Run the parser on the string specified.
Definition: eval_context.cc:37
static bool acceptAll(const ClientClass &client_class)
Accept all client class names.
Definition: eval_context.cc:32