Chromium Code Reviews| 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 24 matching lines...) Expand all Loading... | |
| 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 { | |
| 46 return SrvRecordRdata::kType; | |
| 47 } | |
| 48 | |
| 49 bool SrvRecordRdata::IsEqual(const RecordRdata* other) const { | |
| 50 if (other->Type() != Type()) return false; | |
| 51 const SrvRecordRdata* srv_other = static_cast<const SrvRecordRdata*>(other); | |
| 52 return weight_ == srv_other->weight_ && | |
| 53 port_ == srv_other->port_ && | |
| 54 priority_ == srv_other->priority_ && | |
| 55 target_ == srv_other->target_; | |
| 56 } | |
| 57 | |
| 45 ARecordRdata::ARecordRdata() { | 58 ARecordRdata::ARecordRdata() { |
| 46 } | 59 } |
| 47 | 60 |
| 48 ARecordRdata::~ARecordRdata() { | 61 ARecordRdata::~ARecordRdata() { |
| 49 } | 62 } |
| 50 | 63 |
| 51 // static | 64 // static |
| 52 scoped_ptr<ARecordRdata> ARecordRdata::Create( | 65 scoped_ptr<ARecordRdata> ARecordRdata::Create( |
| 53 const base::StringPiece& data, | 66 const base::StringPiece& data, |
| 54 const DnsRecordParser& parser) { | 67 const DnsRecordParser& parser) { |
| 55 if (data.size() != kIPv4AddressSize) | 68 if (data.size() != kIPv4AddressSize) |
| 56 return scoped_ptr<ARecordRdata>(); | 69 return scoped_ptr<ARecordRdata>(); |
| 57 | 70 |
| 58 scoped_ptr<ARecordRdata> rdata(new ARecordRdata); | 71 scoped_ptr<ARecordRdata> rdata(new ARecordRdata); |
| 59 | 72 |
| 60 rdata->address_.resize(kIPv4AddressSize); | 73 rdata->address_.resize(kIPv4AddressSize); |
| 61 for (unsigned i = 0; i < kIPv4AddressSize; ++i) { | 74 for (unsigned i = 0; i < kIPv4AddressSize; ++i) { |
| 62 rdata->address_[i] = data[i]; | 75 rdata->address_[i] = data[i]; |
| 63 } | 76 } |
| 64 | 77 |
| 65 return rdata.Pass(); | 78 return rdata.Pass(); |
| 66 } | 79 } |
| 67 | 80 |
| 81 uint16 ARecordRdata::Type() const { | |
| 82 return ARecordRdata::kType; | |
| 83 } | |
| 84 | |
| 85 bool ARecordRdata::IsEqual(const RecordRdata* other) const { | |
| 86 if (other->Type() != Type()) return false; | |
| 87 const ARecordRdata* a_other = static_cast<const ARecordRdata*>(other); | |
| 88 return address_ == a_other->address_; | |
| 89 } | |
| 90 | |
| 91 AAAARecordRdata::AAAARecordRdata() { | |
| 92 } | |
| 93 | |
| 94 AAAARecordRdata::~AAAARecordRdata() { | |
| 95 } | |
| 96 | |
| 97 // static | |
| 98 scoped_ptr<AAAARecordRdata> AAAARecordRdata::Create( | |
| 99 const base::StringPiece& data, | |
| 100 const DnsRecordParser& parser) { | |
| 101 if (data.size() != kIPv6AddressSize) | |
| 102 return scoped_ptr<AAAARecordRdata>(); | |
| 103 | |
| 104 scoped_ptr<AAAARecordRdata> rdata(new AAAARecordRdata); | |
| 105 | |
| 106 rdata->address_.resize(kIPv6AddressSize); | |
| 107 for (unsigned i = 0; i < kIPv6AddressSize; ++i) { | |
| 108 rdata->address_[i] = data[i]; | |
| 109 } | |
| 110 | |
| 111 return rdata.Pass(); | |
| 112 } | |
| 113 | |
| 114 uint16 AAAARecordRdata::Type() const { | |
| 115 return AAAARecordRdata::kType; | |
| 116 } | |
| 117 | |
| 118 bool AAAARecordRdata::IsEqual(const RecordRdata* other) const { | |
| 119 if (other->Type() != Type()) return false; | |
| 120 const AAAARecordRdata* a_other = static_cast<const AAAARecordRdata*>(other); | |
| 121 return address_ == a_other->address_; | |
| 122 } | |
| 123 | |
| 68 CnameRecordRdata::CnameRecordRdata() { | 124 CnameRecordRdata::CnameRecordRdata() { |
| 69 } | 125 } |
| 70 | 126 |
| 71 CnameRecordRdata::~CnameRecordRdata() { | 127 CnameRecordRdata::~CnameRecordRdata() { |
| 72 } | 128 } |
| 73 | 129 |
| 74 // static | 130 // static |
| 75 scoped_ptr<CnameRecordRdata> CnameRecordRdata::Create( | 131 scoped_ptr<CnameRecordRdata> CnameRecordRdata::Create( |
| 76 const base::StringPiece& data, | 132 const base::StringPiece& data, |
| 77 const DnsRecordParser& parser) { | 133 const DnsRecordParser& parser) { |
| 78 scoped_ptr<CnameRecordRdata> rdata(new CnameRecordRdata); | 134 scoped_ptr<CnameRecordRdata> rdata(new CnameRecordRdata); |
| 79 | 135 |
| 80 if (!parser.ReadName(data.begin(), &rdata->cname_)) | 136 if (!parser.ReadName(data.begin(), &rdata->cname_)) |
| 81 return scoped_ptr<CnameRecordRdata>(); | 137 return scoped_ptr<CnameRecordRdata>(); |
| 82 | 138 |
| 83 return rdata.Pass(); | 139 return rdata.Pass(); |
| 84 } | 140 } |
| 85 | 141 |
| 142 uint16 CnameRecordRdata::Type() const { | |
| 143 return CnameRecordRdata::kType; | |
| 144 } | |
| 145 | |
| 146 bool CnameRecordRdata::IsEqual(const RecordRdata* other) const { | |
| 147 if (other->Type() != Type()) return false; | |
| 148 const CnameRecordRdata* cname_other = | |
| 149 static_cast<const CnameRecordRdata*>(other); | |
| 150 return cname_ == cname_other->cname_; | |
| 151 } | |
| 152 | |
| 86 PtrRecordRdata::PtrRecordRdata() { | 153 PtrRecordRdata::PtrRecordRdata() { |
| 87 } | 154 } |
| 88 | 155 |
| 89 PtrRecordRdata::~PtrRecordRdata() { | 156 PtrRecordRdata::~PtrRecordRdata() { |
| 90 } | 157 } |
| 91 | 158 |
| 92 // static | 159 // static |
| 93 scoped_ptr<PtrRecordRdata> PtrRecordRdata::Create( | 160 scoped_ptr<PtrRecordRdata> PtrRecordRdata::Create( |
| 94 const base::StringPiece& data, | 161 const base::StringPiece& data, |
| 95 const DnsRecordParser& parser) { | 162 const DnsRecordParser& parser) { |
| 96 scoped_ptr<PtrRecordRdata> rdata(new PtrRecordRdata); | 163 scoped_ptr<PtrRecordRdata> rdata(new PtrRecordRdata); |
| 97 | 164 |
| 98 if (!parser.ReadName(data.begin(), &rdata->ptrdomain_)) | 165 if (!parser.ReadName(data.begin(), &rdata->ptrdomain_)) |
| 99 return scoped_ptr<PtrRecordRdata>(); | 166 return scoped_ptr<PtrRecordRdata>(); |
| 100 | 167 |
| 101 return rdata.Pass(); | 168 return rdata.Pass(); |
| 102 } | 169 } |
| 103 | 170 |
| 171 uint16 PtrRecordRdata::Type() const { | |
| 172 return PtrRecordRdata::kType; | |
| 173 } | |
| 174 | |
| 175 bool PtrRecordRdata::IsEqual(const RecordRdata* other) const { | |
| 176 if (other->Type() != Type()) return false; | |
| 177 const PtrRecordRdata* ptr_other = static_cast<const PtrRecordRdata*>(other); | |
| 178 return ptrdomain_ == ptr_other->ptrdomain_; | |
| 179 } | |
| 180 | |
| 104 TxtRecordRdata::TxtRecordRdata() { | 181 TxtRecordRdata::TxtRecordRdata() { |
| 105 } | 182 } |
| 106 | 183 |
| 107 TxtRecordRdata::~TxtRecordRdata() { | 184 TxtRecordRdata::~TxtRecordRdata() { |
| 108 } | 185 } |
| 109 | 186 |
| 110 // static | 187 // static |
| 111 scoped_ptr<TxtRecordRdata> TxtRecordRdata::Create( | 188 scoped_ptr<TxtRecordRdata> TxtRecordRdata::Create( |
| 112 const base::StringPiece& data, | 189 const base::StringPiece& data, |
| 113 const DnsRecordParser& parser) { | 190 const DnsRecordParser& parser) { |
| 114 scoped_ptr<TxtRecordRdata> rdata(new TxtRecordRdata); | 191 scoped_ptr<TxtRecordRdata> rdata(new TxtRecordRdata); |
| 115 | 192 |
| 116 for (size_t i = 0; i < data.size(); ) { | 193 for (size_t i = 0; i < data.size(); ) { |
| 117 uint8 length = data[i]; | 194 uint8 length = data[i]; |
| 118 | 195 |
| 119 if (i + length >= data.size()) | 196 if (i + length >= data.size()) |
| 120 return scoped_ptr<TxtRecordRdata>(); | 197 return scoped_ptr<TxtRecordRdata>(); |
| 121 | 198 |
| 122 rdata->texts_.push_back(data.substr(i + 1, length).as_string()); | 199 rdata->texts_.push_back(data.substr(i + 1, length).as_string()); |
| 123 | 200 |
| 124 // Move to the next string. | 201 // Move to the next string. |
| 125 i += length + 1; | 202 i += length + 1; |
| 126 } | 203 } |
| 127 | 204 |
| 128 return rdata.Pass(); | 205 return rdata.Pass(); |
| 129 } | 206 } |
| 130 | 207 |
| 208 uint16 TxtRecordRdata::Type() const { | |
| 209 return TxtRecordRdata::kType; | |
| 210 } | |
| 211 | |
| 212 bool TxtRecordRdata::IsEqual(const RecordRdata* other) const { | |
| 213 if (other->Type() != Type()) return false; | |
| 214 const TxtRecordRdata* txt_other = static_cast<const TxtRecordRdata*>(other); | |
| 215 | |
|
szym
2013/05/21 22:09:05
nit: remove blank
Noam Samuel
2013/05/21 23:00:56
Done.
| |
| 216 return texts_ == txt_other->texts_; | |
| 217 } | |
| 218 | |
| 131 } // namespace net | 219 } // namespace net |
| OLD | NEW |