forked from e2guardian/e2guardian
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ListMeta.hpp
151 lines (123 loc) · 5.49 KB
/
ListMeta.hpp
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// ListMeta - super-class for both item and phrase lists
// For all support, instructions and copyright go to:
// http://e2guardian.org/
// Released under the GPL v2, with the OpenSSL exception described in the README file.
#ifndef __HPP_LISTMETA
#define __HPP_LISTMETA
// INLCUDES
#include <vector>
#include <deque>
#include <map>
#include <string>
#include "String.hpp"
#include "RegExp.hpp"
#include "ListContainer.hpp"
#define LIST_TYPE_IP 1
#define LIST_TYPE_SITE 2
#define LIST_TYPE_IPSITE 3
#define LIST_TYPE_URL 4
#define LIST_TYPE_SEARCH 5
#define LIST_TYPE_REGEXP_BOOL 6
#define LIST_TYPE_REGEXP_REP 7
#define LIST_TYPE_PHRASE_BANNED 8
#define LIST_TYPE_PHRASE_WEIGHTED 9
#define LIST_TYPE_PHRASE_EXCEPTION 10
#define LIST_TYPE_MIME 11
#define LIST_TYPE_FILE_EXT 12
#define LIST_TYPE_TIME 13
#define LIST_TYPE_MAP 14
#define LIST_TYPE_IPMAP 15
#define LIST_TYPE_ERROR 16
#define LIST_TYPE_TOP 17
#define LIST_METHOD_READF_SWS 1
#define LIST_METHOD_READF_EWS 2
#define LIST_METHOD_REGEXP_BOOL 3
#define LIST_METHOD_REGEXP_REPL 4
#define LIST_METHOD_PHRASES 5
#define LIST_METHOD_IP 6
#define LIST_METHOD_TIME 7
#define LIST_METHOD_MAP 8
#define LIST_METHOD_IPMAP 9
// DECLARATIONS
class ListMeta
{
public:
int items;
bool reverse_lookups = false;
struct list_info {
String name;
String pwd;
unsigned int type;
unsigned int method_type;
unsigned int list_ref;
std::deque<RegExp> comp;
std::deque<String> source;
std::deque<String> replace;
std::deque<unsigned int> reg_list_ref;
unsigned int mess_no;
unsigned int log_mess_no;
bool anon_log;
bool site_wild;
bool used = false;
};
struct list_result {
String match; // to hold match from list
String category; // holds list category
String result; // to hold any modified Sting
int mess_no = 0;
int log_mess_no = 0;
bool anon_log = false;
};
std::vector<list_info> list_vec;
String list_type(int type);
String type_map[LIST_TYPE_TOP] = { "",
"iplist",
"sitelist",
"ipsitelist",
"urllist",
"searchlist",
"regexpboollist",
"regexpreplacelist",
"phrasebannedlist",
"phraseweightedlist",
"phraseexceptionlist",
"mimelist",
"fileextlist",
"timelist",
"maplist",
"ipmaplist",
"unknown list"
};
ListMeta();
~ListMeta();
void reset();
bool load_type(int type, std::deque<String> &list);
struct list_info findList(String name, int type);
struct list_info *findListPtr(String name, int type);
unsigned int findListId(String name, int type);
bool list_exists(String name, int type);
bool inList(String name, int type, String &tofind, list_result &res);
bool inList(list_info &list, String &tofind, list_result &res);
bool inList(list_info &info, std::deque<String> &header, list_result &res);
bool readFile(const char *filename, const char *pwd, unsigned int *whichlist, bool sortsw, const char *listname,bool isip = false, bool istime = false,
bool is_map = false);
bool readRegExReplacementFile(const char *filename, const char *pwd, const char *listname, unsigned int &listid,
std::deque<String> &list_rep, std::deque<RegExp> &list_comp);
private:
char *inURLList(String &url, unsigned int list, String &lastcategory, bool &site_wild);
const char *inSiteList(String &url, unsigned int list, String &lastcategory, bool &site_wild);
const char *inSearchList(String &words, unsigned int list,String &lastcategory);
int inRegExpURLList(String &url, std::deque<RegExp> &list_comp, std::deque<unsigned int> &list_ref, unsigned int list, String &lastcategory);
bool regExp(String &line, std::deque<RegExp> ®exp_list, std::deque<String> &replacement_list);
bool headerRegExpReplace(ListMeta::list_info &listi, std::deque<String> &header, list_result &res );
int inHeaderRegExp(list_info &listi, std::deque<String> &header, list_result &res, String &lastcategory );
bool isIPHostname(String url);
char *testBlanketBlock(unsigned int list, bool ip, bool ssl, String &lastcategory);
RegExp isiphost;
bool precompileregexps();
bool readRegExMatchFile(const char *filename, const char *pwd, const char *listname, unsigned int &listref,
std::deque<RegExp> &list_comp, std::deque<String> &list_source, std::deque<unsigned int> &list_ref);
bool compileRegExMatchFile(unsigned int list, std::deque<RegExp> &list_comp,
std::deque<String> &list_source, std::deque<unsigned int> &list_ref);
};
#endif