Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Unified Diff: cloud_print/gcp20/prototype/privet_dns_response_builder.h

Issue 16975004: Finished DNS-SD server. Finished Privet-specified DNS-SD server. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed Lint errors. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cloud_print/gcp20/prototype/privet_dns_response_builder.h
diff --git a/cloud_print/gcp20/prototype/privet_dns_response_builder.h b/cloud_print/gcp20/prototype/privet_dns_response_builder.h
new file mode 100644
index 0000000000000000000000000000000000000000..77efcbd6bedbda117cb8eb648825531a9c4db381
--- /dev/null
+++ b/cloud_print/gcp20/prototype/privet_dns_response_builder.h
@@ -0,0 +1,103 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CLOUD_PRINT_GCP20_PROTOTYPE_PRIVET_DNS_RESPONSE_BUILDER_H_
+#define CLOUD_PRINT_GCP20_PROTOTYPE_PRIVET_DNS_RESPONSE_BUILDER_H_
+
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "cloud_print/gcp20/prototype/dns_sd_server.h"
+#include "net/base/io_buffer.h"
+#include "net/dns/dns_protocol.h"
+#include "net/dns/dns_response.h"
+
+// Record for storing response data.
+struct DnsRespondRecord {
+ std::string name; // in dotted form
+ uint16 type;
+ uint16 klass;
+ uint32 ttl;
+ std::string rdata; // points to the original response buffer
+};
+
+// Class for creating DNS Response messages.
+class PrivetDnsResponseBuilder : public DnsResponseBuilderInterface {
+ public:
+ // Initializes builder.
+ PrivetDnsResponseBuilder(uint16 id,
+ const std::string& service_name,
+ const std::string& service_domain_name,
+ const net::IPAddressNumber& http_ip,
+ const uint16 http_port);
Vitaly Buka (NO REVIEWS) 2013/06/14 19:27:07 no need const here for http_port
maksymb 2013/06/14 22:17:14 Done.
+
+ // Destroys builder.
+ ~PrivetDnsResponseBuilder();
+
+ // Returns length of packet.
+ int size() const OVERRIDE { return size_; }
+
+ // Returns |true| if packet is not empty.
+ int HaveAnswers() const OVERRIDE { return !responses_.empty(); }
+
+ // Methods for checking |qname| accordance to different types of responses.
+ bool CheckPtr(const std::string& qname) OVERRIDE;
+ bool CheckSrv(const std::string& qname) OVERRIDE;
+ bool CheckA(const std::string& qname) OVERRIDE;
+ bool CheckTxt(const std::string& qname) OVERRIDE;
+
+ // Methods for appending different types of responses to packet.
+ void AppendPtr(const uint32 ttl) OVERRIDE;
+ void AppendSrv(const uint32 ttl) OVERRIDE;
+ void AppendA(const uint32 ttl) OVERRIDE;
Vitaly Buka (NO REVIEWS) 2013/06/14 19:27:07 no need const here
maksymb 2013/06/14 22:17:14 Done.
+ void AppendTxt(const uint32 ttl) OVERRIDE;
+
+ // Serializes packet to byte sequence.
+ scoped_refptr<net::IOBufferWithSize> Build() const OVERRIDE;
+
+ // Builds DNS packet for announcement with certain TTL.
+ scoped_refptr<net::IOBufferWithSize> BuildAnnouncement(uint32 ttl) OVERRIDE;
+
+ private:
+ // Appends response to packet.
+ void AddResponse(const std::string& name,
+ uint16 type,
+ uint32 ttl,
+ const std::string& rdata);
+
+ std::vector<DnsRespondRecord> responses_;
+ net::dns_protocol::Header header_;
+ int size_;
+
+ // Information about service.
+ const std::string service_name_;
+ const std::string service_domain_name_;
+ net::IPAddressNumber http_ip_;
Vitaly Buka (NO REVIEWS) 2013/06/14 19:27:07 http_ip_ and http_port_ need const here
maksymb 2013/06/14 22:17:14 Done.
+ uint16 http_port_;
+
+ DISALLOW_COPY_AND_ASSIGN(PrivetDnsResponseBuilder);
+};
+
+class PrivetDnsResponseBuilderFactory
+ : public DnsResponseBuilderFactoryInterface {
+ public:
+ PrivetDnsResponseBuilderFactory(const std::string& service_name_prefix,
+ const std::string& service_domain_name,
+ const net::IPAddressNumber& http_port,
+ const uint16 http_ip);
+
+ DnsResponseBuilderInterface* Create(uint16 id) OVERRIDE;
+
+ private:
+ // Information about service.
+ const std::string service_type_;
+ const std::string service_name_prefix_;
+ const std::string service_domain_name_;
+ const net::IPAddressNumber http_ip_;
+ const uint16 http_port_;
+};
+
+#endif // CLOUD_PRINT_GCP20_PROTOTYPE_PRIVET_DNS_RESPONSE_BUILDER_H_
+

Powered by Google App Engine
This is Rietveld 408576698