Kea  2.3.4-git
isc::eval::EvalContext Class Reference

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...
 

Detailed Description

Evaluation context, an interface to the expression evaluation.

Definition at line 34 of file eval_context.h.

Member Typedef Documentation

◆ CheckDefined

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.

Member Enumeration Documentation

◆ ParserType

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.

Constructor & Destructor Documentation

◆ EvalContext()

EvalContext::EvalContext ( const Option::Universe option_universe,
CheckDefined  check_defined = acceptAll 
)

Default constructor.

Parameters
option_universeOption 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_definedA 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.

◆ ~EvalContext()

EvalContext::~EvalContext ( )
virtual

destructor

Definition at line 28 of file eval_context.cc.

Member Function Documentation

◆ acceptAll()

bool EvalContext::acceptAll ( const ClientClass client_class)
static

Accept all client class names.

Parameters
client_class(unused)
Returns
true

Definition at line 32 of file eval_context.cc.

◆ convertInt16()

int16_t EvalContext::convertInt16 ( const std::string &  number,
const isc::eval::location &  loc 
)
static

Attempts to convert string to signed 16bit integer.

Parameters
numberstring to be converted
locthe location of the token
Returns
the integer value
Exceptions
EvalParseErrorif conversion fails or the value is out of range.

Definition at line 180 of file eval_context.cc.

References error().

+ Here is the call graph for this function:

◆ convertInt32()

int32_t EvalContext::convertInt32 ( const std::string &  number,
const isc::eval::location &  loc 
)
static

Attempts to convert string to signed 32bit integer.

Parameters
numberstring to be converted
locthe location of the token
Returns
the integer value
Exceptions
EvalParseErrorif conversion fails or the value is out of range.

Definition at line 215 of file eval_context.cc.

References error().

+ Here is the call graph for this function:

◆ convertInt8()

int8_t EvalContext::convertInt8 ( const std::string &  number,
const isc::eval::location &  loc 
)
static

Attempts to convert string to signed 8bit integer.

Parameters
numberstring to be converted
locthe location of the token
Returns
the integer value
Exceptions
EvalParseErrorif conversion fails or the value is out of range.

Definition at line 145 of file eval_context.cc.

References error().

Referenced by convertNestLevelNumber().

+ Here is the call graph for this function:

◆ convertNestLevelNumber()

int8_t EvalContext::convertNestLevelNumber ( const std::string &  nest_level,
const isc::eval::location &  loc 
)

Nest level conversion.

Parameters
nest_levela string representing the integer nesting level
locthe location of the token
Returns
the nesting level
Exceptions
callsthe 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().

+ Here is the call graph for this function:

◆ convertOptionCode()

uint16_t EvalContext::convertOptionCode ( const std::string &  option_code,
const isc::eval::location &  loc 
)

Option code conversion.

Parameters
option_codea string representing the integer code
locthe location of the token
Returns
the option code
Exceptions
callsthe 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().

+ Here is the call graph for this function:

◆ convertOptionName()

uint16_t EvalContext::convertOptionName ( const std::string &  option_name,
const isc::eval::location &  loc 
)

Option name conversion.

Parameters
option_namethe option name
locthe location of the token
Returns
the option code
Exceptions
callsthe 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().

+ Here is the call graph for this function:

◆ convertUint16()

uint16_t EvalContext::convertUint16 ( const std::string &  number,
const isc::eval::location &  loc 
)
static

Attempts to convert string to unsigned 16bit integer.

For reverse conversion, see fromUint16

Parameters
numberstring to be converted
locthe location of the token
Returns
the integer value
Exceptions
EvalParseErrorif conversion fails or the value is out of range.

Definition at line 163 of file eval_context.cc.

References error().

+ Here is the call graph for this function:

◆ convertUint32()

uint32_t EvalContext::convertUint32 ( const std::string &  number,
const isc::eval::location &  loc 
)
static

Attempts to convert string to unsigned 32bit integer.

For reverse conversion, see fromUint32

Parameters
numberstring to be converted
locthe location of the token
Returns
the integer value
Exceptions
EvalParseErrorif 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().

+ Here is the call graph for this function:

◆ convertUint8()

uint8_t EvalContext::convertUint8 ( const std::string &  number,
const isc::eval::location &  loc 
)
static

Attempts to convert string to unsigned 8bit integer.

Parameters
numberstring to be converted
locthe location of the token
Returns
the integer value
Exceptions
EvalParseErrorif 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().

+ Here is the call graph for this function:

◆ error() [1/2]

void EvalContext::error ( const isc::eval::location &  loc,
const std::string &  what 
)
static

Error handler.

Parameters
loclocation within the parsed file where the problem was experienced.
whatstring 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().

◆ error() [2/2]

void EvalContext::error ( const std::string &  what)
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.

◆ fatal()

void EvalContext::fatal ( const std::string &  what)
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.

◆ fromUint16()

std::string EvalContext::fromUint16 ( const uint16_t  integer)
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.

Parameters
integervalue to be converted
Returns
2 byte long string that encodes the value.

Definition at line 244 of file eval_context.cc.

◆ fromUint32()

std::string EvalContext::fromUint32 ( const uint32_t  integer)
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.

Parameters
integervalue to be converted
Returns
4 byte long string that encodes the value.

Definition at line 233 of file eval_context.cc.

◆ getUniverse()

Option::Universe isc::eval::EvalContext::getUniverse ( )
inline

Returns the universe (v4 or v6)

Returns
universe

Definition at line 218 of file eval_context.h.

References isc::dhcp::isClientClassDefined().

Referenced by isc::eval::EvalParser::parse().

+ Here is the call graph for this function:

◆ isClientClassDefined()

bool EvalContext::isClientClassDefined ( const ClientClass client_class)

Check if a client class is already defined.

Parameters
client_classthe client class name to check
Returns
true if the client class is defined, false if not

Definition at line 253 of file eval_context.cc.

Referenced by isc::eval::EvalParser::parse().

◆ parseString()

bool EvalContext::parseString ( const std::string &  str,
ParserType  type = PARSER_BOOL 
)

Run the parser on the string specified.

Parameters
strstring to be parsed
typetype of the expression expected/parser type to be created
Returns
true on success.

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().

+ Here is the call graph for this function:

◆ scanStringBegin()

void isc::eval::EvalContext::scanStringBegin ( ParserType  type)

Method called before scanning starts on a string.

Parameters
typespecifies type of the expression to be parsed

Referenced by parseString().

◆ scanStringEnd()

void isc::eval::EvalContext::scanStringEnd ( )

Method called after the last tokens are scanned from a string.

Referenced by parseString().

Member Data Documentation

◆ expression

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().

◆ file_

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().

◆ string_

std::string isc::eval::EvalContext::string_

The string being parsed.

Definition at line 89 of file eval_context.h.

Referenced by parseString().


The documentation for this class was generated from the following files: