blob: 4a245a128af91c3e55800554dbbb5196f06a4978 [file] [log] [blame]
[email protected]ce82c0572012-04-16 21:22:191// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]5da98afc2008-09-20 11:42:495#ifndef CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_PARSER_H_
6#define CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_PARSER_H_
initial.commit09911bf2008-07-26 23:55:297
[email protected]d2b383a2014-06-11 07:11:598// Parsers and formatters for SafeBrowsing v3.0 protocol:
mattma64096ac2014-09-22 20:30:469// https://developers.google.com/safe-browsing/developers_guide_v3
initial.commit09911bf2008-07-26 23:55:2910//
[email protected]d2b383a2014-06-11 07:11:5911// The quoted references are with respect to that document.
initial.commit09911bf2008-07-26 23:55:2912
avib896c712015-12-26 02:10:4313#include <stddef.h>
14
initial.commit09911bf2008-07-26 23:55:2915#include <string>
16#include <vector>
17
initial.commit09911bf2008-07-26 23:55:2918#include "chrome/browser/safe_browsing/safe_browsing_util.h"
Tim Volodinee45938472017-09-21 10:08:2219#include "components/safe_browsing/db/util.h"
initial.commit09911bf2008-07-26 23:55:2920
[email protected]d2b383a2014-06-11 07:11:5921namespace base {
22class TimeDelta;
initial.commit09911bf2008-07-26 23:55:2923};
24
[email protected]d2b383a2014-06-11 07:11:5925namespace 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.
36bool 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.
46bool ParseChunk(const char* chunk_data,
47 size_t chunk_len,
dcheng7bacc0e2016-04-11 20:10:5448 std::vector<std::unique_ptr<SBChunkData>>* chunks);
[email protected]d2b383a2014-06-11 07:11:5949
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.
53bool 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.
59std::string FormatGetHash(const std::vector<SBPrefix>& prefixes);
60
61// Format the LIST part of "HTTP Request for Data" body.
62std::string FormatList(const SBListChunkRanges& list);
63
64} // namespace safe_browsing
initial.commit09911bf2008-07-26 23:55:2965
[email protected]5da98afc2008-09-20 11:42:4966#endif // CHROME_BROWSER_SAFE_BROWSING_PROTOCOL_PARSER_H_