]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
commit backwards strrcasecmp by Aki Tuomi, fixing a bug in our own version. Plus...
authorBert Hubert <bert.hubert@netherlabs.nl>
Wed, 25 Jun 2008 20:03:14 +0000 (20:03 +0000)
committerBert Hubert <bert.hubert@netherlabs.nl>
Wed, 25 Jun 2008 20:03:14 +0000 (20:03 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@1227 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/packetcache.hh
pdns/randombackend.cc

index 7ba0b20e3c0e77ac26daaa5148276bd70e0fdf51..8e1bc549d5e91b4378abd68aa0e1f175e3a5feb0 100644 (file)
@@ -51,25 +51,18 @@ using namespace boost;
 
 struct CIBackwardsStringCompare: public binary_function<string, string, bool>  
 {
-  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;
   }
 };
 
index 97ce6b76bec1d7402a9dd7488014bd4be3eaaa97..0e88e5bb05cda3e8569928a2000545641d4c0143 100644 (file)
@@ -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 <boost/algorithm/string.hpp>
+
+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;