• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
3 // found in the LICENSE file.
4 
5 #ifndef CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_PARSER_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_PARSER_H_
7 
8 // Parsers and formatters for SafeBrowsing v3.0 protocol:
9 // https://developers.google.com/safe-browsing/developers_guide_v3
10 //
11 // The quoted references are with respect to that document.
12 
13 #include <string>
14 #include <vector>
15 
16 #include "base/basictypes.h"
17 #include "base/memory/scoped_vector.h"
18 #include "chrome/browser/safe_browsing/safe_browsing_util.h"
19 
20 namespace base {
21 class TimeDelta;
22 };
23 
24 namespace safe_browsing {
25 
26 // TODO(shess): Maybe the data/len pairs could be productively replaced with
27 // const base::StringPiece&.
28 
29 // Parse body of "HTTP Response for Data".  |*next_update_sec| is the minimum
30 // delay to next update.  |*reset| is set to true if the update requested a
31 // database reset.  |*chunk_deletes| receives add-del and sub-del requests,
32 // while |*chunk_urls| receives the list of redirect urls to fetch.  Returns
33 // |false| if the update could not be decoded properly, in which case all
34 // results should be discarded.
35 bool ParseUpdate(const char* chunk_data,
36                  size_t chunk_len,
37                  size_t* next_update_sec,
38                  bool* reset,
39                  std::vector<SBChunkDelete>* chunk_deletes,
40                  std::vector<ChunkUrl>* chunk_urls);
41 
42 // Parse body of a redirect response.  |*chunks| receives the parsed chunk data.
43 // Returns |false| if the data could not be parsed correctly, in which case all
44 // results should be discarded.
45 bool ParseChunk(const char* chunk_data,
46                 size_t chunk_len,
47                 ScopedVector<SBChunkData>* chunks);
48 
49 // Parse body of "HTTP Response for Full-Length Hashes", returning the list of
50 // full hashes.  Returns |false| if the data could not be parsed correctly, in
51 // which case all results should be discarded.
52 bool ParseGetHash(const char* chunk_data,
53                   size_t chunk_len,
54                   base::TimeDelta* cache_lifetime,
55                   std::vector<SBFullHashResult>* full_hashes);
56 
57 // Convert prefix hashes into a "HTTP Request for Full-Length Hashes" body.
58 std::string FormatGetHash(const std::vector<SBPrefix>& prefixes);
59 
60 // Format the LIST part of "HTTP Request for Data" body.
61 std::string FormatList(const SBListChunkRanges& list);
62 
63 }  // namespace safe_browsing
64 
65 #endif  // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_PARSER_H_
66