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
3 // found in the LICENSE file.
5 #include "net/dns/record_parsed.h"
7 #include "base/logging.h"
8 #include "net/dns/dns_response.h"
9 #include "net/dns/record_rdata.h"
13 RecordParsed::RecordParsed(const std::string
& name
, uint16 type
, uint16 klass
,
14 uint32 ttl
, scoped_ptr
<const RecordRdata
> rdata
,
15 base::Time time_created
)
16 : name_(name
), type_(type
), klass_(klass
), ttl_(ttl
), rdata_(rdata
.Pass()),
17 time_created_(time_created
) {
20 RecordParsed::~RecordParsed() {
24 scoped_ptr
<const RecordParsed
> RecordParsed::CreateFrom(
25 DnsRecordParser
* parser
,
26 base::Time time_created
) {
27 DnsResourceRecord record
;
28 scoped_ptr
<const RecordRdata
> rdata
;
30 if (!parser
->ReadRecord(&record
))
31 return scoped_ptr
<const RecordParsed
>();
33 switch (record
.type
) {
34 case ARecordRdata::kType
:
35 rdata
= ARecordRdata::Create(record
.rdata
, *parser
);
37 case AAAARecordRdata::kType
:
38 rdata
= AAAARecordRdata::Create(record
.rdata
, *parser
);
40 case CnameRecordRdata::kType
:
41 rdata
= CnameRecordRdata::Create(record
.rdata
, *parser
);
43 case PtrRecordRdata::kType
:
44 rdata
= PtrRecordRdata::Create(record
.rdata
, *parser
);
46 case SrvRecordRdata::kType
:
47 rdata
= SrvRecordRdata::Create(record
.rdata
, *parser
);
49 case TxtRecordRdata::kType
:
50 rdata
= TxtRecordRdata::Create(record
.rdata
, *parser
);
52 case NsecRecordRdata::kType
:
53 rdata
= NsecRecordRdata::Create(record
.rdata
, *parser
);
56 DVLOG(1) << "Unknown RData type for received record: " << record
.type
;
57 return scoped_ptr
<const RecordParsed
>();
61 return scoped_ptr
<const RecordParsed
>();
63 return scoped_ptr
<const RecordParsed
>(new RecordParsed(record
.name
,
71 bool RecordParsed::IsEqual(const RecordParsed
* other
, bool is_mdns
) const {
73 uint16 klass
= klass_
;
74 uint16 other_klass
= other
->klass_
;
77 klass
&= dns_protocol::kMDnsClassMask
;
78 other_klass
&= dns_protocol::kMDnsClassMask
;
81 return name_
== other
->name_
&&
82 klass
== other_klass
&&
83 type_
== other
->type_
&&
84 rdata_
->IsEqual(other
->rdata_
.get());