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, uint32 ttl, 44 const std::string& service_name); 45 void AppendSrv(const std::string& service_name, uint32 ttl, uint16 priority, 46 uint16 weight, uint16 http_port, 47 const std::string& service_domain_name); 48 void AppendA(const std::string& service_domain_name, uint32 ttl, 49 net::IPAddressNumber http_ipv4); 50 void AppendTxt(const std::string& service_name, uint32 ttl, 51 const std::vector<std::string>& metadata); 52 53 // Serializes packet to byte sequence. 54 scoped_refptr<net::IOBufferWithSize> Build(); 55 56 private: 57 // Appends response to packet. 58 void AddResponse(const std::string& name, uint16 type, uint32 ttl, 59 const std::string& rdata); 60 61 std::vector<DnsResponseRecord> responses_; 62 63 // Header of response package. 64 net::dns_protocol::Header header_; 65 66 DISALLOW_COPY_AND_ASSIGN(DnsResponseBuilder); 67 }; 68 69 #endif // CLOUD_PRINT_GCP20_PROTOTYPE_DNS_RESPONSE_BUILDER_H_ 70 71