From: Marcin Siodelski Date: Thu, 19 Nov 2015 11:52:27 +0000 (+0100) Subject: [4093] Extended TokenOption class ctor with representation type. X-Git-Tag: trac4204_base~1^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5ad49c1f7533dbccd96440c2f0b9d05cf634bc90;p=thirdparty%2Fkea.git [4093] Extended TokenOption class ctor with representation type. --- diff --git a/src/lib/eval/parser.yy b/src/lib/eval/parser.yy index 4fdfa99513..25ee8ed9f5 100644 --- a/src/lib/eval/parser.yy +++ b/src/lib/eval/parser.yy @@ -120,7 +120,7 @@ string_expr : STRING | OPTION "[" INTEGER "]" DOTTEXT { uint16_t numeric_code = convert_option_code($3, @3, ctx); - TokenPtr opt(new TokenOption(numeric_code)); + TokenPtr opt(new TokenOption(numeric_code, TokenOption::TEXTUAL)); ctx.expression.push_back(opt); } | SUBSTRING "(" string_expr "," start_expr "," length_expr ")" diff --git a/src/lib/eval/tests/evaluate_unittest.cc b/src/lib/eval/tests/evaluate_unittest.cc index 5cb090be1a..49e7148251 100644 --- a/src/lib/eval/tests/evaluate_unittest.cc +++ b/src/lib/eval/tests/evaluate_unittest.cc @@ -196,7 +196,7 @@ TEST_F(EvaluateTest, packet) { TokenPtr tstring; TokenPtr tequal; - ASSERT_NO_THROW(toption.reset(new TokenOption(100))); + ASSERT_NO_THROW(toption.reset(new TokenOption(100, TokenOption::TEXTUAL))); e_.push_back(toption); ASSERT_NO_THROW(tstring.reset(new TokenString("hundred4"))); e_.push_back(tstring); @@ -219,7 +219,7 @@ TEST_F(EvaluateTest, complex) { TokenPtr tequal; // Get the option, i.e., "hundred[46]" - ASSERT_NO_THROW(toption.reset(new TokenOption(100))); + ASSERT_NO_THROW(toption.reset(new TokenOption(100, TokenOption::TEXTUAL))); e_.push_back(toption); // Get substring("hundred[46]", 0, 7), i.e., "hundred" diff --git a/src/lib/eval/tests/token_unittest.cc b/src/lib/eval/tests/token_unittest.cc index 1fc8109d12..99581fbb92 100644 --- a/src/lib/eval/tests/token_unittest.cc +++ b/src/lib/eval/tests/token_unittest.cc @@ -253,8 +253,8 @@ TEST_F(TokenTest, optionString4) { TokenPtr not_found; // The packets we use have option 100 with a string in them. - ASSERT_NO_THROW(found.reset(new TokenOption(100))); - ASSERT_NO_THROW(not_found.reset(new TokenOption(101))); + ASSERT_NO_THROW(found.reset(new TokenOption(100, TokenOption::TEXTUAL))); + ASSERT_NO_THROW(not_found.reset(new TokenOption(101, TokenOption::TEXTUAL))); // This should evaluate to the content of the option 100 (i.e. "hundred4") ASSERT_NO_THROW(found->evaluate(*pkt4_, values_)); @@ -281,8 +281,8 @@ TEST_F(TokenTest, optionString6) { TokenPtr not_found; // The packets we use have option 100 with a string in them. - ASSERT_NO_THROW(found.reset(new TokenOption(100))); - ASSERT_NO_THROW(not_found.reset(new TokenOption(101))); + ASSERT_NO_THROW(found.reset(new TokenOption(100, TokenOption::TEXTUAL))); + ASSERT_NO_THROW(not_found.reset(new TokenOption(101, TokenOption::TEXTUAL))); // This should evaluate to the content of the option 100 (i.e. "hundred6") ASSERT_NO_THROW(found->evaluate(*pkt6_, values_)); diff --git a/src/lib/eval/token.h b/src/lib/eval/token.h index a44c6efd91..82da09e011 100644 --- a/src/lib/eval/token.h +++ b/src/lib/eval/token.h @@ -146,6 +146,19 @@ protected: /// option. If the option is not found, an empty string ("") is returned. class TokenOption : public Token { public: + + /// @brief Token representation type. + /// + /// There are many possible ways in which option can be presented. + /// Currently the textual and hexadecimal representations are + /// supported. The type of representation is specified in the + /// constructor and it affects the value generated by the + /// @c TokenOption::evaluate function. + enum RepresentationType { + TEXTUAL, + HEXADECIMAL + }; + /// @brief Constructor that takes an option code as a parameter /// @param option_code code of the option /// @@ -153,8 +166,9 @@ public: /// introduce complex dependency of the libkea-eval on libdhcpsrv. /// /// @param option_code code of the option to be represented. - TokenOption(uint16_t option_code) - :option_code_(option_code) {} + /// @param rep_type Token representation type. + TokenOption(const uint16_t option_code, const RepresentationType& rep_type) + : option_code_(option_code), representation_type_(rep_type) {} /// @brief Evaluates the values of the option /// @@ -177,7 +191,8 @@ public: } private: - uint16_t option_code_; ///< code of the option to be extracted + uint16_t option_code_; ///< Code of the option to be extracted + RepresentationType representation_type_; ///< Representation type. }; /// @brief Token that represents equality operator (compares two other tokens)