// are WE part of parent
bool DNSName::isPartOf(const DNSName& parent) const
{
- if(parent.d_storage.size() > d_storage.size())
+ if(parent.d_storage.empty())
+ return true;
+ if(parent.d_storage.size() > d_storage.size())
return false;
// this is slightly complicated since we can't start from the end, since we can't see where a label begins/ends then
for(auto us=d_storage.cbegin(); us<d_storage.cend() && d_storage.cend()-us >= (unsigned int)parent.d_storage.size(); us+=*us+1) {
if (d_storage.cend()-us == (unsigned int)parent.d_storage.size()) {
auto p = parent.d_storage.cbegin();
- for(; us != d_storage.cend() && p != parent.d_storage.cend(); ++us, ++p) {
+ for(; us != d_storage.cend(); ++us, ++p) {
if(tolower(*p) != tolower(*us))
- break;
+ return false;
}
- return (p==parent.d_storage.end());
+ return true;
}
}
return false;
BOOST_CHECK(DNSName("www.ds9a.nl.").toString() == "www.ds9a.nl.");
+
+ { // Check root part of root
+ DNSName name;
+ DNSName parent;
+ BOOST_CHECK(name.isPartOf(parent));
+ }
+
+ { // Check name part of root
+ DNSName name("a.");
+ DNSName parent;
+ BOOST_CHECK(name.isPartOf(parent));
+ }
+
+ { // Label boundary
+ DNSName name("a\002bb.");
+ DNSName parent("bb.");
+ BOOST_CHECK(!name.isPartOf(parent));
+ }
+
+ { // Multi label parent
+ DNSName name("a.bb.ccc.dddd.");
+ DNSName parent("ccc.dddd.");
+ BOOST_CHECK(name.isPartOf(parent));
+ }
+
+ { // Last char diff
+ DNSName name("a.bb.ccc.dddd.");
+ DNSName parent("ccc.dddx.");
+ BOOST_CHECK(!name.isPartOf(parent));
+ }
+
+ { // Equal length identical
+ DNSName name("aaaa.bbb.cc.d.");
+ DNSName parent("aaaa.bbb.cc.d.");
+ BOOST_CHECK(name.isPartOf(parent));
+ }
+
+ { // Equal length first char diff
+ DNSName name("xaaa.bbb.cc.d.");
+ DNSName parent("aaaa.bbb.cc.d.");
+ BOOST_CHECK(!name.isPartOf(parent));
+ }
+
+
DNSName left("ds9a.nl.");
left.prependRawLabel("www");
BOOST_CHECK( left == DNSName("WwW.Ds9A.Nl."));