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 #include <vector> | |
11 | |
12 #include "net/base/address_family.h" | |
13 #include "net/base/io_buffer.h" | |
14 | |
15 namespace net{ | |
16 | |
17 // 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
| |
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; | |
35 const std::string& qname() const; | |
36 | |
37 // Returns the size of the query in number of bytes. | |
38 size_t size() const; | |
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(); | |
43 | |
44 private: | |
45 FRIEND_TEST_ALL_PREFIXES(DnsQueryTest, ConstructorTest); | |
46 FRIEND_TEST_ALL_PREFIXES(DnsQueryTest, IOBufferAccessRandomizesIdTest); | |
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 char* data() const; | |
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 // Class of query, currently fixed to IN class. | |
66 uint16 qclass_; | |
67 | |
68 // Hostname in DNS format. | |
69 std::string qname_; | |
70 | |
71 // Contains query bytes to be consumed by higher level Write() call. | |
72 scoped_refptr<IOBufferWithSize> io_buffer_; | |
73 }; | |
74 | |
75 } // namespace net | |
76 | |
77 #endif // NET_BASE_DNS_QUERY_H_ | |
OLD | NEW |