[svn] commit: r503 - in /branches/jinmei-dnsrdata/src/lib/dns/cpp: rdata.cc rdata.h

BIND 10 source code commits bind10-changes at lists.isc.org
Thu Jan 21 19:28:32 UTC 2010


Author: jinmei
Date: Thu Jan 21 19:28:32 2010
New Revision: 503

Log:
introduced a separate public function compareNames as a helper subroutine
for rdata classes.

Modified:
    branches/jinmei-dnsrdata/src/lib/dns/cpp/rdata.cc
    branches/jinmei-dnsrdata/src/lib/dns/cpp/rdata.h

Modified: branches/jinmei-dnsrdata/src/lib/dns/cpp/rdata.cc
==============================================================================
--- branches/jinmei-dnsrdata/src/lib/dns/cpp/rdata.cc (original)
+++ branches/jinmei-dnsrdata/src/lib/dns/cpp/rdata.cc Thu Jan 21 19:28:32 2010
@@ -62,6 +62,26 @@
     return (rdata);
 }
 
+int
+compareNames(const Name& n1, const Name& n2)
+{
+    size_t len1 = n1.getLength();
+    size_t len2 = n2.getLength();
+    size_t cmplen = (len1 < len2) ? len1 : len2;
+
+    for (size_t i = 0; i < cmplen; i++) {
+        uint8_t c1 = tolower(n1.at(i));
+        uint8_t c2 = tolower(n2.at(i));
+        if (c1 < c2) {
+            return (-1);
+        } else if (c2 > c1) {
+            return (1);
+        }
+    }
+
+    return ((len1 == len2) ? 0 : (len1 < len2) ? -1 : 1);
+}
+
 namespace generic {
 Generic::Generic(InputBuffer& buffer, size_t rdata_len) :
     data_(rdata_len)
@@ -145,21 +165,7 @@
 {
     const NS& other_ns = dynamic_cast<const NS&>(other);
 
-    size_t len_this = nsname_.getLength();
-    size_t len_other = other_ns.nsname_.getLength();
-    size_t len = (len_this < len_other) ? len_this : len_other;
-
-    for (size_t i = 0; i < len; i++) {
-        uint8_t c_this = tolower(nsname_.at(i));
-        uint8_t c_other = tolower(other_ns.nsname_.at(i));
-        if (c_this < c_other) {
-            return (-1);
-        } else if (c_this > c_other) {
-            return (1);
-        }
-    }
-
-    return ((len_this == len_other) ? 0 : (len_this < len_other) ? -1 : 1);
+    return (compareNames(nsname_, other_ns.nsname_));
 }
 
 } // end of namespace generic

Modified: branches/jinmei-dnsrdata/src/lib/dns/cpp/rdata.h
==============================================================================
--- branches/jinmei-dnsrdata/src/lib/dns/cpp/rdata.h (original)
+++ branches/jinmei-dnsrdata/src/lib/dns/cpp/rdata.h Thu Jan 21 19:28:32 2010
@@ -107,12 +107,6 @@
     //virtual Rdata* copy() const = 0;
 };
 
-/// TBD: document them
-RdataPtr createRdataFromText(const RRType& rrtype, const RRClass& rrclass,
-                             const std::string& rdata_string);
-RdataPtr createRdataFromWire(const RRType& rrtype, const RRClass& rrclass,
-                             InputBuffer& buffer, size_t len);
-
 namespace generic {
 class Generic : public Rdata {
 public:
@@ -179,6 +173,46 @@
 private:
 };
 } // end of namespace "ch"
+
+///
+/// Non class-member functions related to Rdata
+///
+/// TBD: document them
+RdataPtr createRdataFromText(const RRType& rrtype, const RRClass& rrclass,
+                             const std::string& rdata_string);
+RdataPtr createRdataFromWire(const RRType& rrtype, const RRClass& rrclass,
+                             InputBuffer& buffer, size_t len);
+
+///
+/// \brief Gives relative ordering of two names in terms of DNSSEC RDATA
+/// ordering.
+///
+/// This method compares two names as defined in Sections 6.2 and 6.3 of
+/// RFC4034: Comparing two names in their canonical form
+/// (i.e., converting upper case ASCII characters to lower ones) and
+/// as a left-justified unsigned octet sequence.  Note that the ordering is
+/// different from that for owner names.  For example, "a.example" should be
+/// sorted before "example" as RDATA, but the ordering is the opposite when
+/// compared as owner names.
+///
+/// Normally, applications would not need this function directly.
+/// This is mostly an internal helper function for \c Rdata related classes
+/// to implement their \c compare() method.
+/// This function is publicly open, however, for the convenience of
+/// external developers who want to implement new or experimental RR types.
+///
+/// Additional note about applicability: In fact, BIND9's similar function,
+/// \c dns_name_rdatacompare(), is only used in rdata implementations and
+/// for testing purposes.
+///
+/// \param n1,n2 \c Name class objects to compare.
+/// \return -1 if \c n1 would be sorted before \c n2.
+/// \return 0 if \c n1 is identical to \c n2 in terms of sorting order.
+/// \return 1 if \c n1 would be sorted after \c n2.
+///
+int
+compareNames(const Name& n1, const Name& n2);
+
 } // end of namespace "rdata"
 }
 }




More information about the bind10-changes mailing list