| 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 |
| 30 protected: | 33 protected: |
| 31 RecordRdata(); | 34 RecordRdata(); |
| 32 | 35 |
| 33 DISALLOW_COPY_AND_ASSIGN(RecordRdata); | 36 DISALLOW_COPY_AND_ASSIGN(RecordRdata); |
| 34 }; | 37 }; |
| 35 | 38 |
| 36 // SRV record format (http://www.ietf.org/rfc/rfc2782.txt): | 39 // SRV record format (http://www.ietf.org/rfc/rfc2782.txt): |
| 37 // 2 bytes network-order unsigned priority | 40 // 2 bytes network-order unsigned priority |
| 38 // 2 bytes network-order unsigned weight | 41 // 2 bytes network-order unsigned weight |
| 39 // 2 bytes network-order unsigned port | 42 // 2 bytes network-order unsigned port |
| 40 // target: domain name (on-the-wire representation) | 43 // target: domain name (on-the-wire representation) |
| 41 class NET_EXPORT_PRIVATE SrvRecordRdata : public RecordRdata { | 44 class NET_EXPORT_PRIVATE SrvRecordRdata : public RecordRdata { |
| 42 public: | 45 public: |
| 43 static const uint16 kType = dns_protocol::kTypeSRV; | 46 static const uint16 kType = dns_protocol::kTypeSRV; |
| 44 | 47 |
| 45 virtual ~SrvRecordRdata(); | 48 virtual ~SrvRecordRdata(); |
| 46 static scoped_ptr<SrvRecordRdata> Create(const base::StringPiece& data, | 49 static scoped_ptr<SrvRecordRdata> Create(const base::StringPiece& data, |
| 47 const DnsRecordParser& parser); | 50 const DnsRecordParser& parser); |
| 48 | 51 |
| 52 virtual bool IsEqual(const RecordRdata* other) const OVERRIDE; |
| 53 virtual uint16 Type() const OVERRIDE; |
| 54 |
| 49 uint16 priority() const { return priority_; } | 55 uint16 priority() const { return priority_; } |
| 50 uint16 weight() const { return weight_; } | 56 uint16 weight() const { return weight_; } |
| 51 uint16 port() const { return port_; } | 57 uint16 port() const { return port_; } |
| 52 | 58 |
| 53 const std::string& target() const { return target_; } | 59 const std::string& target() const { return target_; } |
| 54 | 60 |
| 55 private: | 61 private: |
| 56 SrvRecordRdata(); | 62 SrvRecordRdata(); |
| 57 | 63 |
| 58 uint16 priority_; | 64 uint16 priority_; |
| 59 uint16 weight_; | 65 uint16 weight_; |
| 60 uint16 port_; | 66 uint16 port_; |
| 61 | 67 |
| 62 std::string target_; | 68 std::string target_; |
| 63 | 69 |
| 64 DISALLOW_COPY_AND_ASSIGN(SrvRecordRdata); | 70 DISALLOW_COPY_AND_ASSIGN(SrvRecordRdata); |
| 65 }; | 71 }; |
| 66 | 72 |
| 67 // A Record format (http://www.ietf.org/rfc/rfc1035.txt): | 73 // A Record format (http://www.ietf.org/rfc/rfc1035.txt): |
| 68 // 4 bytes for IP address. | 74 // 4 bytes for IP address. |
| 69 class NET_EXPORT_PRIVATE ARecordRdata : public RecordRdata { | 75 class NET_EXPORT_PRIVATE ARecordRdata : public RecordRdata { |
| 70 public: | 76 public: |
| 71 static const uint16 kType = dns_protocol::kTypeA; | 77 static const uint16 kType = dns_protocol::kTypeA; |
| 72 | 78 |
| 73 virtual ~ARecordRdata(); | 79 virtual ~ARecordRdata(); |
| 74 static scoped_ptr<ARecordRdata> Create(const base::StringPiece& data, | 80 static scoped_ptr<ARecordRdata> Create(const base::StringPiece& data, |
| 75 const DnsRecordParser& parser); | 81 const DnsRecordParser& parser); |
| 82 virtual bool IsEqual(const RecordRdata* other) const OVERRIDE; |
| 83 virtual uint16 Type() const OVERRIDE; |
| 76 | 84 |
| 77 const IPAddressNumber& address() const { return address_; } | 85 const IPAddressNumber& address() const { return address_; } |
| 78 | 86 |
| 79 private: | 87 private: |
| 80 ARecordRdata(); | 88 ARecordRdata(); |
| 81 | 89 |
| 82 IPAddressNumber address_; | 90 IPAddressNumber address_; |
| 83 | 91 |
| 84 DISALLOW_COPY_AND_ASSIGN(ARecordRdata); | 92 DISALLOW_COPY_AND_ASSIGN(ARecordRdata); |
| 85 }; | 93 }; |
| 86 | 94 |
| 95 // AAAA Record format (http://www.ietf.org/rfc/rfc1035.txt): |
| 96 // 16 bytes for IP address. |
| 97 class NET_EXPORT_PRIVATE AAAARecordRdata : public RecordRdata { |
| 98 public: |
| 99 static const uint16 kType = dns_protocol::kTypeAAAA; |
| 100 |
| 101 virtual ~AAAARecordRdata(); |
| 102 static scoped_ptr<AAAARecordRdata> Create(const base::StringPiece& data, |
| 103 const DnsRecordParser& parser); |
| 104 virtual bool IsEqual(const RecordRdata* other) const OVERRIDE; |
| 105 virtual uint16 Type() const OVERRIDE; |
| 106 |
| 107 const IPAddressNumber& address() const { return address_; } |
| 108 |
| 109 private: |
| 110 AAAARecordRdata(); |
| 111 |
| 112 IPAddressNumber address_; |
| 113 |
| 114 DISALLOW_COPY_AND_ASSIGN(AAAARecordRdata); |
| 115 }; |
| 116 |
| 87 // CNAME record format (http://www.ietf.org/rfc/rfc1035.txt): | 117 // CNAME record format (http://www.ietf.org/rfc/rfc1035.txt): |
| 88 // cname: On the wire representation of domain name. | 118 // cname: On the wire representation of domain name. |
| 89 class NET_EXPORT_PRIVATE CnameRecordRdata : public RecordRdata { | 119 class NET_EXPORT_PRIVATE CnameRecordRdata : public RecordRdata { |
| 90 public: | 120 public: |
| 91 static const uint16 kType = dns_protocol::kTypeCNAME; | 121 static const uint16 kType = dns_protocol::kTypeCNAME; |
| 92 | 122 |
| 93 virtual ~CnameRecordRdata(); | 123 virtual ~CnameRecordRdata(); |
| 94 static scoped_ptr<CnameRecordRdata> Create(const base::StringPiece& data, | 124 static scoped_ptr<CnameRecordRdata> Create(const base::StringPiece& data, |
| 95 const DnsRecordParser& parser); | 125 const DnsRecordParser& parser); |
| 126 virtual bool IsEqual(const RecordRdata* other) const OVERRIDE; |
| 127 virtual uint16 Type() const OVERRIDE; |
| 96 | 128 |
| 97 std::string cname() const { return cname_; } | 129 std::string cname() const { return cname_; } |
| 98 | 130 |
| 99 private: | 131 private: |
| 100 CnameRecordRdata(); | 132 CnameRecordRdata(); |
| 101 | 133 |
| 102 std::string cname_; | 134 std::string cname_; |
| 103 | 135 |
| 104 DISALLOW_COPY_AND_ASSIGN(CnameRecordRdata); | 136 DISALLOW_COPY_AND_ASSIGN(CnameRecordRdata); |
| 105 }; | 137 }; |
| 106 | 138 |
| 107 // PTR record format (http://www.ietf.org/rfc/rfc1035.txt): | 139 // PTR record format (http://www.ietf.org/rfc/rfc1035.txt): |
| 108 // domain: On the wire representation of domain name. | 140 // domain: On the wire representation of domain name. |
| 109 class NET_EXPORT_PRIVATE PtrRecordRdata : public RecordRdata { | 141 class NET_EXPORT_PRIVATE PtrRecordRdata : public RecordRdata { |
| 110 public: | 142 public: |
| 111 static const uint16 kType = dns_protocol::kTypePTR; | 143 static const uint16 kType = dns_protocol::kTypePTR; |
| 112 | 144 |
| 113 virtual ~PtrRecordRdata(); | 145 virtual ~PtrRecordRdata(); |
| 114 static scoped_ptr<PtrRecordRdata> Create(const base::StringPiece& data, | 146 static scoped_ptr<PtrRecordRdata> Create(const base::StringPiece& data, |
| 115 const DnsRecordParser& parser); | 147 const DnsRecordParser& parser); |
| 148 virtual bool IsEqual(const RecordRdata* other) const OVERRIDE; |
| 149 virtual uint16 Type() const OVERRIDE; |
| 116 | 150 |
| 117 std::string ptrdomain() const { return ptrdomain_; } | 151 std::string ptrdomain() const { return ptrdomain_; } |
| 118 | 152 |
| 119 private: | 153 private: |
| 120 PtrRecordRdata(); | 154 PtrRecordRdata(); |
| 121 | 155 |
| 122 std::string ptrdomain_; | 156 std::string ptrdomain_; |
| 123 | 157 |
| 124 DISALLOW_COPY_AND_ASSIGN(PtrRecordRdata); | 158 DISALLOW_COPY_AND_ASSIGN(PtrRecordRdata); |
| 125 }; | 159 }; |
| 126 | 160 |
| 127 // TXT record format (http://www.ietf.org/rfc/rfc1035.txt): | 161 // TXT record format (http://www.ietf.org/rfc/rfc1035.txt): |
| 128 // texts: One or more <character-string>s. | 162 // texts: One or more <character-string>s. |
| 129 // a <character-string> is a length octet followed by as many characters. | 163 // a <character-string> is a length octet followed by as many characters. |
| 130 class NET_EXPORT_PRIVATE TxtRecordRdata : public RecordRdata { | 164 class NET_EXPORT_PRIVATE TxtRecordRdata : public RecordRdata { |
| 131 public: | 165 public: |
| 132 static const uint16 kType = dns_protocol::kTypeTXT; | 166 static const uint16 kType = dns_protocol::kTypeTXT; |
| 133 | 167 |
| 134 virtual ~TxtRecordRdata(); | 168 virtual ~TxtRecordRdata(); |
| 135 static scoped_ptr<TxtRecordRdata> Create(const base::StringPiece& data, | 169 static scoped_ptr<TxtRecordRdata> Create(const base::StringPiece& data, |
| 136 const DnsRecordParser& parser); | 170 const DnsRecordParser& parser); |
| 171 virtual bool IsEqual(const RecordRdata* other) const OVERRIDE; |
| 172 virtual uint16 Type() const OVERRIDE; |
| 137 | 173 |
| 138 const std::vector<std::string>& texts() const { return texts_; } | 174 const std::vector<std::string>& texts() const { return texts_; } |
| 139 | 175 |
| 140 private: | 176 private: |
| 141 TxtRecordRdata(); | 177 TxtRecordRdata(); |
| 142 | 178 |
| 143 std::vector<std::string> texts_; | 179 std::vector<std::string> texts_; |
| 144 | 180 |
| 145 DISALLOW_COPY_AND_ASSIGN(TxtRecordRdata); | 181 DISALLOW_COPY_AND_ASSIGN(TxtRecordRdata); |
| 146 }; | 182 }; |
| 147 } | 183 |
| 184 } // namespace net |
| 148 | 185 |
| 149 #endif // NET_DNS_RECORD_RDATA_H_ | 186 #endif // NET_DNS_RECORD_RDATA_H_ |
| OLD | NEW |