]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2387] Unify code from MX constructors
authorMukund Sivaraman <muks@isc.org>
Thu, 28 Mar 2013 02:48:35 +0000 (08:18 +0530)
committerMukund Sivaraman <muks@isc.org>
Thu, 28 Mar 2013 02:48:37 +0000 (08:18 +0530)
This is an offshoot from #2391. There's no need to create yet another
ticket for it.

src/lib/dns/rdata/generic/mx_15.cc
src/lib/dns/rdata/generic/mx_15.h

index 12ada97d89bc0ac065eeb2122fea61ed2b5a6be8..ae9978e3773c70890d2e45698819626e60b56e28 100644 (file)
@@ -68,15 +68,7 @@ MX::MX(const std::string& 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 in: "
-                      << mx_str);
-        }
-        preference_ = static_cast<uint16_t>(num);
-
-        mxname_ = createNameFromLexer(lexer, NULL);
+        constructFromLexer(lexer, NULL);
 
         if (lexer.getNextToken().getType() != MasterToken::END_OF_FILE) {
             isc_throw(InvalidRdataText, "extra input text for MX: "
@@ -108,8 +100,13 @@ MX::MX(const std::string& mx_str) :
 /// is non-absolute.
 MX::MX(MasterLexer& lexer, const Name* origin,
        MasterLoader::Options, MasterLoaderCallbacks&) :
-    preference_(0), mxname_(".")
+    preference_(0), mxname_(Name::ROOT_NAME())
 {
+    constructFromLexer(lexer, origin);
+}
+
+void
+MX::constructFromLexer(MasterLexer& lexer, const Name* origin) {
     const uint32_t num = lexer.getNextToken(MasterToken::NUMBER).getNumber();
     if (num > 65535) {
         isc_throw(InvalidRdataText, "Invalid MX preference: " << num);
index 1381f18b05152927f9c7afc590b5d24106db2b14..84e7112b3a312bba390a02d58ad7c8e39400b323 100644 (file)
@@ -42,6 +42,9 @@ public:
     uint16_t getMXPref() const;
 
 private:
+    void constructFromLexer(isc::dns::MasterLexer& lexer,
+                            const isc::dns::Name* origin);
+
     /// Note: this is a prototype version; we may reconsider
     /// this representation later.
     uint16_t preference_;