Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/dns/record_rdata.h" | 5 #include "net/dns/record_rdata.h" |
| 6 | 6 |
| 7 #include "net/base/big_endian.h" | 7 #include "net/base/big_endian.h" |
| 8 #include "net/base/dns_util.h" | 8 #include "net/base/dns_util.h" |
| 9 #include "net/dns/dns_protocol.h" | 9 #include "net/dns/dns_protocol.h" |
| 10 #include "net/dns/dns_response.h" | 10 #include "net/dns/dns_response.h" |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 uint16 TxtRecordRdata::Type() const { | 208 uint16 TxtRecordRdata::Type() const { |
| 209 return TxtRecordRdata::kType; | 209 return TxtRecordRdata::kType; |
| 210 } | 210 } |
| 211 | 211 |
| 212 bool TxtRecordRdata::IsEqual(const RecordRdata* other) const { | 212 bool TxtRecordRdata::IsEqual(const RecordRdata* other) const { |
| 213 if (other->Type() != Type()) return false; | 213 if (other->Type() != Type()) return false; |
| 214 const TxtRecordRdata* txt_other = static_cast<const TxtRecordRdata*>(other); | 214 const TxtRecordRdata* txt_other = static_cast<const TxtRecordRdata*>(other); |
| 215 return texts_ == txt_other->texts_; | 215 return texts_ == txt_other->texts_; |
| 216 } | 216 } |
| 217 | 217 |
| 218 NsecRecordRdata::NsecRecordRdata() { | |
| 219 } | |
| 220 | |
| 221 NsecRecordRdata::~NsecRecordRdata() { | |
| 222 } | |
| 223 | |
| 224 // static | |
| 225 scoped_ptr<NsecRecordRdata> NsecRecordRdata::Create( | |
| 226 const base::StringPiece& data, | |
| 227 const DnsRecordParser& parser) { | |
| 228 scoped_ptr<NsecRecordRdata> rdata(new NsecRecordRdata); | |
| 229 | |
| 230 // Read the "next domain". This part for the NSEC record format is | |
| 231 // ignored for mDNS, since it has no semantic meaning. | |
| 232 unsigned next_domain_length = parser.ReadName(data.data(), NULL); | |
| 233 | |
| 234 // If we did not succeed in getting the next domain or the data length | |
| 235 // is too short for reading the bitmap header, return. | |
| 236 if (next_domain_length == 0 || data.length() < next_domain_length + 2) | |
| 237 return scoped_ptr<NsecRecordRdata>(); | |
| 238 | |
| 239 struct BitmapHeader { | |
| 240 uint8 block_number; // The block number should be zero. | |
| 241 uint8 length; // Bitmap length in bytes. Between 1 and 32. | |
| 242 }; | |
| 243 | |
| 244 const BitmapHeader* header = reinterpret_cast<const BitmapHeader*>( | |
| 245 data.data() + next_domain_length); | |
| 246 | |
| 247 // The window number must be zero in mDns-specific NSEC records. The bitmap | |
|
szym
2013/06/25 01:40:57
"block number"
Noam Samuel
2013/06/25 01:58:41
Done.
| |
| 248 // length must be between 1 and 32. | |
| 249 if (header->block_number != 0 || header->length == 0 || header->length > 32) | |
| 250 return scoped_ptr<NsecRecordRdata>(); | |
| 251 | |
| 252 base::StringPiece bitmap_data = data.substr(next_domain_length + 2); | |
| 253 | |
| 254 // Since we may only have one window, the data length must be exactly equal to | |
| 255 // the domain length plus bitmap size. | |
| 256 if (bitmap_data.length() != header->length) | |
| 257 return scoped_ptr<NsecRecordRdata>(); | |
| 258 | |
| 259 rdata->bitmap_.insert(rdata->bitmap_.begin(), | |
| 260 bitmap_data.begin(), | |
| 261 bitmap_data.end()); | |
| 262 | |
| 263 return rdata.Pass(); | |
| 264 } | |
| 265 | |
| 266 uint16 NsecRecordRdata::Type() const { | |
| 267 return NsecRecordRdata::kType; | |
| 268 } | |
| 269 | |
| 270 bool NsecRecordRdata::IsEqual(const RecordRdata* other) const { | |
| 271 if (other->Type() != Type()) | |
| 272 return false; | |
| 273 const NsecRecordRdata* nsec_other = | |
| 274 static_cast<const NsecRecordRdata*>(other); | |
| 275 return bitmap_ == nsec_other->bitmap_; | |
| 276 } | |
| 277 | |
| 278 bool NsecRecordRdata::GetBit(unsigned i) { | |
| 279 unsigned byte_num = i/8; | |
| 280 if (bitmap_.size() < byte_num + 1) | |
| 281 return false; | |
| 282 | |
| 283 unsigned bit_num = 7 - i % 8; | |
| 284 return (bitmap_[byte_num] & (1 << bit_num)) != 0; | |
| 285 } | |
| 286 | |
| 218 } // namespace net | 287 } // namespace net |
| OLD | NEW |