annotate src/context.h @ 74:b7449114ebb0

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