forked from brave-experiments/ad-block
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ad_block_client.h
107 lines (92 loc) · 3.58 KB
/
ad_block_client.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* Copyright (c) 2015 Brian R. Bondy. Distributed under the MPL2 license.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef AD_BLOCK_CLIENT_H_
#define AD_BLOCK_CLIENT_H_
#include "./filter.h"
class CosmeticFilter;
class BloomFilter;
class BadFingerprintsHashSet;
template<class T>
class HashSet;
class AdBlockClient {
public:
AdBlockClient();
~AdBlockClient();
void clear();
bool parse(const char *input);
bool matches(const char *input,
FilterOption contextOption = FONoFilterOption,
const char *contextDomain = nullptr);
bool findMatchingFilters(const char *input,
FilterOption contextOption,
const char *contextDomain,
Filter **matchingFilter,
Filter **matchingExceptionFilter);
// Serializes a the parsed data and bloom filter data into a single buffer.
// The returned buffer should be deleted.
char * serialize(int *size,
bool ignoreCosmeticFilters = true,
bool ignoreHtmlFilters = true);
// Deserializes the buffer, a size is not needed since a serialized.
// buffer is self described
bool deserialize(char *buffer);
void enableBadFingerprintDetection();
const char * getDeserializedBuffer() {
return deserializedBuffer;
}
Filter *filters;
Filter *cosmeticFilters;
Filter *htmlFilters;
Filter *exceptionFilters;
Filter *noFingerprintFilters;
Filter *noFingerprintExceptionFilters;
int numFilters;
int numCosmeticFilters;
int numHtmlFilters;
int numExceptionFilters;
int numNoFingerprintFilters;
int numNoFingerprintExceptionFilters;
int numHostAnchoredFilters;
int numHostAnchoredExceptionFilters;
BloomFilter *bloomFilter;
BloomFilter *exceptionBloomFilter;
HashSet<Filter> *hostAnchoredHashSet;
HashSet<Filter> *hostAnchoredExceptionHashSet;
// Used only in the perf program to create a list of bad fingerprints
BadFingerprintsHashSet *badFingerprintsHashSet;
// Stats kept for matching
unsigned int numFalsePositives;
unsigned int numExceptionFalsePositives;
unsigned int numBloomFilterSaves;
unsigned int numExceptionBloomFilterSaves;
unsigned int numHashSetSaves;
unsigned int numExceptionHashSetSaves;
protected:
// Determines if a passed in array of filter pointers matches for any of
// the input
bool hasMatchingFilters(Filter *filter, int numFilters, const char *input,
int inputLen, FilterOption contextOption, const char *contextDomain,
BloomFilter *inputBloomFilter, const char *inputHost, int inputHostLen,
Filter **matchingFilter = nullptr);
void initBloomFilter(BloomFilter**, const char *buffer, int len);
bool initHashSet(HashSet<Filter>**, char *buffer, int len);
char *deserializedBuffer;
};
extern const char *separatorCharacters;
void parseFilter(const char *input, const char *end, Filter *f,
BloomFilter *bloomFilter = nullptr,
BloomFilter *exceptionBloomFilter = nullptr,
HashSet<Filter> *hostAnchoredHashSet = nullptr,
HashSet<Filter> *hostAnchoredExceptionHashSet = nullptr,
HashSet<CosmeticFilter> *simpleCosmeticFilters = nullptr);
void parseFilter(const char *input, Filter *f,
BloomFilter *bloomFilter = nullptr,
BloomFilter *exceptionBloomFilter = nullptr,
HashSet<Filter> *hostAnchoredHashSet = nullptr,
HashSet<Filter> *hostAnchoredExceptionHashSet = nullptr,
HashSet<CosmeticFilter> *simpleCosmeticFilters = nullptr);
bool isSeparatorChar(char c);
int findFirstSeparatorChar(const char *input, const char *end);
#endif // AD_BLOCK_CLIENT_H_