| 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 ~DnsResponse(); | 108 ~DnsResponse(); |
| 109 | 109 |
| 110 // Internal buffer accessor into which actual bytes of response will be | 110 // Internal buffer accessor into which actual bytes of response will be |
| 111 // read. | 111 // read. |
| 112 IOBufferWithSize* io_buffer() { return io_buffer_.get(); } | 112 IOBufferWithSize* io_buffer() { return io_buffer_.get(); } |
| 113 | 113 |
| 114 // Assuming the internal buffer holds |nbytes| bytes, returns true iff the | 114 // Assuming the internal buffer holds |nbytes| bytes, returns true iff the |
| 115 // packet matches the |query| id and question. | 115 // packet matches the |query| id and question. |
| 116 bool InitParse(int nbytes, const DnsQuery& query); | 116 bool InitParse(int nbytes, const DnsQuery& query); |
| 117 | 117 |
| 118 // Assuming the internal buffer holds |nbytes| bytes, initialize the parser |
| 119 // without matching it against an existing query. |
| 120 bool InitParseNoQuery(int nbytes); |
| 121 |
| 118 // Returns true if response is valid, that is, after successful InitParse. | 122 // Returns true if response is valid, that is, after successful InitParse. |
| 119 bool IsValid() const; | 123 bool IsValid() const; |
| 120 | 124 |
| 121 // All of the methods below are valid only if the response is valid. | 125 // All of the methods below are valid only if the response is valid. |
| 122 | 126 |
| 123 // Accessors for the header. | 127 // Accessors for the header. |
| 124 uint16 flags() const; // excluding rcode | 128 uint16 flags() const; // excluding rcode |
| 125 uint8 rcode() const; | 129 uint8 rcode() const; |
| 126 unsigned answer_count() const; | 130 unsigned answer_count() const; |
| 127 | 131 |
| 128 // Accessors to the question. The qname is unparsed. | 132 // Accessors to the question. The qname is unparsed. |
| 129 base::StringPiece qname() const; | 133 base::StringPiece qname() const; |
| 130 uint16 qtype() const; | 134 uint16 qtype() const; |
| 131 | 135 |
| 132 // Returns qname in dotted format. | 136 // Returns qname in dotted format. |
| 133 std::string GetDottedName() const; | 137 std::string GetDottedName() const; |
| 134 | 138 |
| 139 // Returns the length of the question section. |
| 140 size_t GetQuestionSectionSize() const; |
| 141 |
| 135 // Returns an iterator to the resource records in the answer section. | 142 // Returns an iterator to the resource records in the answer section. |
| 136 // The iterator is valid only in the scope of the DnsResponse. | 143 // The iterator is valid only in the scope of the DnsResponse. |
| 137 // This operation is idempotent. | 144 // This operation is idempotent. |
| 138 DnsRecordParser Parser() const; | 145 DnsRecordParser Parser() const; |
| 139 | 146 |
| 140 // Extracts an AddressList from this response. Returns SUCCESS if succeeded. | 147 // Extracts an AddressList from this response. Returns SUCCESS if succeeded. |
| 141 // Otherwise returns a detailed error number. | 148 // Otherwise returns a detailed error number. |
| 142 Result ParseToAddressList(AddressList* addr_list, base::TimeDelta* ttl) const; | 149 Result ParseToAddressList(AddressList* addr_list, base::TimeDelta* ttl) const; |
| 143 | 150 |
| 144 private: | 151 private: |
| 145 // Convenience for header access. | 152 // Convenience for header access. |
| 146 const dns_protocol::Header* header() const; | 153 const dns_protocol::Header* header() const; |
| 147 | 154 |
| 148 // Buffer into which response bytes are read. | 155 // Buffer into which response bytes are read. |
| 149 scoped_refptr<IOBufferWithSize> io_buffer_; | 156 scoped_refptr<IOBufferWithSize> io_buffer_; |
| 150 | 157 |
| 151 // Iterator constructed after InitParse positioned at the answer section. | 158 // Iterator constructed after InitParse positioned at the answer section. |
| 152 // It is never updated afterwards, so can be used in accessors. | 159 // It is never updated afterwards, so can be used in accessors. |
| 153 DnsRecordParser parser_; | 160 DnsRecordParser parser_; |
| 154 | 161 |
| 155 DISALLOW_COPY_AND_ASSIGN(DnsResponse); | 162 DISALLOW_COPY_AND_ASSIGN(DnsResponse); |
| 156 }; | 163 }; |
| 157 | 164 |
| 158 } // namespace net | 165 } // namespace net |
| 159 | 166 |
| 160 #endif // NET_DNS_DNS_RESPONSE_H_ | 167 #endif // NET_DNS_DNS_RESPONSE_H_ |
| OLD | NEW |