Index: net/base/dns_query.h |
diff --git a/net/base/dns_query.h b/net/base/dns_query.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d88072b8b1aab5498c256311e147837a4dc510fa |
--- /dev/null |
+++ b/net/base/dns_query.h |
@@ -0,0 +1,80 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef NET_BASE_DNS_QUERY_H_ |
+#define NET_BASE_DNS_QUERY_H_ |
+#pragma once |
+ |
+#include <string> |
+ |
+#include "net/base/address_family.h" |
+#include "net/base/io_buffer.h" |
+#include "net/base/net_util.h" |
+ |
+namespace net{ |
+ |
+// A class that encapsulates bits and pieces related to DNS request processing. |
+class DnsQuery { |
+ public: |
+ // Constructs an object containing an IOBuffer with raw DNS query string |
+ // for |hostname| with the given |address_family|; |port| is here due to |
+ // legacy -- getaddrinfo() takes service name, which is mapped to some |
+ // port and returns sockaddr_in structures with ports filled in, so do we |
+ // -- look at DnsResponse::Parse() to see where it is used. |
+ DnsQuery(const std::string& hostname, AddressFamily address_family, int port); |
+ |
+ // Returns true if the constructed object was valid. |
+ bool IsValid() const { return io_buffer_.get() != NULL; } |
+ |
+ // DnsQuery field accessors. |
+ int port() const; |
+ uint16 id() const; |
+ uint16 qtype() const; |
+ uint16 qclass() const; |
agl
2011/05/30 18:35:30
Classes are a really obscure corner of DNS. I'd te
agayev
2011/05/31 15:19:06
DnsResponse was using it to match the Question par
agayev
2011/06/01 15:58:24
Hardcoded class to IN.
|
+ const std::string& hostname() const; |
+ |
+ // Returns the size of the query in number of bytes. |
+ int size() const; |
agl
2011/05/30 18:35:30
size_t for sizes?
agayev
2011/05/31 15:19:06
Originally, I had it size_t, but eventually, I nee
|
+ |
+ // IOBuffer accessor to be used for writing out the query. This has a |
+ // side effect of randomizing the ID portion of a query buffer. |
+ IOBuffer* io_buffer(); |
agl
2011/05/30 18:35:30
IOBuffers are refcounted, but returning a raw poin
agayev
2011/05/31 15:19:06
I agree that it's an error-prone API, however, the
|
+ |
+ private: |
+ FRIEND_TEST_ALL_PREFIXES(DnsQueryTest, ConstructorTest); |
+ FRIEND_TEST_ALL_PREFIXES(DnsQueryTest, IOBufferAccessRandomizesIdTest); |
+ FRIEND_TEST_ALL_PREFIXES(DnsResponseTest, ResponseWithCnameA); |
+ |
+ // Randomizes ID field in the IOBuffer, also sets |id_|. |
+ void RandomizeId(); |
+ |
+ // Gives access to the query bytes without randomizing ID field, used by |
+ // tests. |
+ char* data() const; |
agl
2011/05/30 18:35:30
const char*?
agayev
2011/05/31 15:19:06
Will do.
|
+ |
+ // Port to be used by corresponding DnsResponse when filling sockaddr_ins |
+ // to be returned. |
+ int port_; |
+ |
+ // ID of the query; changes on each io_buffer_ access. |
+ uint16 id_; |
+ |
+ // Type of query, currently, either A or AAAA. |
+ uint16 qtype_; |
+ |
+ // Class of query, currently fixed to IN class. |
agl
2011/05/30 18:35:30
This is so unlikely to ever change I wouldn't make
agayev
2011/05/31 15:19:06
Will do.
|
+ uint16 qclass_; |
+ |
+ // Hostname for we are trying to resolve. |
agl
2011/05/30 18:35:30
s/for/that/
agayev
2011/05/31 15:19:06
Will do.
|
+ std::string hostname_; |
+ |
+ // Contains query bytes to be consumed by higher level Write() call. |
+ scoped_refptr<IOBufferWithSize> io_buffer_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(DnsQuery); |
+}; |
+ |
+} // namespace net |
+ |
+#endif // NET_BASE_DNS_QUERY_H_ |