| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // TODOv3(shess): Review these changes carefully. | 7 // TODOv3(shess): Review these changes carefully. |
| 8 | 8 |
| 9 #include <stdint.h> |
| 9 #include <stdlib.h> | 10 #include <stdlib.h> |
| 10 | 11 |
| 11 #include "base/format_macros.h" | 12 #include "base/format_macros.h" |
| 12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/macros.h" |
| 13 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/string_split.h" | 16 #include "base/strings/string_split.h" |
| 15 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 16 #include "base/sys_byteorder.h" | 18 #include "base/sys_byteorder.h" |
| 17 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 18 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 19 #include "chrome/browser/safe_browsing/protocol_parser.h" | 21 #include "chrome/browser/safe_browsing/protocol_parser.h" |
| 20 #include "chrome/browser/safe_browsing/safe_browsing_util.h" | 22 #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
| 21 | 23 |
| 22 namespace safe_browsing { | 24 namespace safe_browsing { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 // Copy data out of the buffer. | 67 // Copy data out of the buffer. |
| 66 bool GetData(void* ptr, size_t l) { | 68 bool GetData(void* ptr, size_t l) { |
| 67 const void* buf_ptr; | 69 const void* buf_ptr; |
| 68 if (!RefData(&buf_ptr, l)) | 70 if (!RefData(&buf_ptr, l)) |
| 69 return false; | 71 return false; |
| 70 | 72 |
| 71 memcpy(ptr, buf_ptr, l); | 73 memcpy(ptr, buf_ptr, l); |
| 72 return true; | 74 return true; |
| 73 } | 75 } |
| 74 | 76 |
| 75 // Read a 32-bit integer in network byte order into a local uint32. | 77 // Read a 32-bit integer in network byte order into a local uint32_t. |
| 76 bool GetNet32(uint32* i) { | 78 bool GetNet32(uint32_t* i) { |
| 77 if (!GetData(i, sizeof(*i))) | 79 if (!GetData(i, sizeof(*i))) |
| 78 return false; | 80 return false; |
| 79 | 81 |
| 80 *i = base::NetToHost32(*i); | 82 *i = base::NetToHost32(*i); |
| 81 return true; | 83 return true; |
| 82 } | 84 } |
| 83 | 85 |
| 84 // Returns false if there is no data, otherwise fills |*line| with a reference | 86 // Returns false if there is no data, otherwise fills |*line| with a reference |
| 85 // to the next line of data in the buffer. | 87 // to the next line of data in the buffer. |
| 86 bool GetLine(base::StringPiece* line) { | 88 bool GetLine(base::StringPiece* line) { |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 | 349 |
| 348 // BODY = (UINT32 CHUNKDATA)+ | 350 // BODY = (UINT32 CHUNKDATA)+ |
| 349 // UINT32 = Unsigned 32-bit integer in network byte order | 351 // UINT32 = Unsigned 32-bit integer in network byte order |
| 350 // CHUNKDATA = Encoded ChunkData protocol message | 352 // CHUNKDATA = Encoded ChunkData protocol message |
| 351 bool ParseChunk(const char* data, | 353 bool ParseChunk(const char* data, |
| 352 size_t length, | 354 size_t length, |
| 353 std::vector<scoped_ptr<SBChunkData>>* chunks) { | 355 std::vector<scoped_ptr<SBChunkData>>* chunks) { |
| 354 BufferReader reader(data, length); | 356 BufferReader reader(data, length); |
| 355 | 357 |
| 356 while (!reader.empty()) { | 358 while (!reader.empty()) { |
| 357 uint32 l = 0; | 359 uint32_t l = 0; |
| 358 if (!reader.GetNet32(&l) || l == 0 || l > reader.length()) | 360 if (!reader.GetNet32(&l) || l == 0 || l > reader.length()) |
| 359 return false; | 361 return false; |
| 360 | 362 |
| 361 const void* p = NULL; | 363 const void* p = NULL; |
| 362 if (!reader.RefData(&p, l)) | 364 if (!reader.RefData(&p, l)) |
| 363 return false; | 365 return false; |
| 364 | 366 |
| 365 scoped_ptr<SBChunkData> chunk(new SBChunkData()); | 367 scoped_ptr<SBChunkData> chunk(new SBChunkData()); |
| 366 if (!chunk->ParseFrom(reinterpret_cast<const unsigned char*>(p), l)) | 368 if (!chunk->ParseFrom(reinterpret_cast<const unsigned char*>(p), l)) |
| 367 return false; | 369 return false; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 388 if (!list.adds.empty() && !list.subs.empty()) | 390 if (!list.adds.empty() && !list.subs.empty()) |
| 389 formatted_results.append(":"); | 391 formatted_results.append(":"); |
| 390 if (!list.subs.empty()) | 392 if (!list.subs.empty()) |
| 391 formatted_results.append("s:").append(list.subs); | 393 formatted_results.append("s:").append(list.subs); |
| 392 formatted_results.append("\n"); | 394 formatted_results.append("\n"); |
| 393 | 395 |
| 394 return formatted_results; | 396 return formatted_results; |
| 395 } | 397 } |
| 396 | 398 |
| 397 } // namespace safe_browsing | 399 } // namespace safe_browsing |
| OLD | NEW |