[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 | |||||
[email protected] | 4e09d24 | 2013-05-02 03:19:35 | [diff] [blame] | 10 | #include <string> |
11 | |||||
12 | #include "base/memory/scoped_ptr.h" | ||||
[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. | ||||
[email protected] | f6a9add | 2013-05-23 00:56:36 | [diff] [blame] | 28 | static scoped_ptr<const RecordParsed> CreateFrom(DnsRecordParser* parser, |
29 | base::Time time_created); | ||||
[email protected] | 4e09d24 | 2013-05-02 03:19:35 | [diff] [blame] | 30 | |
31 | const std::string& name() const { return name_; } | ||||
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame^] | 32 | uint16_t type() const { return type_; } |
33 | uint16_t klass() const { return klass_; } | ||||
34 | uint32_t ttl() const { return ttl_; } | ||||
[email protected] | 4e09d24 | 2013-05-02 03:19:35 | [diff] [blame] | 35 | |
[email protected] | f6a9add | 2013-05-23 00:56:36 | [diff] [blame] | 36 | base::Time time_created() const { return time_created_; } |
37 | |||||
[email protected] | 4e09d24 | 2013-05-02 03:19:35 | [diff] [blame] | 38 | template <class T> const T* rdata() const { |
39 | if (T::kType != type_) | ||||
40 | return NULL; | ||||
41 | return static_cast<const T*>(rdata_.get()); | ||||
42 | } | ||||
43 | |||||
[email protected] | f6a9add | 2013-05-23 00:56:36 | [diff] [blame] | 44 | // Check if two records have the same data. Ignores time_created and ttl. |
45 | // If |is_mdns| is true, ignore the top bit of the class | ||||
46 | // (the cache flush bit). | ||||
47 | bool IsEqual(const RecordParsed* other, bool is_mdns) const; | ||||
48 | |||||
[email protected] | 4e09d24 | 2013-05-02 03:19:35 | [diff] [blame] | 49 | private: |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame^] | 50 | RecordParsed(const std::string& name, |
51 | uint16_t type, | ||||
52 | uint16_t klass, | ||||
53 | uint32_t ttl, | ||||
54 | scoped_ptr<const RecordRdata> rdata, | ||||
[email protected] | f6a9add | 2013-05-23 00:56:36 | [diff] [blame] | 55 | base::Time time_created); |
[email protected] | 4e09d24 | 2013-05-02 03:19:35 | [diff] [blame] | 56 | |
57 | std::string name_; // in dotted form | ||||
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame^] | 58 | const uint16_t type_; |
59 | const uint16_t klass_; | ||||
60 | const uint32_t ttl_; | ||||
[email protected] | 4e09d24 | 2013-05-02 03:19:35 | [diff] [blame] | 61 | |
62 | const scoped_ptr<const RecordRdata> rdata_; | ||||
63 | |||||
[email protected] | f6a9add | 2013-05-23 00:56:36 | [diff] [blame] | 64 | const base::Time time_created_; |
[email protected] | 4e09d24 | 2013-05-02 03:19:35 | [diff] [blame] | 65 | }; |
66 | |||||
67 | } // namespace net | ||||
68 | |||||
69 | #endif // NET_DNS_RECORD_PARSED_H_ |