From: Bert Hubert Date: Sun, 18 Apr 2010 19:18:42 +0000 (+0000) Subject: add more dnssec infra (stuff to make a zone relative, stuff to reverse labels for... X-Git-Tag: rec-3.3~145 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4dadd22f125f5a59b465e38e85bf2c59bd18b4df;p=pdns add more dnssec infra (stuff to make a zone relative, stuff to reverse labels for canonical ordering...) git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1557 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/pdns/misc.cc b/pdns/misc.cc index b7ed4a6fe..bedd5aaa1 100644 --- a/pdns/misc.cc +++ b/pdns/misc.cc @@ -621,3 +621,34 @@ string stripDot(const string& dom) return dom.substr(0,dom.size()-1); } + + +string labelReverse(const std::string& qname) +{ + if(qname.empty()) + return qname; + + vector labels; + stringtok(labels, qname, "."); + if(labels.size()==1) + return qname; + + string ret; + for(vector::const_reverse_iterator iter = labels.rbegin(); iter != labels.rend(); ++iter) { + if(iter != labels.rbegin()) + ret.append(1,'.'); + ret+=*iter; + } + return ret; +} + +// do NOT feed trailing dots! +// www.powerdns.com, powerdns.com -> www +string makeRelative(const std::string& fqdn, const std::string& zone) +{ + if(zone.empty()) + return fqdn; + if(fqdn != zone) + return fqdn.substr(0, fqdn.size() - zone.length() - 1); // strip domain name + return ""; +} diff --git a/pdns/misc.hh b/pdns/misc.hh index 7c4053409..b81c976eb 100644 --- a/pdns/misc.hh +++ b/pdns/misc.hh @@ -380,4 +380,7 @@ inline void setSocketReusable(int fd) string stripDot(const string& dom); void seedRandom(const string& source); +string makeRelative(const std::string& fqdn, const std::string& zone); +string labelReverse(const std::string& qname); + #endif