73
|
1 #ifndef context_include
|
|
2 #define context_include
|
|
3
|
71
|
4 #include "tokenizer.h"
|
|
5 #include <map>
|
|
6
|
|
7
|
|
8 enum status {oksofar, // not rejected yet
|
|
9 white, // whitelisted
|
|
10 black, // blacklisted
|
|
11 reject, // rejected by a dns list
|
|
12 reject_tag, // too many bad html tags
|
|
13 reject_host}; // too many hosts/urls in body
|
|
14
|
|
15 class DNSBL;
|
|
16 class CONTEXT;
|
73
|
17 class recorder;
|
71
|
18
|
|
19 typedef map<char *, char *, ltstr> string_map;
|
|
20 typedef set<int> int_set;
|
|
21 typedef list<char *> string_list;
|
|
22 typedef DNSBL * DNSBLP;
|
|
23 typedef list<DNSBLP> dnsblp_list;
|
|
24 typedef map<char *, DNSBLP, ltstr> dnsblp_map;
|
|
25 typedef CONTEXT * CONTEXTP;
|
|
26 typedef list<CONTEXTP> context_list;
|
|
27 typedef map<char *, CONTEXTP, ltstr> context_map;
|
|
28 typedef map<char *, int, ltstr> ns_mapper;
|
|
29
|
|
30 struct DNSBL {
|
|
31 char *name; // nickname for this dns based list
|
|
32 char *suffix; // blacklist suffix like blackholes.five-ten-sg.com
|
|
33 char *message; // error message with one or two %s operators for the ip address replacement
|
|
34 DNSBL(char *n, char *s, char *m);
|
|
35 };
|
|
36
|
|
37 class CONTEXT {
|
|
38 CONTEXTP parent;
|
|
39 char * name;
|
|
40 context_map children; // map child context names to their contexts
|
|
41 string_set env_to; //
|
|
42 string_map env_from; // map senders to white/black/unknown
|
|
43 context_map env_from_context; // map senders to a child context
|
|
44 char * env_from_default; // default value for senders that are not found in the map white/black/unknown/inherit
|
|
45 bool content_filtering; //
|
|
46 char * content_suffix; // for sbl url body filtering
|
|
47 char * content_message; // ""
|
|
48 string_set content_host_ignore;// hosts to ignore for content sbl checking
|
|
49 string_set content_tlds; //
|
|
50 string_set html_tags; // set of valid html tags
|
|
51 int host_limit; // limit on host names
|
|
52 char * host_limit_message; // error message for excessive host names
|
|
53 bool host_random; // pick a random selection of host names rather than error for excessive hosts
|
|
54 int tag_limit; // limit on bad html tags
|
|
55 char * tag_limit_message; // error message for excessive bad html tags
|
|
56 dnsblp_map dnsbl_names; // name to dnsbl mapping for lists that are available in this context and children
|
|
57 dnsblp_list dnsbl_list; // list of dnsbls to be used in this context
|
|
58
|
|
59 public:
|
|
60 CONTEXT(CONTEXTP parent_, char *name_);
|
|
61 ~CONTEXT();
|
|
62 CONTEXTP get_parent() {return parent;};
|
|
63 char* get_full_name(char *buf, int size);
|
|
64 void add_context(CONTEXTP child) {children[child->name] = child;};
|
|
65 bool allow_env_to(char *to) {return (parent) ? parent->cover_env_to(to) : true;};
|
|
66 bool cover_env_to(char *to);
|
|
67
|
|
68 void add_to(char *to) {env_to.insert(to);};
|
|
69 void add_from(char *from, char *status) {env_from[from] = status;};
|
|
70 void add_from_context(char *from, CONTEXTP con) {env_from_context[from] = con;};
|
|
71 void set_from_default(char *status) {env_from_default = status;};
|
|
72 char* find_from(char *from);
|
|
73 CONTEXTP find_from_context(char *from);
|
|
74 CONTEXTP find_from_context_name(char *name);
|
|
75
|
|
76 void set_content_filtering(bool filter) {content_filtering = filter;};
|
|
77 void set_content_suffix(char *suffix) {content_suffix = suffix;};
|
|
78 void set_content_message(char *message) {content_message = message;};
|
|
79 void add_ignore(char *host) {content_host_ignore.insert(host);};
|
|
80 void add_tld(char *tld) {content_tlds.insert(tld);};
|
|
81
|
|
82 void set_host_limit(int limit) {host_limit = limit;};
|
|
83 void set_host_message(char *message) {host_limit_message = message;};
|
|
84 void set_host_random(bool random) {host_random = random;};
|
|
85 void set_tag_limit(int limit) {tag_limit = limit;};
|
|
86 void set_tag_message(char *message) {tag_limit_message = message;};
|
|
87 void add_tag(char *tag) {html_tags.insert(tag);};
|
|
88
|
|
89 void add_dnsbl(char *name, DNSBLP dns) {dnsbl_names[name] = dns;};
|
|
90 void add_dnsbl(DNSBLP dns) {dnsbl_list.push_back(dns);};
|
|
91 DNSBLP find_dnsbl(char *name);
|
|
92
|
73
|
93 int get_host_limit() {return host_limit;};
|
|
94 bool get_host_random() {return host_random;};
|
|
95 char* get_content_suffix() {return content_suffix;};
|
|
96 char* get_content_message() {return content_message;};
|
|
97 string_set& get_content_host_ignore() {return content_host_ignore;};
|
|
98 string_set& get_content_tlds() {return content_tlds;};
|
|
99 string_set& get_html_tags() {return html_tags;};
|
|
100 dnsblp_list& get_dnsbl_list() {return dnsbl_list;};
|
|
101 bool get_content_filtering() {return content_filtering;};
|
|
102
|
74
|
103 bool acceptable_content(recorder &memory, char *&msg);
|
73
|
104 bool ignore_host(char *host);
|
|
105
|
71
|
106 void dump(int level = 0);
|
|
107 };
|
|
108
|
|
109
|
|
110 struct CONFIG {
|
|
111 // the only mutable stuff once it has been loaded from the config file
|
|
112 int reference_count; // protected by the global config_mutex
|
|
113 // all the rest is constant after loading from the config file
|
|
114 int generation;
|
|
115 time_t load_time;
|
|
116 string_set config_files;
|
|
117 context_list contexts; // owns all the contexts, not just top level contexts
|
|
118 context_map env_to; // map recipient to a filtering context
|
|
119 CONTEXTP default_context;// for env_to values that don't have their own specific filtering context
|
73
|
120 // the default context is also used for some of the content filtering values
|
71
|
121
|
|
122 CONFIG();
|
|
123 ~CONFIG();
|
|
124 void add_context(CONTEXTP con);
|
|
125 void add_to(char *to, CONTEXTP con) {env_to[to] = con;};
|
|
126 CONTEXTP find_context(char *to, char *from);
|
73
|
127
|
|
128 char* get_content_suffix() {return default_context->get_content_suffix() ;};
|
|
129 char* get_content_message() {return default_context->get_content_message() ;};
|
|
130 string_set& get_content_host_ignore() {return default_context->get_content_host_ignore() ;};
|
|
131 string_set& get_content_tlds() {return default_context->get_content_tlds() ;};
|
|
132 string_set& get_html_tags() {return default_context->get_html_tags() ;};
|
|
133
|
71
|
134 void dump();
|
|
135 };
|
|
136
|
|
137 extern char *token_black;
|
|
138 extern char *token_content;
|
|
139 extern char *token_context;
|
|
140 extern char *token_dccfrom;
|
|
141 extern char *token_dccto;
|
|
142 extern char *token_default;
|
|
143 extern char *token_dnsbl;
|
|
144 extern char *token_dnsbll;
|
|
145 extern char *token_envfrom;
|
|
146 extern char *token_envto;
|
|
147 extern char *token_filter;
|
|
148 extern char *token_host_limit;
|
|
149 extern char *token_html_limit;
|
|
150 extern char *token_html_tags;
|
|
151 extern char *token_ignore;
|
|
152 extern char *token_include;
|
|
153 extern char *token_inherit;
|
|
154 extern char *token_lbrace;
|
|
155 extern char *token_many;
|
|
156 extern char *token_off;
|
|
157 extern char *token_ok;
|
|
158 extern char *token_ok2;
|
|
159 extern char *token_on;
|
|
160 extern char *token_rbrace;
|
|
161 extern char *token_semi;
|
|
162 extern char *token_soft;
|
|
163 extern char *token_tld;
|
|
164 extern char *token_unknown;
|
|
165 extern char *token_white;
|
|
166
|
|
167 extern string_set all_strings; // owns all the strings, only modified by the config loader thread
|
|
168
|
74
|
169 void discard(string_set &s);
|
71
|
170 char* register_string(string_set &s, char *name);
|
|
171 char* register_string(char *name);
|
|
172 CONFIG *parse_config(char *fn);
|
|
173 bool load_conf(CONFIG &dc, char *fn);
|
|
174 void token_init();
|
73
|
175
|
|
176 #endif
|