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

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: Renamed dns_client -> dns_transaction. 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 28 matching lines...) Expand all
39 class NET_EXPORT_PRIVATE DnsRecordParser { 39 class NET_EXPORT_PRIVATE DnsRecordParser {
40 public: 40 public:
41 // Construct an uninitialized iterator. 41 // Construct an uninitialized iterator.
42 DnsRecordParser(); 42 DnsRecordParser();
43 43
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 is_valid() const { return packet_ != NULL; }
cbentzel 2012/01/13 22:17:25 Old naming scheme is more appropriate here.
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 20 matching lines...) Expand all
84 ~DnsResponse(); 87 ~DnsResponse();
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
97 // Returns true if response is valid, that is, after successful InitParse.
98 bool is_valid() const;
cbentzel 2012/01/13 22:17:25 Ditto, prefer IsValid().
99
100 // All of the methods below are valid only if the response is valid.
101
94 // Accessors for the header. 102 // Accessors for the header.
95 uint8 flags0() const; // first byte of flags 103 uint16 flags() const; // excluding rcode
96 uint8 flags1() const; // second byte of flags excluding rcode
97 uint8 rcode() const; 104 uint8 rcode() const;
98 int answer_count() const; 105 int answer_count() const;
99 106
100 // Returns an iterator to the resource records in the answer section. Must be 107 // Accessors to the question. The qname is unparsed.
101 // called after InitParse. The iterator is valid only in the scope of the 108 base::StringPiece qname() const;
cbentzel 2012/01/13 22:17:25 Where are these being used?
szym 2012/01/17 15:38:25 I'm not sure these will be used outside of tests.
102 // DnsResponse. 109 uint16 qtype() const;
110
111 // Returns qname in dotted format.
112 std::string GetDottedName() const;
113
114 // Returns an iterator to the resource records in the answer section.
115 // The iterator is valid only in the scope of the DnsResponse.
116 // This operation is idempotent.
103 DnsRecordParser Parser() const; 117 DnsRecordParser Parser() const;
104 118
105 private: 119 private:
106 // Convenience for header access. 120 // Convenience for header access.
107 const dns_protocol::Header* header() const; 121 const dns_protocol::Header* header() const;
108 122
109 // Buffer into which response bytes are read. 123 // Buffer into which response bytes are read.
110 scoped_refptr<IOBufferWithSize> io_buffer_; 124 scoped_refptr<IOBufferWithSize> io_buffer_;
111 125
112 // Iterator constructed after InitParse positioned at the answer section. 126 // Iterator constructed after InitParse positioned at the answer section.
127 // It is never updated afterwards, so can be used in accessors.
113 DnsRecordParser parser_; 128 DnsRecordParser parser_;
114 129
115 DISALLOW_COPY_AND_ASSIGN(DnsResponse); 130 DISALLOW_COPY_AND_ASSIGN(DnsResponse);
116 }; 131 };
117 132
118 } // namespace net 133 } // namespace net
119 134
120 #endif // NET_DNS_DNS_RESPONSE_H_ 135 #endif // NET_DNS_DNS_RESPONSE_H_
OLDNEW
« no previous file with comments | « net/dns/dns_query.cc ('k') | net/dns/dns_response.cc » ('j') | net/dns/dns_response.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698