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