Kea  1.5.0
eval_context.h
Go to the documentation of this file.
1 // Copyright (C) 2015-2018 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 
35 {
36 public:
37 
39  typedef enum {
42  } ParserType;
43 
45  typedef std::function<bool(const ClientClass&)> CheckDefined;
46 
55  EvalContext(const Option::Universe& option_universe,
56  CheckDefined check_defined = acceptAll);
57 
59  virtual ~EvalContext();
60 
65  static bool acceptAll(const ClientClass& client_class);
66 
69 
73  void scanStringBegin(ParserType type);
74 
76  void scanStringEnd();
77 
83  bool parseString(const std::string& str, ParserType type = PARSER_BOOL);
84 
87  std::string file_;
88 
90  std::string string_;
91 
96  static void error(const isc::eval::location& loc, const std::string& what);
97 
102  static void error(const std::string& what);
103 
107  static void fatal(const std::string& what);
108 
116  uint16_t convertOptionCode(const std::string& option_code,
117  const isc::eval::location& loc);
118 
125  uint16_t convertOptionName(const std::string& option_name,
126  const isc::eval::location& loc);
127 
136  static uint32_t convertUint32(const std::string& number,
137  const isc::eval::location& loc);
138 
145  static uint8_t convertUint8(const std::string& number,
146  const isc::eval::location& loc);
147 
154  static int8_t convertInt8(const std::string& number,
155  const isc::eval::location& loc);
156 
164  int8_t convertNestLevelNumber(const std::string& nest_level,
165  const isc::eval::location& loc);
166 
175  static std::string fromUint32(const uint32_t integer);
176 
181  return (option_universe_);
182  }
183 
188  bool isClientClassDefined(const ClientClass& client_class);
189 
190  private:
192  bool trace_scanning_;
193 
195  bool trace_parsing_;
196 
201  Option::Universe option_universe_;
202 
204  CheckDefined check_defined_;
205 
206 };
207 
208 }; // end of isc::eval namespace
209 }; // end of isc namespace
210 
211 #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:180
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:68
Universe
defines option universe DHCPv4 or DHCPv6
Definition: option.h:67
static void error(const isc::eval::location &loc, const std::string &what)
Error handler.
Definition: eval_context.cc:57
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.
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:40
std::string string_
The string being parsed.
Definition: eval_context.h:90
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:87
static std::string fromUint32(const uint32_t integer)
Converts 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:94
uint16_t convertOptionCode(const std::string &option_code, const isc::eval::location &loc)
Option code conversion.
Definition: eval_context.cc:69
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.
expression is expected to evaluate to string
Definition: eval_context.h:41
ParserType
Specifies what type of expression the parser is expected to see.
Definition: eval_context.h:39
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:45
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:38
static bool acceptAll(const ClientClass &client_class)
Accept all client class names.
Definition: eval_context.cc:33