72
|
1 /*
|
|
2
|
|
3 Copyright (c) 2004 Carl Byington - 510 Software Group, released under
|
|
4 the GPL version 2 or any later version at your choice available at
|
|
5 http://www.fsf.org/licenses/gpl.txt
|
|
6
|
|
7 */
|
|
8
|
|
9 #include "includes.h"
|
71
|
10
|
73
|
11 static char* context_version="$Id$";
|
71
|
12
|
|
13 char *token_black;
|
|
14 char *token_content;
|
|
15 char *token_context;
|
|
16 char *token_dccfrom;
|
|
17 char *token_dccto;
|
|
18 char *token_default;
|
|
19 char *token_dnsbl;
|
|
20 char *token_dnsbll;
|
|
21 char *token_envfrom;
|
|
22 char *token_envto;
|
|
23 char *token_filter;
|
|
24 char *token_host_limit;
|
|
25 char *token_html_limit;
|
|
26 char *token_html_tags;
|
|
27 char *token_ignore;
|
|
28 char *token_include;
|
|
29 char *token_inherit;
|
|
30 char *token_lbrace;
|
|
31 char *token_many;
|
|
32 char *token_off;
|
|
33 char *token_ok;
|
|
34 char *token_ok2;
|
|
35 char *token_on;
|
|
36 char *token_rbrace;
|
|
37 char *token_semi;
|
|
38 char *token_soft;
|
|
39 char *token_tld;
|
|
40 char *token_unknown;
|
|
41 char *token_white;
|
|
42
|
|
43 string_set all_strings; // owns all the strings, only modified by the config loader thread
|
|
44
|
|
45 DNSBL::DNSBL(char *n, char *s, char *m) {
|
|
46 name = n;
|
|
47 suffix = s;
|
|
48 message = m;
|
|
49 }
|
|
50
|
|
51
|
|
52 CONFIG::CONFIG() {
|
|
53 reference_count = 0;
|
|
54 generation = 0;
|
|
55 load_time = 0;
|
|
56 default_context = NULL;
|
|
57 }
|
|
58
|
|
59
|
|
60 CONFIG::~CONFIG() {
|
|
61 for (context_list::iterator i=contexts.begin(); i!=contexts.end(); i++) {
|
|
62 CONTEXT *c = *i;
|
|
63 delete c;
|
|
64 }
|
|
65 }
|
|
66
|
|
67
|
|
68 void CONFIG::add_context(CONTEXTP con) {
|
|
69 contexts.push_back(con);
|
|
70 if (!default_context && !con->get_parent()) {
|
|
71 // first global context
|
|
72 default_context = con;
|
|
73 }
|
|
74 }
|
|
75
|
|
76
|
|
77 CONTEXTP CONFIG::find_context(char *to, char *from) {
|
|
78 CONTEXTP con = NULL;
|
|
79 context_map::iterator i = env_to.find(from);
|
|
80 if (i != env_to.end()) {
|
|
81 con = (*i).second;
|
|
82 return con->find_from_context(from);
|
|
83 }
|
|
84 char *x = strchr(to, '@');
|
|
85 if (x) {
|
|
86 x++;
|
|
87 i = env_to.find(x);
|
|
88 if (i != env_to.end()) {
|
|
89 con = (*i).second;
|
|
90 return con->find_from_context(from);
|
|
91 }
|
|
92 }
|
72
|
93 return default_context->find_from_context(from);
|
71
|
94 }
|
|
95
|
|
96
|
|
97 void CONFIG::dump() {
|
|
98 if (default_context) default_context->dump();
|
|
99 for (context_list::iterator i=contexts.begin(); i!=contexts.end(); i++) {
|
|
100 CONTEXTP c = *i;
|
|
101 CONTEXTP p = c->get_parent();
|
|
102 if (!p && (c != default_context)) c->dump();
|
|
103 }
|
|
104 }
|
|
105
|
|
106
|
|
107 CONTEXT::CONTEXT(CONTEXTP parent_, char *name_) {
|
|
108 parent = parent_;
|
|
109 name = name_;
|
|
110 env_from_default = (parent) ? token_inherit : token_unknown;
|
|
111 content_filtering = (parent) ? parent->content_filtering : false;
|
|
112 content_suffix = NULL;
|
|
113 content_message = NULL;
|
|
114 host_limit = 0;
|
|
115 host_limit_message = NULL;
|
|
116 host_random = false;
|
|
117 tag_limit = 0;
|
|
118 tag_limit_message = NULL;
|
|
119 }
|
|
120
|
|
121
|
|
122 CONTEXT::~CONTEXT() {
|
|
123 for (dnsblp_map::iterator i=dnsbl_names.begin(); i!=dnsbl_names.end(); i++) {
|
|
124 DNSBLP d = (*i).second;
|
|
125 // delete the underlying DNSBL objects.
|
|
126 delete d;
|
|
127 }
|
|
128 }
|
|
129
|
|
130
|
|
131 char *CONTEXT::get_full_name(char *buffer, int size) {
|
|
132 if (!parent) return name;
|
|
133 const int maxlen = 1000;
|
|
134 char buf[maxlen];
|
|
135 snprintf(buffer, size, "%s.%s", parent->get_full_name(buf, maxlen), name);
|
|
136 return buffer;
|
|
137 }
|
|
138
|
|
139
|
|
140 bool CONTEXT::cover_env_to(char *to) {
|
|
141 const int maxlen = 1000;
|
|
142 char buffer[maxlen];
|
|
143 char *x = strchr(to, '@');
|
|
144 if (x) x++;
|
|
145 else x = to;
|
|
146 string_set::iterator i = env_to.find(x);
|
|
147 if (i != env_to.end()) return true;
|
|
148 return (parent) ? parent->cover_env_to(to) : false;
|
|
149 }
|
|
150
|
|
151
|
|
152 char *CONTEXT::find_from(char *from) {
|
|
153 // do we have a white/black/unknown for this full from value?
|
|
154 string_map::iterator i = env_from.find(from);
|
|
155 if (i != env_from.end()) return (*i).second;
|
|
156 // do we have a white/black/unknown for the source domain name?
|
|
157 char *x = strchr(from, '@');
|
|
158 if (x) {
|
|
159 x++;
|
|
160 i = env_from.find(x);
|
|
161 if (i != env_from.end()) return (*i).second;
|
|
162 }
|
|
163 if ((env_from_default == token_inherit) && parent) {
|
|
164 return parent->find_from(from);
|
|
165 }
|
|
166 return env_from_default;
|
|
167 }
|
|
168
|
|
169
|
|
170 CONTEXTP CONTEXT::find_from_context(char *from) {
|
|
171 // do we have a special child context for this full from value?
|
|
172 context_map::iterator j = env_from_context.find(from);
|
|
173 if (j != env_from_context.end()) {
|
|
174 CONTEXTP con = (*j).second;
|
|
175 return con->find_from_context(from);
|
|
176 }
|
|
177 char *x = strchr(from, '@');
|
|
178 if (x) {
|
|
179 x++;
|
|
180 // do we have a special context for the source domain name?
|
|
181 j = env_from_context.find(x);
|
|
182 if (j != env_from_context.end()) {
|
|
183 CONTEXTP con = (*j).second;
|
|
184 return con->find_from_context(from);
|
|
185 }
|
|
186 }
|
|
187 return this;
|
|
188 }
|
|
189
|
|
190
|
|
191 CONTEXTP CONTEXT::find_from_context_name(char *name) {
|
|
192 context_map::iterator i = children.find(name);
|
|
193 if (i != children.end()) return (*i).second;
|
|
194 return NULL;
|
|
195 }
|
|
196
|
|
197
|
|
198 DNSBLP CONTEXT::find_dnsbl(char *name) {
|
|
199 dnsblp_map::iterator i = dnsbl_names.find(name);
|
|
200 if (i != dnsbl_names.end()) return (*i).second;
|
|
201 if (parent) return parent->find_dnsbl(name);
|
|
202 return NULL;
|
|
203 }
|
|
204
|
|
205
|
72
|
206 bool CONTEXT::acceptable_content(recorder &memory, char *&msg) {
|
|
207 if (memory.excessive_bad_tags(tag_limit)) {
|
|
208 msg = tag_limit_message;
|
|
209 return false;
|
|
210 }
|
|
211 if (!host_random && memory.excessive_hosts(host_limit)) {
|
|
212 msg = host_limit_message;
|
|
213 return false;
|
|
214 }
|
|
215 }
|
|
216
|
|
217
|
71
|
218 void CONTEXT::dump(int level) {
|
|
219 const int maxlen = 1000;
|
|
220 char indent[maxlen];
|
|
221 int i = min(maxlen-1, level*4);
|
|
222 memset(indent, ' ', i);
|
|
223 indent[i] = '\0';
|
|
224 printf("%s context %s { \n", indent, name);
|
|
225
|
|
226 for (dnsblp_map::iterator i=dnsbl_names.begin(); i!=dnsbl_names.end(); i++) {
|
|
227 char *n = (*i).first;
|
|
228 DNSBL &d = *(*i).second;
|
|
229 printf("%s dnsbl %s %s \"%s\"; \n", indent, n, d.suffix, d.message);
|
|
230 }
|
|
231
|
|
232 if (!dnsbl_list.empty()) {
|
|
233 printf("%s dnsbl_list", indent);
|
|
234 for (dnsblp_list::iterator i=dnsbl_list.begin(); i!=dnsbl_list.end(); i++) {
|
|
235 DNSBL &d = *(*i);
|
|
236 printf(" %s", d.name);
|
|
237 }
|
|
238 printf("; \n");
|
|
239 }
|
|
240
|
|
241 if (content_filtering) {
|
|
242 printf("%s content on { \n", indent, env_from_default);
|
|
243 if (content_suffix) {
|
|
244 printf("%s filter %s \"%s\"; \n", indent, content_suffix, content_message);
|
|
245 }
|
|
246 if (!content_host_ignore.empty()) {
|
|
247 printf("%s ignore { \n", indent);
|
|
248 for (string_set::iterator i=content_host_ignore.begin(); i!=content_host_ignore.end(); i++) {
|
|
249 printf("%s %s; \n", indent, *i);
|
|
250 }
|
|
251 printf("%s }; \n", indent);
|
|
252 }
|
|
253 if (!content_tlds.empty()) {
|
|
254 printf("%s tld { \n", indent);
|
|
255 printf("%s ", indent);
|
|
256 for (string_set::iterator i=content_tlds.begin(); i!=content_tlds.end(); i++) {
|
|
257 printf("%s; ", *i);
|
|
258 }
|
|
259 printf("\n%s }; \n", indent);
|
|
260 }
|
|
261 if (!html_tags.empty()) {
|
|
262 printf("%s html_tags { \n", indent);
|
|
263 printf("%s ", indent);
|
|
264 for (string_set::iterator i=html_tags.begin(); i!=html_tags.end(); i++) {
|
|
265 printf("%s; ", *i);
|
|
266 }
|
|
267 printf("\n%s }; \n", indent);
|
|
268 }
|
|
269 if (host_limit_message) {
|
|
270 printf("%s host_limit on %d \"%s\"; \n", indent, host_limit, host_limit_message);
|
|
271 }
|
|
272 else if (host_random) {
|
|
273 printf("%s host_limit soft %d; \n", indent, host_limit);
|
|
274 }
|
|
275 else {
|
|
276 printf("%s host_limit off; \n", indent);
|
|
277 }
|
|
278 if (tag_limit_message) {
|
|
279 printf("%s tag_limit on %d \"%s\"; \n", indent, tag_limit, tag_limit_message);
|
|
280 }
|
|
281 else {
|
|
282 printf("%s tag_limit off; \n", indent);
|
|
283 }
|
|
284 printf("%s }; \n", indent);
|
|
285 }
|
|
286 else {
|
|
287 printf("%s content off {}; \n", indent, env_from_default);
|
|
288 }
|
|
289
|
|
290 printf("%s env_to { \n", indent);
|
|
291 for (string_set::iterator i=env_to.begin(); i!=env_to.end(); i++) {
|
|
292 printf("%s %s; \n", indent, *i);
|
|
293 }
|
|
294 printf("%s }; \n", indent);
|
|
295
|
|
296 for (context_map::iterator i=children.begin(); i!=children.end(); i++) {
|
|
297 CONTEXTP c = (*i).second;
|
|
298 c->dump(level+1);
|
|
299 }
|
|
300
|
|
301 printf("%s env_from %s { \n", indent, env_from_default);
|
|
302 if (!env_from.empty()) {
|
|
303 printf("%s // white/black/unknown \n", indent);
|
|
304 for (string_map::iterator i=env_from.begin(); i!=env_from.end(); i++) {
|
|
305 char *f = (*i).first;
|
|
306 char *t = (*i).second;
|
|
307 printf("%s %s \t %s; \n", indent, f, t);
|
|
308 }
|
|
309 }
|
|
310 if (!env_from_context.empty()) {
|
|
311 printf("%s // child contexts \n", indent);
|
|
312 for (context_map::iterator j=env_from_context.begin(); j!=env_from_context.end(); j++) {
|
|
313 char *f = (*j).first;
|
|
314 CONTEXTP t = (*j).second;
|
|
315 printf("%s %s \t %s; \n", indent, f, t->name);
|
|
316 }
|
|
317 }
|
|
318 printf("%s }; \n", indent);
|
|
319
|
|
320 printf("%s }; \n", indent);
|
|
321 }
|
|
322
|
|
323
|
|
324 ////////////////////////////////////////////////
|
|
325 // helper to discard the strings held by a string_set
|
|
326 //
|
|
327 static void discard(string_set &s) {
|
|
328 for (string_set::iterator i=s.begin(); i!=s.end(); i++) {
|
|
329 free(*i);
|
|
330 }
|
|
331 s.clear();
|
|
332 }
|
|
333
|
|
334
|
|
335 ////////////////////////////////////////////////
|
|
336 // helper to register a string in a string set
|
|
337 //
|
|
338 char* register_string(string_set &s, char *name) {
|
|
339 string_set::iterator i = s.find(name);
|
|
340 if (i != s.end()) return *i;
|
|
341 char *x = strdup(name);
|
|
342 s.insert(x);
|
|
343 return x;
|
|
344 }
|
|
345
|
|
346
|
|
347 ////////////////////////////////////////////////
|
|
348 // register a global string
|
|
349 //
|
|
350 char* register_string(char *name) {
|
|
351 return register_string(all_strings, name);
|
|
352 }
|
|
353
|
|
354
|
|
355 ////////////////////////////////////////////////
|
|
356 //
|
|
357 bool tsa(TOKEN &tok, char *token);
|
|
358 bool tsa(TOKEN &tok, char *token) {
|
|
359 char *have = tok.next();
|
|
360 if (have == token) return true;
|
|
361 tok.token_error(token, have);
|
|
362 return false;
|
|
363 }
|
|
364
|
|
365
|
|
366 ////////////////////////////////////////////////
|
|
367 //
|
|
368 bool parse_dnsbl(TOKEN &tok, CONFIG &dc, CONTEXT &me);
|
|
369 bool parse_dnsbl(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
|
|
370 char *name = tok.next();
|
|
371 char *suf = tok.next();
|
|
372 char *msg = tok.next();
|
|
373 if (!tsa(tok, token_semi)) return false;
|
|
374 DNSBLP dns = new DNSBL(name, suf, msg);
|
|
375 me.add_dnsbl(name, dns);
|
|
376 return true;
|
|
377 }
|
|
378
|
|
379
|
|
380 ////////////////////////////////////////////////
|
|
381 //
|
|
382 bool parse_dnsbll(TOKEN &tok, CONFIG &dc, CONTEXT &me);
|
|
383 bool parse_dnsbll(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
|
|
384 while (true) {
|
|
385 char *have = tok.next();
|
|
386 if (!have) break;
|
|
387 if (have == token_semi) break;
|
|
388 DNSBLP dns = me.find_dnsbl(have);
|
|
389 if (dns) {
|
|
390 me.add_dnsbl(dns);
|
|
391 }
|
|
392 else {
|
|
393 tok.token_error("dnsbl name", have);
|
|
394 return false;
|
|
395 }
|
|
396 }
|
|
397 return true;
|
|
398 }
|
|
399
|
|
400
|
|
401 ////////////////////////////////////////////////
|
|
402 //
|
|
403 bool parse_content(TOKEN &tok, CONFIG &dc, CONTEXT &me);
|
|
404 bool parse_content(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
|
|
405 char *setting = tok.next();
|
|
406 if (setting == token_on) {
|
|
407 me.set_content_filtering(true);
|
|
408 }
|
|
409 else if (setting == token_off) {
|
|
410 me.set_content_filtering(false);
|
|
411 }
|
|
412 else {
|
|
413 tok.token_error("on/off", setting);
|
|
414 return false;
|
|
415 }
|
|
416 if (!tsa(tok, token_lbrace)) return false;
|
|
417 while (true) {
|
|
418 char *have = tok.next();
|
|
419 if (!have) break;
|
|
420 if (have == token_filter) {
|
|
421 me.set_content_suffix(tok.next());
|
|
422 me.set_content_message(tok.next());
|
|
423 if (!tsa(tok, token_semi)) return false;
|
|
424 }
|
|
425 else if (have == token_ignore) {
|
|
426 if (!tsa(tok, token_lbrace)) return false;
|
|
427 while (true) {
|
|
428 if (!have) break;
|
|
429 char *have = tok.next();
|
|
430 if (have == token_rbrace) {
|
|
431 break; // done
|
|
432 }
|
|
433 else {
|
|
434 me.add_ignore(have);
|
|
435 }
|
|
436 }
|
|
437 if (!tsa(tok, token_semi)) return false;
|
|
438 }
|
|
439 else if (have == token_tld) {
|
|
440 if (!tsa(tok, token_lbrace)) return false;
|
|
441 while (true) {
|
|
442 char *have = tok.next();
|
|
443 if (!have) break;
|
|
444 if (have == token_rbrace) {
|
|
445 break; // done
|
|
446 }
|
|
447 else {
|
|
448 me.add_tld(have);
|
|
449 }
|
|
450 }
|
|
451 if (!tsa(tok, token_semi)) return false;
|
|
452 }
|
|
453 else if (have == token_html_limit) {
|
|
454 have = tok.next();
|
|
455 if (have == token_on) {
|
|
456 me.set_tag_limit(tok.nextint());
|
|
457 me.set_tag_message(tok.next());
|
|
458 }
|
|
459 else if (have == token_off) {
|
|
460 me.set_tag_limit(0);
|
|
461 me.set_tag_message(NULL);
|
|
462 }
|
|
463 else {
|
|
464 tok.token_error("on/off", have);
|
|
465 return false;
|
|
466 }
|
|
467 if (!tsa(tok, token_semi)) return false;
|
|
468 }
|
|
469 else if (have == token_html_tags) {
|
|
470 if (!tsa(tok, token_lbrace)) return false;
|
|
471 while (true) {
|
|
472 char *have = tok.next();
|
|
473 if (!have) break;
|
|
474 if (have == token_rbrace) {
|
|
475 break; // done
|
|
476 }
|
|
477 else {
|
|
478 me.add_tag(have);
|
|
479 }
|
|
480 }
|
|
481 if (!tsa(tok, token_semi)) return false;
|
|
482 }
|
|
483 else if (have == token_host_limit) {
|
|
484 have = tok.next();
|
|
485 if (have == token_on) {
|
|
486 me.set_host_limit(tok.nextint());
|
|
487 me.set_host_message(tok.next());
|
|
488 me.set_host_random(false);
|
|
489 }
|
|
490 else if (have == token_off) {
|
|
491 me.set_host_limit(0);
|
|
492 me.set_host_message(NULL);
|
|
493 me.set_host_random(false);
|
|
494 }
|
|
495 else if (have == token_soft) {
|
|
496 me.set_host_limit(tok.nextint());
|
|
497 me.set_host_message(NULL);
|
|
498 me.set_host_random(true);
|
|
499 }
|
|
500 else {
|
|
501 tok.token_error("on/off/soft", have);
|
|
502 return false;
|
|
503 }
|
|
504 if (!tsa(tok, token_semi)) return false;
|
|
505 }
|
|
506 else if (have == token_rbrace) {
|
|
507 break; // done
|
|
508 }
|
|
509 else {
|
|
510 tok.token_error("content keyword", have);
|
|
511 return false;
|
|
512 }
|
|
513 }
|
|
514 return tsa(tok, token_semi);
|
|
515 }
|
|
516
|
|
517
|
|
518 ////////////////////////////////////////////////
|
|
519 //
|
|
520 bool parse_envto(TOKEN &tok, CONFIG &dc, CONTEXT &me);
|
|
521 bool parse_envto(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
|
|
522 if (!tsa(tok, token_lbrace)) return false;
|
|
523 while (true) {
|
|
524 char *have = tok.next();
|
|
525 if (!have) break;
|
|
526 if (have == token_rbrace) break;
|
|
527 if (have == token_semi) {
|
|
528 // optional separators
|
|
529 }
|
|
530 else if (have == token_dccto) {
|
|
531 char *flavor = tok.next();
|
|
532 if (!tsa(tok, token_lbrace)) return false;
|
|
533 bool keeping = false;
|
|
534 while (true) {
|
|
535 char *have = tok.next();
|
|
536 if (!have) break;
|
|
537 if (have == token_rbrace) break;
|
|
538 if (have == flavor) {
|
|
539 keeping = true;
|
|
540 continue;
|
|
541 }
|
|
542 else if ((have == token_ok) || (have == token_ok2) || (have == token_many)) {
|
|
543 keeping = false;
|
|
544 continue;
|
|
545 }
|
|
546 if (have == token_envto) {
|
|
547 have = tok.next();
|
|
548 if (keeping) {
|
|
549 if (me.allow_env_to(have)) {
|
|
550 me.add_to(have);
|
|
551 dc.add_to(have, &me);
|
|
552 }
|
|
553 }
|
|
554 }
|
|
555 tok.skipeol();
|
|
556 }
|
|
557 }
|
|
558 else if (me.allow_env_to(have)) {
|
|
559 me.add_to(have);
|
|
560 dc.add_to(have, &me);
|
|
561 }
|
|
562 else {
|
|
563 tok.token_error("valid env_to address or domain name", have);
|
|
564 return false;
|
|
565 }
|
|
566 }
|
|
567 return tsa(tok, token_semi);
|
|
568 }
|
|
569
|
|
570
|
|
571 ////////////////////////////////////////////////
|
|
572 //
|
|
573 bool parse_envfrom(TOKEN &tok, CONFIG &dc, CONTEXT &me);
|
|
574 bool parse_envfrom(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
|
|
575 char *st = tok.next();
|
|
576 if ((st == token_black) || (st == token_white) || (st == token_unknown)) {
|
|
577 me.set_from_default(st);
|
|
578 }
|
|
579 else {
|
|
580 tok.push(st);
|
|
581 }
|
|
582 if (!tsa(tok, token_lbrace)) return false;
|
|
583 while (true) {
|
|
584 char *have = tok.next();
|
|
585 if (!have) break;
|
|
586 if (have == token_rbrace) break;
|
|
587 if (have == token_semi) {
|
|
588 // optional separators
|
|
589 }
|
|
590 else if (have == token_dccfrom) {
|
|
591 if (!tsa(tok, token_lbrace)) return false;
|
|
592 bool keeping = false;
|
|
593 bool many = false;
|
|
594 while (true) {
|
|
595 char *have = tok.next();
|
|
596 if (!have) break;
|
|
597 if (have == token_rbrace) break;
|
|
598 if (have == token_ok) {
|
|
599 keeping = true;
|
|
600 many = false;
|
|
601 continue;
|
|
602 }
|
|
603 else if (have == token_many) {
|
|
604 keeping = true;
|
|
605 many = true;
|
|
606 continue;
|
|
607 }
|
|
608 else if (have == token_ok2) {
|
|
609 keeping = false;
|
|
610 continue;
|
|
611 }
|
|
612 if (have == token_envfrom) {
|
|
613 have = tok.next();
|
|
614 if (keeping) {
|
|
615 me.add_from(have, (many) ? token_black : token_white);
|
|
616 }
|
|
617 }
|
|
618 tok.skipeol();
|
|
619 }
|
|
620 }
|
|
621 else {
|
|
622 // may be a valid email address or domain name
|
|
623 char *st = tok.next();
|
|
624 if ((st == token_black) || (st == token_white) || (st == token_unknown)) {
|
|
625 me.add_from(have, st);
|
|
626 }
|
|
627 else {
|
|
628 CONTEXTP con = me.find_from_context_name(st);
|
|
629 if (con) {
|
|
630 me.add_from_context(have, con);
|
|
631 }
|
|
632 else {
|
|
633 tok.token_error("white/black/unknown or child context name", st);
|
|
634 return false;
|
|
635 }
|
|
636 }
|
|
637 }
|
|
638 }
|
|
639 return tsa(tok, token_semi);
|
|
640 }
|
|
641
|
|
642
|
|
643 ////////////////////////////////////////////////
|
|
644 //
|
|
645 bool parse_context(TOKEN &tok, CONFIG &dc, CONTEXTP parent);
|
|
646 bool parse_context(TOKEN &tok, CONFIG &dc, CONTEXTP parent) {
|
|
647 char *name = tok.next();
|
|
648 if (!tsa(tok, token_lbrace)) return false;
|
|
649 CONTEXTP con = new CONTEXT(parent, name);
|
|
650
|
|
651 while (true) {
|
|
652 char *have = tok.next();
|
|
653 if (!have) break;
|
|
654 if (have == token_rbrace) break; // done
|
|
655 if (have == token_dnsbl) {
|
|
656 if (!parse_dnsbl(tok, dc, *con)) return false;
|
|
657 }
|
|
658 else if (have == token_dnsbll) {
|
|
659 if (!parse_dnsbll(tok, dc, *con)) return false;
|
|
660 }
|
|
661 else if (have == token_content) {
|
|
662 if (!parse_content(tok, dc, *con)) return false;
|
|
663 }
|
|
664 else if (have == token_envto) {
|
|
665 if (!parse_envto(tok, dc, *con)) return false;
|
|
666 }
|
|
667 else if (have == token_envfrom) {
|
|
668 if (!parse_envfrom(tok, dc, *con)) return false;
|
|
669 }
|
|
670 else if (have == token_context) {
|
|
671 if (!parse_context(tok, dc, con)) return false;
|
|
672 }
|
|
673 else {
|
|
674 tok.token_error("context keyword", have);
|
|
675 return false;
|
|
676 }
|
|
677 }
|
|
678
|
|
679 if (!tsa(tok, token_semi)) {
|
|
680 delete con;
|
|
681 return false;
|
|
682 }
|
|
683 dc.add_context(con);
|
|
684 if (parent) parent->add_context(con);
|
|
685 return true;
|
|
686 }
|
|
687
|
|
688
|
|
689 ////////////////////////////////////////////////
|
|
690 // parse a config file
|
|
691 //
|
|
692 bool load_conf(CONFIG &dc, char *fn) {
|
|
693 TOKEN tok(fn, &dc.config_files);
|
|
694 while (true) {
|
|
695 char *have = tok.next();
|
|
696 if (!have) break;
|
|
697 if (have == token_context) {
|
|
698 if (!parse_context(tok, dc, NULL)) {
|
|
699 return false;
|
|
700 }
|
|
701 }
|
|
702 else {
|
|
703 tok.token_error(token_context, have);
|
|
704 return false;
|
|
705 }
|
|
706 }
|
72
|
707 return (dc.default_context) ? true : false;
|
71
|
708 }
|
|
709
|
|
710
|
|
711 ////////////////////////////////////////////////
|
|
712 // init the tokens
|
|
713 //
|
|
714 void token_init() {
|
|
715 token_black = register_string("black");
|
|
716 token_content = register_string("content");
|
|
717 token_context = register_string("context");
|
|
718 token_dccfrom = register_string("dcc_from");
|
|
719 token_dccto = register_string("dcc_to");
|
|
720 token_default = register_string("default");
|
|
721 token_dnsbl = register_string("dnsbl");
|
|
722 token_dnsbll = register_string("dnsbl_list");
|
|
723 token_envfrom = register_string("env_from");
|
|
724 token_envto = register_string("env_to");
|
|
725 token_filter = register_string("filter");
|
|
726 token_host_limit = register_string("host_limit");
|
|
727 token_html_limit = register_string("html_limit");
|
|
728 token_html_tags = register_string("html_tags");
|
|
729 token_ignore = register_string("ignore");
|
|
730 token_include = register_string("include");
|
|
731 token_inherit = register_string("inherit");
|
|
732 token_lbrace = register_string("{");
|
|
733 token_many = register_string("many");
|
|
734 token_off = register_string("off");
|
|
735 token_ok = register_string("ok");
|
|
736 token_ok2 = register_string("ok2");
|
|
737 token_on = register_string("on");
|
|
738 token_rbrace = register_string("}");
|
|
739 token_semi = register_string(";");
|
|
740 token_soft = register_string("soft");
|
|
741 token_tld = register_string("tld");
|
|
742 token_unknown = register_string("unknown");
|
|
743 token_white = register_string("white");
|
|
744 }
|