Browse Source

[2565] Update textToTypeCode() to match textToClassCode()

Mukund Sivaraman 12 years ago
parent
commit
0758ead7f4
3 changed files with 21 additions and 20 deletions
  1. 6 11
      src/lib/dns/rrparamregistry-placeholder.cc
  2. 11 8
      src/lib/dns/rrparamregistry.h
  3. 4 1
      src/lib/dns/rrtype.cc

+ 6 - 11
src/lib/dns/rrparamregistry-placeholder.cc

@@ -478,17 +478,12 @@ RRParamRegistry::removeType(uint16_t code) {
                                                      impl_->str2typemap));
                                                      impl_->str2typemap));
 }
 }
 
 
-uint16_t
-RRParamRegistry::textToTypeCode(const string& type_string) const {
-    uint16_t code;
-
-    if (!textToCode<RRTypeParam, StrRRTypeMap>
-        (type_string, impl_->str2typemap, code)) {
-         isc_throw(InvalidRRType,
-                   "Unrecognized RR parameter string: " + type_string);
-    }
-
-    return (code);
+bool
+RRParamRegistry::textToTypeCode(const string& type_string,
+                                uint16_t& type_code) const
+{
+    return (textToCode<RRTypeParam, StrRRTypeMap>
+            (type_string, impl_->str2typemap, type_code));
 }
 }
 
 
 string
 string

+ 11 - 8
src/lib/dns/rrparamregistry.h

@@ -384,16 +384,19 @@ public:
     /// \brief Convert a textual representation of an RR type to the
     /// \brief Convert a textual representation of an RR type to the
     /// corresponding 16-bit integer code.
     /// corresponding 16-bit integer code.
     ///
     ///
-    /// This method searches the \c RRParamRegistry for the mapping from the
-    /// given textual representation of RR type to the corresponding integer
-    /// code.  If a mapping is found, it returns the associated type code;
-    /// otherwise, if the given string is in the form of "TYPEnnnn", it returns
-    /// the corresponding number as the type code; otherwise, it throws an
-    /// exception of class \c InvalidRRType.
+    /// This method searches the \c RRParamRegistry for the mapping from
+    /// the given textual representation of RR type to the corresponding
+    /// integer code. If a mapping is found, it returns true with the
+    /// associated type code in \c type_code; otherwise, if the given
+    /// string is in the form of "TYPEnnnn", it returns true with the
+    /// corresponding number as the type code in \c type_code;
+    /// otherwise, it returns false and \c type_code is untouched.
     ///
     ///
     /// \param type_string The textual representation of the RR type.
     /// \param type_string The textual representation of the RR type.
-    /// \return The RR type code for \c type_string.
-    uint16_t textToTypeCode(const std::string& type_string) const;
+    /// \param type_code Returns the RR type code in this argument.
+    /// \return true if conversion is successful, false otherwise.
+    bool textToTypeCode(const std::string& type_string,
+                        uint16_t& type_code) const;
 
 
     /// \brief Convert type code into its textual representation.
     /// \brief Convert type code into its textual representation.
     ///
     ///

+ 4 - 1
src/lib/dns/rrtype.cc

@@ -32,7 +32,10 @@ namespace isc {
 namespace dns {
 namespace dns {
 
 
 RRType::RRType(const std::string& typestr) {
 RRType::RRType(const std::string& typestr) {
-    typecode_ = RRParamRegistry::getRegistry().textToTypeCode(typestr);
+    if (!RRParamRegistry::getRegistry().textToTypeCode(typestr, typecode_)) {
+        isc_throw(InvalidRRType,
+                  "Unrecognized RR parameter string: " + typestr);
+    }
 }
 }
 
 
 RRType::RRType(InputBuffer& buffer) {
 RRType::RRType(InputBuffer& buffer) {