Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(638)

Side by Side Diff: net/dns/dns_response.h

Issue 9190031: DnsClient refactoring + features (timeout, suffix search, server rotation). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added comments. Fixed tests. Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 // Construct an iterator to process the |packet| of given |length|. 44 // Construct an iterator to process the |packet| of given |length|.
45 // |offset| points to the beginning of the answer section. 45 // |offset| points to the beginning of the answer section.
46 DnsRecordParser(const void* packet, size_t length, size_t offset); 46 DnsRecordParser(const void* packet, size_t length, size_t offset);
47 47
48 // Returns |true| if initialized. 48 // Returns |true| if initialized.
49 bool IsValid() const { return packet_ != NULL; } 49 bool IsValid() const { return packet_ != NULL; }
50 50
51 // Returns |true| if no more bytes remain in the packet. 51 // Returns |true| if no more bytes remain in the packet.
52 bool AtEnd() const { return cur_ == packet_ + length_; } 52 bool AtEnd() const { return cur_ == packet_ + length_; }
53 53
54 // Returns current offset into the packet.
55 size_t offset() const { return cur_ - packet_; }
56
54 // Parses a (possibly compressed) DNS name from the packet starting at 57 // Parses a (possibly compressed) DNS name from the packet starting at
55 // |pos|. Stores output (even partial) in |out| unless |out| is NULL. |out| 58 // |pos|. Stores output (even partial) in |out| unless |out| is NULL. |out|
56 // is stored in the dotted form, e.g., "example.com". Returns number of bytes 59 // is stored in the dotted form, e.g., "example.com". Returns number of bytes
57 // consumed or 0 on failure. 60 // consumed or 0 on failure.
58 // This is exposed to allow parsing compressed names within RRDATA for TYPEs 61 // This is exposed to allow parsing compressed names within RRDATA for TYPEs
59 // such as NS, CNAME, PTR, MX, SOA. 62 // such as NS, CNAME, PTR, MX, SOA.
60 // See RFC 1035 section 4.1.4. 63 // See RFC 1035 section 4.1.4.
61 int ParseName(const void* pos, std::string* out) const; 64 int ParseName(const void* pos, std::string* out) const;
62 65
63 // Parses the next resource record. Returns true if succeeded. 66 // Parses the next resource record. Returns true if succeeded.
(...skipping 21 matching lines...) Expand all
85 88
86 // Internal buffer accessor into which actual bytes of response will be 89 // Internal buffer accessor into which actual bytes of response will be
87 // read. 90 // read.
88 IOBufferWithSize* io_buffer() { return io_buffer_.get(); } 91 IOBufferWithSize* io_buffer() { return io_buffer_.get(); }
89 92
90 // Returns false if the packet is shorter than the header or does not match 93 // Returns false if the packet is shorter than the header or does not match
91 // |query| id or question. 94 // |query| id or question.
92 bool InitParse(int nbytes, const DnsQuery& query); 95 bool InitParse(int nbytes, const DnsQuery& query);
93 96
94 // Accessors for the header. 97 // Accessors for the header.
95 uint8 flags0() const; // first byte of flags 98 uint16 flags() const; // excluding rcode
96 uint8 flags1() const; // second byte of flags excluding rcode
97 uint8 rcode() const; 99 uint8 rcode() const;
98 int answer_count() const; 100 int answer_count() const;
99 101
102 // Accessors to the question. The qname is unparsed.
103 base::StringPiece qname() const;
104 uint16 qtype() const;
105
106 // Returns qname in dotted format.
107 std::string GetDottedName() const;
108
100 // Returns an iterator to the resource records in the answer section. Must be 109 // Returns an iterator to the resource records in the answer section. Must be
101 // called after InitParse. The iterator is valid only in the scope of the 110 // called after InitParse. The iterator is valid only in the scope of the
102 // DnsResponse. 111 // DnsResponse.
103 DnsRecordParser Parser() const; 112 DnsRecordParser Parser() const;
104 113
105 private: 114 private:
106 // Convenience for header access. 115 // Convenience for header access.
107 const dns_protocol::Header* header() const; 116 const dns_protocol::Header* header() const;
108 117
109 // Buffer into which response bytes are read. 118 // Buffer into which response bytes are read.
110 scoped_refptr<IOBufferWithSize> io_buffer_; 119 scoped_refptr<IOBufferWithSize> io_buffer_;
111 120
112 // Iterator constructed after InitParse positioned at the answer section. 121 // Iterator constructed after InitParse positioned at the answer section.
113 DnsRecordParser parser_; 122 DnsRecordParser parser_;
114 123
115 DISALLOW_COPY_AND_ASSIGN(DnsResponse); 124 DISALLOW_COPY_AND_ASSIGN(DnsResponse);
116 }; 125 };
117 126
118 } // namespace net 127 } // namespace net
119 128
120 #endif // NET_DNS_DNS_RESPONSE_H_ 129 #endif // NET_DNS_DNS_RESPONSE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698