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

Side by Side Diff: cloud_print/gcp20/prototype/dns_response_builder.cc

Issue 145873006: ui/base/resource: Roll our own version of ReadBigEndian() function. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 6 years, 10 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cloud_print/gcp20/prototype/dns_response_builder.h" 5 #include "cloud_print/gcp20/prototype/dns_response_builder.h"
6 6
7 #include "base/big_endian.h"
7 #include "base/logging.h" 8 #include "base/logging.h"
8 #include "net/base/big_endian.h"
9 #include "net/base/dns_util.h" 9 #include "net/base/dns_util.h"
10 #include "net/base/io_buffer.h" 10 #include "net/base/io_buffer.h"
11 #include "net/base/ip_endpoint.h" 11 #include "net/base/ip_endpoint.h"
12 #include "net/dns/dns_response.h" 12 #include "net/dns/dns_response.h"
13 13
14 namespace { 14 namespace {
15 15
16 uint16 klass = net::dns_protocol::kClassIN; 16 uint16 klass = net::dns_protocol::kClassIN;
17 17
18 } // namespace 18 } // namespace
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 uint16 weight, 54 uint16 weight,
55 uint16 http_port, 55 uint16 http_port,
56 const std::string& service_domain_name, 56 const std::string& service_domain_name,
57 bool answer) { 57 bool answer) {
58 std::string domain_name; 58 std::string domain_name;
59 bool success = net::DNSDomainFromDot(service_domain_name, &domain_name); 59 bool success = net::DNSDomainFromDot(service_domain_name, &domain_name);
60 DCHECK(success); 60 DCHECK(success);
61 61
62 std::vector<uint8> rdata(2 + 2 + 2 + domain_name.size()); 62 std::vector<uint8> rdata(2 + 2 + 2 + domain_name.size());
63 63
64 net::BigEndianWriter writer(rdata.data(), rdata.size()); 64 base::BigEndianWriter writer(reinterpret_cast<char*>(rdata.data()),
65 rdata.size());
65 success = writer.WriteU16(priority) && 66 success = writer.WriteU16(priority) &&
66 writer.WriteU16(weight) && 67 writer.WriteU16(weight) &&
67 writer.WriteU16(http_port) && 68 writer.WriteU16(http_port) &&
68 writer.WriteBytes(domain_name.data(), domain_name.size()); 69 writer.WriteBytes(domain_name.data(), domain_name.size());
69 DCHECK(success); 70 DCHECK(success);
70 DCHECK_EQ(writer.remaining(), 0); // For warranty of correct size allocation. 71 DCHECK_EQ(writer.remaining(), 0); // For warranty of correct size allocation.
71 72
72 AddResponse(service_name, net::dns_protocol::kTypeSRV, ttl, 73 AddResponse(service_name, net::dns_protocol::kTypeSRV, ttl,
73 std::string(rdata.begin(), rdata.end()), answer); 74 std::string(rdata.begin(), rdata.end()), answer);
74 } 75 }
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 iter->rdata.size(); 130 iter->rdata.size();
130 } 131 }
131 132
132 if (responses_.empty()) 133 if (responses_.empty())
133 return NULL; // No answer. 134 return NULL; // No answer.
134 135
135 DCHECK_EQ(static_cast<size_t>(header_.ancount + header_.arcount), 136 DCHECK_EQ(static_cast<size_t>(header_.ancount + header_.arcount),
136 responses_.size()); 137 responses_.size());
137 scoped_refptr<net::IOBufferWithSize> message( 138 scoped_refptr<net::IOBufferWithSize> message(
138 new net::IOBufferWithSize(static_cast<int>(size))); 139 new net::IOBufferWithSize(static_cast<int>(size)));
139 net::BigEndianWriter writer(message->data(), message->size()); 140 base::BigEndianWriter writer(message->data(), message->size());
140 bool success = writer.WriteU16(header_.id) && 141 bool success = writer.WriteU16(header_.id) &&
141 writer.WriteU16(header_.flags) && 142 writer.WriteU16(header_.flags) &&
142 writer.WriteU16(header_.qdcount) && 143 writer.WriteU16(header_.qdcount) &&
143 writer.WriteU16(header_.ancount) && 144 writer.WriteU16(header_.ancount) &&
144 writer.WriteU16(header_.nscount) && 145 writer.WriteU16(header_.nscount) &&
145 writer.WriteU16(header_.arcount); 146 writer.WriteU16(header_.arcount);
146 DCHECK(success); 147 DCHECK(success);
147 148
148 std::string name_in_dns_format; 149 std::string name_in_dns_format;
149 for (std::vector<DnsResponseRecord>::const_iterator iter = responses_.begin(); 150 for (std::vector<DnsResponseRecord>::const_iterator iter = responses_.begin();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 182
182 if (answer) { 183 if (answer) {
183 responses_.insert(responses_.begin() + header_.ancount, response); 184 responses_.insert(responses_.begin() + header_.ancount, response);
184 ++header_.ancount; 185 ++header_.ancount;
185 } else { 186 } else {
186 responses_.push_back(response); 187 responses_.push_back(response);
187 ++header_.arcount; 188 ++header_.arcount;
188 } 189 }
189 } 190 }
190 191
OLDNEW
« no previous file with comments | « cloud_print/gcp20/prototype/dns_packet_parser.cc ('k') | cloud_print/gcp20/prototype/dns_sd_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698