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

Side by Side Diff: net/base/dns_query.h

Issue 7008021: Added DnsQuery class (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix issues mentioned by agl Created 9 years, 6 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
« no previous file with comments | « no previous file | net/base/dns_query.cc » ('j') | net/base/dns_query.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef NET_BASE_DNS_QUERY_H_
6 #define NET_BASE_DNS_QUERY_H_
7 #pragma once
8
9 #include <string>
10
11 #include "net/base/address_family.h"
12 #include "net/base/io_buffer.h"
13 #include "net/base/net_util.h"
14
15 namespace net{
16
17 // A class that encapsulates bits and pieces related to DNS request processing.
18 class DnsQuery {
19 public:
20 // Constructs an object containing an IOBuffer with raw DNS query string
21 // for |hostname| with the given |address_family|; |port| is here due to
22 // legacy -- getaddrinfo() takes service name, which is mapped to some
23 // port and returns sockaddr_in structures with ports filled in, so do we
24 // -- look at DnsResponse::Parse() to see where it is used.
25 DnsQuery(const std::string& hostname, AddressFamily address_family, int port);
26
27 // Returns true if the constructed object was valid.
28 bool IsValid() const { return io_buffer_.get() != NULL; }
29
30 // DnsQuery field accessors.
31 int port() const;
cbentzel 2011/06/01 17:17:03 Should port be a uint16 rather than an int?
32 uint16 id() const;
33 uint16 qtype() const;
34 const std::string& hostname() const;
35
36 // Returns the size of the query in number of bytes.
37 int size() const;
38
39 // IOBuffer accessor to be used for writing out the query. This has a
40 // side effect of randomizing the ID portion of a query buffer.
41 IOBuffer* io_buffer();
42
43 private:
44 FRIEND_TEST_ALL_PREFIXES(DnsQueryTest, ConstructorTest);
45 FRIEND_TEST_ALL_PREFIXES(DnsQueryTest, IOBufferAccessRandomizesIdTest);
46 FRIEND_TEST_ALL_PREFIXES(DnsResponseTest, ResponseWithCnameA);
47
48 // Randomizes ID field in the IOBuffer, also sets |id_|.
49 void RandomizeId();
50
51 // Gives access to the query bytes without randomizing ID field, used by
52 // tests.
53 const char* data() const;
cbentzel 2011/06/01 17:17:03 I'd recommend removing data(), and just use io_buf
54
55 // Port to be used by corresponding DnsResponse when filling sockaddr_ins
56 // to be returned.
57 int port_;
58
59 // ID of the query; changes on each io_buffer_ access.
60 uint16 id_;
61
62 // Type of query, currently, either A or AAAA.
63 uint16 qtype_;
64
65 // Hostname that we are trying to resolve.
66 std::string hostname_;
67
68 // Contains query bytes to be consumed by higher level Write() call.
69 scoped_refptr<IOBufferWithSize> io_buffer_;
70
71 DISALLOW_COPY_AND_ASSIGN(DnsQuery);
72 };
73
74 } // namespace net
75
76 #endif // NET_BASE_DNS_QUERY_H_
OLDNEW
« no previous file with comments | « no previous file | net/base/dns_query.cc » ('j') | net/base/dns_query.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698