blob: 27d771dc47aa068b358da570d4b07e6188477f2e [file] [log] [blame]
[email protected]4e09d242013-05-02 03:19:351// 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.
4
5#ifndef NET_DNS_RECORD_PARSED_H_
6#define NET_DNS_RECORD_PARSED_H_
7
Avi Drissman13fc8932015-12-20 04:40:468#include <stdint.h>
9
danakj22f90e72016-04-16 01:55:4010#include <memory>
[email protected]4e09d242013-05-02 03:19:3511#include <string>
12
[email protected]66e96c42013-06-28 15:20:3113#include "base/time/time.h"
[email protected]4e09d242013-05-02 03:19:3514#include "net/base/net_export.h"
15
16namespace net {
17
18class DnsRecordParser;
19class RecordRdata;
20
21// Parsed record. This is a form of DnsResourceRecord where the rdata section
22// has been parsed into a data structure.
23class NET_EXPORT_PRIVATE RecordParsed {
24 public:
25 virtual ~RecordParsed();
26
27 // All records are inherently immutable. Return a const pointer.
danakj22f90e72016-04-16 01:55:4028 static std::unique_ptr<const RecordParsed> CreateFrom(
29 DnsRecordParser* parser,
30 base::Time time_created);
[email protected]4e09d242013-05-02 03:19:3531
32 const std::string& name() const { return name_; }
Avi Drissman13fc8932015-12-20 04:40:4633 uint16_t type() const { return type_; }
34 uint16_t klass() const { return klass_; }
35 uint32_t ttl() const { return ttl_; }
[email protected]4e09d242013-05-02 03:19:3536
[email protected]f6a9add2013-05-23 00:56:3637 base::Time time_created() const { return time_created_; }
38
[email protected]4e09d242013-05-02 03:19:3539 template <class T> const T* rdata() const {
40 if (T::kType != type_)
Raul Tambre94493c652019-03-11 17:18:3541 return nullptr;
[email protected]4e09d242013-05-02 03:19:3542 return static_cast<const T*>(rdata_.get());
43 }
44
[email protected]f6a9add2013-05-23 00:56:3645 // Check if two records have the same data. Ignores time_created and ttl.
46 // If |is_mdns| is true, ignore the top bit of the class
47 // (the cache flush bit).
48 bool IsEqual(const RecordParsed* other, bool is_mdns) const;
49
[email protected]4e09d242013-05-02 03:19:3550 private:
Avi Drissman13fc8932015-12-20 04:40:4651 RecordParsed(const std::string& name,
52 uint16_t type,
53 uint16_t klass,
54 uint32_t ttl,
danakj22f90e72016-04-16 01:55:4055 std::unique_ptr<const RecordRdata> rdata,
[email protected]f6a9add2013-05-23 00:56:3656 base::Time time_created);
[email protected]4e09d242013-05-02 03:19:3557
58 std::string name_; // in dotted form
Avi Drissman13fc8932015-12-20 04:40:4659 const uint16_t type_;
60 const uint16_t klass_;
61 const uint32_t ttl_;
[email protected]4e09d242013-05-02 03:19:3562
danakj22f90e72016-04-16 01:55:4063 const std::unique_ptr<const RecordRdata> rdata_;
[email protected]4e09d242013-05-02 03:19:3564
[email protected]f6a9add2013-05-23 00:56:3665 const base::Time time_created_;
[email protected]4e09d242013-05-02 03:19:3566};
67
68} // namespace net
69
70#endif // NET_DNS_RECORD_PARSED_H_