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;
}
};
/*
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
#include "dnspacket.hh"
#include "ahuexception.hh"
#include "logger.hh"
+#include <boost/algorithm/string.hpp>
+
+using boost::iequals;
/* FIRST PART */
class RandomBackend : public DNSBackend
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;