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..6d094b009a102bb1d1584c236ecf0b7fcc31dbc9 |
--- /dev/null |
+++ b/net/base/dns_query.h |
@@ -0,0 +1,76 @@ |
+// 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; |
cbentzel
2011/06/01 17:17:03
Should port be a uint16 rather than an int?
|
+ uint16 id() const; |
+ uint16 qtype() const; |
+ const std::string& hostname() const; |
+ |
+ // Returns the size of the query in number of bytes. |
+ int size() const; |
+ |
+ // 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(); |
+ |
+ 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. |
+ const char* data() const; |
cbentzel
2011/06/01 17:17:03
I'd recommend removing data(), and just use io_buf
|
+ |
+ // 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_; |
+ |
+ // Hostname that we are trying to resolve. |
+ 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_ |