Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / net / dns / record_parsed.cc
blob4ae6ed292105248319fcbd90285ec2a886182f76
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"
11 namespace net {
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() {
23 // static
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);
36 break;
37 case AAAARecordRdata::kType:
38 rdata = AAAARecordRdata::Create(record.rdata, *parser);
39 break;
40 case CnameRecordRdata::kType:
41 rdata = CnameRecordRdata::Create(record.rdata, *parser);
42 break;
43 case PtrRecordRdata::kType:
44 rdata = PtrRecordRdata::Create(record.rdata, *parser);
45 break;
46 case SrvRecordRdata::kType:
47 rdata = SrvRecordRdata::Create(record.rdata, *parser);
48 break;
49 case TxtRecordRdata::kType:
50 rdata = TxtRecordRdata::Create(record.rdata, *parser);
51 break;
52 case NsecRecordRdata::kType:
53 rdata = NsecRecordRdata::Create(record.rdata, *parser);
54 break;
55 default:
56 DVLOG(1) << "Unknown RData type for received record: " << record.type;
57 return scoped_ptr<const RecordParsed>();
60 if (!rdata.get())
61 return scoped_ptr<const RecordParsed>();
63 return scoped_ptr<const RecordParsed>(new RecordParsed(record.name,
64 record.type,
65 record.klass,
66 record.ttl,
67 rdata.Pass(),
68 time_created));
71 bool RecordParsed::IsEqual(const RecordParsed* other, bool is_mdns) const {
72 DCHECK(other);
73 uint16 klass = klass_;
74 uint16 other_klass = other->klass_;
76 if (is_mdns) {
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());