OLD | NEW |
---|---|
(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; | |
32 uint16 id() const; | |
33 uint16 qtype() const; | |
34 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.
| |
35 const std::string& hostname() const; | |
36 | |
37 // Returns the size of the query in number of bytes. | |
38 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
| |
39 | |
40 // IOBuffer accessor to be used for writing out the query. This has a | |
41 // side effect of randomizing the ID portion of a query buffer. | |
42 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
| |
43 | |
44 private: | |
45 FRIEND_TEST_ALL_PREFIXES(DnsQueryTest, ConstructorTest); | |
46 FRIEND_TEST_ALL_PREFIXES(DnsQueryTest, IOBufferAccessRandomizesIdTest); | |
47 FRIEND_TEST_ALL_PREFIXES(DnsResponseTest, ResponseWithCnameA); | |
48 | |
49 // Randomizes ID field in the IOBuffer, also sets |id_|. | |
50 void RandomizeId(); | |
51 | |
52 // Gives access to the query bytes without randomizing ID field, used by | |
53 // tests. | |
54 char* data() const; | |
agl
2011/05/30 18:35:30
const char*?
agayev
2011/05/31 15:19:06
Will do.
| |
55 | |
56 // Port to be used by corresponding DnsResponse when filling sockaddr_ins | |
57 // to be returned. | |
58 int port_; | |
59 | |
60 // ID of the query; changes on each io_buffer_ access. | |
61 uint16 id_; | |
62 | |
63 // Type of query, currently, either A or AAAA. | |
64 uint16 qtype_; | |
65 | |
66 // 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.
| |
67 uint16 qclass_; | |
68 | |
69 // 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.
| |
70 std::string hostname_; | |
71 | |
72 // Contains query bytes to be consumed by higher level Write() call. | |
73 scoped_refptr<IOBufferWithSize> io_buffer_; | |
74 | |
75 DISALLOW_COPY_AND_ASSIGN(DnsQuery); | |
76 }; | |
77 | |
78 } // namespace net | |
79 | |
80 #endif // NET_BASE_DNS_QUERY_H_ | |
OLD | NEW |