17 #include <boost/lexical_cast.hpp> 23 : trace_scanning_(false), trace_parsing_(false),
24 option_universe_(option_universe), check_defined_(check_defined)
70 const isc::eval::location& loc)
74 n = boost::lexical_cast<int>(option_code);
75 }
catch (
const boost::bad_lexical_cast &) {
77 error(loc,
"Option code has invalid value in " + option_code);
79 if (option_universe_ == Option::V6) {
80 if (n < 0 || n > 65535) {
81 error(loc,
"Option code has invalid value in " 82 + option_code +
". Allowed range: 0..65535");
85 if (n < 0 || n > 255) {
86 error(loc,
"Option code has invalid value in " 87 + option_code +
". Allowed range: 0..255");
90 return (static_cast<uint16_t>(n));
95 const isc::eval::location& loc)
97 const std::string global_space = (option_universe_ == Option::V4) ?
103 option_def = LibDHCP::getRuntimeOptionDef(global_space, option_name);
107 option_def = LibDHCP::getLastResortOptionDef(global_space, option_name);
111 error(loc,
"option '" + option_name +
"' is not defined");
114 return (option_def->getCode());
119 const isc::eval::location& loc)
122 if (option_universe_ == Option::V6) {
124 error(loc,
"Nest level has invalid value in " 125 + nest_level +
". Allowed range: -32..31");
128 error(loc,
"Nest level invalid for DHCPv4 packets");
136 const isc::eval::location& loc)
140 n = boost::lexical_cast<int>(number);
141 }
catch (
const boost::bad_lexical_cast &) {
142 error(loc,
"Invalid integer value in " + number);
144 if (n < 0 || n > std::numeric_limits<uint8_t>::max()) {
145 error(loc,
"Invalid value in " 146 + number +
". Allowed range: 0..255");
149 return (static_cast<uint8_t>(n));
154 const isc::eval::location& loc)
158 n = boost::lexical_cast<int>(number);
159 }
catch (
const boost::bad_lexical_cast &) {
160 error(loc,
"Invalid integer value in " + number);
162 if (n < std::numeric_limits<int8_t>::min() ||
163 n > std::numeric_limits<int8_t>::max()) {
164 error(loc,
"Invalid value in " 165 + number +
". Allowed range: 0..255");
168 return (static_cast<uint8_t>(n));
173 const isc::eval::location& loc)
177 n = boost::lexical_cast<uint64_t>(number);
178 }
catch (
const boost::bad_lexical_cast &) {
179 error(loc,
"Invalid value in " + number);
181 if (n > std::numeric_limits<uint32_t>::max()) {
182 error(loc,
"Invalid value in " 183 + number +
". Allowed range: 0..4294967295");
186 return (static_cast<uint32_t>(n));
191 std::string tmp(4, 0);
192 tmp[0] = (integer >> 24) & 0xff;
193 tmp[1] = (integer >> 16) & 0xff;
194 tmp[2] = (integer >> 8) & 0xff;
195 tmp[3] = integer & 0xff;
202 return (check_defined_(client_class));
void set_debug_level(debug_level_type l)
Set the current debugging level.
static uint32_t convertUint32(const std::string &number, const isc::eval::location &loc)
Attempts to convert string to unsigned 32bit integer.
Evaluation error exception raised when trying to parse an exceptions.
#define DHCP6_OPTION_SPACE
Universe
defines option universe DHCPv4 or DHCPv6
static void error(const isc::eval::location &loc, const std::string &what)
Error handler.
void scanStringBegin(ParserType type)
Method called before scanning starts on a string.
std::string string_
The string being parsed.
Define the isc::eval::parser class.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
A generic exception that is thrown when an unexpected error condition occurs.
std::string file_
The name of the file being parsed.
static std::string fromUint32(const uint32_t integer)
Converts integer to string representation.
static uint8_t convertUint8(const std::string &number, const isc::eval::location &loc)
Attempts to convert string to unsigned 8bit integer.
uint16_t convertOptionName(const std::string &option_name, const isc::eval::location &loc)
Option name conversion.
uint16_t convertOptionCode(const std::string &option_code, const isc::eval::location &loc)
Option code conversion.
virtual int parse()
Parse.
#define DHCP4_OPTION_SPACE
static void fatal(const std::string &what)
Fatal error handler.
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.
boost::shared_ptr< OptionDefinition > OptionDefinitionPtr
Pointer to option definition object.
int8_t convertNestLevelNumber(const std::string &nest_level, const isc::eval::location &loc)
Nest level conversion.
std::string ClientClass
Defines a single class name.
static int8_t convertInt8(const std::string &number, const isc::eval::location &loc)
Attempts to convert string to signed 8bit integer.
std::function< bool(const ClientClass &)> CheckDefined
Type of the check defined function.
virtual ~EvalContext()
destructor
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.
static bool acceptAll(const ClientClass &client_class)
Accept all client class names.