Kea 2.5.6
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>
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
22namespace isc {
23namespace eval {
24
27public:
28 EvalParseError(const char* file, size_t line, const char* what) :
29 isc::Exception(file, line, what) { };
30};
31
32
35public:
36
38 typedef enum {
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
73
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
228private:
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
This is a base class for exceptions thrown from the DNS library module.
virtual const char * what() const
Returns a C-style character string of the cause of the exception.
Universe
defines option universe DHCPv4 or DHCPv6
Definition: option.h:83
Evaluation context, an interface to the expression evaluation.
Definition: eval_context.h:34
std::function< bool(const ClientClass &)> CheckDefined
Type of the check defined function.
Definition: eval_context.h:44
bool parseString(const std::string &str, ParserType type=PARSER_BOOL)
Run the parser on the string specified.
Definition: eval_context.cc:37
static std::string fromUint16(const uint16_t integer)
Converts unsigned 16bit integer to string representation.
void scanStringEnd()
Method called after the last tokens are scanned from a string.
ParserType
Specifies what type of expression the parser is expected to see.
Definition: eval_context.h:38
@ PARSER_BOOL
expression is expected to evaluate to bool
Definition: eval_context.h:39
@ PARSER_STRING
expression is expected to evaluate to string
Definition: eval_context.h:40
static int16_t convertInt16(const std::string &number, const isc::eval::location &loc)
Attempts to convert string to signed 16bit integer.
static std::string fromUint32(const uint32_t integer)
Converts unsigned 32bit integer to string representation.
virtual ~EvalContext()
destructor
Definition: eval_context.cc:28
int8_t convertNestLevelNumber(const std::string &nest_level, const isc::eval::location &loc)
Nest level conversion.
uint16_t convertOptionCode(const std::string &option_code, const isc::eval::location &loc)
Option code conversion.
Definition: eval_context.cc:65
uint16_t convertOptionName(const std::string &option_name, const isc::eval::location &loc)
Option name conversion.
Definition: eval_context.cc:89
isc::dhcp::Expression expression
Parsed expression (output tokens are stored here)
Definition: eval_context.h:67
static bool acceptAll(const ClientClass &client_class)
Accept all client class names.
Definition: eval_context.cc:32
static int32_t convertInt32(const std::string &number, const isc::eval::location &loc)
Attempts to convert string to signed 32bit integer.
Option::Universe getUniverse()
Returns the universe (v4 or v6)
Definition: eval_context.h:218
void scanStringBegin(ParserType type)
Method called before scanning starts on a string.
static uint32_t convertUint32(const std::string &number, const isc::eval::location &loc)
Attempts to convert string to unsigned 32bit integer.
bool isClientClassDefined(const ClientClass &client_class)
Check if a client class is already defined.
std::string file_
The name of the file being parsed.
Definition: eval_context.h:86
std::string string_
The string being parsed.
Definition: eval_context.h:89
static uint8_t convertUint8(const std::string &number, const isc::eval::location &loc)
Attempts to convert string to unsigned 8bit integer.
static int8_t convertInt8(const std::string &number, const isc::eval::location &loc)
Attempts to convert string to signed 8bit integer.
static uint16_t convertUint16(const std::string &number, const isc::eval::location &loc)
Attempts to convert string to unsigned 16bit integer.
Evaluation error exception raised when trying to parse an exceptions.
Definition: eval_context.h:26
EvalParseError(const char *file, size_t line, const char *what)
Definition: eval_context.h:28
#define YY_DECL
Definition: eval_context.h:16
Forward declaration of the EvalContext class.
@ fatal
Definition: db_log.h:117
@ error
Definition: db_log.h:118
std::string ClientClass
Defines a single class name.
Definition: classify.h:42
std::vector< TokenPtr > Expression
This is a structure that holds an expression converted to RPN.
Definition: token.h:28
Defines the logger used by the top-level component of kea-lfc.
Define the isc::eval::parser class.