17#include <boost/lexical_cast.hpp>
22 CheckDefined check_defined)
23 : trace_scanning_(false), trace_parsing_(false),
24 option_universe_(option_universe), check_defined_(check_defined)
44 parser.set_debug_level(trace_parsing_);
66 const isc::eval::location& loc) {
69 n = boost::lexical_cast<int>(option_code);
70 }
catch (
const boost::bad_lexical_cast &) {
72 error(loc,
"Option code has invalid value in " + option_code);
75 if (n < 0 || n > 65535) {
76 error(loc,
"Option code has invalid value in "
77 + option_code +
". Allowed range: 0..65535");
80 if (n < 0 || n > 255) {
81 error(loc,
"Option code has invalid value in "
82 + option_code +
". Allowed range: 0..255");
85 return (
static_cast<uint16_t
>(n));
90 const isc::eval::location& loc) {
91 const std::string global_space = (option_universe_ ==
Option::V4) ?
105 error(loc,
"option '" + option_name +
"' is not defined");
108 return (option_def->getCode());
113 const isc::eval::location& loc) {
117 error(loc,
"Nest level has invalid value in "
118 + nest_level +
". Allowed range: -32..31");
121 error(loc,
"Nest level invalid for DHCPv4 packets");
129 const isc::eval::location& loc) {
132 n = boost::lexical_cast<int64_t>(number);
133 }
catch (
const boost::bad_lexical_cast &) {
134 error(loc,
"Invalid integer value in " + number);
136 if (n < 0 || n > std::numeric_limits<uint8_t>::max()) {
137 error(loc,
"Invalid value in "
138 + number +
". Allowed range: 0..255");
141 return (
static_cast<uint8_t
>(n));
146 const isc::eval::location& loc) {
149 n = boost::lexical_cast<int64_t>(number);
150 }
catch (
const boost::bad_lexical_cast &) {
151 error(loc,
"Invalid integer value in " + number);
153 if (n < std::numeric_limits<int8_t>::min() ||
154 n > std::numeric_limits<int8_t>::max()) {
155 error(loc,
"Invalid value in "
156 + number +
". Allowed range: -128..127");
159 return (
static_cast<int8_t
>(n));
164 const isc::eval::location& loc) {
167 n = boost::lexical_cast<int64_t>(number);
168 }
catch (
const boost::bad_lexical_cast &) {
169 error(loc,
"Invalid value in " + number);
171 if (n < 0 || n > std::numeric_limits<uint16_t>::max()) {
172 error(loc,
"Invalid value in "
173 + number +
". Allowed range: 0..65535");
176 return (
static_cast<uint16_t
>(n));
181 const isc::eval::location& loc) {
184 n = boost::lexical_cast<int64_t>(number);
185 }
catch (
const boost::bad_lexical_cast &) {
186 error(loc,
"Invalid value in " + number);
188 if (n > std::numeric_limits<int16_t>::max() ||
189 n < std::numeric_limits<int16_t>::max()) {
190 error(loc,
"Invalid value in "
191 + number +
". Allowed range: -32768..32767");
194 return (
static_cast<int16_t
>(n));
199 const isc::eval::location& loc) {
202 n = boost::lexical_cast<int64_t>(number);
203 }
catch (
const boost::bad_lexical_cast &) {
204 error(loc,
"Invalid value in " + number);
206 if (n < 0 || n > std::numeric_limits<uint32_t>::max()) {
207 error(loc,
"Invalid value in "
208 + number +
". Allowed range: 0..4294967295");
211 return (
static_cast<uint32_t
>(n));
216 const isc::eval::location& loc) {
219 n = boost::lexical_cast<int64_t>(number);
220 }
catch (
const boost::bad_lexical_cast &) {
221 error(loc,
"Invalid value in " + number);
223 if (n > std::numeric_limits<int32_t>::max() ||
224 n < std::numeric_limits<int32_t>::max()) {
225 error(loc,
"Invalid value in "
226 + number +
". Allowed range: -2147483648..2147483647");
229 return (
static_cast<int32_t
>(n));
234 std::string tmp(4, 0);
235 tmp[0] = (integer >> 24) & 0xff;
236 tmp[1] = (integer >> 16) & 0xff;
237 tmp[2] = (integer >> 8) & 0xff;
238 tmp[3] = integer & 0xff;
245 std::string tmp(2, 0);
246 tmp[0] = (integer >> 8) & 0xff;
247 tmp[1] = integer & 0xff;
254 return (check_defined_(client_class));
A generic exception that is thrown when an unexpected error condition occurs.
static OptionDefinitionPtr getOptionDef(const std::string &space, const uint16_t code)
Return the first option definition matching a particular option code.
static OptionDefinitionPtr getRuntimeOptionDef(const std::string &space, const uint16_t code)
Returns runtime (non-standard) option definition by space and option code.
static OptionDefinitionPtr getLastResortOptionDef(const std::string &space, const uint16_t code)
Returns last resort option definition by space and option code.
Universe
defines option universe DHCPv4 or DHCPv6
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.
static int16_t convertInt16(const std::string &number, const isc::eval::location &loc)
Attempts to convert string to signed 16bit integer.
static std::string fromUint32(const uint32_t integer)
Converts unsigned 32bit integer to string representation.
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.
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.
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.
static void fatal(const std::string &what)
Fatal error handler.
static void error(const isc::eval::location &loc, const std::string &what)
Error handler.
EvalContext(const Option::Universe &option_universe, CheckDefined check_defined=acceptAll)
Default constructor.
Evaluation error exception raised when trying to parse an exceptions.
virtual int parse()
Parse.
#define isc_throw(type, stream)
A shortcut macro to insert known values into exception arguments.
std::string ClientClass
Defines a single class name.
boost::shared_ptr< OptionDefinition > OptionDefinitionPtr
Pointer to option definition object.
Define the isc::eval::parser class.
#define DHCP4_OPTION_SPACE
global std option spaces
#define DHCP6_OPTION_SPACE