Kea
1.9.9-git
|
Evaluation context, an interface to the expression evaluation. More...
#include <eval_context.h>
Public Types | |
typedef std::function< bool(const ClientClass &)> | CheckDefined |
Type of the check defined function. More... | |
enum | ParserType { PARSER_BOOL, PARSER_STRING } |
Specifies what type of expression the parser is expected to see. More... | |
Public Member Functions | |
EvalContext (const Option::Universe &option_universe, CheckDefined check_defined=acceptAll) | |
Default constructor. More... | |
virtual | ~EvalContext () |
destructor More... | |
int8_t | convertNestLevelNumber (const std::string &nest_level, const isc::eval::location &loc) |
Nest level conversion. More... | |
uint16_t | convertOptionCode (const std::string &option_code, const isc::eval::location &loc) |
Option code conversion. More... | |
uint16_t | convertOptionName (const std::string &option_name, const isc::eval::location &loc) |
Option name conversion. More... | |
Option::Universe | getUniverse () |
Returns the universe (v4 or v6) More... | |
bool | isClientClassDefined (const ClientClass &client_class) |
Check if a client class is already defined. More... | |
bool | parseString (const std::string &str, ParserType type=PARSER_BOOL) |
Run the parser on the string specified. More... | |
void | scanStringBegin (ParserType type) |
Method called before scanning starts on a string. More... | |
void | scanStringEnd () |
Method called after the last tokens are scanned from a string. More... | |
Static Public Member Functions | |
static bool | acceptAll (const ClientClass &client_class) |
Accept all client class names. More... | |
static int16_t | convertInt16 (const std::string &number, const isc::eval::location &loc) |
Attempts to convert string to signed 16bit integer. More... | |
static int32_t | convertInt32 (const std::string &number, const isc::eval::location &loc) |
Attempts to convert string to signed 32bit integer. More... | |
static int8_t | convertInt8 (const std::string &number, const isc::eval::location &loc) |
Attempts to convert string to signed 8bit integer. More... | |
static uint16_t | convertUint16 (const std::string &number, const isc::eval::location &loc) |
Attempts to convert string to unsigned 16bit integer. More... | |
static uint32_t | convertUint32 (const std::string &number, const isc::eval::location &loc) |
Attempts to convert string to unsigned 32bit integer. More... | |
static uint8_t | convertUint8 (const std::string &number, const isc::eval::location &loc) |
Attempts to convert string to unsigned 8bit integer. More... | |
static void | error (const isc::eval::location &loc, const std::string &what) |
Error handler. More... | |
static void | error (const std::string &what) |
Error handler. More... | |
static void | fatal (const std::string &what) |
Fatal error handler. More... | |
static std::string | fromUint16 (const uint16_t integer) |
Converts unsigned 16bit integer to string representation. More... | |
static std::string | fromUint32 (const uint32_t integer) |
Converts unsigned 32bit integer to string representation. More... | |
Public Attributes | |
isc::dhcp::Expression | expression |
Parsed expression (output tokens are stored here) More... | |
std::string | file_ |
The name of the file being parsed. More... | |
std::string | string_ |
The string being parsed. More... | |
Evaluation context, an interface to the expression evaluation.
Definition at line 34 of file eval_context.h.
typedef std::function<bool(const ClientClass&)> isc::eval::EvalContext::CheckDefined |
Type of the check defined function.
Definition at line 44 of file eval_context.h.
Specifies what type of expression the parser is expected to see.
Enumerator | |
---|---|
PARSER_BOOL |
expression is expected to evaluate to bool |
PARSER_STRING |
expression is expected to evaluate to string |
Definition at line 38 of file eval_context.h.
EvalContext::EvalContext | ( | const Option::Universe & | option_universe, |
CheckDefined | check_defined = acceptAll |
||
) |
Default constructor.
option_universe | Option universe: DHCPv4 or DHCPv6. This is used by the parser to determine which option definitions set should be used to map option names to option codes. |
check_defined | A function called to check if a client class used for membership is already defined. If it is not the parser will fail: only backward or built-in references are accepted. |
Definition at line 21 of file eval_context.cc.
|
virtual |
destructor
Definition at line 28 of file eval_context.cc.
|
static |
Accept all client class names.
client_class | (unused) |
Definition at line 32 of file eval_context.cc.
|
static |
Attempts to convert string to signed 16bit integer.
number | string to be converted |
loc | the location of the token |
EvalParseError | if conversion fails or the value is out of range. |
Definition at line 180 of file eval_context.cc.
References error().
|
static |
Attempts to convert string to signed 32bit integer.
number | string to be converted |
loc | the location of the token |
EvalParseError | if conversion fails or the value is out of range. |
Definition at line 215 of file eval_context.cc.
References error().
|
static |
Attempts to convert string to signed 8bit integer.
number | string to be converted |
loc | the location of the token |
EvalParseError | if conversion fails or the value is out of range. |
Definition at line 145 of file eval_context.cc.
References error().
Referenced by convertNestLevelNumber().
int8_t EvalContext::convertNestLevelNumber | ( | const std::string & | nest_level, |
const isc::eval::location & | loc | ||
) |
Nest level conversion.
nest_level | a string representing the integer nesting level |
loc | the location of the token |
calls | the syntax error function if the value is not in the range -32..31 |
Definition at line 112 of file eval_context.cc.
References convertInt8(), error(), and HOP_COUNT_LIMIT.
Referenced by isc::eval::EvalParser::parse().
uint16_t EvalContext::convertOptionCode | ( | const std::string & | option_code, |
const isc::eval::location & | loc | ||
) |
Option code conversion.
option_code | a string representing the integer code |
loc | the location of the token |
calls | the syntax error function if the value is not in the range 0..255 or 0..65535 |
Definition at line 65 of file eval_context.cc.
References error().
Referenced by isc::eval::EvalParser::parse().
uint16_t EvalContext::convertOptionName | ( | const std::string & | option_name, |
const isc::eval::location & | loc | ||
) |
Option name conversion.
option_name | the option name |
loc | the location of the token |
calls | the syntax error function if the name cannot be resolved |
Definition at line 89 of file eval_context.cc.
References DHCP4_OPTION_SPACE, DHCP6_OPTION_SPACE, and error().
Referenced by isc::eval::EvalParser::parse().
|
static |
Attempts to convert string to unsigned 16bit integer.
For reverse conversion, see fromUint16
number | string to be converted |
loc | the location of the token |
EvalParseError | if conversion fails or the value is out of range. |
Definition at line 163 of file eval_context.cc.
References error().
|
static |
Attempts to convert string to unsigned 32bit integer.
For reverse conversion, see fromUint32
number | string to be converted |
loc | the location of the token |
EvalParseError | if conversion fails or the value is out of range. |
Definition at line 198 of file eval_context.cc.
References error().
Referenced by isc::eval::EvalParser::parse().
|
static |
Attempts to convert string to unsigned 8bit integer.
number | string to be converted |
loc | the location of the token |
EvalParseError | if conversion fails or the value is out of range. |
Definition at line 128 of file eval_context.cc.
References error().
Referenced by isc::eval::EvalParser::parse().
|
static |
Error handler.
loc | location within the parsed file when experienced a problem. |
what | string explaining the nature of the error. |
Definition at line 55 of file eval_context.cc.
References isc_throw.
Referenced by convertInt16(), convertInt32(), convertInt8(), convertNestLevelNumber(), convertOptionCode(), convertOptionName(), convertUint16(), convertUint32(), and convertUint8().
|
static |
Error handler.
This is a simplified error reporting tool for possible future cases when the EvalParser is not able to handle the packet.
Definition at line 60 of file eval_context.cc.
References isc_throw.
|
static |
Fatal error handler.
This is for should not happen but fatal errors
Definition at line 258 of file eval_context.cc.
References isc_throw.
|
static |
Converts unsigned 16bit integer to string representation.
The integer is coded as a 2 byte long string in network order, e.g. 6 is represented as 0006. For reverse conversion, see convertUint16.
integer | value to be converted |
Definition at line 244 of file eval_context.cc.
|
static |
Converts unsigned 32bit integer to string representation.
The integer is coded as a 4 byte long string in network order, e.g. 6 is represented as 00000006. For reverse conversion, see convertUint32.
integer | value to be converted |
Definition at line 233 of file eval_context.cc.
|
inline |
Returns the universe (v4 or v6)
Definition at line 218 of file eval_context.h.
Referenced by isc::eval::EvalParser::parse().
bool EvalContext::isClientClassDefined | ( | const ClientClass & | client_class | ) |
Check if a client class is already defined.
client_class | the client class name to check |
Definition at line 253 of file eval_context.cc.
Referenced by isc::eval::EvalParser::parse().
bool EvalContext::parseString | ( | const std::string & | str, |
ParserType | type = PARSER_BOOL |
||
) |
Run the parser on the string specified.
str | string to be parsed |
type | type of the expression expected/parser type to be created |
Definition at line 37 of file eval_context.cc.
References file_, isc::eval::EvalParser::parse(), scanStringBegin(), scanStringEnd(), isc::eval::EvalParser::set_debug_level(), and string_.
Referenced by isc::dhcp::ExpressionParser::parse().
void isc::eval::EvalContext::scanStringBegin | ( | ParserType | type | ) |
Method called before scanning starts on a string.
type | specifies type of the expression to be parsed |
Referenced by parseString().
void isc::eval::EvalContext::scanStringEnd | ( | ) |
Method called after the last tokens are scanned from a string.
Referenced by parseString().
isc::dhcp::Expression isc::eval::EvalContext::expression |
Parsed expression (output tokens are stored here)
Definition at line 67 of file eval_context.h.
Referenced by isc::dhcp::ExpressionParser::parse(), and isc::eval::EvalParser::parse().
std::string isc::eval::EvalContext::file_ |
The name of the file being parsed.
Used later to pass the file name to the location tracker.
Definition at line 86 of file eval_context.h.
Referenced by parseString().
std::string isc::eval::EvalContext::string_ |