BIND 10 trac2431, updated. 693ff3e2fcba8c216e1720e3d561b27f16357190 [2431] Avoid redundant construction in parseRRParams()
BIND 10 source code commits
bind10-changes at lists.isc.org
Mon Dec 17 06:46:32 UTC 2012
The branch, trac2431 has been updated
via 693ff3e2fcba8c216e1720e3d561b27f16357190 (commit)
via 3febd2c9532d2ba597d19f1bf10cc1811fe44098 (commit)
via 3ee0cf28be2ec86b2423709532b646d1f88d698b (commit)
from 757d91ff52158a17e9e17990aa39815fda2ed3f6 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 693ff3e2fcba8c216e1720e3d561b27f16357190
Author: Mukund Sivaraman <muks at isc.org>
Date: Mon Dec 17 12:16:01 2012 +0530
[2431] Avoid redundant construction in parseRRParams()
commit 3febd2c9532d2ba597d19f1bf10cc1811fe44098
Author: Mukund Sivaraman <muks at isc.org>
Date: Mon Dec 17 12:14:54 2012 +0530
[2431] Add RRClass.fromText()
commit 3ee0cf28be2ec86b2423709532b646d1f88d698b
Author: Mukund Sivaraman <muks at isc.org>
Date: Mon Dec 17 11:50:05 2012 +0530
[2431] Refactor code so that RRParamRegistry::textToClassCode() does not throw
-----------------------------------------------------------------------
Summary of changes:
src/lib/dns/master_loader.cc | 21 +++++++---------
src/lib/dns/rrclass.cc | 12 +++++++++-
src/lib/dns/rrparamregistry-placeholder.cc | 36 ++++++++++++++++++----------
src/lib/dns/rrparamregistry.h | 20 +++++++++-------
src/lib/dns/tests/rrclass_unittest.cc | 13 +++++++++-
5 files changed, 67 insertions(+), 35 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/lib/dns/master_loader.cc b/src/lib/dns/master_loader.cc
index 30930ed..5246bf7 100644
--- a/src/lib/dns/master_loader.cc
+++ b/src/lib/dns/master_loader.cc
@@ -162,13 +162,15 @@ private:
// after the RR class below.
}
- boost::scoped_ptr<RRClass> rrclass;
- try {
- rrclass.reset(new RRClass(rrparam_token.getString()));
+ RRClass rrclass(zone_class_);
+ if (rrclass.fromText(rrparam_token.getString())) {
+ if (rrclass != zone_class_) {
+ // It doesn't really matter much what type of exception
+ // we throw, we catch it just below.
+ isc_throw(isc::BadValue, "Class mismatch: " << rrclass <<
+ "vs. " << zone_class_);
+ }
rrparam_token = lexer_.getNextToken(MasterToken::STRING);
- } catch (const InvalidRRClass&) {
- // If it's not an rrclass here, use the zone's class.
- rrclass.reset(new RRClass(zone_class_));
}
// If we couldn't parse TTL earlier in the stream (above), try
@@ -179,13 +181,6 @@ private:
rrparam_token = lexer_.getNextToken(MasterToken::STRING);
}
- if (*rrclass != zone_class_) {
- // It doesn't really matter much what type of exception
- // we throw, we catch it just below.
- isc_throw(isc::BadValue, "Class mismatch: " << *rrclass <<
- "vs. " << zone_class_);
- }
-
// Return the current string token's value as the RRType.
return (RRType(rrparam_token.getString()));
}
diff --git a/src/lib/dns/rrclass.cc b/src/lib/dns/rrclass.cc
index ac5823c..a608dc8 100644
--- a/src/lib/dns/rrclass.cc
+++ b/src/lib/dns/rrclass.cc
@@ -31,7 +31,11 @@ namespace isc {
namespace dns {
RRClass::RRClass(const std::string& classstr) {
- classcode_ = RRParamRegistry::getRegistry().textToClassCode(classstr);
+ if (!RRParamRegistry::getRegistry().textToClassCode(classstr,
+ classcode_)) {
+ isc_throw(InvalidRRClass,
+ "Unrecognized RR parameter string: " + classstr);
+ }
}
RRClass::RRClass(InputBuffer& buffer) {
@@ -56,6 +60,12 @@ RRClass::toWire(AbstractMessageRenderer& renderer) const {
renderer.writeUint16(classcode_);
}
+bool
+RRClass::fromText(const std::string& class_str) {
+ return (RRParamRegistry::getRegistry().textToClassCode(class_str,
+ classcode_));
+}
+
ostream&
operator<<(ostream& os, const RRClass& rrclass) {
os << rrclass.toText();
diff --git a/src/lib/dns/rrparamregistry-placeholder.cc b/src/lib/dns/rrparamregistry-placeholder.cc
index 16ec23c..9729d86 100644
--- a/src/lib/dns/rrparamregistry-placeholder.cc
+++ b/src/lib/dns/rrparamregistry-placeholder.cc
@@ -421,14 +421,15 @@ removeParam(uint16_t code, MC& codemap, MS& stringmap) {
return (false);
}
-template <typename PT, typename MS, typename ET>
-inline uint16_t
-textToCode(const string& code_str, MS& stringmap) {
+template <typename PT, typename MS>
+inline bool
+textToCode(const string& code_str, MS& stringmap, uint16_t& class_code) {
typename MS::const_iterator found;
found = stringmap.find(code_str);
if (found != stringmap.end()) {
- return (found->second->code_);
+ class_code = found->second->code_;
+ return (true);
}
size_t l = code_str.size();
@@ -441,10 +442,12 @@ textToCode(const string& code_str, MS& stringmap) {
l - PT::UNKNOWN_PREFIXLEN()));
iss >> dec >> code;
if (iss.rdstate() == ios::eofbit && code <= PT::MAX_CODE) {
- return (code);
+ class_code = code;
+ return (true);
}
}
- isc_throw(ET, "Unrecognized RR parameter string: " + code_str);
+
+ return (false);
}
template <typename PT, typename MC>
@@ -477,8 +480,15 @@ RRParamRegistry::removeType(uint16_t code) {
uint16_t
RRParamRegistry::textToTypeCode(const string& type_string) const {
- return (textToCode<RRTypeParam, StrRRTypeMap,
- InvalidRRType>(type_string, impl_->str2typemap));
+ uint16_t code;
+
+ if (!textToCode<RRTypeParam, StrRRTypeMap>
+ (type_string, impl_->str2typemap, code)) {
+ isc_throw(InvalidRRType,
+ "Unrecognized RR parameter string: " + type_string);
+ }
+
+ return (code);
}
string
@@ -499,10 +509,12 @@ RRParamRegistry::removeClass(uint16_t code) {
impl_->str2classmap));
}
-uint16_t
-RRParamRegistry::textToClassCode(const string& class_string) const {
- return (textToCode<RRClassParam, StrRRClassMap,
- InvalidRRClass>(class_string, impl_->str2classmap));
+bool
+RRParamRegistry::textToClassCode(const string& class_string,
+ uint16_t& class_code) const
+{
+ return (textToCode<RRClassParam, StrRRClassMap>
+ (class_string, impl_->str2classmap, class_code));
}
string
diff --git a/src/lib/dns/rrparamregistry.h b/src/lib/dns/rrparamregistry.h
index 56ae981..6924e05 100644
--- a/src/lib/dns/rrparamregistry.h
+++ b/src/lib/dns/rrparamregistry.h
@@ -415,16 +415,20 @@ public:
/// \brief Convert a textual representation of an RR class to the
/// corresponding 16-bit integer code.
///
- /// This method searches the \c RRParamRegistry for the mapping from the
- /// given textual representation of RR class to the corresponding integer
- /// code. If a mapping is found, it returns the associated class code;
- /// otherwise, if the given string is in the form of "CLASSnnnn", it returns
- /// the corresponding number as the class code; otherwise, it throws an
- /// exception of class \c InvalidRRClass.
+ /// This method searches the \c RRParamRegistry for the mapping from
+ /// the given textual representation of RR class to the
+ /// corresponding integer code. If a mapping is found, it returns
+ /// true with the associated class code in \c class_code; otherwise,
+ /// if the given string is in the form of "CLASSnnnn", it returns
+ /// true with the corresponding number as the class code in \c
+ /// class_code; otherwise, it returns false and \c class_code is
+ /// untouched.
///
/// \param class_string The textual representation of the RR class.
- /// \return The RR class code for \c class_string.
- uint16_t textToClassCode(const std::string& class_string) const;
+ /// \param class_code Returns the RR class code in this argument.
+ /// \return true if conversion is successful, false otherwise.
+ bool textToClassCode(const std::string& class_string,
+ uint16_t& class_code) const;
/// \brief Convert class code into its textual representation.
///
diff --git a/src/lib/dns/tests/rrclass_unittest.cc b/src/lib/dns/tests/rrclass_unittest.cc
index 6156be5..697a51c 100644
--- a/src/lib/dns/tests/rrclass_unittest.cc
+++ b/src/lib/dns/tests/rrclass_unittest.cc
@@ -59,7 +59,7 @@ RRClassTest::rrclassFactoryFromWire(const char* datafile) {
return (RRClass(buffer));
}
-TEST_F(RRClassTest, fromText) {
+TEST_F(RRClassTest, fromTextConstructor) {
EXPECT_EQ("IN", RRClass("IN").toText());
EXPECT_EQ("CH", RRClass("CH").toText());
@@ -96,6 +96,17 @@ TEST_F(RRClassTest, toText) {
EXPECT_EQ("CLASS65000", RRClass(65000).toText());
}
+TEST_F(RRClassTest, fromText) {
+ RRClass frc(1);
+ EXPECT_EQ("IN", frc.toText());
+ EXPECT_TRUE(frc.fromText("CH"));
+ EXPECT_EQ("CH", frc.toText());
+ EXPECT_FALSE(frc.fromText("ZZ"));
+ EXPECT_EQ("CH", frc.toText());
+ EXPECT_TRUE(frc.fromText("IN"));
+ EXPECT_EQ("IN", frc.toText());
+}
+
TEST_F(RRClassTest, toWireBuffer) {
rrclass_1.toWire(obuffer);
rrclass_0x80.toWire(obuffer);
More information about the bind10-changes
mailing list