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

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

Issue 1535363003: Switch to standard integer types in net/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: stddef Created 5 years 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
« no previous file with comments | « net/dns/record_rdata.h ('k') | net/dns/record_rdata_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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 24 matching lines...) Expand all
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.Pass();
43 } 43 }
44 44
45 uint16 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_ &&
53 port_ == srv_other->port_ && 53 port_ == srv_other->port_ &&
54 priority_ == srv_other->priority_ && 54 priority_ == srv_other->priority_ &&
55 target_ == srv_other->target_; 55 target_ == srv_other->target_;
(...skipping 15 matching lines...) Expand all
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.Pass();
79 } 79 }
80 80
81 uint16 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_;
89 } 89 }
90 90
91 AAAARecordRdata::AAAARecordRdata() { 91 AAAARecordRdata::AAAARecordRdata() {
(...skipping 12 matching lines...) Expand all
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.Pass();
112 } 112 }
113 113
114 uint16 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.Pass();
140 } 140 }
141 141
142 uint16 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.Pass();
169 } 169 }
170 170
171 uint16 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_;
179 } 179 }
180 180
181 TxtRecordRdata::TxtRecordRdata() { 181 TxtRecordRdata::TxtRecordRdata() {
182 } 182 }
183 183
184 TxtRecordRdata::~TxtRecordRdata() { 184 TxtRecordRdata::~TxtRecordRdata() {
185 } 185 }
186 186
187 // static 187 // static
188 scoped_ptr<TxtRecordRdata> TxtRecordRdata::Create( 188 scoped_ptr<TxtRecordRdata> TxtRecordRdata::Create(
189 const base::StringPiece& data, 189 const base::StringPiece& data,
190 const DnsRecordParser& parser) { 190 const DnsRecordParser& parser) {
191 scoped_ptr<TxtRecordRdata> rdata(new TxtRecordRdata); 191 scoped_ptr<TxtRecordRdata> rdata(new TxtRecordRdata);
192 192
193 for (size_t i = 0; i < data.size(); ) { 193 for (size_t i = 0; i < data.size(); ) {
194 uint8 length = data[i]; 194 uint8_t length = data[i];
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.Pass();
206 } 206 }
207 207
208 uint16 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_;
216 } 216 }
217 217
218 NsecRecordRdata::NsecRecordRdata() { 218 NsecRecordRdata::NsecRecordRdata() {
(...skipping 11 matching lines...) Expand all
230 // Read the "next domain". This part for the NSEC record format is 230 // Read the "next domain". This part for the NSEC record format is
231 // ignored for mDNS, since it has no semantic meaning. 231 // ignored for mDNS, since it has no semantic meaning.
232 unsigned next_domain_length = parser.ReadName(data.data(), NULL); 232 unsigned next_domain_length = parser.ReadName(data.data(), NULL);
233 233
234 // If we did not succeed in getting the next domain or the data length 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. 235 // is too short for reading the bitmap header, return.
236 if (next_domain_length == 0 || data.length() < next_domain_length + 2) 236 if (next_domain_length == 0 || data.length() < next_domain_length + 2)
237 return scoped_ptr<NsecRecordRdata>(); 237 return scoped_ptr<NsecRecordRdata>();
238 238
239 struct BitmapHeader { 239 struct BitmapHeader {
240 uint8 block_number; // The block number should be zero. 240 uint8_t block_number; // The block number should be zero.
241 uint8 length; // Bitmap length in bytes. Between 1 and 32. 241 uint8_t length; // Bitmap length in bytes. Between 1 and 32.
242 }; 242 };
243 243
244 const BitmapHeader* header = reinterpret_cast<const BitmapHeader*>( 244 const BitmapHeader* header = reinterpret_cast<const BitmapHeader*>(
245 data.data() + next_domain_length); 245 data.data() + next_domain_length);
246 246
247 // The block number must be zero in mDns-specific NSEC records. The bitmap 247 // The block number must be zero in mDns-specific NSEC records. The bitmap
248 // length must be between 1 and 32. 248 // length must be between 1 and 32.
249 if (header->block_number != 0 || header->length == 0 || header->length > 32) 249 if (header->block_number != 0 || header->length == 0 || header->length > 32)
250 return scoped_ptr<NsecRecordRdata>(); 250 return scoped_ptr<NsecRecordRdata>();
251 251
252 base::StringPiece bitmap_data = data.substr(next_domain_length + 2); 252 base::StringPiece bitmap_data = data.substr(next_domain_length + 2);
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.Pass();
264 } 264 }
265 265
266 uint16 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
OLDNEW
« no previous file with comments | « net/dns/record_rdata.h ('k') | net/dns/record_rdata_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698