| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_DNS_RECORD_RDATA_H_ | 5 #ifndef NET_DNS_RECORD_RDATA_H_ |
| 6 #define NET_DNS_RECORD_RDATA_H_ | 6 #define NET_DNS_RECORD_RDATA_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/strings/string_piece.h" | 14 #include "base/strings/string_piece.h" |
| 15 #include "net/base/big_endian.h" | 15 #include "net/base/big_endian.h" |
| 16 #include "net/base/net_export.h" | 16 #include "net/base/net_export.h" |
| 17 #include "net/base/net_util.h" | 17 #include "net/base/net_util.h" |
| 18 #include "net/dns/dns_protocol.h" | 18 #include "net/dns/dns_protocol.h" |
| 19 | 19 |
| 20 namespace net { | 20 namespace net { |
| 21 | 21 |
| 22 class DnsRecordParser; | 22 class DnsRecordParser; |
| 23 | 23 |
| 24 // Parsed represenation of the extra data in a record. Does not include standard | 24 // Parsed represenation of the extra data in a record. Does not include standard |
| 25 // DNS record data such as TTL, Name, Type and Class. | 25 // DNS record data such as TTL, Name, Type and Class. |
| 26 class NET_EXPORT_PRIVATE RecordRdata { | 26 class NET_EXPORT_PRIVATE RecordRdata { |
| 27 public: | 27 public: |
| 28 virtual ~RecordRdata() {} | 28 virtual ~RecordRdata() {} |
| 29 | 29 |
| 30 virtual bool IsEqual(const RecordRdata* other) const = 0; |
| 31 virtual uint16 Type() const = 0; |
| 32 virtual scoped_ptr<const RecordRdata> Copy() const = 0; |
| 33 |
| 30 protected: | 34 protected: |
| 31 RecordRdata(); | 35 RecordRdata(); |
| 32 | 36 |
| 33 DISALLOW_COPY_AND_ASSIGN(RecordRdata); | 37 DISALLOW_COPY_AND_ASSIGN(RecordRdata); |
| 34 }; | 38 }; |
| 35 | 39 |
| 36 // SRV record format (http://www.ietf.org/rfc/rfc2782.txt): | 40 // SRV record format (http://www.ietf.org/rfc/rfc2782.txt): |
| 37 // 2 bytes network-order unsigned priority | 41 // 2 bytes network-order unsigned priority |
| 38 // 2 bytes network-order unsigned weight | 42 // 2 bytes network-order unsigned weight |
| 39 // 2 bytes network-order unsigned port | 43 // 2 bytes network-order unsigned port |
| 40 // target: domain name (on-the-wire representation) | 44 // target: domain name (on-the-wire representation) |
| 41 class NET_EXPORT_PRIVATE SrvRecordRdata : public RecordRdata { | 45 class NET_EXPORT_PRIVATE SrvRecordRdata : public RecordRdata { |
| 42 public: | 46 public: |
| 43 static const uint16 kType = dns_protocol::kTypeSRV; | 47 static const uint16 kType = dns_protocol::kTypeSRV; |
| 44 | 48 |
| 45 virtual ~SrvRecordRdata(); | 49 virtual ~SrvRecordRdata(); |
| 46 static scoped_ptr<SrvRecordRdata> Create(const base::StringPiece& data, | 50 static scoped_ptr<SrvRecordRdata> Create(const base::StringPiece& data, |
| 47 const DnsRecordParser& parser); | 51 const DnsRecordParser& parser); |
| 48 | 52 |
| 53 virtual bool IsEqual(const RecordRdata* other) const OVERRIDE; |
| 54 virtual uint16 Type() const OVERRIDE; |
| 55 virtual scoped_ptr<const RecordRdata> Copy() const OVERRIDE; |
| 56 |
| 49 uint16 priority() const { return priority_; } | 57 uint16 priority() const { return priority_; } |
| 50 uint16 weight() const { return weight_; } | 58 uint16 weight() const { return weight_; } |
| 51 uint16 port() const { return port_; } | 59 uint16 port() const { return port_; } |
| 52 | 60 |
| 53 const std::string& target() const { return target_; } | 61 const std::string& target() const { return target_; } |
| 54 | 62 |
| 55 private: | 63 private: |
| 56 SrvRecordRdata(); | 64 SrvRecordRdata(); |
| 57 | 65 |
| 58 uint16 priority_; | 66 uint16 priority_; |
| 59 uint16 weight_; | 67 uint16 weight_; |
| 60 uint16 port_; | 68 uint16 port_; |
| 61 | 69 |
| 62 std::string target_; | 70 std::string target_; |
| 63 | 71 |
| 64 DISALLOW_COPY_AND_ASSIGN(SrvRecordRdata); | 72 DISALLOW_COPY_AND_ASSIGN(SrvRecordRdata); |
| 65 }; | 73 }; |
| 66 | 74 |
| 67 // A Record format (http://www.ietf.org/rfc/rfc1035.txt): | 75 // A Record format (http://www.ietf.org/rfc/rfc1035.txt): |
| 68 // 4 bytes for IP address. | 76 // 4 bytes for IP address. |
| 69 class NET_EXPORT_PRIVATE ARecordRdata : public RecordRdata { | 77 class NET_EXPORT_PRIVATE ARecordRdata : public RecordRdata { |
| 70 public: | 78 public: |
| 71 static const uint16 kType = dns_protocol::kTypeA; | 79 static const uint16 kType = dns_protocol::kTypeA; |
| 72 | 80 |
| 73 virtual ~ARecordRdata(); | 81 virtual ~ARecordRdata(); |
| 74 static scoped_ptr<ARecordRdata> Create(const base::StringPiece& data, | 82 static scoped_ptr<ARecordRdata> Create(const base::StringPiece& data, |
| 75 const DnsRecordParser& parser); | 83 const DnsRecordParser& parser); |
| 84 virtual bool IsEqual(const RecordRdata* other) const OVERRIDE; |
| 85 virtual uint16 Type() const OVERRIDE; |
| 86 virtual scoped_ptr<const RecordRdata> Copy() const OVERRIDE; |
| 76 | 87 |
| 77 const IPAddressNumber& address() const { return address_; } | 88 const IPAddressNumber& address() const { return address_; } |
| 78 | 89 |
| 79 private: | 90 private: |
| 80 ARecordRdata(); | 91 ARecordRdata(); |
| 81 | 92 |
| 82 IPAddressNumber address_; | 93 IPAddressNumber address_; |
| 83 | 94 |
| 84 DISALLOW_COPY_AND_ASSIGN(ARecordRdata); | 95 DISALLOW_COPY_AND_ASSIGN(ARecordRdata); |
| 85 }; | 96 }; |
| 86 | 97 |
| 98 // AAAA Record format (http://www.ietf.org/rfc/rfc1035.txt): |
| 99 // 16 bytes for IP address. |
| 100 class NET_EXPORT_PRIVATE AAAARecordRdata : public RecordRdata { |
| 101 public: |
| 102 static const uint16 kType = dns_protocol::kTypeAAAA; |
| 103 |
| 104 virtual ~AAAARecordRdata(); |
| 105 static scoped_ptr<AAAARecordRdata> Create(const base::StringPiece& data, |
| 106 const DnsRecordParser& parser); |
| 107 virtual bool IsEqual(const RecordRdata* other) const OVERRIDE; |
| 108 virtual uint16 Type() const OVERRIDE; |
| 109 virtual scoped_ptr<const RecordRdata> Copy() const OVERRIDE; |
| 110 |
| 111 const IPAddressNumber& address() const { return address_; } |
| 112 |
| 113 private: |
| 114 AAAARecordRdata(); |
| 115 |
| 116 IPAddressNumber address_; |
| 117 |
| 118 DISALLOW_COPY_AND_ASSIGN(AAAARecordRdata); |
| 119 }; |
| 120 |
| 87 // CNAME record format (http://www.ietf.org/rfc/rfc1035.txt): | 121 // CNAME record format (http://www.ietf.org/rfc/rfc1035.txt): |
| 88 // cname: On the wire representation of domain name. | 122 // cname: On the wire representation of domain name. |
| 89 class NET_EXPORT_PRIVATE CnameRecordRdata : public RecordRdata { | 123 class NET_EXPORT_PRIVATE CnameRecordRdata : public RecordRdata { |
| 90 public: | 124 public: |
| 91 static const uint16 kType = dns_protocol::kTypeCNAME; | 125 static const uint16 kType = dns_protocol::kTypeCNAME; |
| 92 | 126 |
| 93 virtual ~CnameRecordRdata(); | 127 virtual ~CnameRecordRdata(); |
| 94 static scoped_ptr<CnameRecordRdata> Create(const base::StringPiece& data, | 128 static scoped_ptr<CnameRecordRdata> Create(const base::StringPiece& data, |
| 95 const DnsRecordParser& parser); | 129 const DnsRecordParser& parser); |
| 130 virtual bool IsEqual(const RecordRdata* other) const OVERRIDE; |
| 131 virtual uint16 Type() const OVERRIDE; |
| 132 virtual scoped_ptr<const RecordRdata> Copy() const OVERRIDE; |
| 96 | 133 |
| 97 std::string cname() const { return cname_; } | 134 std::string cname() const { return cname_; } |
| 98 | 135 |
| 99 private: | 136 private: |
| 100 CnameRecordRdata(); | 137 CnameRecordRdata(); |
| 101 | 138 |
| 102 std::string cname_; | 139 std::string cname_; |
| 103 | 140 |
| 104 DISALLOW_COPY_AND_ASSIGN(CnameRecordRdata); | 141 DISALLOW_COPY_AND_ASSIGN(CnameRecordRdata); |
| 105 }; | 142 }; |
| 106 | 143 |
| 107 // PTR record format (http://www.ietf.org/rfc/rfc1035.txt): | 144 // PTR record format (http://www.ietf.org/rfc/rfc1035.txt): |
| 108 // domain: On the wire representation of domain name. | 145 // domain: On the wire representation of domain name. |
| 109 class NET_EXPORT_PRIVATE PtrRecordRdata : public RecordRdata { | 146 class NET_EXPORT_PRIVATE PtrRecordRdata : public RecordRdata { |
| 110 public: | 147 public: |
| 111 static const uint16 kType = dns_protocol::kTypePTR; | 148 static const uint16 kType = dns_protocol::kTypePTR; |
| 112 | 149 |
| 113 virtual ~PtrRecordRdata(); | 150 virtual ~PtrRecordRdata(); |
| 114 static scoped_ptr<PtrRecordRdata> Create(const base::StringPiece& data, | 151 static scoped_ptr<PtrRecordRdata> Create(const base::StringPiece& data, |
| 115 const DnsRecordParser& parser); | 152 const DnsRecordParser& parser); |
| 153 virtual bool IsEqual(const RecordRdata* other) const OVERRIDE; |
| 154 virtual uint16 Type() const OVERRIDE; |
| 155 virtual scoped_ptr<const RecordRdata> Copy() const OVERRIDE; |
| 116 | 156 |
| 117 std::string ptrdomain() const { return ptrdomain_; } | 157 std::string ptrdomain() const { return ptrdomain_; } |
| 118 | 158 |
| 119 private: | 159 private: |
| 120 PtrRecordRdata(); | 160 PtrRecordRdata(); |
| 121 | 161 |
| 122 std::string ptrdomain_; | 162 std::string ptrdomain_; |
| 123 | 163 |
| 124 DISALLOW_COPY_AND_ASSIGN(PtrRecordRdata); | 164 DISALLOW_COPY_AND_ASSIGN(PtrRecordRdata); |
| 125 }; | 165 }; |
| 126 | 166 |
| 127 // TXT record format (http://www.ietf.org/rfc/rfc1035.txt): | 167 // TXT record format (http://www.ietf.org/rfc/rfc1035.txt): |
| 128 // texts: One or more <character-string>s. | 168 // texts: One or more <character-string>s. |
| 129 // a <character-string> is a length octet followed by as many characters. | 169 // a <character-string> is a length octet followed by as many characters. |
| 130 class NET_EXPORT_PRIVATE TxtRecordRdata : public RecordRdata { | 170 class NET_EXPORT_PRIVATE TxtRecordRdata : public RecordRdata { |
| 131 public: | 171 public: |
| 132 static const uint16 kType = dns_protocol::kTypeTXT; | 172 static const uint16 kType = dns_protocol::kTypeTXT; |
| 133 | 173 |
| 134 virtual ~TxtRecordRdata(); | 174 virtual ~TxtRecordRdata(); |
| 135 static scoped_ptr<TxtRecordRdata> Create(const base::StringPiece& data, | 175 static scoped_ptr<TxtRecordRdata> Create(const base::StringPiece& data, |
| 136 const DnsRecordParser& parser); | 176 const DnsRecordParser& parser); |
| 177 virtual bool IsEqual(const RecordRdata* other) const OVERRIDE; |
| 178 virtual uint16 Type() const OVERRIDE; |
| 179 virtual scoped_ptr<const RecordRdata> Copy() const OVERRIDE; |
| 137 | 180 |
| 138 const std::vector<std::string>& texts() const { return texts_; } | 181 const std::vector<std::string>& texts() const { return texts_; } |
| 139 | 182 |
| 140 private: | 183 private: |
| 141 TxtRecordRdata(); | 184 TxtRecordRdata(); |
| 142 | 185 |
| 143 std::vector<std::string> texts_; | 186 std::vector<std::string> texts_; |
| 144 | 187 |
| 145 DISALLOW_COPY_AND_ASSIGN(TxtRecordRdata); | 188 DISALLOW_COPY_AND_ASSIGN(TxtRecordRdata); |
| 146 }; | 189 }; |
| 147 } | 190 } |
| 148 | 191 |
| 149 #endif // NET_DNS_RECORD_RDATA_H_ | 192 #endif // NET_DNS_RECORD_RDATA_H_ |
| OLD | NEW |