| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_DNS_RESPONSE_H_ | 5 #ifndef NET_DNS_DNS_RESPONSE_H_ |
| 6 #define NET_DNS_DNS_RESPONSE_H_ | 6 #define NET_DNS_DNS_RESPONSE_H_ |
| 7 | 7 |
| 8 #include <stdint.h> |
| 9 |
| 8 #include <string> | 10 #include <string> |
| 9 | 11 |
| 10 #include "base/basictypes.h" | 12 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 12 #include "base/strings/string_piece.h" | 14 #include "base/strings/string_piece.h" |
| 13 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 14 #include "net/base/net_export.h" | 16 #include "net/base/net_export.h" |
| 15 | 17 |
| 16 namespace net { | 18 namespace net { |
| 17 | 19 |
| 18 class AddressList; | 20 class AddressList; |
| 19 class DnsQuery; | 21 class DnsQuery; |
| 20 class IOBufferWithSize; | 22 class IOBufferWithSize; |
| 21 | 23 |
| 22 namespace dns_protocol { | 24 namespace dns_protocol { |
| 23 struct Header; | 25 struct Header; |
| 24 } | 26 } |
| 25 | 27 |
| 26 // Parsed resource record. | 28 // Parsed resource record. |
| 27 struct NET_EXPORT_PRIVATE DnsResourceRecord { | 29 struct NET_EXPORT_PRIVATE DnsResourceRecord { |
| 28 DnsResourceRecord(); | 30 DnsResourceRecord(); |
| 29 ~DnsResourceRecord(); | 31 ~DnsResourceRecord(); |
| 30 | 32 |
| 31 std::string name; // in dotted form | 33 std::string name; // in dotted form |
| 32 uint16 type; | 34 uint16_t type; |
| 33 uint16 klass; | 35 uint16_t klass; |
| 34 uint32 ttl; | 36 uint32_t ttl; |
| 35 base::StringPiece rdata; // points to the original response buffer | 37 base::StringPiece rdata; // points to the original response buffer |
| 36 }; | 38 }; |
| 37 | 39 |
| 38 // Iterator to walk over resource records of the DNS response packet. | 40 // Iterator to walk over resource records of the DNS response packet. |
| 39 class NET_EXPORT_PRIVATE DnsRecordParser { | 41 class NET_EXPORT_PRIVATE DnsRecordParser { |
| 40 public: | 42 public: |
| 41 // Construct an uninitialized iterator. | 43 // Construct an uninitialized iterator. |
| 42 DnsRecordParser(); | 44 DnsRecordParser(); |
| 43 | 45 |
| 44 // Construct an iterator to process the |packet| of given |length|. | 46 // Construct an iterator to process the |packet| of given |length|. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 // Assuming the internal buffer holds |nbytes| bytes, initialize the parser | 122 // Assuming the internal buffer holds |nbytes| bytes, initialize the parser |
| 121 // without matching it against an existing query. | 123 // without matching it against an existing query. |
| 122 bool InitParseWithoutQuery(int nbytes); | 124 bool InitParseWithoutQuery(int nbytes); |
| 123 | 125 |
| 124 // Returns true if response is valid, that is, after successful InitParse. | 126 // Returns true if response is valid, that is, after successful InitParse. |
| 125 bool IsValid() const; | 127 bool IsValid() const; |
| 126 | 128 |
| 127 // All of the methods below are valid only if the response is valid. | 129 // All of the methods below are valid only if the response is valid. |
| 128 | 130 |
| 129 // Accessors for the header. | 131 // Accessors for the header. |
| 130 uint16 flags() const; // excluding rcode | 132 uint16_t flags() const; // excluding rcode |
| 131 uint8 rcode() const; | 133 uint8_t rcode() const; |
| 132 | 134 |
| 133 unsigned answer_count() const; | 135 unsigned answer_count() const; |
| 134 unsigned additional_answer_count() const; | 136 unsigned additional_answer_count() const; |
| 135 | 137 |
| 136 // Accessors to the question. The qname is unparsed. | 138 // Accessors to the question. The qname is unparsed. |
| 137 base::StringPiece qname() const; | 139 base::StringPiece qname() const; |
| 138 uint16 qtype() const; | 140 uint16_t qtype() const; |
| 139 | 141 |
| 140 // Returns qname in dotted format. | 142 // Returns qname in dotted format. |
| 141 std::string GetDottedName() const; | 143 std::string GetDottedName() const; |
| 142 | 144 |
| 143 // Returns an iterator to the resource records in the answer section. | 145 // Returns an iterator to the resource records in the answer section. |
| 144 // The iterator is valid only in the scope of the DnsResponse. | 146 // The iterator is valid only in the scope of the DnsResponse. |
| 145 // This operation is idempotent. | 147 // This operation is idempotent. |
| 146 DnsRecordParser Parser() const; | 148 DnsRecordParser Parser() const; |
| 147 | 149 |
| 148 // Extracts an AddressList from this response. Returns SUCCESS if succeeded. | 150 // Extracts an AddressList from this response. Returns SUCCESS if succeeded. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 159 // Iterator constructed after InitParse positioned at the answer section. | 161 // Iterator constructed after InitParse positioned at the answer section. |
| 160 // It is never updated afterwards, so can be used in accessors. | 162 // It is never updated afterwards, so can be used in accessors. |
| 161 DnsRecordParser parser_; | 163 DnsRecordParser parser_; |
| 162 | 164 |
| 163 DISALLOW_COPY_AND_ASSIGN(DnsResponse); | 165 DISALLOW_COPY_AND_ASSIGN(DnsResponse); |
| 164 }; | 166 }; |
| 165 | 167 |
| 166 } // namespace net | 168 } // namespace net |
| 167 | 169 |
| 168 #endif // NET_DNS_DNS_RESPONSE_H_ | 170 #endif // NET_DNS_DNS_RESPONSE_H_ |
| OLD | NEW |