summaryrefslogtreecommitdiffstats
path: root/src/lib/dns
diff options
context:
space:
mode:
authorMukund Sivaraman <muks@isc.org>2013-01-28 10:54:34 +0100
committerMukund Sivaraman <muks@isc.org>2013-01-29 05:59:00 +0100
commite8c5250c5b3924c34159c92b2e3a23b8878572e6 (patch)
tree65b1047fecadc51b2c8d0ec45b2cfc3f2f349021 /src/lib/dns
parent[2390] Update std::string NS constructor to use the MasterLexer (diff)
downloadkea-e8c5250c5b3924c34159c92b2e3a23b8878572e6.tar.xz
kea-e8c5250c5b3924c34159c92b2e3a23b8878572e6.zip
[2390] Update std::string MX constructor to use the MasterLexer
Also adjust tests.
Diffstat (limited to 'src/lib/dns')
-rw-r--r--src/lib/dns/rdata/generic/mx_15.cc37
-rw-r--r--src/lib/dns/tests/rdata_mx_unittest.cc5
2 files changed, 28 insertions, 14 deletions
diff --git a/src/lib/dns/rdata/generic/mx_15.cc b/src/lib/dns/rdata/generic/mx_15.cc
index 32c01f3d9e..70fa294fa6 100644
--- a/src/lib/dns/rdata/generic/mx_15.cc
+++ b/src/lib/dns/rdata/generic/mx_15.cc
@@ -43,27 +43,38 @@ MX::MX(InputBuffer& buffer, size_t) :
}
MX::MX(const std::string& mx_str) :
- preference_(0), mxname_(".")
+ // Fill in dummy name and replace them soon below.
+ preference_(0), mxname_(Name::ROOT_NAME())
{
- istringstream iss(mx_str);
- uint16_t pref;
- string mxname;
-
- iss >> pref >> mxname;
-
- if (iss.bad() || iss.fail() || !iss.eof()) {
- isc_throw(InvalidRdataText, "Invalid MX text format");
+ try {
+ std::istringstream ss(mx_str);
+ MasterLexer lexer;
+ lexer.pushSource(ss);
+
+ const uint32_t num =
+ lexer.getNextToken(MasterToken::NUMBER).getNumber();
+ if (num > 65535) {
+ isc_throw(InvalidRdataText, "Invalid MX preference");
+ }
+ preference_ = static_cast<uint16_t>(num);
+
+ mxname_ = createNameFromLexer(lexer, NULL);
+
+ if (lexer.getNextToken().getType() != MasterToken::END_OF_FILE) {
+ isc_throw(InvalidRdataText, "extra input text for MX: "
+ << mx_str);
+ }
+ } catch (const MasterLexer::LexerError& ex) {
+ isc_throw(InvalidRdataText, "Failed to construct MX from '" <<
+ mx_str << "': " << ex.what());
}
-
- preference_ = pref;
- mxname_ = Name(mxname);
}
MX::MX(MasterLexer& lexer, const Name* origin,
MasterLoader::Options, MasterLoaderCallbacks&) :
preference_(0), mxname_(".")
{
- uint32_t num = lexer.getNextToken(MasterToken::NUMBER).getNumber();
+ const uint32_t num = lexer.getNextToken(MasterToken::NUMBER).getNumber();
if (num > 65535) {
isc_throw(InvalidRdataText, "Invalid MX preference");
}
diff --git a/src/lib/dns/tests/rdata_mx_unittest.cc b/src/lib/dns/tests/rdata_mx_unittest.cc
index 59639444a7..e1ae811a56 100644
--- a/src/lib/dns/tests/rdata_mx_unittest.cc
+++ b/src/lib/dns/tests/rdata_mx_unittest.cc
@@ -38,7 +38,7 @@ class Rdata_MX_Test : public RdataTest {
const generic::MX rdata_mx(10, Name("mx.example.com"));
TEST_F(Rdata_MX_Test, createFromText) {
- const generic::MX rdata_mx2("10 mx.example.com");
+ const generic::MX rdata_mx2("10 mx.example.com.");
EXPECT_EQ(0, rdata_mx2.compare(rdata_mx));
}
@@ -48,6 +48,9 @@ TEST_F(Rdata_MX_Test, badText) {
EXPECT_THROW(const generic::MX rdata_mx("SPOON"), InvalidRdataText);
EXPECT_THROW(const generic::MX rdata_mx("10 mx. example.com."),
InvalidRdataText);
+ // No origin and relative
+ EXPECT_THROW(const generic::MX rdata_mx("10 mx.example.com"),
+ MissingNameOrigin);
}
TEST_F(Rdata_MX_Test, copy) {