Chromium Code Reviews| 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..cd95c4440e3dfa8407ed8bc057b88ffc4afd4d16 |
| --- /dev/null |
| +++ b/net/base/dns_query.h |
| @@ -0,0 +1,77 @@ |
| +// 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 <vector> |
| + |
| +#include "net/base/address_family.h" |
| +#include "net/base/io_buffer.h" |
| + |
| +namespace net{ |
| + |
| +// A class that encapsulates bits and pieces related to DNS request processing. |
|
cbentzel
2011/05/26 17:32:40
Right now this is A and AAAA only. Do you want to
agayev
2011/05/26 22:55:55
We will probably want most of that, but I'd rather
|
| +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; |
| + const std::string& qname() const; |
| + |
| + // Returns the size of the query in number of bytes. |
| + size_t 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); |
| + |
| + // 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; |
| + |
| + // 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. |
| + uint16 qclass_; |
| + |
| + // Hostname in DNS format. |
| + std::string qname_; |
| + |
| + // Contains query bytes to be consumed by higher level Write() call. |
| + scoped_refptr<IOBufferWithSize> io_buffer_; |
| +}; |
| + |
| +} // namespace net |
| + |
| +#endif // NET_BASE_DNS_QUERY_H_ |