From: Marcin Siodelski Date: Mon, 11 Mar 2019 13:57:58 +0000 (+0100) Subject: [#521,!270] Addressed review comments. X-Git-Tag: Kea-1.6.0-beta~376 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8edf2fb25330a75d0b1a6dde5e319a3640f53e51;p=thirdparty%2Fkea.git [#521,!270] Addressed review comments. --- diff --git a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc index 0e104120e5..8ac602aa8a 100644 --- a/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc +++ b/src/hooks/dhcp/mysql_cb/mysql_cb_impl.cc @@ -602,17 +602,21 @@ MySqlConfigBackendImpl::processOptionRow(const Option::Universe& universe, code = (*(first_binding + 1))->getInteger(); } - // Option can be stored as a blob or formatted value in the configuration. - std::vector blob; - if (!(*(first_binding + 2))->amNull()) { - blob = (*(first_binding + 2))->getBlob(); - } - OptionBuffer buf(blob.begin(), blob.end()); // Get formatted value if available. std::string formatted_value = (*(first_binding + 3))->getStringOrDefault(""); - OptionPtr option(new Option(universe, code, buf.begin(), buf.end())); + OptionPtr option(new Option(universe, code)); + + // If we don't have a formatted value, check for a blob. Add it to the + // option if it exists. + if (formatted_value.empty()) { + std::vector blob; + if (!(*(first_binding + 2))->amNull()) { + blob = (*(first_binding + 2))->getBlob(); + } + option->setData(blob.begin(), blob.end()); + } // Check if the option is persistent. bool persistent = static_cast((*(first_binding + 5))->getIntegerOrDefault(0)); diff --git a/src/lib/dhcpsrv/testutils/generic_backend_unittest.cc b/src/lib/dhcpsrv/testutils/generic_backend_unittest.cc index 85f2fc82d9..baceb72f13 100644 --- a/src/lib/dhcpsrv/testutils/generic_backend_unittest.cc +++ b/src/lib/dhcpsrv/testutils/generic_backend_unittest.cc @@ -84,6 +84,10 @@ GenericBackendTest::testOptionsEquivalent(const OptionDescriptor& ref_option, // Compare the on-wire data. EXPECT_EQ(ref_option_buf_vec, tested_option_buf_vec); + + } else { + // If the formatted value is non-empty the buffer should be empty. + EXPECT_TRUE(tested_option.option_->getData().empty()); } // Compare other members of the @c OptionDescriptor, e.g. the