// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
+#include <dhcp/option.h>
+#include <dhcp/option_definition.h>
+#include <dhcp/libdhcp++.h>
#include <eval/eval_context.h>
#include <eval/parser.h>
#include <exceptions/exceptions.h>
-#include <dhcp/option.h>
+#include <boost/lexical_cast.hpp>
#include <fstream>
EvalContext::EvalContext(const Option::Universe& option_universe)
return (static_cast<uint16_t>(n));
}
+uint16_t
+EvalContext::convert_option_name(const std::string& option_name,
+ const isc::eval::location& loc)
+{
+ OptionDefinitionPtr option_def = LibDHCP::getOptionDef(option_universe_,
+ option_name);
+ if (!option_def) {
+ const std::string global_space =
+ (option_universe_ == Option::V4) ? "dhcp4" : "dhcp6";
+ option_def = LibDHCP::getRuntimeOptionDef(global_space, option_name);
+ }
+
+ if (!option_def) {
+ error(loc, "option '" + option_name + "' is not defined");
+ }
+
+ return (option_def->getCode());
+}
case 8:
#line 109 "parser.yy" // lalr1.cc:859
{
- try {
- // This may result in exception if the specified
- // name is unknown.
- TokenPtr opt(new TokenOption(yystack_[3].value.as< std::string > (),
- ctx.option_universe_,
- TokenOption::TEXTUAL));
- ctx.expression.push_back(opt);
-
- } catch (const isc::BadValue& ex) {
- ctx.error(yystack_[3].location, ex.what());
- }
+ uint16_t numeric_code = ctx.convert_option_name(yystack_[3].value.as< std::string > (), yystack_[3].location);
+ TokenPtr opt(new TokenOption(numeric_code, TokenOption::TEXTUAL));
+ ctx.expression.push_back(opt);
}
-#line 641 "parser.cc" // lalr1.cc:859
+#line 633 "parser.cc" // lalr1.cc:859
break;
case 9:
-#line 123 "parser.yy" // lalr1.cc:859
+#line 115 "parser.yy" // lalr1.cc:859
{
- try {
- // This may result in exception if the specified
- // name is unknown.
- TokenPtr opt(new TokenOption(yystack_[3].value.as< std::string > (),
- ctx.option_universe_,
- TokenOption::HEXADECIMAL));
- ctx.expression.push_back(opt);
-
- } catch (const isc::BadValue& ex) {
- ctx.error(yystack_[3].location, ex.what());
- }
+ uint16_t numeric_code = ctx.convert_option_name(yystack_[3].value.as< std::string > (), yystack_[3].location);
+ TokenPtr opt(new TokenOption(numeric_code, TokenOption::HEXADECIMAL));
+ ctx.expression.push_back(opt);
}
-#line 659 "parser.cc" // lalr1.cc:859
+#line 643 "parser.cc" // lalr1.cc:859
break;
case 10:
-#line 137 "parser.yy" // lalr1.cc:859
+#line 121 "parser.yy" // lalr1.cc:859
{
TokenPtr sub(new TokenSubstring());
ctx.expression.push_back(sub);
}
-#line 668 "parser.cc" // lalr1.cc:859
+#line 652 "parser.cc" // lalr1.cc:859
break;
case 12:
-#line 146 "parser.yy" // lalr1.cc:859
+#line 130 "parser.yy" // lalr1.cc:859
{
TokenPtr str(new TokenString(yystack_[0].value.as< std::string > ()));
ctx.expression.push_back(str);
}
-#line 677 "parser.cc" // lalr1.cc:859
+#line 661 "parser.cc" // lalr1.cc:859
break;
case 13:
-#line 153 "parser.yy" // lalr1.cc:859
+#line 137 "parser.yy" // lalr1.cc:859
{
TokenPtr str(new TokenString(yystack_[0].value.as< std::string > ()));
ctx.expression.push_back(str);
}
-#line 686 "parser.cc" // lalr1.cc:859
+#line 670 "parser.cc" // lalr1.cc:859
break;
case 14:
-#line 158 "parser.yy" // lalr1.cc:859
+#line 142 "parser.yy" // lalr1.cc:859
{
TokenPtr str(new TokenString("all"));
ctx.expression.push_back(str);
}
-#line 695 "parser.cc" // lalr1.cc:859
+#line 679 "parser.cc" // lalr1.cc:859
break;
-#line 699 "parser.cc" // lalr1.cc:859
+#line 683 "parser.cc" // lalr1.cc:859
default:
break;
}
const unsigned char
EvalParser::yyrline_[] =
{
- 0, 76, 76, 79, 86, 91, 96, 102, 108, 122,
- 136, 141, 145, 152, 157
+ 0, 76, 76, 79, 86, 91, 96, 102, 108, 114,
+ 120, 125, 129, 136, 141
};
// Print the state stack on the debug stream.
#line 21 "parser.yy" // lalr1.cc:1167
} } // isc::eval
-#line 1083 "parser.cc" // lalr1.cc:1167
-#line 164 "parser.yy" // lalr1.cc:1168
+#line 1067 "parser.cc" // lalr1.cc:1167
+#line 148 "parser.yy" // lalr1.cc:1168
void
isc::eval::EvalParser::error(const location_type& loc,
}
| OPTION "[" OPTION_NAME "]" DOT TEXT
{
- try {
- // This may result in exception if the specified
- // name is unknown.
- TokenPtr opt(new TokenOption($3,
- ctx.option_universe_,
- TokenOption::TEXTUAL));
- ctx.expression.push_back(opt);
-
- } catch (const isc::BadValue& ex) {
- ctx.error(@3, ex.what());
- }
+ uint16_t numeric_code = ctx.convert_option_name($3, @3);
+ TokenPtr opt(new TokenOption(numeric_code, TokenOption::TEXTUAL));
+ ctx.expression.push_back(opt);
}
| OPTION "[" OPTION_NAME "]" DOT HEX
{
- try {
- // This may result in exception if the specified
- // name is unknown.
- TokenPtr opt(new TokenOption($3,
- ctx.option_universe_,
- TokenOption::HEXADECIMAL));
- ctx.expression.push_back(opt);
-
- } catch (const isc::BadValue& ex) {
- ctx.error(@3, ex.what());
- }
+ uint16_t numeric_code = ctx.convert_option_name($3, @3);
+ TokenPtr opt(new TokenOption(numeric_code, TokenOption::HEXADECIMAL));
+ ctx.expression.push_back(opt);
}
| SUBSTRING "(" string_expr "," start_expr "," length_expr ")"
{