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

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

Issue 14697022: Cache for mDNS records (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@record_parsed_klassbit
Patch Set: Created 7 years, 7 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"
11 11
12 // TODO(noamsml): PRE-SUBMIT figure out better way to pass scoped_ptrs.
13
12 namespace net { 14 namespace net {
13 15
14 static const size_t kSrvRecordMinimumSize = 6; 16 static const size_t kSrvRecordMinimumSize = 6;
15 17
16 RecordRdata::RecordRdata() { 18 RecordRdata::RecordRdata() {
17 } 19 }
18 20
19 SrvRecordRdata::SrvRecordRdata() : priority_(0), weight_(0), port_(0) { 21 SrvRecordRdata::SrvRecordRdata() : priority_(0), weight_(0), port_(0) {
20 } 22 }
21 23
(...skipping 13 matching lines...) Expand all
35 reader.ReadU16(&rdata->weight_); 37 reader.ReadU16(&rdata->weight_);
36 reader.ReadU16(&rdata->port_); 38 reader.ReadU16(&rdata->port_);
37 39
38 if (!parser.ReadName(data.substr(kSrvRecordMinimumSize).begin(), 40 if (!parser.ReadName(data.substr(kSrvRecordMinimumSize).begin(),
39 &rdata->target_)) 41 &rdata->target_))
40 return scoped_ptr<SrvRecordRdata>(); 42 return scoped_ptr<SrvRecordRdata>();
41 43
42 return rdata.Pass(); 44 return rdata.Pass();
43 } 45 }
44 46
47 uint16 SrvRecordRdata::Type() const {
48 return SrvRecordRdata::kType;
49 }
50
51 bool SrvRecordRdata::IsEqual(const RecordRdata* other) const {
52 if (other->Type() != Type()) return false;
53 const SrvRecordRdata* srv_other = static_cast<const SrvRecordRdata*>(other);
54 return weight_ == srv_other->weight_ &&
55 port_ == srv_other->port_ &&
56 priority_ == srv_other->priority_ &&
57 target_ == srv_other->target_;
58 }
59
60 scoped_ptr<const RecordRdata> SrvRecordRdata::Copy() const {
61 scoped_ptr<SrvRecordRdata> return_value(new SrvRecordRdata);
62
63 return_value->port_ = port_;
64 return_value->weight_ = weight_;
65 return_value->priority_ = priority_;
66 return_value->target_ = target_;
67
68 return scoped_ptr<const RecordRdata>(return_value.Pass());
szym 2013/05/14 18:14:27 I think you can use |return_value.PassAs<const Rec
Noam Samuel 2013/05/15 20:17:57 Done.
69 }
70
45 ARecordRdata::ARecordRdata() { 71 ARecordRdata::ARecordRdata() {
46 } 72 }
47 73
48 ARecordRdata::~ARecordRdata() { 74 ARecordRdata::~ARecordRdata() {
49 } 75 }
50 76
51 // static 77 // static
52 scoped_ptr<ARecordRdata> ARecordRdata::Create( 78 scoped_ptr<ARecordRdata> ARecordRdata::Create(
53 const base::StringPiece& data, 79 const base::StringPiece& data,
54 const DnsRecordParser& parser) { 80 const DnsRecordParser& parser) {
55 if (data.size() != kIPv4AddressSize) 81 if (data.size() != kIPv4AddressSize)
56 return scoped_ptr<ARecordRdata>(); 82 return scoped_ptr<ARecordRdata>();
57 83
58 scoped_ptr<ARecordRdata> rdata(new ARecordRdata); 84 scoped_ptr<ARecordRdata> rdata(new ARecordRdata);
59 85
60 rdata->address_.resize(kIPv4AddressSize); 86 rdata->address_.resize(kIPv4AddressSize);
61 for (unsigned i = 0; i < kIPv4AddressSize; ++i) { 87 for (unsigned i = 0; i < kIPv4AddressSize; ++i) {
62 rdata->address_[i] = data[i]; 88 rdata->address_[i] = data[i];
63 } 89 }
64 90
65 return rdata.Pass(); 91 return rdata.Pass();
66 } 92 }
67 93
94 uint16 ARecordRdata::Type() const {
95 return ARecordRdata::kType;
96 }
97
98 bool ARecordRdata::IsEqual(const RecordRdata* other) const {
99 if (other->Type() != Type()) return false;
100 const ARecordRdata* a_other = static_cast<const ARecordRdata*>(other);
101 return address_ == a_other->address_;
102 }
103
104 scoped_ptr<const RecordRdata> ARecordRdata::Copy() const {
105 scoped_ptr<ARecordRdata> return_value(new ARecordRdata);
106
107 return_value->address_ = address_;
108
109 return scoped_ptr<const RecordRdata>(return_value.Pass());
110 }
111
112 AAAARecordRdata::AAAARecordRdata() {
113 }
114
115 AAAARecordRdata::~AAAARecordRdata() {
116 }
117
118 // static
119 scoped_ptr<AAAARecordRdata> AAAARecordRdata::Create(
120 const base::StringPiece& data,
121 const DnsRecordParser& parser) {
122 if (data.size() != kIPv6AddressSize)
123 return scoped_ptr<AAAARecordRdata>();
124
125 scoped_ptr<AAAARecordRdata> rdata(new AAAARecordRdata);
126
127 rdata->address_.resize(kIPv6AddressSize);
128 for (unsigned i = 0; i < kIPv6AddressSize; ++i) {
129 rdata->address_[i] = data[i];
130 }
131
132 return rdata.Pass();
133 }
134
135 uint16 AAAARecordRdata::Type() const {
136 return AAAARecordRdata::kType;
137 }
138
139 bool AAAARecordRdata::IsEqual(const RecordRdata* other) const {
140 if (other->Type() != Type()) return false;
141 const AAAARecordRdata* a_other = static_cast<const AAAARecordRdata*>(other);
142 return address_ == a_other->address_;
143 }
144
145 scoped_ptr<const RecordRdata> AAAARecordRdata::Copy() const {
146 scoped_ptr<AAAARecordRdata> return_value(new AAAARecordRdata);
147
148 return_value->address_ = address_;
149
150 return scoped_ptr<const RecordRdata>(return_value.Pass());
151 }
152
68 CnameRecordRdata::CnameRecordRdata() { 153 CnameRecordRdata::CnameRecordRdata() {
69 } 154 }
70 155
71 CnameRecordRdata::~CnameRecordRdata() { 156 CnameRecordRdata::~CnameRecordRdata() {
72 } 157 }
73 158
74 // static 159 // static
75 scoped_ptr<CnameRecordRdata> CnameRecordRdata::Create( 160 scoped_ptr<CnameRecordRdata> CnameRecordRdata::Create(
76 const base::StringPiece& data, 161 const base::StringPiece& data,
77 const DnsRecordParser& parser) { 162 const DnsRecordParser& parser) {
78 scoped_ptr<CnameRecordRdata> rdata(new CnameRecordRdata); 163 scoped_ptr<CnameRecordRdata> rdata(new CnameRecordRdata);
79 164
80 if (!parser.ReadName(data.begin(), &rdata->cname_)) 165 if (!parser.ReadName(data.begin(), &rdata->cname_))
81 return scoped_ptr<CnameRecordRdata>(); 166 return scoped_ptr<CnameRecordRdata>();
82 167
83 return rdata.Pass(); 168 return rdata.Pass();
84 } 169 }
85 170
171 uint16 CnameRecordRdata::Type() const {
172 return CnameRecordRdata::kType;
173 }
174
175 bool CnameRecordRdata::IsEqual(const RecordRdata* other) const {
176 if (other->Type() != Type()) return false;
177 const CnameRecordRdata* cname_other =
178 static_cast<const CnameRecordRdata*>(other);
179 return cname_ == cname_other->cname_;
180 }
181
182 scoped_ptr<const RecordRdata> CnameRecordRdata::Copy() const {
183 scoped_ptr<CnameRecordRdata> return_value(new CnameRecordRdata);
184
185 return_value->cname_ = cname_;
186
187 return scoped_ptr<const RecordRdata>(return_value.Pass());
188 }
189
86 PtrRecordRdata::PtrRecordRdata() { 190 PtrRecordRdata::PtrRecordRdata() {
87 } 191 }
88 192
89 PtrRecordRdata::~PtrRecordRdata() { 193 PtrRecordRdata::~PtrRecordRdata() {
90 } 194 }
91 195
92 // static 196 // static
93 scoped_ptr<PtrRecordRdata> PtrRecordRdata::Create( 197 scoped_ptr<PtrRecordRdata> PtrRecordRdata::Create(
94 const base::StringPiece& data, 198 const base::StringPiece& data,
95 const DnsRecordParser& parser) { 199 const DnsRecordParser& parser) {
96 scoped_ptr<PtrRecordRdata> rdata(new PtrRecordRdata); 200 scoped_ptr<PtrRecordRdata> rdata(new PtrRecordRdata);
97 201
98 if (!parser.ReadName(data.begin(), &rdata->ptrdomain_)) 202 if (!parser.ReadName(data.begin(), &rdata->ptrdomain_))
99 return scoped_ptr<PtrRecordRdata>(); 203 return scoped_ptr<PtrRecordRdata>();
100 204
101 return rdata.Pass(); 205 return rdata.Pass();
102 } 206 }
103 207
208 uint16 PtrRecordRdata::Type() const {
209 return PtrRecordRdata::kType;
210 }
211
212 bool PtrRecordRdata::IsEqual(const RecordRdata* other) const {
213 if (other->Type() != Type()) return false;
214 const PtrRecordRdata* ptr_other = static_cast<const PtrRecordRdata*>(other);
215 return ptrdomain_ == ptr_other->ptrdomain_;
216 }
217
218 scoped_ptr<const RecordRdata> PtrRecordRdata::Copy() const {
219 scoped_ptr<PtrRecordRdata> return_value(new PtrRecordRdata);
220
221 return_value->ptrdomain_ = ptrdomain_;
222
223 return scoped_ptr<const RecordRdata>(return_value.Pass());
224 }
225
104 TxtRecordRdata::TxtRecordRdata() { 226 TxtRecordRdata::TxtRecordRdata() {
105 } 227 }
106 228
107 TxtRecordRdata::~TxtRecordRdata() { 229 TxtRecordRdata::~TxtRecordRdata() {
108 } 230 }
109 231
110 // static 232 // static
111 scoped_ptr<TxtRecordRdata> TxtRecordRdata::Create( 233 scoped_ptr<TxtRecordRdata> TxtRecordRdata::Create(
112 const base::StringPiece& data, 234 const base::StringPiece& data,
113 const DnsRecordParser& parser) { 235 const DnsRecordParser& parser) {
114 scoped_ptr<TxtRecordRdata> rdata(new TxtRecordRdata); 236 scoped_ptr<TxtRecordRdata> rdata(new TxtRecordRdata);
115 237
116 for (size_t i = 0; i < data.size(); ) { 238 for (size_t i = 0; i < data.size(); ) {
117 uint8 length = data[i]; 239 uint8 length = data[i];
118 240
119 if (i + length >= data.size()) 241 if (i + length >= data.size())
120 return scoped_ptr<TxtRecordRdata>(); 242 return scoped_ptr<TxtRecordRdata>();
121 243
122 rdata->texts_.push_back(data.substr(i + 1, length).as_string()); 244 rdata->texts_.push_back(data.substr(i + 1, length).as_string());
123 245
124 // Move to the next string. 246 // Move to the next string.
125 i += length + 1; 247 i += length + 1;
126 } 248 }
127 249
128 return rdata.Pass(); 250 return rdata.Pass();
129 } 251 }
130 252
253 uint16 TxtRecordRdata::Type() const {
254 return TxtRecordRdata::kType;
255 }
256
257 bool TxtRecordRdata::IsEqual(const RecordRdata* other) const {
258 if (other->Type() != Type()) return false;
259 const TxtRecordRdata* txt_other = static_cast<const TxtRecordRdata*>(other);
260
261 return texts_ == txt_other->texts_;
262 }
263
264 scoped_ptr<const RecordRdata> TxtRecordRdata::Copy() const {
265 scoped_ptr<TxtRecordRdata> return_value(new TxtRecordRdata);
266
267 return_value->texts_ = texts_;
268
269 return scoped_ptr<const RecordRdata>(return_value.Pass());
270 }
271
131 } // namespace net 272 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698