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) {
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();
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>
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
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
/// \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.
///