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 unsigned len_next_domain = parser.ReadName(data.data(), NULL); |
| 231 |
| 232 if (len_next_domain == 0 || data.length() < len_next_domain + 2) |
| 233 return scoped_ptr<NsecRecordRdata>(); |
| 234 |
| 235 unsigned window_num = data[len_next_domain]; |
| 236 unsigned len = data[len_next_domain+1]; |
| 237 |
| 238 // The window number must be zero in mDns-secific nsec records. The bitmap |
| 239 // length must be between 1 and 32, and since we may only have one window, the |
| 240 // data length must be exactl equal to the domain length plus bitmap size. |
| 241 if (window_num != 0 || len == 0 || len > 32 || |
| 242 data.length() != len_next_domain + 2 + len) |
| 243 return scoped_ptr<NsecRecordRdata>(); |
| 244 |
| 245 base::StringPiece bitmap_data = data.substr(len_next_domain + 2); |
| 246 |
| 247 rdata->bitmap_.insert(rdata->bitmap_.begin(), |
| 248 bitmap_data.begin(), |
| 249 bitmap_data.end()); |
| 250 |
| 251 return rdata.Pass(); |
| 252 } |
| 253 |
| 254 uint16 NsecRecordRdata::Type() const { |
| 255 return NsecRecordRdata::kType; |
| 256 } |
| 257 |
| 258 bool NsecRecordRdata::IsEqual(const RecordRdata* other) const { |
| 259 if (other->Type() != Type()) |
| 260 return false; |
| 261 const NsecRecordRdata* nsec_other = |
| 262 static_cast<const NsecRecordRdata*>(other); |
| 263 return bitmap_ == nsec_other->bitmap_; |
| 264 } |
| 265 |
| 266 bool NsecRecordRdata::GetBit(unsigned i) { |
| 267 unsigned byte_num = i/8; |
| 268 if (bitmap_.size() < byte_num + 1) |
| 269 return false; |
| 270 |
| 271 unsigned bit_num = 7 - i % 8; |
| 272 return (bitmap_[byte_num] & (1 << bit_num)) != 0; |
| 273 } |
| 274 |
218 } // namespace net | 275 } // namespace net |
OLD | NEW |