blob: 654574cc26e611968a1bbd81b757938fa1154113 [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
[email protected]4e09d242013-05-02 03:19:3510#include <string>
11
12#include "base/memory/scoped_ptr.h"
[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.
[email protected]f6a9add2013-05-23 00:56:3628 static scoped_ptr<const RecordParsed> CreateFrom(DnsRecordParser* parser,
29 base::Time time_created);
[email protected]4e09d242013-05-02 03:19:3530
31 const std::string& name() const { return name_; }
Avi Drissman13fc8932015-12-20 04:40:4632 uint16_t type() const { return type_; }
33 uint16_t klass() const { return klass_; }
34 uint32_t ttl() const { return ttl_; }
[email protected]4e09d242013-05-02 03:19:3535
[email protected]f6a9add2013-05-23 00:56:3636 base::Time time_created() const { return time_created_; }
37
[email protected]4e09d242013-05-02 03:19:3538 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]f6a9add2013-05-23 00:56:3644 // 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]4e09d242013-05-02 03:19:3549 private:
Avi Drissman13fc8932015-12-20 04:40:4650 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]f6a9add2013-05-23 00:56:3655 base::Time time_created);
[email protected]4e09d242013-05-02 03:19:3556
57 std::string name_; // in dotted form
Avi Drissman13fc8932015-12-20 04:40:4658 const uint16_t type_;
59 const uint16_t klass_;
60 const uint32_t ttl_;
[email protected]4e09d242013-05-02 03:19:3561
62 const scoped_ptr<const RecordRdata> rdata_;
63
[email protected]f6a9add2013-05-23 00:56:3664 const base::Time time_created_;
[email protected]4e09d242013-05-02 03:19:3565};
66
67} // namespace net
68
69#endif // NET_DNS_RECORD_PARSED_H_