From: bert hubert Date: Sun, 25 Oct 2015 09:48:09 +0000 (+0100) Subject: add makeUsRelative, and use it to implement makeRelative, plus small speedup reserve() X-Git-Tag: dnsdist-1.0.0-alpha1~252^2~6^2~11 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8ca152245a531f2818001525938053af10e750ee;p=pdns add makeUsRelative, and use it to implement makeRelative, plus small speedup reserve() --- diff --git a/pdns/dnsname.cc b/pdns/dnsname.cc index ffea62f2d..5e6ffe134 100644 --- a/pdns/dnsname.cc +++ b/pdns/dnsname.cc @@ -25,6 +25,7 @@ DNSName::DNSName(const char* p) { d_empty=false; d_recurse=0; + d_storage.reserve(strlen(p)+1); auto labels = segmentDNSName(p); for(const auto& e : labels) appendRawLabel(e); @@ -55,7 +56,7 @@ void DNSName::packetParser(const char* pos, int len, int offset, bool uncompress if(newpos < offset) { if (++d_recurse > 100) throw std::range_error("Abort label decompression after 100 redirects"); - packetParser(opos, len, newpos, true); + packetParser(opos, len, newpos, true); } else throw std::range_error("Found a forward reference during label decompression"); pos++; @@ -121,7 +122,7 @@ bool DNSName::isPartOf(const DNSName& parent) const if (std::distance(us,d_storage.cend()) == static_cast(parent.d_storage.size())) { auto p = parent.d_storage.cbegin(); for(; us != d_storage.cend(); ++us, ++p) { - if(tolower(*p) != tolower(*us)) + if(dns2_tolower(*p) != dns2_tolower(*us)) return false; } return true; @@ -133,12 +134,17 @@ bool DNSName::isPartOf(const DNSName& parent) const DNSName DNSName::makeRelative(const DNSName& zone) const { DNSName ret(*this); - if (ret.isPartOf(zone)) { - ret.d_storage.erase(ret.d_storage.size()-zone.d_storage.size()); - } else - ret.clear(); + ret.makeUsRelative(zone); return ret; } +void DNSName::makeUsRelative(const DNSName& zone) +{ + if (isPartOf(zone)) { + d_storage.erase(d_storage.size()-zone.d_storage.size()); + } + else + clear(); +} DNSName DNSName::labelReverse() const { diff --git a/pdns/dnsname.hh b/pdns/dnsname.hh index b0a571975..889b719c1 100644 --- a/pdns/dnsname.hh +++ b/pdns/dnsname.hh @@ -9,7 +9,7 @@ // #include "dns.hh" // #include "logger.hh" -// #include +//#include /* Quest in life: accept escaped ascii presentations of DNS names and store them "natively" @@ -44,6 +44,7 @@ public: std::vector getRawLabels() const; //!< Individual raw unescaped labels bool chopOff(); //!< Turn www.powerdns.com. into powerdns.com., returns false for . DNSName makeRelative(const DNSName& zone) const; + void makeUsRelative(const DNSName& zone); DNSName labelReverse() const; bool isWildcard() const; unsigned int countLabels() const; @@ -81,7 +82,7 @@ public: inline bool canonCompare(const DNSName& rhs) const; private: - // typedef __gnu_cxx::__sso_string string_t; + //typedef __gnu_cxx::__sso_string string_t; typedef std::string string_t; bool slowCanonCompare(const DNSName& rhs) const; string_t d_storage;