Kea 2.7.6
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.
 
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.
 
virtual ~EvalContext ()
 destructor
 
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.
 
Option::Universe getUniverse ()
 Returns the universe (v4 or v6)
 
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.
 
void scanStringBegin (ParserType type)
 Method called before scanning starts on a string.
 
void scanStringEnd ()
 Method called after the last tokens are scanned from a string.
 

Static Public Member Functions

static bool acceptAll (const ClientClass &client_class)
 Accept all client class names.
 
static int16_t convertInt16 (const std::string &number, const isc::eval::location &loc)
 Attempts to convert string to signed 16bit integer.
 
static int32_t convertInt32 (const std::string &number, const isc::eval::location &loc)
 Attempts to convert string to signed 32bit 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.
 
static uint32_t convertUint32 (const std::string &number, const isc::eval::location &loc)
 Attempts to convert string to unsigned 32bit integer.
 
static uint8_t convertUint8 (const std::string &number, const isc::eval::location &loc)
 Attempts to convert string to unsigned 8bit integer.
 
static void error (const isc::eval::location &loc, const std::string &what)
 Error handler.
 
static void error (const std::string &what)
 Error handler.
 
static void fatal (const std::string &what)
 Fatal error handler.
 
static std::string fromUint16 (const uint16_t integer)
 Converts unsigned 16bit integer to string representation.
 
static std::string fromUint32 (const uint32_t integer)
 Converts unsigned 32bit integer to string representation.
 

Public Attributes

isc::dhcp::Expression expression_
 Parsed expression (output tokens are stored here)
 
std::string file_
 The name of the file being parsed.
 
unsigned label_
 Label counter.
 
std::vector< unsigned > labels_
 Label stack.
 
std::string string_
 The string being parsed.
 

Detailed Description

Evaluation context, an interface to the expression evaluation.

Definition at line 35 of file eval_context.h.

Member Typedef Documentation

◆ CheckDefined

Type of the check defined function.

Definition at line 45 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 39 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.

Referenced by isc::dhcp::ClientClassDictionary::initMatchExpr(), and isc::dhcp::ClientClassDefParser::parse().

◆ 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 isc::db::error.

◆ 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 isc::db::error.

◆ 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 isc::db::error.

Referenced by convertNestLevelNumber().

◆ 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(), isc::db::error, HOP_COUNT_LIMIT, and isc::dhcp::Option::V6.

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 isc::db::error, and isc::dhcp::Option::V6.

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

◆ 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, isc::db::error, isc::dhcp::LibDHCP::getLastResortOptionDef(), isc::dhcp::LibDHCP::getOptionDef(), isc::dhcp::LibDHCP::getRuntimeOptionDef(), and isc::dhcp::Option::V4.

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 isc::db::error.

◆ 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 isc::db::error.

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

◆ 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 isc::db::error.

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

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

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

Referenced by isc::dhcp::TokenPkt4::evaluate(), isc::dhcp::TokenPkt6::evaluate(), and isc::dhcp::TokenPkt::evaluate().

◆ getUniverse()

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

Returns the universe (v4 or v6)

Returns
universe

Definition at line 225 of file eval_context.h.

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

◆ 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(), 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 68 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 93 of file eval_context.h.

Referenced by parseString().

◆ label_

unsigned isc::eval::EvalContext::label_

Label counter.

Definition at line 71 of file eval_context.h.

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

◆ labels_

std::vector<unsigned> isc::eval::EvalContext::labels_

Label stack.

Definition at line 74 of file eval_context.h.

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

◆ string_

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

The string being parsed.

Definition at line 96 of file eval_context.h.

Referenced by parseString().


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