blob: 5d35ff319bbed0cae39b5b44757ada6a06e5f5da [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
8#include <string>
9
10#include "base/memory/scoped_ptr.h"
[email protected]f6a9add2013-05-23 00:56:3611#include "base/time.h"
[email protected]4e09d242013-05-02 03:19:3512#include "net/base/net_export.h"
13
14namespace net {
15
16class DnsRecordParser;
17class RecordRdata;
18
19// Parsed record. This is a form of DnsResourceRecord where the rdata section
20// has been parsed into a data structure.
21class NET_EXPORT_PRIVATE RecordParsed {
22 public:
23 virtual ~RecordParsed();
24
25 // All records are inherently immutable. Return a const pointer.
[email protected]f6a9add2013-05-23 00:56:3626 static scoped_ptr<const RecordParsed> CreateFrom(DnsRecordParser* parser,
27 base::Time time_created);
[email protected]4e09d242013-05-02 03:19:3528
29 const std::string& name() const { return name_; }
30 uint16 type() const { return type_; }
31 uint16 klass() const { return klass_; }
32 uint32 ttl() const { return ttl_; }
33
[email protected]f6a9add2013-05-23 00:56:3634 base::Time time_created() const { return time_created_; }
35
[email protected]4e09d242013-05-02 03:19:3536 template <class T> const T* rdata() const {
37 if (T::kType != type_)
38 return NULL;
39 return static_cast<const T*>(rdata_.get());
40 }
41
[email protected]f6a9add2013-05-23 00:56:3642 // Check if two records have the same data. Ignores time_created and ttl.
43 // If |is_mdns| is true, ignore the top bit of the class
44 // (the cache flush bit).
45 bool IsEqual(const RecordParsed* other, bool is_mdns) const;
46
[email protected]4e09d242013-05-02 03:19:3547 private:
[email protected]f6a9add2013-05-23 00:56:3648 RecordParsed(const std::string& name, uint16 type, uint16 klass,
49 uint32 ttl, scoped_ptr<const RecordRdata> rdata,
50 base::Time time_created);
[email protected]4e09d242013-05-02 03:19:3551
52 std::string name_; // in dotted form
53 const uint16 type_;
54 const uint16 klass_;
55 const uint32 ttl_;
56
57 const scoped_ptr<const RecordRdata> rdata_;
58
[email protected]f6a9add2013-05-23 00:56:3659 const base::Time time_created_;
[email protected]4e09d242013-05-02 03:19:3560};
61
62} // namespace net
63
64#endif // NET_DNS_RECORD_PARSED_H_