From: Pieter Lexis Date: Fri, 31 Mar 2017 12:55:20 +0000 (+0200) Subject: DNSName: add getLastLabel() function X-Git-Tag: rec-4.1.0-alpha1~166^2~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=41e015928a0446979cd1da49eb4a26da4a694f12;p=pdns DNSName: add getLastLabel() function --- diff --git a/pdns/dnsname.cc b/pdns/dnsname.cc index 3f98d8487..ac93e2d51 100644 --- a/pdns/dnsname.cc +++ b/pdns/dnsname.cc @@ -340,6 +340,13 @@ std::string DNSName::getRawLabel(unsigned int pos) const throw std::out_of_range("trying to get label at position "+std::to_string(pos)+" of a DNSName that only has "+std::to_string(currentPos)+" labels"); } +DNSName DNSName::getLastLabel() const +{ + DNSName ret(*this); + ret.trimToLabels(1); + return ret; +} + bool DNSName::chopOff() { if(d_storage.empty() || d_storage[0]==0) diff --git a/pdns/dnsname.hh b/pdns/dnsname.hh index eba45665c..4caf7438f 100644 --- a/pdns/dnsname.hh +++ b/pdns/dnsname.hh @@ -83,6 +83,7 @@ public: void prependRawLabel(const std::string& str); //!< Prepend this unescaped label std::vector getRawLabels() const; //!< Individual raw unescaped labels std::string getRawLabel(unsigned int pos) const; //!< Get the specified raw unescaped label + DNSName getLastLabel() const; //!< Get the DNSName of the last label bool chopOff(); //!< Turn www.powerdns.com. into powerdns.com., returns false for . DNSName makeRelative(const DNSName& zone) const; DNSName makeLowerCase() const