[email protected] | 4e09d24 | 2013-05-02 03:19:35 | [diff] [blame] | 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. | ||||
4 | |||||
5 | #ifndef NET_DNS_RECORD_PARSED_H_ | ||||
6 | #define NET_DNS_RECORD_PARSED_H_ | ||||
7 | |||||
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 8 | #include <stdint.h> |
9 | |||||
danakj | 22f90e7 | 2016-04-16 01:55:40 | [diff] [blame] | 10 | #include <memory> |
[email protected] | 4e09d24 | 2013-05-02 03:19:35 | [diff] [blame] | 11 | #include <string> |
12 | |||||
[email protected] | 66e96c4 | 2013-06-28 15:20:31 | [diff] [blame] | 13 | #include "base/time/time.h" |
[email protected] | 4e09d24 | 2013-05-02 03:19:35 | [diff] [blame] | 14 | #include "net/base/net_export.h" |
15 | |||||
16 | namespace net { | ||||
17 | |||||
18 | class DnsRecordParser; | ||||
19 | class RecordRdata; | ||||
20 | |||||
21 | // Parsed record. This is a form of DnsResourceRecord where the rdata section | ||||
22 | // has been parsed into a data structure. | ||||
23 | class NET_EXPORT_PRIVATE RecordParsed { | ||||
24 | public: | ||||
25 | virtual ~RecordParsed(); | ||||
26 | |||||
27 | // All records are inherently immutable. Return a const pointer. | ||||
danakj | 22f90e7 | 2016-04-16 01:55:40 | [diff] [blame] | 28 | static std::unique_ptr<const RecordParsed> CreateFrom( |
29 | DnsRecordParser* parser, | ||||
30 | base::Time time_created); | ||||
[email protected] | 4e09d24 | 2013-05-02 03:19:35 | [diff] [blame] | 31 | |
32 | const std::string& name() const { return name_; } | ||||
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 33 | uint16_t type() const { return type_; } |
34 | uint16_t klass() const { return klass_; } | ||||
35 | uint32_t ttl() const { return ttl_; } | ||||
[email protected] | 4e09d24 | 2013-05-02 03:19:35 | [diff] [blame] | 36 | |
[email protected] | f6a9add | 2013-05-23 00:56:36 | [diff] [blame] | 37 | base::Time time_created() const { return time_created_; } |
38 | |||||
[email protected] | 4e09d24 | 2013-05-02 03:19:35 | [diff] [blame] | 39 | template <class T> const T* rdata() const { |
40 | if (T::kType != type_) | ||||
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame] | 41 | return nullptr; |
[email protected] | 4e09d24 | 2013-05-02 03:19:35 | [diff] [blame] | 42 | return static_cast<const T*>(rdata_.get()); |
43 | } | ||||
44 | |||||
[email protected] | f6a9add | 2013-05-23 00:56:36 | [diff] [blame] | 45 | // 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] | 4e09d24 | 2013-05-02 03:19:35 | [diff] [blame] | 50 | private: |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 51 | RecordParsed(const std::string& name, |
52 | uint16_t type, | ||||
53 | uint16_t klass, | ||||
54 | uint32_t ttl, | ||||
danakj | 22f90e7 | 2016-04-16 01:55:40 | [diff] [blame] | 55 | std::unique_ptr<const RecordRdata> rdata, |
[email protected] | f6a9add | 2013-05-23 00:56:36 | [diff] [blame] | 56 | base::Time time_created); |
[email protected] | 4e09d24 | 2013-05-02 03:19:35 | [diff] [blame] | 57 | |
58 | std::string name_; // in dotted form | ||||
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 59 | const uint16_t type_; |
60 | const uint16_t klass_; | ||||
61 | const uint32_t ttl_; | ||||
[email protected] | 4e09d24 | 2013-05-02 03:19:35 | [diff] [blame] | 62 | |
danakj | 22f90e7 | 2016-04-16 01:55:40 | [diff] [blame] | 63 | const std::unique_ptr<const RecordRdata> rdata_; |
[email protected] | 4e09d24 | 2013-05-02 03:19:35 | [diff] [blame] | 64 | |
[email protected] | f6a9add | 2013-05-23 00:56:36 | [diff] [blame] | 65 | const base::Time time_created_; |
[email protected] | 4e09d24 | 2013-05-02 03:19:35 | [diff] [blame] | 66 | }; |
67 | |||||
68 | } // namespace net | ||||
69 | |||||
70 | #endif // NET_DNS_RECORD_PARSED_H_ |