From: Bert Hubert Date: Wed, 25 Jun 2008 20:03:14 +0000 (+0000) Subject: commit backwards strrcasecmp by Aki Tuomi, fixing a bug in our own version. Plus... X-Git-Tag: rec-3.2~295 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=66d21e075d7ca38cc2a05154b0db211f6cb81e38;p=thirdparty%2Fpdns.git commit backwards strrcasecmp by Aki Tuomi, fixing a bug in our own version. Plus make the random backend case insensitive! git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1227 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/pdns/packetcache.hh b/pdns/packetcache.hh index 7ba0b20e3c..8e1bc549d5 100644 --- a/pdns/packetcache.hh +++ b/pdns/packetcache.hh @@ -51,25 +51,18 @@ using namespace boost; struct CIBackwardsStringCompare: public binary_function { - bool operator()(const string& a, const string& b) const + bool operator()(const string& str_a, const string& str_b) const { - const unsigned char *p1 = (const unsigned char *) a.c_str() + a.length(); - const unsigned char *p2 = (const unsigned char *) b.c_str() + b.length(); - int result; + string::const_reverse_iterator ra, rb; + char a=0, b=0; + for(ra = str_a.rbegin(), rb = str_b.rbegin(); + ra < str_a.rend() && rb < str_b.rend() && (a=dns_tolower(*ra)) == (b=dns_tolower(*rb)); + ra++, rb++); - if (p1 == p2) { - return 0; - } - - while ((result = dns_tolower (*p1--) - dns_tolower (*p2--)) == 0) - if (p1 == (unsigned char*)a.c_str() || p2 == (unsigned char*) b.c_str()) - break; - - if(result==0) { // one of our strings ended, the shortest one is smaller then - return a.length() < b.length(); - } + if (ra < str_a.rend() && rb==str_b.rend()) { a=*(ra++); b=0; } + if (rb < str_b.rend() && ra==str_a.rend()) { b=*(rb++); a=0; } - return result < 0; + return a < b; } }; diff --git a/pdns/randombackend.cc b/pdns/randombackend.cc index 97ce6b76be..0e88e5bb05 100644 --- a/pdns/randombackend.cc +++ b/pdns/randombackend.cc @@ -1,6 +1,6 @@ /* PowerDNS Versatile Database Driven Nameserver - Copyright (C) 2002 PowerDNS.COM BV + Copyright (C) 2002 - 2008 PowerDNS.COM BV This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 @@ -23,6 +23,9 @@ #include "dnspacket.hh" #include "ahuexception.hh" #include "logger.hh" +#include + +using boost::iequals; /* FIRST PART */ class RandomBackend : public DNSBackend @@ -40,7 +43,7 @@ public: void lookup(const QType &type, const string &qdomain, DNSPacket *p, int zoneId) { - if((type.getCode()!=QType::ANY && type.getCode()!=QType::A) || qdomain!=d_ourname) // we only know about random.powerdns.com A + if((type.getCode()!=QType::ANY && type.getCode()!=QType::A) || !iequals(qdomain, d_ourname)) // we only know about random.powerdns.com A d_answer=""; // no answer else { ostringstream os;