comparison src/context.h @ 71:dd21c8e13074

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