From: Thiago Farina Date: Wed, 29 Mar 2017 01:12:43 +0000 (-0300) Subject: pdns: remove duplicated dns2_tolower() function X-Git-Tag: rec-4.1.0-alpha1~168^2~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2b62292dbcee416c60978662c82d1803aeaeeccd;p=pdns pdns: remove duplicated dns2_tolower() function There is already a version of dns2_tolower() in misc.hh, called simply dns_tolower(), but due to some inclusion issues it was necessary to extract it into another header file (named ascii.hh). --- diff --git a/pdns/ascii.hh b/pdns/ascii.hh new file mode 100644 index 000000000..69b1a3935 --- /dev/null +++ b/pdns/ascii.hh @@ -0,0 +1,29 @@ +/* + * This file is part of PowerDNS or dnsdist. + * Copyright -- PowerDNS.COM B.V. and its contributors + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * In addition, for the avoidance of any doubt, permission is granted to + * link this program with OpenSSL and to (re)distribute the binaries + * produced as the result of such linking. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ +#pragma once + +inline unsigned char dns_tolower(unsigned char c) +{ + if(c>='A' && c<='Z') + c+='a'-'A'; + return c; +} diff --git a/pdns/dnsdistdist/ascii.hh b/pdns/dnsdistdist/ascii.hh new file mode 120000 index 000000000..6d5e3ebf9 --- /dev/null +++ b/pdns/dnsdistdist/ascii.hh @@ -0,0 +1 @@ +../ascii.hh \ No newline at end of file diff --git a/pdns/dnsname.cc b/pdns/dnsname.cc index 3f98d8487..6f5eab5c7 100644 --- a/pdns/dnsname.cc +++ b/pdns/dnsname.cc @@ -225,7 +225,7 @@ bool DNSName::isPartOf(const DNSName& parent) const if (static_cast(distance) == parent.d_storage.size()) { auto p = parent.d_storage.cbegin(); for(; us != d_storage.cend(); ++us, ++p) { - if(dns2_tolower(*p) != dns2_tolower(*us)) + if(dns_tolower(*p) != dns_tolower(*us)) return false; } return true; diff --git a/pdns/dnsname.hh b/pdns/dnsname.hh index eba45665c..9dd388a5b 100644 --- a/pdns/dnsname.hh +++ b/pdns/dnsname.hh @@ -34,6 +34,8 @@ #include #endif +#include "ascii.hh" + uint32_t burtleCI(const unsigned char* k, uint32_t length, uint32_t init); // #include "dns.hh" @@ -53,13 +55,6 @@ uint32_t burtleCI(const unsigned char* k, uint32_t length, uint32_t init); NOTE: For now, everything MUST be . terminated, otherwise it is an error */ -inline unsigned char dns2_tolower(unsigned char c) -{ - if(c>='A' && c<='Z') - return c+('a'-'A'); - return c; -} - class DNSName { public: @@ -90,7 +85,7 @@ public: DNSName ret; ret.d_storage = d_storage; for(auto & c : ret.d_storage) { - c=dns2_tolower(c); + c=dns_tolower(c); } return ret; } @@ -128,7 +123,7 @@ public: return std::lexicographical_compare(d_storage.rbegin(), d_storage.rend(), rhs.d_storage.rbegin(), rhs.d_storage.rend(), [](const unsigned char& a, const unsigned char& b) { - return dns2_tolower(a) < dns2_tolower(b); + return dns_tolower(a) < dns_tolower(b); }); // note that this is case insensitive, including on the label lengths } @@ -192,7 +187,7 @@ inline bool DNSName::canonCompare(const DNSName& rhs) const rhs.d_storage.c_str() + rhspos[rhscount] + 1, rhs.d_storage.c_str() + rhspos[rhscount] + 1 + *(rhs.d_storage.c_str() + rhspos[rhscount]), [](const unsigned char& a, const unsigned char& b) { - return dns2_tolower(a) < dns2_tolower(b); + return dns_tolower(a) < dns_tolower(b); }); // cout<<"Forward: "<='A' && c<='Z') - c+='a'-'A'; - return c; -} - inline unsigned char dns_toupper(unsigned char c) { if(c>='a' && c<='z') diff --git a/pdns/recursordist/ascii.hh b/pdns/recursordist/ascii.hh new file mode 120000 index 000000000..6d5e3ebf9 --- /dev/null +++ b/pdns/recursordist/ascii.hh @@ -0,0 +1 @@ +../ascii.hh \ No newline at end of file