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 "base/big_endian.h" | 7 #include "base/big_endian.h" |
8 #include "net/base/ip_address_number.h" | 8 #include "net/base/ip_address_number.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 21 matching lines...) Expand all Loading... |
32 base::BigEndianReader reader(data.data(), data.size()); | 32 base::BigEndianReader reader(data.data(), data.size()); |
33 // 2 bytes for priority, 2 bytes for weight, 2 bytes for port. | 33 // 2 bytes for priority, 2 bytes for weight, 2 bytes for port. |
34 reader.ReadU16(&rdata->priority_); | 34 reader.ReadU16(&rdata->priority_); |
35 reader.ReadU16(&rdata->weight_); | 35 reader.ReadU16(&rdata->weight_); |
36 reader.ReadU16(&rdata->port_); | 36 reader.ReadU16(&rdata->port_); |
37 | 37 |
38 if (!parser.ReadName(data.substr(kSrvRecordMinimumSize).begin(), | 38 if (!parser.ReadName(data.substr(kSrvRecordMinimumSize).begin(), |
39 &rdata->target_)) | 39 &rdata->target_)) |
40 return scoped_ptr<SrvRecordRdata>(); | 40 return scoped_ptr<SrvRecordRdata>(); |
41 | 41 |
42 return rdata.Pass(); | 42 return rdata; |
43 } | 43 } |
44 | 44 |
45 uint16_t SrvRecordRdata::Type() const { | 45 uint16_t SrvRecordRdata::Type() const { |
46 return SrvRecordRdata::kType; | 46 return SrvRecordRdata::kType; |
47 } | 47 } |
48 | 48 |
49 bool SrvRecordRdata::IsEqual(const RecordRdata* other) const { | 49 bool SrvRecordRdata::IsEqual(const RecordRdata* other) const { |
50 if (other->Type() != Type()) return false; | 50 if (other->Type() != Type()) return false; |
51 const SrvRecordRdata* srv_other = static_cast<const SrvRecordRdata*>(other); | 51 const SrvRecordRdata* srv_other = static_cast<const SrvRecordRdata*>(other); |
52 return weight_ == srv_other->weight_ && | 52 return weight_ == srv_other->weight_ && |
(...skipping 15 matching lines...) Expand all Loading... |
68 if (data.size() != kIPv4AddressSize) | 68 if (data.size() != kIPv4AddressSize) |
69 return scoped_ptr<ARecordRdata>(); | 69 return scoped_ptr<ARecordRdata>(); |
70 | 70 |
71 scoped_ptr<ARecordRdata> rdata(new ARecordRdata); | 71 scoped_ptr<ARecordRdata> rdata(new ARecordRdata); |
72 | 72 |
73 rdata->address_.resize(kIPv4AddressSize); | 73 rdata->address_.resize(kIPv4AddressSize); |
74 for (unsigned i = 0; i < kIPv4AddressSize; ++i) { | 74 for (unsigned i = 0; i < kIPv4AddressSize; ++i) { |
75 rdata->address_[i] = data[i]; | 75 rdata->address_[i] = data[i]; |
76 } | 76 } |
77 | 77 |
78 return rdata.Pass(); | 78 return rdata; |
79 } | 79 } |
80 | 80 |
81 uint16_t ARecordRdata::Type() const { | 81 uint16_t ARecordRdata::Type() const { |
82 return ARecordRdata::kType; | 82 return ARecordRdata::kType; |
83 } | 83 } |
84 | 84 |
85 bool ARecordRdata::IsEqual(const RecordRdata* other) const { | 85 bool ARecordRdata::IsEqual(const RecordRdata* other) const { |
86 if (other->Type() != Type()) return false; | 86 if (other->Type() != Type()) return false; |
87 const ARecordRdata* a_other = static_cast<const ARecordRdata*>(other); | 87 const ARecordRdata* a_other = static_cast<const ARecordRdata*>(other); |
88 return address_ == a_other->address_; | 88 return address_ == a_other->address_; |
(...skipping 12 matching lines...) Expand all Loading... |
101 if (data.size() != kIPv6AddressSize) | 101 if (data.size() != kIPv6AddressSize) |
102 return scoped_ptr<AAAARecordRdata>(); | 102 return scoped_ptr<AAAARecordRdata>(); |
103 | 103 |
104 scoped_ptr<AAAARecordRdata> rdata(new AAAARecordRdata); | 104 scoped_ptr<AAAARecordRdata> rdata(new AAAARecordRdata); |
105 | 105 |
106 rdata->address_.resize(kIPv6AddressSize); | 106 rdata->address_.resize(kIPv6AddressSize); |
107 for (unsigned i = 0; i < kIPv6AddressSize; ++i) { | 107 for (unsigned i = 0; i < kIPv6AddressSize; ++i) { |
108 rdata->address_[i] = data[i]; | 108 rdata->address_[i] = data[i]; |
109 } | 109 } |
110 | 110 |
111 return rdata.Pass(); | 111 return rdata; |
112 } | 112 } |
113 | 113 |
114 uint16_t AAAARecordRdata::Type() const { | 114 uint16_t AAAARecordRdata::Type() const { |
115 return AAAARecordRdata::kType; | 115 return AAAARecordRdata::kType; |
116 } | 116 } |
117 | 117 |
118 bool AAAARecordRdata::IsEqual(const RecordRdata* other) const { | 118 bool AAAARecordRdata::IsEqual(const RecordRdata* other) const { |
119 if (other->Type() != Type()) return false; | 119 if (other->Type() != Type()) return false; |
120 const AAAARecordRdata* a_other = static_cast<const AAAARecordRdata*>(other); | 120 const AAAARecordRdata* a_other = static_cast<const AAAARecordRdata*>(other); |
121 return address_ == a_other->address_; | 121 return address_ == a_other->address_; |
122 } | 122 } |
123 | 123 |
124 CnameRecordRdata::CnameRecordRdata() { | 124 CnameRecordRdata::CnameRecordRdata() { |
125 } | 125 } |
126 | 126 |
127 CnameRecordRdata::~CnameRecordRdata() { | 127 CnameRecordRdata::~CnameRecordRdata() { |
128 } | 128 } |
129 | 129 |
130 // static | 130 // static |
131 scoped_ptr<CnameRecordRdata> CnameRecordRdata::Create( | 131 scoped_ptr<CnameRecordRdata> CnameRecordRdata::Create( |
132 const base::StringPiece& data, | 132 const base::StringPiece& data, |
133 const DnsRecordParser& parser) { | 133 const DnsRecordParser& parser) { |
134 scoped_ptr<CnameRecordRdata> rdata(new CnameRecordRdata); | 134 scoped_ptr<CnameRecordRdata> rdata(new CnameRecordRdata); |
135 | 135 |
136 if (!parser.ReadName(data.begin(), &rdata->cname_)) | 136 if (!parser.ReadName(data.begin(), &rdata->cname_)) |
137 return scoped_ptr<CnameRecordRdata>(); | 137 return scoped_ptr<CnameRecordRdata>(); |
138 | 138 |
139 return rdata.Pass(); | 139 return rdata; |
140 } | 140 } |
141 | 141 |
142 uint16_t CnameRecordRdata::Type() const { | 142 uint16_t CnameRecordRdata::Type() const { |
143 return CnameRecordRdata::kType; | 143 return CnameRecordRdata::kType; |
144 } | 144 } |
145 | 145 |
146 bool CnameRecordRdata::IsEqual(const RecordRdata* other) const { | 146 bool CnameRecordRdata::IsEqual(const RecordRdata* other) const { |
147 if (other->Type() != Type()) return false; | 147 if (other->Type() != Type()) return false; |
148 const CnameRecordRdata* cname_other = | 148 const CnameRecordRdata* cname_other = |
149 static_cast<const CnameRecordRdata*>(other); | 149 static_cast<const CnameRecordRdata*>(other); |
150 return cname_ == cname_other->cname_; | 150 return cname_ == cname_other->cname_; |
151 } | 151 } |
152 | 152 |
153 PtrRecordRdata::PtrRecordRdata() { | 153 PtrRecordRdata::PtrRecordRdata() { |
154 } | 154 } |
155 | 155 |
156 PtrRecordRdata::~PtrRecordRdata() { | 156 PtrRecordRdata::~PtrRecordRdata() { |
157 } | 157 } |
158 | 158 |
159 // static | 159 // static |
160 scoped_ptr<PtrRecordRdata> PtrRecordRdata::Create( | 160 scoped_ptr<PtrRecordRdata> PtrRecordRdata::Create( |
161 const base::StringPiece& data, | 161 const base::StringPiece& data, |
162 const DnsRecordParser& parser) { | 162 const DnsRecordParser& parser) { |
163 scoped_ptr<PtrRecordRdata> rdata(new PtrRecordRdata); | 163 scoped_ptr<PtrRecordRdata> rdata(new PtrRecordRdata); |
164 | 164 |
165 if (!parser.ReadName(data.begin(), &rdata->ptrdomain_)) | 165 if (!parser.ReadName(data.begin(), &rdata->ptrdomain_)) |
166 return scoped_ptr<PtrRecordRdata>(); | 166 return scoped_ptr<PtrRecordRdata>(); |
167 | 167 |
168 return rdata.Pass(); | 168 return rdata; |
169 } | 169 } |
170 | 170 |
171 uint16_t PtrRecordRdata::Type() const { | 171 uint16_t PtrRecordRdata::Type() const { |
172 return PtrRecordRdata::kType; | 172 return PtrRecordRdata::kType; |
173 } | 173 } |
174 | 174 |
175 bool PtrRecordRdata::IsEqual(const RecordRdata* other) const { | 175 bool PtrRecordRdata::IsEqual(const RecordRdata* other) const { |
176 if (other->Type() != Type()) return false; | 176 if (other->Type() != Type()) return false; |
177 const PtrRecordRdata* ptr_other = static_cast<const PtrRecordRdata*>(other); | 177 const PtrRecordRdata* ptr_other = static_cast<const PtrRecordRdata*>(other); |
178 return ptrdomain_ == ptr_other->ptrdomain_; | 178 return ptrdomain_ == ptr_other->ptrdomain_; |
(...skipping 16 matching lines...) Expand all Loading... |
195 | 195 |
196 if (i + length >= data.size()) | 196 if (i + length >= data.size()) |
197 return scoped_ptr<TxtRecordRdata>(); | 197 return scoped_ptr<TxtRecordRdata>(); |
198 | 198 |
199 rdata->texts_.push_back(data.substr(i + 1, length).as_string()); | 199 rdata->texts_.push_back(data.substr(i + 1, length).as_string()); |
200 | 200 |
201 // Move to the next string. | 201 // Move to the next string. |
202 i += length + 1; | 202 i += length + 1; |
203 } | 203 } |
204 | 204 |
205 return rdata.Pass(); | 205 return rdata; |
206 } | 206 } |
207 | 207 |
208 uint16_t TxtRecordRdata::Type() const { | 208 uint16_t 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_; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 | 253 |
254 // Since we may only have one block, the data length must be exactly equal to | 254 // Since we may only have one block, the data length must be exactly equal to |
255 // the domain length plus bitmap size. | 255 // the domain length plus bitmap size. |
256 if (bitmap_data.length() != header->length) | 256 if (bitmap_data.length() != header->length) |
257 return scoped_ptr<NsecRecordRdata>(); | 257 return scoped_ptr<NsecRecordRdata>(); |
258 | 258 |
259 rdata->bitmap_.insert(rdata->bitmap_.begin(), | 259 rdata->bitmap_.insert(rdata->bitmap_.begin(), |
260 bitmap_data.begin(), | 260 bitmap_data.begin(), |
261 bitmap_data.end()); | 261 bitmap_data.end()); |
262 | 262 |
263 return rdata.Pass(); | 263 return rdata; |
264 } | 264 } |
265 | 265 |
266 uint16_t NsecRecordRdata::Type() const { | 266 uint16_t NsecRecordRdata::Type() const { |
267 return NsecRecordRdata::kType; | 267 return NsecRecordRdata::kType; |
268 } | 268 } |
269 | 269 |
270 bool NsecRecordRdata::IsEqual(const RecordRdata* other) const { | 270 bool NsecRecordRdata::IsEqual(const RecordRdata* other) const { |
271 if (other->Type() != Type()) | 271 if (other->Type() != Type()) |
272 return false; | 272 return false; |
273 const NsecRecordRdata* nsec_other = | 273 const NsecRecordRdata* nsec_other = |
274 static_cast<const NsecRecordRdata*>(other); | 274 static_cast<const NsecRecordRdata*>(other); |
275 return bitmap_ == nsec_other->bitmap_; | 275 return bitmap_ == nsec_other->bitmap_; |
276 } | 276 } |
277 | 277 |
278 bool NsecRecordRdata::GetBit(unsigned i) const { | 278 bool NsecRecordRdata::GetBit(unsigned i) const { |
279 unsigned byte_num = i/8; | 279 unsigned byte_num = i/8; |
280 if (bitmap_.size() < byte_num + 1) | 280 if (bitmap_.size() < byte_num + 1) |
281 return false; | 281 return false; |
282 | 282 |
283 unsigned bit_num = 7 - i % 8; | 283 unsigned bit_num = 7 - i % 8; |
284 return (bitmap_[byte_num] & (1 << bit_num)) != 0; | 284 return (bitmap_[byte_num] & (1 << bit_num)) != 0; |
285 } | 285 } |
286 | 286 |
287 } // namespace net | 287 } // namespace net |
OLD | NEW |