[email protected] | ce82c057 | 2012-04-16 21:22:19 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 5da98afc | 2008-09-20 11:42:49 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_PARSER_H_ |
| 6 | #define CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_PARSER_H_ |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 7 | |
[email protected] | d2b383a | 2014-06-11 07:11:59 | [diff] [blame] | 8 | // Parsers and formatters for SafeBrowsing v3.0 protocol: |
mattm | a64096ac | 2014-09-22 20:30:46 | [diff] [blame] | 9 | // https://developers.google.com/safe-browsing/developers_guide_v3 |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 10 | // |
[email protected] | d2b383a | 2014-06-11 07:11:59 | [diff] [blame] | 11 | // The quoted references are with respect to that document. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 12 | |
avi | b896c71 | 2015-12-26 02:10:43 | [diff] [blame] | 13 | #include <stddef.h> |
| 14 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 15 | #include <string> |
| 16 | #include <vector> |
| 17 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 18 | #include "chrome/browser/safe_browsing/safe_browsing_util.h" |
Tim Volodine | e4593847 | 2017-09-21 10:08:22 | [diff] [blame] | 19 | #include "components/safe_browsing/db/util.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 20 | |
[email protected] | d2b383a | 2014-06-11 07:11:59 | [diff] [blame] | 21 | namespace base { |
| 22 | class TimeDelta; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 23 | }; |
| 24 | |
[email protected] | d2b383a | 2014-06-11 07:11:59 | [diff] [blame] | 25 | namespace safe_browsing { |
| 26 | |
| 27 | // TODO(shess): Maybe the data/len pairs could be productively replaced with |
| 28 | // const base::StringPiece&. |
| 29 | |
| 30 | // Parse body of "HTTP Response for Data". |*next_update_sec| is the minimum |
| 31 | // delay to next update. |*reset| is set to true if the update requested a |
| 32 | // database reset. |*chunk_deletes| receives add-del and sub-del requests, |
| 33 | // while |*chunk_urls| receives the list of redirect urls to fetch. Returns |
| 34 | // |false| if the update could not be decoded properly, in which case all |
| 35 | // results should be discarded. |
| 36 | bool ParseUpdate(const char* chunk_data, |
| 37 | size_t chunk_len, |
| 38 | size_t* next_update_sec, |
| 39 | bool* reset, |
| 40 | std::vector<SBChunkDelete>* chunk_deletes, |
| 41 | std::vector<ChunkUrl>* chunk_urls); |
| 42 | |
| 43 | // Parse body of a redirect response. |*chunks| receives the parsed chunk data. |
| 44 | // Returns |false| if the data could not be parsed correctly, in which case all |
| 45 | // results should be discarded. |
| 46 | bool ParseChunk(const char* chunk_data, |
| 47 | size_t chunk_len, |
dcheng | 7bacc0e | 2016-04-11 20:10:54 | [diff] [blame] | 48 | std::vector<std::unique_ptr<SBChunkData>>* chunks); |
[email protected] | d2b383a | 2014-06-11 07:11:59 | [diff] [blame] | 49 | |
| 50 | // Parse body of "HTTP Response for Full-Length Hashes", returning the list of |
| 51 | // full hashes. Returns |false| if the data could not be parsed correctly, in |
| 52 | // which case all results should be discarded. |
| 53 | bool ParseGetHash(const char* chunk_data, |
| 54 | size_t chunk_len, |
| 55 | base::TimeDelta* cache_lifetime, |
| 56 | std::vector<SBFullHashResult>* full_hashes); |
| 57 | |
| 58 | // Convert prefix hashes into a "HTTP Request for Full-Length Hashes" body. |
| 59 | std::string FormatGetHash(const std::vector<SBPrefix>& prefixes); |
| 60 | |
| 61 | // Format the LIST part of "HTTP Request for Data" body. |
| 62 | std::string FormatList(const SBListChunkRanges& list); |
| 63 | |
| 64 | } // namespace safe_browsing |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 65 | |
[email protected] | 5da98afc | 2008-09-20 11:42:49 | [diff] [blame] | 66 | #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_PARSER_H_ |