NameComparisonResult
Name::compare(const Name& other) const {
- return (partial_compare(other, 0, 0));
+ return (partial_compare(other, 0, 0, labelcount_, other.labelcount_));
}
NameComparisonResult
Name::partial_compare(const Name& other,
unsigned int first_label,
unsigned int first_label_other,
+ unsigned int last_label,
+ unsigned int last_label_other,
bool case_sensitive) const {
// Determine the relative ordering under the DNSSEC order relation of
// 'this' and 'other', and also determine the hierarchical relationship
// of the names.
+ if ((first_label > last_label) ||
+ (first_label_other > last_label_other)) {
+ isc_throw(BadValue, "Bad label index ranges were passed");
+ }
+
if ((first_label > labelcount_) ||
(first_label_other > other.labelcount_)) {
isc_throw(BadValue, "Bad first label indices were passed");
}
unsigned int nlabels = 0;
- int l1 = labelcount_ - first_label;
- int l2 = other.labelcount_ - first_label_other;
+ int l1 = last_label - first_label;
+ int l2 = last_label_other - first_label_other;
int ldiff = (int)l1 - (int)l2;
unsigned int l = (ldiff < 0) ? l1 : l2;
}
if (chdiff != 0) {
- return (NameComparisonResult(chdiff, nlabels,
- NameComparisonResult::COMMONANCESTOR));
+ if ((nlabels == 0) &&
+ ((last_label < labelcount_) ||
+ (last_label_other < other.labelcount_))) {
+ return (NameComparisonResult(chdiff, 0,
+ NameComparisonResult::NONE));
+ } else {
+ return (NameComparisonResult(chdiff, nlabels,
+ NameComparisonResult::COMMONANCESTOR));
+ }
}
--count;
++pos1;
++pos2;
}
if (cdiff != 0) {
+ if ((nlabels == 0) &&
+ ((last_label < labelcount_) ||
+ (last_label_other < other.labelcount_))) {
+ return (NameComparisonResult(cdiff, 0,
+ NameComparisonResult::NONE));
+ } else {
return (NameComparisonResult(cdiff, nlabels,
- NameComparisonResult::COMMONANCESTOR));
+ NameComparisonResult::COMMONANCESTOR));
+ }
}
++nlabels;
}
/// indices are passed.
///
/// \param other the right-hand operand to compare against.
- /// \param first_label the leftmost label of <code>Name</code> to
+ /// \param first_label the left-most label of <code>Name</code> to
/// begin comparing from.
- /// \param first_label_other the leftmost label of
+ /// \param first_label_other the left-most label of
/// <code>other</code> to begin comparing from.
+ /// \param last_label the right-most label of <code>Name</code> to
+ /// end comparing at.
+ /// \param last_label_other the right-most label of
+ /// <code>other</code> to end comparing at.
/// \param case_sensitive If true, comparison is case-insensitive
/// \return a <code>NameComparisonResult</code> object representing the
/// comparison result.
NameComparisonResult partial_compare(const Name& other,
unsigned int first_label,
unsigned int first_label_other,
+ unsigned int last_label,
+ unsigned int last_label_other,
bool case_sensitive = false) const;
public: