| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // Parse the data returned from the SafeBrowsing v2.1 protocol response. | 5 // Parse the data returned from the SafeBrowsing v2.1 protocol response. |
| 6 | 6 |
| 7 #include "chrome/browser/safe_browsing/protocol_parser.h" |
| 8 |
| 7 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 8 | 10 |
| 9 #if defined(OS_WIN) | 11 #if defined(OS_WIN) |
| 10 #include <Winsock2.h> | 12 #include <Winsock2.h> |
| 11 #elif defined(OS_POSIX) | 13 #elif defined(OS_POSIX) |
| 12 #include <arpa/inet.h> | 14 #include <arpa/inet.h> |
| 13 #endif | 15 #endif |
| 14 | 16 |
| 15 #include "chrome/browser/safe_browsing/protocol_parser.h" | 17 #include "base/format_macros.h" |
| 16 | |
| 17 #include "base/logging.h" | 18 #include "base/logging.h" |
| 18 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 // Helper function for quick scans of a line oriented protocol. Note that we use | 22 // Helper function for quick scans of a line oriented protocol. Note that we use |
| 22 // std::string::assign(const charT* s, size_type n) | 23 // std::string::assign(const charT* s, size_type n) |
| 23 // to copy data into 'line'. This form of 'assign' does not call strlen on | 24 // to copy data into 'line'. This form of 'assign' does not call strlen on |
| 24 // 'input', which is binary data and is not NULL terminated. 'input' may also | 25 // 'input', which is binary data and is not NULL terminated. 'input' may also |
| 25 // contain valid NULL bytes in the payload, which a strlen based copy would | 26 // contain valid NULL bytes in the payload, which a strlen based copy would |
| 26 // truncate. | 27 // truncate. |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 } | 109 } |
| 109 | 110 |
| 110 return length == 0; | 111 return length == 0; |
| 111 } | 112 } |
| 112 | 113 |
| 113 void SafeBrowsingProtocolParser::FormatGetHash( | 114 void SafeBrowsingProtocolParser::FormatGetHash( |
| 114 const std::vector<SBPrefix>& prefixes, std::string* request) { | 115 const std::vector<SBPrefix>& prefixes, std::string* request) { |
| 115 DCHECK(request); | 116 DCHECK(request); |
| 116 | 117 |
| 117 // Format the request for GetHash. | 118 // Format the request for GetHash. |
| 118 request->append(StringPrintf("%d:%d\n", | 119 request->append(StringPrintf("%" PRIuS ":%" PRIuS "\n", |
| 119 sizeof(SBPrefix), | 120 sizeof(SBPrefix), |
| 120 sizeof(SBPrefix) * prefixes.size())); | 121 sizeof(SBPrefix) * prefixes.size())); |
| 121 for (size_t i = 0; i < prefixes.size(); ++i) { | 122 for (size_t i = 0; i < prefixes.size(); ++i) { |
| 122 request->append(reinterpret_cast<const char*>(&prefixes[i]), | 123 request->append(reinterpret_cast<const char*>(&prefixes[i]), |
| 123 sizeof(SBPrefix)); | 124 sizeof(SBPrefix)); |
| 124 } | 125 } |
| 125 } | 126 } |
| 126 | 127 |
| 127 bool SafeBrowsingProtocolParser::ParseUpdate( | 128 bool SafeBrowsingProtocolParser::ParseUpdate( |
| 128 const char* chunk_data, | 129 const char* chunk_data, |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 | 483 |
| 483 data += line.size() + 1; | 484 data += line.size() + 1; |
| 484 remaining -= static_cast<int>(line.size()) + 1; | 485 remaining -= static_cast<int>(line.size()) + 1; |
| 485 } | 486 } |
| 486 | 487 |
| 487 if (client_key->empty() || wrapped_key->empty()) | 488 if (client_key->empty() || wrapped_key->empty()) |
| 488 return false; | 489 return false; |
| 489 | 490 |
| 490 return true; | 491 return true; |
| 491 } | 492 } |
| OLD | NEW |