Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / cloud_print / gcp20 / prototype / dns_response_builder.h
1 // Copyright 2013 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 CLOUD_PRINT_GCP20_PROTOTYPE_DNS_RESPONSE_BUILDER_H_
6 #define CLOUD_PRINT_GCP20_PROTOTYPE_DNS_RESPONSE_BUILDER_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "net/base/net_util.h"
13 #include "net/dns/dns_protocol.h"
14
15 namespace net {
16
17 class IOBufferWithSize;
18
19 }  // namespace net
20
21 // Record for storing response data.
22 struct DnsResponseRecord {
23   DnsResponseRecord();
24   ~DnsResponseRecord();
25
26   std::string name;  // in dotted form
27   uint16 type;
28   uint16 klass;
29   uint32 ttl;
30   std::string rdata;
31 };
32
33 // Class for building service-specified responses.
34 class DnsResponseBuilder {
35  public:
36   // Initializes builder.
37   explicit DnsResponseBuilder(uint16 id);
38
39   // Destroys the object.
40   ~DnsResponseBuilder();
41
42   // Methods for appending different types of responses to packet.
43   void AppendPtr(const std::string& service_type,
44                  uint32 ttl,
45                  const std::string& service_name,
46                  bool answer);
47
48   void AppendSrv(const std::string& service_name,
49                  uint32 ttl,
50                  uint16 priority,
51                  uint16 weight, uint16 http_port,
52                  const std::string& service_domain_name,
53                  bool answer);
54
55   void AppendA(const std::string& service_domain_name,
56                uint32 ttl,
57                net::IPAddressNumber http_ipv4,
58                bool answer);
59
60   void AppendAAAA(const std::string& service_domain_name,
61                   uint32 ttl,
62                   net::IPAddressNumber http_ipv6,
63                   bool answer);
64
65   void AppendTxt(const std::string& service_name,
66                  uint32 ttl,
67                  const std::vector<std::string>& metadata,
68                  bool answer);
69
70   // Serializes packet to byte sequence.
71   scoped_refptr<net::IOBufferWithSize> Build();
72
73  private:
74   // Appends response to packet.
75   void AddResponse(const std::string& name,
76                    uint16 type,
77                    uint32 ttl,
78                    const std::string& rdata,
79                    bool answer);
80
81   std::vector<DnsResponseRecord> responses_;
82
83   // Header of response package.
84   net::dns_protocol::Header header_;
85
86   DISALLOW_COPY_AND_ASSIGN(DnsResponseBuilder);
87 };
88
89 #endif  // CLOUD_PRINT_GCP20_PROTOTYPE_DNS_RESPONSE_BUILDER_H_
90