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/dns_packet_parser.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/dns_packet_parser.h
diff --git a/cloud_print/gcp20/prototype/dns_packet_parser.h b/cloud_print/gcp20/prototype/dns_packet_parser.h
new file mode 100644
index 0000000000000000000000000000000000000000..1508c1c63000d63e0172b8f4f5b60a8d1b113cec
--- /dev/null
+++ b/cloud_print/gcp20/prototype/dns_packet_parser.h
@@ -0,0 +1,78 @@
+// 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_DNS_PACKET_PARSER_H_
+#define CLOUD_PRINT_GCP20_PROTOTYPE_DNS_PACKET_PARSER_H_
+
+#include <string>
+
+#include "net/dns/dns_protocol.h"
+#include "net/dns/dns_response.h"
+
+// Parsed response record.
+struct DnsQueryRecord {
+ DnsQueryRecord() : qtype(0), qclass(0) {}
+ ~DnsQueryRecord() {}
+
+ std::string qname; // in dotted form
+ uint16 qtype;
+ uint16 qclass;
+};
+
+// Iterator to walk over records of the DNS response packet. Encapsulates
+// |DnsRecordParser| object for using its functionality.
+class DnsPacketParser {
+ public:
+ // Constructs an iterator to process the |packet| of given |length|.
+ DnsPacketParser(const char* packet, size_t length);
+
+ // Destroys the object.
+ ~DnsPacketParser() {}
+
+ bool IsValid() const { return record_parser_.IsValid() && is_header_read_; }
+
+ // Returns |true| if no more bytes remain in the packet.
+ bool AtEnd() const { return record_parser_.AtEnd(); }
+
+ // Returns header of DNS packet.
+ const net::dns_protocol::Header& header() { return header_; }
gene 2013/06/19 05:40:51 const?
maksymb 2013/06/19 21:47:21 Done.
+
+ // Parses the next query record into |record|. Returns true if succeeded.
+ bool ReadRecord(DnsQueryRecord* record);
+
+ // Parses the next resource record into |record|. Returns true if succeeded.
+ bool ReadRecord(net::DnsResourceRecord* record) {
+ return record_parser_.ReadRecord(record);
+ }
+
+ private:
+ // Returns current offset into the packet.
+ size_t GetOffset() const { return record_parser_.GetOffset(); }
+
+ // Parses a (possibly compressed) DNS name from the packet starting at
+ // |pos|. Stores output (even partial) in |out| unless |out| is NULL. |out|
+ // is stored in the dotted form, e.g., "example.com". Returns number of bytes
+ // consumed or 0 on failure.
+ // This is exposed to allow parsing compressed names within RRDATA for TYPEs
+ // such as NS, CNAME, PTR, MX, SOA.
+ // See RFC 1035 section 4.1.4.
+ unsigned ReadName(std::string* out) const {
+ return record_parser_.ReadName(packet_ + GetOffset(), out);
+ }
+
+ const char* packet_;
+ size_t length_;
+
+ // Contents parsed header_;
+ net::dns_protocol::Header header_;
+ bool is_header_read_;
+
+ // Encapsulated parser.
+ net::DnsRecordParser record_parser_;
+
+ DISALLOW_COPY_AND_ASSIGN(DnsPacketParser);
+};
+
+#endif // CLOUD_PRINT_GCP20_PROTOTYPE_DNS_PACKET_PARSER_H_
+
« no previous file with comments | « no previous file | cloud_print/gcp20/prototype/dns_packet_parser.cc » ('j') | cloud_print/gcp20/prototype/dns_response_builder.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698