Kea 2.7.5
eval_context.h
Go to the documentation of this file.
1// Copyright (C) 2015-2024 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 <vector>
12#include <eval/parser.h>
15
16// Tell Flex the lexer's prototype ...
17#define YY_DECL \
18 isc::eval::EvalParser::symbol_type evallex (EvalContext& driver)
19
20// ... and declare it for the parser's sake.
22
23namespace isc {
24namespace eval {
25
28public:
29 EvalParseError(const char* file, size_t line, const char* what) :
30 isc::Exception(file, line, what) { }
31};
32
33
36public:
37
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
71 unsigned label_;
72
74 std::vector<unsigned> labels_;
75
80
83
89 bool parseString(const std::string& str, ParserType type = PARSER_BOOL);
90
93 std::string file_;
94
96 std::string string_;
97
102 static void error(const isc::eval::location& loc, const std::string& what);
103
108 static void error(const std::string& what);
109
113 static void fatal(const std::string& what);
114
122 uint16_t convertOptionCode(const std::string& option_code,
123 const isc::eval::location& loc);
124
131 uint16_t convertOptionName(const std::string& option_name,
132 const isc::eval::location& loc);
133
142 static uint32_t convertUint32(const std::string& number,
143 const isc::eval::location& loc);
144
151 static int32_t convertInt32(const std::string& number,
152 const isc::eval::location& loc);
153
162 static uint16_t convertUint16(const std::string& number,
163 const isc::eval::location& loc);
164
171 static int16_t convertInt16(const std::string& number,
172 const isc::eval::location& loc);
173
180 static uint8_t convertUint8(const std::string& number,
181 const isc::eval::location& loc);
182
189 static int8_t convertInt8(const std::string& number,
190 const isc::eval::location& loc);
191
199 int8_t convertNestLevelNumber(const std::string& nest_level,
200 const isc::eval::location& loc);
201
210 static std::string fromUint32(const uint32_t integer);
211
220 static std::string fromUint16(const uint16_t integer);
221
226 return (option_universe_);
227 }
228
233 bool isClientClassDefined(const ClientClass& client_class);
234
235private:
237 bool trace_scanning_;
238
240 bool trace_parsing_;
241
246 Option::Universe option_universe_;
247
249 CheckDefined check_defined_;
250
251};
252
253} // end of isc::eval namespace
254} // end of isc namespace
255
256#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:90
Evaluation context, an interface to the expression evaluation.
unsigned label_
Label counter.
bool parseString(const std::string &str, ParserType type=PARSER_BOOL)
Run the parser on the string specified.
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.
@ PARSER_BOOL
expression is expected to evaluate to bool
@ PARSER_STRING
expression is expected to evaluate to string
static int16_t convertInt16(const std::string &number, const isc::eval::location &loc)
Attempts to convert string to signed 16bit integer.
std::function< bool(const ClientClass &) CheckDefined)
Type of the check defined function.
static std::string fromUint32(const uint32_t integer)
Converts unsigned 32bit integer to string representation.
virtual ~EvalContext()
destructor
std::vector< unsigned > labels_
Label stack.
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.
uint16_t convertOptionName(const std::string &option_name, const isc::eval::location &loc)
Option name conversion.
static bool acceptAll(const ClientClass &client_class)
Accept all client class names.
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)
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.
std::string string_
The string being parsed.
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.
isc::dhcp::Expression expression_
Parsed expression (output tokens are stored here)
EvalContext(const Option::Universe &option_universe, CheckDefined check_defined=acceptAll)
Default constructor.
Evaluation error exception raised when trying to parse an exceptions.
EvalParseError(const char *file, size_t line, const char *what)
#define YY_DECL
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:29
Defines the logger used by the top-level component of kea-lfc.
Define the isc::eval::parser class.