1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "net/dns/record_parsed.h"
#include "base/logging.h"
#include "net/dns/dns_response.h"
#include "net/dns/record_rdata.h"
namespace net {
RecordParsed::RecordParsed(const std::string& name,
uint16_t type,
uint16_t klass,
uint32_t ttl,
scoped_ptr<const RecordRdata> rdata,
base::Time time_created)
: name_(name),
type_(type),
klass_(klass),
ttl_(ttl),
rdata_(rdata.Pass()),
time_created_(time_created) {}
RecordParsed::~RecordParsed() {
}
// static
scoped_ptr<const RecordParsed> RecordParsed::CreateFrom(
DnsRecordParser* parser,
base::Time time_created) {
DnsResourceRecord record;
scoped_ptr<const RecordRdata> rdata;
if (!parser->ReadRecord(&record))
return scoped_ptr<const RecordParsed>();
switch (record.type) {
case ARecordRdata::kType:
rdata = ARecordRdata::Create(record.rdata, *parser);
break;
case AAAARecordRdata::kType:
rdata = AAAARecordRdata::Create(record.rdata, *parser);
break;
case CnameRecordRdata::kType:
rdata = CnameRecordRdata::Create(record.rdata, *parser);
break;
case PtrRecordRdata::kType:
rdata = PtrRecordRdata::Create(record.rdata, *parser);
break;
case SrvRecordRdata::kType:
rdata = SrvRecordRdata::Create(record.rdata, *parser);
break;
case TxtRecordRdata::kType:
rdata = TxtRecordRdata::Create(record.rdata, *parser);
break;
case NsecRecordRdata::kType:
rdata = NsecRecordRdata::Create(record.rdata, *parser);
break;
default:
DVLOG(1) << "Unknown RData type for received record: " << record.type;
return scoped_ptr<const RecordParsed>();
}
if (!rdata.get())
return scoped_ptr<const RecordParsed>();
return scoped_ptr<const RecordParsed>(new RecordParsed(record.name,
record.type,
record.klass,
record.ttl,
rdata.Pass(),
time_created));
}
bool RecordParsed::IsEqual(const RecordParsed* other, bool is_mdns) const {
DCHECK(other);
uint16_t klass = klass_;
uint16_t other_klass = other->klass_;
if (is_mdns) {
klass &= dns_protocol::kMDnsClassMask;
other_klass &= dns_protocol::kMDnsClassMask;
}
return name_ == other->name_ &&
klass == other_klass &&
type_ == other->type_ &&
rdata_->IsEqual(other->rdata_.get());
}
}
|