Debian Codegraph @

src/ListMeta.hpp

raw
1 // ListMeta - super-class for both item and phrase lists
2
3 // For all support, instructions and copyright go to:
4 // http://e2guardian.org/
5 // Released under the GPL v2, with the OpenSSL exception described in the README file.
6
7 #ifndef __HPP_LISTMETA
8 #define __HPP_LISTMETA
9
10 // INLCUDES
11
12 #include <cstdint>
13 #include <vector>
14 #include <deque>
15 #include <map>
16 #include <string>
17 #include "String.hpp"
18 #include "RegExp.hpp"
19 #include "ListContainer.hpp"
20
21 #define LIST_TYPE_IP 1
22 #define LIST_TYPE_SITE 2
23 #define LIST_TYPE_IPSITE 3
24 #define LIST_TYPE_URL 4
25 #define LIST_TYPE_SEARCH 5
26 #define LIST_TYPE_REGEXP_BOOL 6
27 #define LIST_TYPE_REGEXP_REP 7
28 #define LIST_TYPE_PHRASE_BANNED 8
29 #define LIST_TYPE_PHRASE_WEIGHTED 9
30 #define LIST_TYPE_PHRASE_EXCEPTION 10
31 #define LIST_TYPE_MIME 11
32 #define LIST_TYPE_FILE_EXT 12
33 #define LIST_TYPE_TIME 13
34 #define LIST_TYPE_MAP 14
35 #define LIST_TYPE_IPMAP 15
36 #define LIST_TYPE_CATEGORY 16
37 #define LIST_TYPE_ERROR 17
38 #define LIST_TYPE_TOP 18
39
40 #define LIST_METHOD_READF_SWS 1
41 #define LIST_METHOD_READF_EWS 2
42 #define LIST_METHOD_REGEXP_BOOL 3
43 #define LIST_METHOD_REGEXP_REPL 4
44 #define LIST_METHOD_PHRASES 5
45 #define LIST_METHOD_IP 6
46 #define LIST_METHOD_TIME 7
47 #define LIST_METHOD_MAP 8
48 #define LIST_METHOD_IPMAP 9
49
50 // DECLARATIONS
51
52 class ListMeta
53 {
54 public:
55 int items;
56 bool reverse_lookups = false;
57
58 struct list_info {
59 String name;
60 String pwd;
61 unsigned int type;
62 unsigned int method_type;
63 unsigned int list_ref;
64 std::deque<RegExp> comp;
65 std::deque<String> source;
66 std::deque<String> replace;
67 std::deque<unsigned int> reg_list_ref;
68 unsigned int mess_no;
69 unsigned int log_mess_no;
70 bool anon_log;
71 bool site_wild;
72 bool used = false;
73 };
74
75 struct list_result {
76 String match; // to hold match from list
77 String category; // holds list category
78 String result; // to hold any modified Sting
79 int mess_no = 0;
80 int log_mess_no = 0;
81 bool anon_log = false;
82 };
83
84 std::vector<list_info> list_vec;
85
86 String list_type(int type);
87
88 String type_map[LIST_TYPE_TOP] = { "",
89 "iplist",
90 "sitelist",
91 "ipsitelist",
92 "urllist",
93 "searchlist",
94 "regexpboollist",
95 "regexpreplacelist",
96 "phrasebannedlist",
97 "phraseweightedlist",
98 "phraseexceptionlist",
99 "mimelist",
100 "fileextlist",
101 "timelist",
102 "maplist",
103 "ipmaplist",
104 "categorylist",
105 "unknown list"
106 };
107
108 ListMeta();
109 ~ListMeta();
110
111 void reset();
112
113 bool load_type(int type, std::deque<String> &list);
114
115 struct list_info findList(String name, int type);
116 struct list_info *findListPtr(String name, int type);
117
118 unsigned int findListId(String name, int type);
119
120 bool list_exists(String name, int type);
121
122 bool inList(String name, int type, String &tofind, list_result &res);
123 bool inList(list_info &list, String &tofind, list_result &res);
124 bool inList(list_info &info, std::deque<String> &header, list_result &res);
125
126
127
128 bool readFile(const char *filename, const char *pwd, unsigned int *whichlist, bool sortsw, const char *listname,bool isip = false, bool istime = false,
129 bool is_map = false);
130
131 bool readRegExReplacementFile(const char *filename, const char *pwd, const char *listname, unsigned int &listid,
132 std::deque<String> &list_rep, std::deque<RegExp> &list_comp);
133
134 private:
135
136 bool inURLList(String &url, unsigned int list, String &lastcategory, bool &site_wild, String &match, String &result);
137 bool inSiteList(String &url, unsigned int list, String &lastcategory, bool &site_wild, String &match, String &result);
138 bool inSearchList(String &words, unsigned int list,String &lastcategory, String &match, String &result);
139 int inRegExpURLList(String &url, std::deque<RegExp> &list_comp, std::deque<unsigned int> &list_ref, unsigned int list, String &lastcategory);
140 bool regExp(String &line, std::deque<RegExp> &regexp_list, std::deque<String> &replacement_list);
141 bool headerRegExpReplace(ListMeta::list_info &listi, std::deque<String> &header, list_result &res );
142 int inHeaderRegExp(list_info &listi, std::deque<String> &header, list_result &res, String &lastcategory );
143 bool isIPHostname(String url);
144 char *testBlanketBlock(unsigned int list, bool ip, bool ssl, String &lastcategory);
145 RegExp isiphost;
146 bool precompileregexps();
147 bool readRegExMatchFile(const char *filename, const char *pwd, const char *listname, unsigned int &listref,
148 std::deque<RegExp> &list_comp, std::deque<String> &list_source, std::deque<unsigned int> &list_ref);
149 bool compileRegExMatchFile(unsigned int list, std::deque<RegExp> &list_comp,
150 std::deque<String> &list_source, std::deque<unsigned int> &list_ref);
151
152 };
153
154 #endif