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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 // is stored in the dotted form, e.g., "example.com". Returns number of bytes | 60 // is stored in the dotted form, e.g., "example.com". Returns number of bytes |
61 // consumed or 0 on failure. | 61 // consumed or 0 on failure. |
62 // This is exposed to allow parsing compressed names within RRDATA for TYPEs | 62 // This is exposed to allow parsing compressed names within RRDATA for TYPEs |
63 // such as NS, CNAME, PTR, MX, SOA. | 63 // such as NS, CNAME, PTR, MX, SOA. |
64 // See RFC 1035 section 4.1.4. | 64 // See RFC 1035 section 4.1.4. |
65 unsigned ReadName(const void* pos, std::string* out) const; | 65 unsigned ReadName(const void* pos, std::string* out) const; |
66 | 66 |
67 // Parses the next resource record into |record|. Returns true if succeeded. | 67 // Parses the next resource record into |record|. Returns true if succeeded. |
68 bool ReadRecord(DnsResourceRecord* record); | 68 bool ReadRecord(DnsResourceRecord* record); |
69 | 69 |
| 70 // Skip a question section, returns true if succeeded. |
| 71 bool SkipQuestion(); |
| 72 |
70 private: | 73 private: |
71 const char* packet_; | 74 const char* packet_; |
72 size_t length_; | 75 size_t length_; |
73 // Current offset within the packet. | 76 // Current offset within the packet. |
74 const char* cur_; | 77 const char* cur_; |
75 }; | 78 }; |
76 | 79 |
77 // Buffer-holder for the DNS response allowing easy access to the header fields | 80 // Buffer-holder for the DNS response allowing easy access to the header fields |
78 // and resource records. After reading into |io_buffer| must call InitParse to | 81 // and resource records. After reading into |io_buffer| must call InitParse to |
79 // position the RR parser. | 82 // position the RR parser. |
(...skipping 28 matching lines...) Expand all Loading... |
108 ~DnsResponse(); | 111 ~DnsResponse(); |
109 | 112 |
110 // Internal buffer accessor into which actual bytes of response will be | 113 // Internal buffer accessor into which actual bytes of response will be |
111 // read. | 114 // read. |
112 IOBufferWithSize* io_buffer() { return io_buffer_.get(); } | 115 IOBufferWithSize* io_buffer() { return io_buffer_.get(); } |
113 | 116 |
114 // Assuming the internal buffer holds |nbytes| bytes, returns true iff the | 117 // Assuming the internal buffer holds |nbytes| bytes, returns true iff the |
115 // packet matches the |query| id and question. | 118 // packet matches the |query| id and question. |
116 bool InitParse(int nbytes, const DnsQuery& query); | 119 bool InitParse(int nbytes, const DnsQuery& query); |
117 | 120 |
| 121 // Assuming the internal buffer holds |nbytes| bytes, initialize the parser |
| 122 // without matching it against an existing query. |
| 123 bool InitParseWithoutQuery(int nbytes); |
| 124 |
118 // Returns true if response is valid, that is, after successful InitParse. | 125 // Returns true if response is valid, that is, after successful InitParse. |
119 bool IsValid() const; | 126 bool IsValid() const; |
120 | 127 |
121 // All of the methods below are valid only if the response is valid. | 128 // All of the methods below are valid only if the response is valid. |
122 | 129 |
123 // Accessors for the header. | 130 // Accessors for the header. |
124 uint16 flags() const; // excluding rcode | 131 uint16 flags() const; // excluding rcode |
125 uint8 rcode() const; | 132 uint8 rcode() const; |
126 unsigned answer_count() const; | 133 unsigned answer_count() const; |
127 | 134 |
(...skipping 23 matching lines...) Expand all Loading... |
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 |