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..13a04eef05f8140784a31d7a830bbee5d73197c7 |
--- /dev/null |
+++ b/cloud_print/gcp20/prototype/dns_packet_parser.h |
@@ -0,0 +1,73 @@ |
+// 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_response.h" |
+ |
+// Parsed responde record. |
+struct DnsQueryRecord { |
+ DnsQueryRecord(); |
gene
2013/06/15 02:13:23
why do you need constructor/destructor here?
maksymb
2013/06/18 01:14:48
constructor now initializes |qtype| and |qclass| v
|
+ ~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 uninitialized iterator. |
+ DnsPacketParser(); |
gene
2013/06/15 02:13:23
Is there a value in having uninitialized iterator?
maksymb
2013/06/18 01:14:48
No reason. Deleted.
|
+ |
+ // Constructs an iterator to process the |packet| of given |length|. |
+ // |offset| points to the beginning of the answer section. |
+ DnsPacketParser(const char* packet, size_t length, size_t offset); |
+ |
+ // Returns |true| if initialized. |
+ bool IsValid() const { return record_parser_.IsValid(); } |
+ |
+ // Returns |true| if no more bytes remain in the packet. |
+ bool AtEnd() const { return record_parser_.AtEnd(); } |
+ |
+ // 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); |
+ } |
+ |
+ // Skip a question section, returns true if succeeded. |
+ bool SkipQuestion() { return record_parser_.SkipQuestion(); } |
gene
2013/06/15 02:13:23
Do you need SkipQuestion() in the public section o
maksymb
2013/06/18 01:14:48
Deleted.
|
+ |
+ 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 |
gene
2013/06/15 02:13:23
I think you mean "decompress" or "expand" here
maksymb
2013/06/18 01:14:48
Left as is.
|
+ // |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_; |
+ |
+ // Encapsulated parser. |
+ net::DnsRecordParser record_parser_; |
+}; |
gene
2013/06/15 02:13:23
Could you please use Chrome macro here to disable
maksymb
2013/06/18 01:14:48
Done.
|
+ |
+#endif // CLOUD_PRINT_GCP20_PROTOTYPE_DNS_PACKET_PARSER_H_ |
+ |