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 <stdint.h> |
| 9 |
8 #include <string> | 10 #include <string> |
9 #include <vector> | 11 #include <vector> |
10 | 12 |
11 #include "base/basictypes.h" | |
12 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/macros.h" |
13 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
14 #include "base/strings/string_piece.h" | 16 #include "base/strings/string_piece.h" |
15 #include "net/base/ip_address_number.h" | 17 #include "net/base/ip_address_number.h" |
16 #include "net/base/net_export.h" | 18 #include "net/base/net_export.h" |
17 #include "net/dns/dns_protocol.h" | 19 #include "net/dns/dns_protocol.h" |
18 | 20 |
19 namespace net { | 21 namespace net { |
20 | 22 |
21 class DnsRecordParser; | 23 class DnsRecordParser; |
22 | 24 |
23 // Parsed represenation of the extra data in a record. Does not include standard | 25 // Parsed represenation of the extra data in a record. Does not include standard |
24 // DNS record data such as TTL, Name, Type and Class. | 26 // DNS record data such as TTL, Name, Type and Class. |
25 class NET_EXPORT_PRIVATE RecordRdata { | 27 class NET_EXPORT_PRIVATE RecordRdata { |
26 public: | 28 public: |
27 virtual ~RecordRdata() {} | 29 virtual ~RecordRdata() {} |
28 | 30 |
29 virtual bool IsEqual(const RecordRdata* other) const = 0; | 31 virtual bool IsEqual(const RecordRdata* other) const = 0; |
30 virtual uint16 Type() const = 0; | 32 virtual uint16_t Type() const = 0; |
31 | 33 |
32 protected: | 34 protected: |
33 RecordRdata(); | 35 RecordRdata(); |
34 | 36 |
35 DISALLOW_COPY_AND_ASSIGN(RecordRdata); | 37 DISALLOW_COPY_AND_ASSIGN(RecordRdata); |
36 }; | 38 }; |
37 | 39 |
38 // SRV record format (http://www.ietf.org/rfc/rfc2782.txt): | 40 // SRV record format (http://www.ietf.org/rfc/rfc2782.txt): |
39 // 2 bytes network-order unsigned priority | 41 // 2 bytes network-order unsigned priority |
40 // 2 bytes network-order unsigned weight | 42 // 2 bytes network-order unsigned weight |
41 // 2 bytes network-order unsigned port | 43 // 2 bytes network-order unsigned port |
42 // target: domain name (on-the-wire representation) | 44 // target: domain name (on-the-wire representation) |
43 class NET_EXPORT_PRIVATE SrvRecordRdata : public RecordRdata { | 45 class NET_EXPORT_PRIVATE SrvRecordRdata : public RecordRdata { |
44 public: | 46 public: |
45 static const uint16 kType = dns_protocol::kTypeSRV; | 47 static const uint16_t kType = dns_protocol::kTypeSRV; |
46 | 48 |
47 ~SrvRecordRdata() override; | 49 ~SrvRecordRdata() override; |
48 static scoped_ptr<SrvRecordRdata> Create(const base::StringPiece& data, | 50 static scoped_ptr<SrvRecordRdata> Create(const base::StringPiece& data, |
49 const DnsRecordParser& parser); | 51 const DnsRecordParser& parser); |
50 | 52 |
51 bool IsEqual(const RecordRdata* other) const override; | 53 bool IsEqual(const RecordRdata* other) const override; |
52 uint16 Type() const override; | 54 uint16_t Type() const override; |
53 | 55 |
54 uint16 priority() const { return priority_; } | 56 uint16_t priority() const { return priority_; } |
55 uint16 weight() const { return weight_; } | 57 uint16_t weight() const { return weight_; } |
56 uint16 port() const { return port_; } | 58 uint16_t port() const { return port_; } |
57 | 59 |
58 const std::string& target() const { return target_; } | 60 const std::string& target() const { return target_; } |
59 | 61 |
60 private: | 62 private: |
61 SrvRecordRdata(); | 63 SrvRecordRdata(); |
62 | 64 |
63 uint16 priority_; | 65 uint16_t priority_; |
64 uint16 weight_; | 66 uint16_t weight_; |
65 uint16 port_; | 67 uint16_t port_; |
66 | 68 |
67 std::string target_; | 69 std::string target_; |
68 | 70 |
69 DISALLOW_COPY_AND_ASSIGN(SrvRecordRdata); | 71 DISALLOW_COPY_AND_ASSIGN(SrvRecordRdata); |
70 }; | 72 }; |
71 | 73 |
72 // A Record format (http://www.ietf.org/rfc/rfc1035.txt): | 74 // A Record format (http://www.ietf.org/rfc/rfc1035.txt): |
73 // 4 bytes for IP address. | 75 // 4 bytes for IP address. |
74 class NET_EXPORT_PRIVATE ARecordRdata : public RecordRdata { | 76 class NET_EXPORT_PRIVATE ARecordRdata : public RecordRdata { |
75 public: | 77 public: |
76 static const uint16 kType = dns_protocol::kTypeA; | 78 static const uint16_t kType = dns_protocol::kTypeA; |
77 | 79 |
78 ~ARecordRdata() override; | 80 ~ARecordRdata() override; |
79 static scoped_ptr<ARecordRdata> Create(const base::StringPiece& data, | 81 static scoped_ptr<ARecordRdata> Create(const base::StringPiece& data, |
80 const DnsRecordParser& parser); | 82 const DnsRecordParser& parser); |
81 bool IsEqual(const RecordRdata* other) const override; | 83 bool IsEqual(const RecordRdata* other) const override; |
82 uint16 Type() const override; | 84 uint16_t Type() const override; |
83 | 85 |
84 const IPAddressNumber& address() const { return address_; } | 86 const IPAddressNumber& address() const { return address_; } |
85 | 87 |
86 private: | 88 private: |
87 ARecordRdata(); | 89 ARecordRdata(); |
88 | 90 |
89 IPAddressNumber address_; | 91 IPAddressNumber address_; |
90 | 92 |
91 DISALLOW_COPY_AND_ASSIGN(ARecordRdata); | 93 DISALLOW_COPY_AND_ASSIGN(ARecordRdata); |
92 }; | 94 }; |
93 | 95 |
94 // AAAA Record format (http://www.ietf.org/rfc/rfc1035.txt): | 96 // AAAA Record format (http://www.ietf.org/rfc/rfc1035.txt): |
95 // 16 bytes for IP address. | 97 // 16 bytes for IP address. |
96 class NET_EXPORT_PRIVATE AAAARecordRdata : public RecordRdata { | 98 class NET_EXPORT_PRIVATE AAAARecordRdata : public RecordRdata { |
97 public: | 99 public: |
98 static const uint16 kType = dns_protocol::kTypeAAAA; | 100 static const uint16_t kType = dns_protocol::kTypeAAAA; |
99 | 101 |
100 ~AAAARecordRdata() override; | 102 ~AAAARecordRdata() override; |
101 static scoped_ptr<AAAARecordRdata> Create(const base::StringPiece& data, | 103 static scoped_ptr<AAAARecordRdata> Create(const base::StringPiece& data, |
102 const DnsRecordParser& parser); | 104 const DnsRecordParser& parser); |
103 bool IsEqual(const RecordRdata* other) const override; | 105 bool IsEqual(const RecordRdata* other) const override; |
104 uint16 Type() const override; | 106 uint16_t Type() const override; |
105 | 107 |
106 const IPAddressNumber& address() const { return address_; } | 108 const IPAddressNumber& address() const { return address_; } |
107 | 109 |
108 private: | 110 private: |
109 AAAARecordRdata(); | 111 AAAARecordRdata(); |
110 | 112 |
111 IPAddressNumber address_; | 113 IPAddressNumber address_; |
112 | 114 |
113 DISALLOW_COPY_AND_ASSIGN(AAAARecordRdata); | 115 DISALLOW_COPY_AND_ASSIGN(AAAARecordRdata); |
114 }; | 116 }; |
115 | 117 |
116 // CNAME record format (http://www.ietf.org/rfc/rfc1035.txt): | 118 // CNAME record format (http://www.ietf.org/rfc/rfc1035.txt): |
117 // cname: On the wire representation of domain name. | 119 // cname: On the wire representation of domain name. |
118 class NET_EXPORT_PRIVATE CnameRecordRdata : public RecordRdata { | 120 class NET_EXPORT_PRIVATE CnameRecordRdata : public RecordRdata { |
119 public: | 121 public: |
120 static const uint16 kType = dns_protocol::kTypeCNAME; | 122 static const uint16_t kType = dns_protocol::kTypeCNAME; |
121 | 123 |
122 ~CnameRecordRdata() override; | 124 ~CnameRecordRdata() override; |
123 static scoped_ptr<CnameRecordRdata> Create(const base::StringPiece& data, | 125 static scoped_ptr<CnameRecordRdata> Create(const base::StringPiece& data, |
124 const DnsRecordParser& parser); | 126 const DnsRecordParser& parser); |
125 bool IsEqual(const RecordRdata* other) const override; | 127 bool IsEqual(const RecordRdata* other) const override; |
126 uint16 Type() const override; | 128 uint16_t Type() const override; |
127 | 129 |
128 std::string cname() const { return cname_; } | 130 std::string cname() const { return cname_; } |
129 | 131 |
130 private: | 132 private: |
131 CnameRecordRdata(); | 133 CnameRecordRdata(); |
132 | 134 |
133 std::string cname_; | 135 std::string cname_; |
134 | 136 |
135 DISALLOW_COPY_AND_ASSIGN(CnameRecordRdata); | 137 DISALLOW_COPY_AND_ASSIGN(CnameRecordRdata); |
136 }; | 138 }; |
137 | 139 |
138 // PTR record format (http://www.ietf.org/rfc/rfc1035.txt): | 140 // PTR record format (http://www.ietf.org/rfc/rfc1035.txt): |
139 // domain: On the wire representation of domain name. | 141 // domain: On the wire representation of domain name. |
140 class NET_EXPORT_PRIVATE PtrRecordRdata : public RecordRdata { | 142 class NET_EXPORT_PRIVATE PtrRecordRdata : public RecordRdata { |
141 public: | 143 public: |
142 static const uint16 kType = dns_protocol::kTypePTR; | 144 static const uint16_t kType = dns_protocol::kTypePTR; |
143 | 145 |
144 ~PtrRecordRdata() override; | 146 ~PtrRecordRdata() override; |
145 static scoped_ptr<PtrRecordRdata> Create(const base::StringPiece& data, | 147 static scoped_ptr<PtrRecordRdata> Create(const base::StringPiece& data, |
146 const DnsRecordParser& parser); | 148 const DnsRecordParser& parser); |
147 bool IsEqual(const RecordRdata* other) const override; | 149 bool IsEqual(const RecordRdata* other) const override; |
148 uint16 Type() const override; | 150 uint16_t Type() const override; |
149 | 151 |
150 std::string ptrdomain() const { return ptrdomain_; } | 152 std::string ptrdomain() const { return ptrdomain_; } |
151 | 153 |
152 private: | 154 private: |
153 PtrRecordRdata(); | 155 PtrRecordRdata(); |
154 | 156 |
155 std::string ptrdomain_; | 157 std::string ptrdomain_; |
156 | 158 |
157 DISALLOW_COPY_AND_ASSIGN(PtrRecordRdata); | 159 DISALLOW_COPY_AND_ASSIGN(PtrRecordRdata); |
158 }; | 160 }; |
159 | 161 |
160 // TXT record format (http://www.ietf.org/rfc/rfc1035.txt): | 162 // TXT record format (http://www.ietf.org/rfc/rfc1035.txt): |
161 // texts: One or more <character-string>s. | 163 // texts: One or more <character-string>s. |
162 // a <character-string> is a length octet followed by as many characters. | 164 // a <character-string> is a length octet followed by as many characters. |
163 class NET_EXPORT_PRIVATE TxtRecordRdata : public RecordRdata { | 165 class NET_EXPORT_PRIVATE TxtRecordRdata : public RecordRdata { |
164 public: | 166 public: |
165 static const uint16 kType = dns_protocol::kTypeTXT; | 167 static const uint16_t kType = dns_protocol::kTypeTXT; |
166 | 168 |
167 ~TxtRecordRdata() override; | 169 ~TxtRecordRdata() override; |
168 static scoped_ptr<TxtRecordRdata> Create(const base::StringPiece& data, | 170 static scoped_ptr<TxtRecordRdata> Create(const base::StringPiece& data, |
169 const DnsRecordParser& parser); | 171 const DnsRecordParser& parser); |
170 bool IsEqual(const RecordRdata* other) const override; | 172 bool IsEqual(const RecordRdata* other) const override; |
171 uint16 Type() const override; | 173 uint16_t Type() const override; |
172 | 174 |
173 const std::vector<std::string>& texts() const { return texts_; } | 175 const std::vector<std::string>& texts() const { return texts_; } |
174 | 176 |
175 private: | 177 private: |
176 TxtRecordRdata(); | 178 TxtRecordRdata(); |
177 | 179 |
178 std::vector<std::string> texts_; | 180 std::vector<std::string> texts_; |
179 | 181 |
180 DISALLOW_COPY_AND_ASSIGN(TxtRecordRdata); | 182 DISALLOW_COPY_AND_ASSIGN(TxtRecordRdata); |
181 }; | 183 }; |
182 | 184 |
183 // Only the subset of the NSEC record format required by mDNS is supported. | 185 // Only the subset of the NSEC record format required by mDNS is supported. |
184 // Nsec record format is described in http://www.ietf.org/rfc/rfc3845.txt and | 186 // Nsec record format is described in http://www.ietf.org/rfc/rfc3845.txt and |
185 // the limited version required for mDNS described in | 187 // the limited version required for mDNS described in |
186 // http://www.rfc-editor.org/rfc/rfc6762.txt Section 6.1. | 188 // http://www.rfc-editor.org/rfc/rfc6762.txt Section 6.1. |
187 class NET_EXPORT_PRIVATE NsecRecordRdata : public RecordRdata { | 189 class NET_EXPORT_PRIVATE NsecRecordRdata : public RecordRdata { |
188 public: | 190 public: |
189 static const uint16 kType = dns_protocol::kTypeNSEC; | 191 static const uint16_t kType = dns_protocol::kTypeNSEC; |
190 | 192 |
191 ~NsecRecordRdata() override; | 193 ~NsecRecordRdata() override; |
192 static scoped_ptr<NsecRecordRdata> Create(const base::StringPiece& data, | 194 static scoped_ptr<NsecRecordRdata> Create(const base::StringPiece& data, |
193 const DnsRecordParser& parser); | 195 const DnsRecordParser& parser); |
194 bool IsEqual(const RecordRdata* other) const override; | 196 bool IsEqual(const RecordRdata* other) const override; |
195 uint16 Type() const override; | 197 uint16_t Type() const override; |
196 | 198 |
197 // Length of the bitmap in bits. | 199 // Length of the bitmap in bits. |
198 unsigned bitmap_length() const { return bitmap_.size() * 8; } | 200 unsigned bitmap_length() const { return bitmap_.size() * 8; } |
199 | 201 |
200 // Returns bit i-th bit in the bitmap, where bits withing a byte are organized | 202 // Returns bit i-th bit in the bitmap, where bits withing a byte are organized |
201 // most to least significant. If it is set, a record with rrtype i exists for | 203 // most to least significant. If it is set, a record with rrtype i exists for |
202 // the domain name of this nsec record. | 204 // the domain name of this nsec record. |
203 bool GetBit(unsigned i) const; | 205 bool GetBit(unsigned i) const; |
204 | 206 |
205 private: | 207 private: |
206 NsecRecordRdata(); | 208 NsecRecordRdata(); |
207 | 209 |
208 std::vector<uint8> bitmap_; | 210 std::vector<uint8_t> bitmap_; |
209 | 211 |
210 DISALLOW_COPY_AND_ASSIGN(NsecRecordRdata); | 212 DISALLOW_COPY_AND_ASSIGN(NsecRecordRdata); |
211 }; | 213 }; |
212 | 214 |
213 | 215 |
214 } // namespace net | 216 } // namespace net |
215 | 217 |
216 #endif // NET_DNS_RECORD_RDATA_H_ | 218 #endif // NET_DNS_RECORD_RDATA_H_ |
OLD | NEW |