annotate src/context.cpp @ 86:c1280cd3e248

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