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.
5 #ifndef CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_PARSER_H_
6 #define CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_PARSER_H_
8 // Parsers and formatters for SafeBrowsing v3.0 protocol:
9 // https://devsite.googleplex.com/safe-browsing/developers_guide_v3
11 // The quoted references are with respect to that document.
16 #include "base/basictypes.h"
17 #include "base/memory/scoped_vector.h"
18 #include "chrome/browser/safe_browsing/safe_browsing_util.h"
24 namespace safe_browsing
{
26 // TODO(shess): Maybe the data/len pairs could be productively replaced with
27 // const base::StringPiece&.
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
,
37 size_t* next_update_sec
,
39 std::vector
<SBChunkDelete
>* chunk_deletes
,
40 std::vector
<ChunkUrl
>* chunk_urls
);
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
,
47 ScopedVector
<SBChunkData
>* chunks
);
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
,
54 base::TimeDelta
* cache_lifetime
,
55 std::vector
<SBFullHashResult
>* full_hashes
);
57 // Convert prefix hashes into a "HTTP Request for Full-Length Hashes" body.
58 std::string
FormatGetHash(const std::vector
<SBPrefix
>& prefixes
);
60 // Format the LIST part of "HTTP Request for Data" body.
61 std::string
FormatList(const SBListChunkRanges
& list
);
63 } // namespace safe_browsing
65 #endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_PARSER_H_