~ubuntu-branches/ubuntu/maverick/pdns/maverick-updates

« back to all changes in this revision

Viewing changes to pdns/misc.cc

  • Committer: Bazaar Package Importer
  • Author(s): Debian PowerDNS Maintainers
  • Date: 2006-05-06 10:40:44 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060506104044-v9hczzfl7dcri6qt
Tags: 2.9.20-3
Disable the recursor, this is in a separate package now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
106
106
  return true;
107
107
}
108
108
 
 
109
bool ciEqual(const string& a, const string& b)
 
110
{
 
111
  if(a.size()!=b.size())
 
112
    return false;
 
113
 
 
114
  string::size_type pos=0, epos=a.size();
 
115
  for(;pos < epos; ++pos)
 
116
    if(dns_tolower(a[pos])!=dns_tolower(b[pos]))
 
117
      return false;
 
118
  return true;
 
119
}
 
120
 
109
121
/** does domain end on suffix? Is smart about "wwwds9a.nl" "ds9a.nl" not matching */
110
122
bool endsOn(const string &domain, const string &suffix) 
111
123
{
112
 
  if(toLower(domain)==toLower(suffix) || suffix.empty())
 
124
  if( suffix.empty() || ciEqual(domain, suffix) )
113
125
    return true;
114
126
  if(domain.size()<=suffix.size())
115
127
    return false;
116
 
  return (toLower(domain.substr(domain.size()-suffix.size()-1,suffix.size()+1))=="."+toLower(suffix));
 
128
  
 
129
  string::size_type dpos=domain.size()-suffix.size()-1, spos=0;
 
130
  if(domain[dpos++]!='.')
 
131
    return false;
 
132
 
 
133
  for(; dpos < domain.size(); ++dpos, ++spos)
 
134
    if(dns_tolower(domain[dpos]) != dns_tolower(suffix[spos]))
 
135
      return false;
 
136
 
 
137
  return true;
117
138
}
118
139
 
119
 
 
120
140
int sendData(const char *buffer, int replen, int outsock)
121
141
{
122
142
  uint16_t nlen=htons(replen);
136
156
  return 0;
137
157
}
138
158
 
139
 
 
140
159
void parseService(const string &descr, ServiceTuple &st)
141
160
{
142
161
 
331
350
}
332
351
 
333
352
 
 
353
 
 
354
// shuffle, maintaining some semblance of order
 
355
void shuffle(vector<DNSResourceRecord>& rrs)
 
356
{
 
357
  vector<DNSResourceRecord>::iterator first, second;
 
358
  for(first=rrs.begin();first!=rrs.end();++first) 
 
359
    if(first->d_place==DNSResourceRecord::ANSWER && first->qtype.getCode() != QType::CNAME) // CNAME must come first
 
360
      break;
 
361
  for(second=first;second!=rrs.end();++second)
 
362
    if(second->d_place!=DNSResourceRecord::ANSWER)
 
363
      break;
 
364
  
 
365
  if(second-first>1)
 
366
    random_shuffle(first,second);
 
367
  
 
368
  // now shuffle the additional records
 
369
  for(first=second;first!=rrs.end();++first) 
 
370
    if(first->d_place==DNSResourceRecord::ADDITIONAL && first->qtype.getCode() != QType::CNAME) // CNAME must come first
 
371
      break;
 
372
  for(second=first;second!=rrs.end();++second)
 
373
    if(second->d_place!=DNSResourceRecord::ADDITIONAL)
 
374
      break;
 
375
  
 
376
  if(second-first>1)
 
377
    random_shuffle(first,second);
 
378
 
 
379
  // we don't shuffle the rest
 
380
}