Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Side by Side Diff: net/dns/record_rdata.cc

Issue 17143006: Limited NSEC support to RecordParsed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@mdns_transaction_cleanup
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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);
szym 2013/06/24 21:50:28 nit: |next_domain_len| would be better, |next_doma
Noam Samuel 2013/06/25 01:31:31 Done.
231
232 if (len_next_domain == 0 || data.length() < len_next_domain + 2)
233 return scoped_ptr<NsecRecordRdata>();
234
szym 2013/06/24 21:50:28 StringPiece::operator[] returns char, so I'd sugge
Noam Samuel 2013/06/25 01:31:31 Done.
235 unsigned window_num = data[len_next_domain];
szym 2013/06/24 21:50:28 I suggest block_num or block_number "window number
Noam Samuel 2013/06/25 01:31:31 Done.
236 unsigned len = data[len_next_domain+1];
szym 2013/06/24 21:50:28 bitmap_length
Noam Samuel 2013/06/25 01:31:31 Done.
237
238 // The window number must be zero in mDns-secific nsec records. The bitmap
szym 2013/06/24 21:50:28 "specific" "NSEC"
Noam Samuel 2013/06/25 01:31:31 Done.
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.
szym 2013/06/24 21:50:28 "exactly"
Noam Samuel 2013/06/25 01:31:31 Done.
241 if (window_num != 0 || len == 0 || len > 32 ||
242 data.length() != len_next_domain + 2 + len)
szym 2013/06/24 21:50:28 The last check would be easier to understand if yo
Noam Samuel 2013/06/25 01:31:31 Done.
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(),
gene 2013/06/24 19:47:16 indentation
Noam Samuel 2013/06/24 21:31:30 Done.
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()) return false;
gene 2013/06/24 19:47:16 move return to the next line
Noam Samuel 2013/06/24 21:31:30 Done.
260 const NsecRecordRdata* nsec_other =
261 static_cast<const NsecRecordRdata*>(other);
262 return bitmap_ == nsec_other->bitmap_;
263 }
264
265 bool NsecRecordRdata::bit(unsigned i) {
266 unsigned byte_num = i/8;
267 if (bitmap_.size() < byte_num + 1)
268 return false;
269
270 unsigned bit_num = 7 - i % 8;
271 return (bitmap_[byte_num] & (1 << bit_num)) != 0;
272 }
273
218 } // namespace net 274 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698