annotate src/context.cpp @ 79:091d3fe3db46

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