annotate src/context.cpp @ 85:7e4a90e5f213 initial-5-0 **INVALID**

start coding on new config syntax
author carl
date Sun, 17 Jul 2005 08:56:33 -0700
parents fa47e1e401f1
children c1280cd3e248
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() {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
162 for (dnsblp_map::iterator i=dnsbl_names.begin(); i!=dnsbl_names.end(); i++) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
163 DNSBLP d = (*i).second;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
164 // delete the underlying DNSBL objects.
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
165 delete d;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
166 }
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
76
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
170 bool CONTEXT::is_parent(CONTEXTP p) {
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
171 if (p == parent) return true;
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
172 if (!parent) return false;
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
173 return parent->is_parent(p);
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
174 }
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
175
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
176
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
177 char *CONTEXT::get_full_name(char *buffer, int size) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
178 if (!parent) return name;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
179 char buf[maxlen];
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
180 snprintf(buffer, size, "%s.%s", parent->get_full_name(buf, maxlen), name);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
181 return buffer;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
182 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
183
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
184
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
185 bool CONTEXT::cover_env_to(char *to) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
186 char buffer[maxlen];
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
187 char *x = strchr(to, '@');
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
188 if (x) x++;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
189 else x = to;
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
190 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
191 string_set::iterator i = env_to.find(x);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
192 if (i != env_to.end()) return true;
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
193 return false;
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
194 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
195
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
196
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
197 char *CONTEXT::find_from(char *from) {
76
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
198 char *rc = token_inherit;
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
199 string_map::iterator i = env_from.find(from);
76
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
200 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
201 else {
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
202 char *x = strchr(from, '@');
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
203 if (x) {
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
204 x++;
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
205 i = env_from.find(x);
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
206 if (i != env_from.end()) rc = (*i).second; // found 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 y = *x;
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
209 *x = '\0';
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
210 i = env_from.find(from);
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
211 *x = y;
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
212 if (i != env_from.end()) rc = (*i).second; // found user@ key
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
213 }
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
214 }
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
215 }
76
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
216 if (rc == token_inherit) rc = env_from_default;
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
217 if ((rc == token_inherit) && parent) return parent->find_from(from);
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
218 return (rc == token_inherit) ? token_unknown : rc;
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
219 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
220
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
221
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
222 CONTEXTP CONTEXT::find_context(char *from) {
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
223 context_map::iterator i = env_from_context.find(from);
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
224 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
225 char *x = strchr(from, '@');
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
226 if (x) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
227 x++;
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
228 i = env_from_context.find(x);
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
229 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
230 char y = *x;
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
231 *x = '\0';
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
232 i = env_from_context.find(from);
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
233 *x = y;
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
234 if (i != env_from_context.end()) return (*i).second; // found user@ key
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
235 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
236 return this;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
237 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
238
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
239
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
240 CONTEXTP CONTEXT::find_from_context_name(char *name) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
241 context_map::iterator i = children.find(name);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
242 if (i != children.end()) return (*i).second;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
243 return NULL;
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
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
247 DNSBLP CONTEXT::find_dnsbl(char *name) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
248 dnsblp_map::iterator i = dnsbl_names.find(name);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
249 if (i != dnsbl_names.end()) return (*i).second;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
250 if (parent) return parent->find_dnsbl(name);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
251 return NULL;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
252 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
253
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
254
76
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
255 char* CONTEXT::get_content_suffix() {
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
256 if (!content_suffix && parent) return parent->get_content_suffix();
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
257 return content_suffix;
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
258 }
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
259
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
260
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
261 char* CONTEXT::get_content_message() {
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
262 if (!content_message && parent) return parent->get_content_message();
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
263 return content_message;
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 string_set& CONTEXT::get_content_host_ignore() {
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
268 if (content_host_ignore.empty() && parent) return parent->get_content_host_ignore();
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
269 return content_host_ignore;
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_tlds() {
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
274 if (content_tlds.empty() && parent) return parent->get_content_tlds();
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
275 return content_tlds;
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_html_tags() {
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
280 if (html_tags.empty() && parent) return parent->get_html_tags();
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
281 return html_tags;
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 dnsblp_list& CONTEXT::get_dnsbl_list() {
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
286 if (dnsbl_list.empty() && parent) return parent->get_dnsbl_list();
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
287 return dnsbl_list;
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
72
e6a2d0be7c5e start coding on new config syntax
carl
parents: 71
diff changeset
291 bool CONTEXT::acceptable_content(recorder &memory, char *&msg) {
e6a2d0be7c5e start coding on new config syntax
carl
parents: 71
diff changeset
292 if (memory.excessive_bad_tags(tag_limit)) {
e6a2d0be7c5e start coding on new config syntax
carl
parents: 71
diff changeset
293 msg = tag_limit_message;
e6a2d0be7c5e start coding on new config syntax
carl
parents: 71
diff changeset
294 return false;
e6a2d0be7c5e start coding on new config syntax
carl
parents: 71
diff changeset
295 }
e6a2d0be7c5e start coding on new config syntax
carl
parents: 71
diff changeset
296 if (!host_random && memory.excessive_hosts(host_limit)) {
e6a2d0be7c5e start coding on new config syntax
carl
parents: 71
diff changeset
297 msg = host_limit_message;
e6a2d0be7c5e start coding on new config syntax
carl
parents: 71
diff changeset
298 return false;
e6a2d0be7c5e start coding on new config syntax
carl
parents: 71
diff changeset
299 }
e6a2d0be7c5e start coding on new config syntax
carl
parents: 71
diff changeset
300 }
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
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
303 void CONTEXT::dump(int level) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
304 char indent[maxlen];
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
305 int i = min(maxlen-1, level*4);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
306 memset(indent, ' ', i);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
307 indent[i] = '\0';
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
308 char buf[maxlen];
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
309 char *fullname = get_full_name(buf,maxlen);
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
310 printf("%s context %s { \t// %s\n", indent, name, fullname);
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
311
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
312 for (dnsblp_map::iterator i=dnsbl_names.begin(); i!=dnsbl_names.end(); i++) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
313 char *n = (*i).first;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
314 DNSBL &d = *(*i).second;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
315 printf("%s dnsbl %s %s \"%s\"; \n", indent, n, d.suffix, d.message);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
316 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
317
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
318 if (!dnsbl_list.empty()) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
319 printf("%s dnsbl_list", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
320 for (dnsblp_list::iterator i=dnsbl_list.begin(); i!=dnsbl_list.end(); i++) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
321 DNSBL &d = *(*i);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
322 printf(" %s", d.name);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
323 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
324 printf("; \n");
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 (content_filtering) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
328 printf("%s content on { \n", indent, env_from_default);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
329 if (content_suffix) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
330 printf("%s filter %s \"%s\"; \n", indent, content_suffix, content_message);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
331 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
332 if (!content_host_ignore.empty()) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
333 printf("%s ignore { \n", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
334 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
335 printf("%s %s; \n", indent, *i);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
336 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
337 printf("%s }; \n", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
338 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
339 if (!content_tlds.empty()) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
340 printf("%s tld { \n", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
341 printf("%s ", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
342 for (string_set::iterator i=content_tlds.begin(); i!=content_tlds.end(); i++) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
343 printf("%s; ", *i);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
344 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
345 printf("\n%s }; \n", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
346 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
347 if (!html_tags.empty()) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
348 printf("%s html_tags { \n", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
349 printf("%s ", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
350 for (string_set::iterator i=html_tags.begin(); i!=html_tags.end(); i++) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
351 printf("%s; ", *i);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
352 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
353 printf("\n%s }; \n", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
354 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
355 if (host_limit_message) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
356 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
357 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
358 else if (host_random) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
359 printf("%s host_limit soft %d; \n", indent, host_limit);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
360 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
361 else {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
362 printf("%s host_limit off; \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 (tag_limit_message) {
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
365 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
366 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
367 else {
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
368 printf("%s html_limit off; \n", indent);
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
369 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
370 printf("%s }; \n", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
371 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
372 else {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
373 printf("%s content off {}; \n", indent, env_from_default);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
374 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
375
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
376 printf("%s env_to { \t// %s\n", indent, fullname);
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
377 for (string_set::iterator i=env_to.begin(); i!=env_to.end(); i++) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
378 printf("%s %s; \n", indent, *i);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
379 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
380 printf("%s }; \n", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
381
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
382 for (context_map::iterator i=children.begin(); i!=children.end(); i++) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
383 CONTEXTP c = (*i).second;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
384 c->dump(level+1);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
385 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
386
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
387 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
388 if (!env_from.empty()) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
389 printf("%s // white/black/unknown \n", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
390 for (string_map::iterator i=env_from.begin(); i!=env_from.end(); i++) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
391 char *f = (*i).first;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
392 char *t = (*i).second;
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
393 printf("%s %s \t%s; \n", indent, f, t);
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
394 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
395 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
396 if (!env_from_context.empty()) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
397 printf("%s // child contexts \n", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
398 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
399 char *f = (*j).first;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
400 CONTEXTP t = (*j).second;
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
401 printf("%s %s \t%s; \n", indent, f, t->name);
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
402 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
403 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
404 printf("%s }; \n", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
405
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
406 printf("%s }; \n", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
407 }
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 ////////////////////////////////////////////////
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
411 // helper to discard the strings held by a string_set
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
412 //
74
b7449114ebb0 start coding on new config syntax
carl
parents: 73
diff changeset
413 void discard(string_set &s) {
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
414 for (string_set::iterator i=s.begin(); i!=s.end(); i++) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
415 free(*i);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
416 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
417 s.clear();
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
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
421 ////////////////////////////////////////////////
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
422 // helper to register a string in a string set
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
423 //
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
424 char* register_string(string_set &s, char *name) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
425 string_set::iterator i = s.find(name);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
426 if (i != s.end()) return *i;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
427 char *x = strdup(name);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
428 s.insert(x);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
429 return x;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
430 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
431
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
432
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
433 ////////////////////////////////////////////////
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
434 // register a global string
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
435 //
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
436 char* register_string(char *name) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
437 return register_string(all_strings, name);
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
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 bool tsa(TOKEN &tok, char *token);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
444 bool tsa(TOKEN &tok, char *token) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
445 char *have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
446 if (have == token) return true;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
447 tok.token_error(token, have);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
448 return false;
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 ////////////////////////////////////////////////
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
453 //
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
454 bool parse_dnsbl(TOKEN &tok, CONFIG &dc, CONTEXT &me);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
455 bool parse_dnsbl(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
456 char *name = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
457 char *suf = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
458 char *msg = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
459 if (!tsa(tok, token_semi)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
460 DNSBLP dns = new DNSBL(name, suf, msg);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
461 me.add_dnsbl(name, dns);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
462 return true;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
463 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
464
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
465
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
466 ////////////////////////////////////////////////
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
467 //
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
468 bool parse_dnsbll(TOKEN &tok, CONFIG &dc, CONTEXT &me);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
469 bool parse_dnsbll(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
470 while (true) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
471 char *have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
472 if (!have) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
473 if (have == token_semi) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
474 DNSBLP dns = me.find_dnsbl(have);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
475 if (dns) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
476 me.add_dnsbl(dns);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
477 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
478 else {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
479 tok.token_error("dnsbl name", have);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
480 return false;
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 return true;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
484 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
485
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
486
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 bool parse_content(TOKEN &tok, CONFIG &dc, CONTEXT &me);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
490 bool parse_content(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
491 char *setting = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
492 if (setting == token_on) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
493 me.set_content_filtering(true);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
494 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
495 else if (setting == token_off) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
496 me.set_content_filtering(false);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
497 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
498 else {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
499 tok.token_error("on/off", setting);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
500 return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
501 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
502 if (!tsa(tok, token_lbrace)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
503 while (true) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
504 char *have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
505 if (!have) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
506 if (have == token_filter) {
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
507 char *suffix = tok.next();
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
508 char *messag = tok.next();
76
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
509 me.set_content_suffix(suffix);
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
510 me.set_content_message(messag);
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
511 if (!tsa(tok, token_semi)) return 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 if (have == token_ignore) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
514 if (!tsa(tok, token_lbrace)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
515 while (true) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
516 if (!have) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
517 char *have = tok.next();
76
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
518 if (have == token_rbrace) break; // done
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
519 me.add_ignore(have);
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
520 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
521 if (!tsa(tok, token_semi)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
522 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
523 else if (have == token_tld) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
524 if (!tsa(tok, token_lbrace)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
525 while (true) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
526 char *have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
527 if (!have) break;
76
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
528 if (have == token_rbrace) break; // done
81f1e400e8ab start coding on new config syntax
carl
parents: 75
diff changeset
529 me.add_tld(have);
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
530 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
531 if (!tsa(tok, token_semi)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
532 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
533 else if (have == token_html_limit) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
534 have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
535 if (have == token_on) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
536 me.set_tag_limit(tok.nextint());
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
537 me.set_tag_message(tok.next());
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_off) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
540 me.set_tag_limit(0);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
541 me.set_tag_message(NULL);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
542 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
543 else {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
544 tok.token_error("on/off", have);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
545 return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
546 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
547 if (!tsa(tok, token_semi)) return false;
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 if (have == token_html_tags) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
550 if (!tsa(tok, token_lbrace)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
551 while (true) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
552 char *have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
553 if (!have) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
554 if (have == token_rbrace) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
555 break; // done
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
556 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
557 else {
79
091d3fe3db46 start coding on new config syntax
carl
parents: 77
diff changeset
558 me.add_tag(have); // base version
091d3fe3db46 start coding on new config syntax
carl
parents: 77
diff changeset
559 char buf[200];
091d3fe3db46 start coding on new config syntax
carl
parents: 77
diff changeset
560 snprintf(buf, sizeof(buf), "/%s", have);
091d3fe3db46 start coding on new config syntax
carl
parents: 77
diff changeset
561 me.add_tag(register_string(buf)); // leading /
091d3fe3db46 start coding on new config syntax
carl
parents: 77
diff changeset
562 snprintf(buf, sizeof(buf), "%s/", have);
091d3fe3db46 start coding on new config syntax
carl
parents: 77
diff changeset
563 me.add_tag(register_string(buf)); // trailing /
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
564 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
565 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
566 if (!tsa(tok, token_semi)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
567 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
568 else if (have == token_host_limit) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
569 have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
570 if (have == token_on) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
571 me.set_host_limit(tok.nextint());
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
572 me.set_host_message(tok.next());
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
573 me.set_host_random(false);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
574 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
575 else if (have == token_off) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
576 me.set_host_limit(0);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
577 me.set_host_message(NULL);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
578 me.set_host_random(false);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
579 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
580 else if (have == token_soft) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
581 me.set_host_limit(tok.nextint());
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
582 me.set_host_message(NULL);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
583 me.set_host_random(true);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
584 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
585 else {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
586 tok.token_error("on/off/soft", have);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
587 return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
588 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
589 if (!tsa(tok, token_semi)) return false;
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 if (have == token_rbrace) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
592 break; // done
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
593 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
594 else {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
595 tok.token_error("content keyword", have);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
596 return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
597 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
598 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
599 return tsa(tok, token_semi);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
600 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
601
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
602
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 bool parse_envto(TOKEN &tok, CONFIG &dc, CONTEXT &me);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
606 bool parse_envto(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
607 if (!tsa(tok, token_lbrace)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
608 while (true) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
609 char *have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
610 if (!have) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
611 if (have == token_rbrace) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
612 if (have == token_semi) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
613 // optional separators
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
614 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
615 else if (have == token_dccto) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
616 char *flavor = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
617 if (!tsa(tok, token_lbrace)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
618 bool keeping = false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
619 while (true) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
620 char *have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
621 if (!have) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
622 if (have == token_rbrace) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
623 if (have == flavor) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
624 keeping = true;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
625 continue;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
626 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
627 else if ((have == token_ok) || (have == token_ok2) || (have == token_many)) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
628 keeping = false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
629 continue;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
630 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
631 if (have == token_envto) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
632 have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
633 if (keeping) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
634 if (me.allow_env_to(have)) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
635 me.add_to(have);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
636 dc.add_to(have, &me);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
637 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
638 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
639 }
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
640 else if (have == token_substitute) {
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
641 if (tok.next() == token_mailhost) {
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
642 have = tok.next();
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
643 if (keeping) {
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
644 if (me.allow_env_to(have)) {
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
645 me.add_to(have);
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
646 dc.add_to(have, &me);
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
647 }
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
648 }
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
649 }
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
650 }
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
651 tok.skipeol();
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 else if (me.allow_env_to(have)) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
655 me.add_to(have);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
656 dc.add_to(have, &me);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
657 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
658 else {
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
659 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
660 return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
661 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
662 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
663 return tsa(tok, token_semi);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
664 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
665
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
666
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 bool parse_envfrom(TOKEN &tok, CONFIG &dc, CONTEXT &me);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
670 bool parse_envfrom(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
671 char *st = tok.next();
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
672 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
673 me.set_from_default(st);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
674 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
675 else {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
676 tok.push(st);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
677 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
678 if (!tsa(tok, token_lbrace)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
679 while (true) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
680 char *have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
681 if (!have) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
682 if (have == token_rbrace) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
683 if (have == token_semi) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
684 // optional separators
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
685 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
686 else if (have == token_dccfrom) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
687 if (!tsa(tok, token_lbrace)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
688 bool keeping = false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
689 bool many = false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
690 while (true) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
691 char *have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
692 if (!have) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
693 if (have == token_rbrace) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
694 if (have == token_ok) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
695 keeping = true;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
696 many = false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
697 continue;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
698 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
699 else if (have == token_many) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
700 keeping = true;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
701 many = true;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
702 continue;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
703 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
704 else if (have == token_ok2) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
705 keeping = false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
706 continue;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
707 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
708 if (have == token_envfrom) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
709 have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
710 if (keeping) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
711 me.add_from(have, (many) ? token_black : token_white);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
712 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
713 }
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
714 else if (have == token_substitute) {
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
715 if (tok.next() == token_mailhost) {
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
716 have = tok.next();
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
717 me.add_from(have, (many) ? token_black : token_white);
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
718 }
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
719 }
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
720 tok.skipeol();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
721 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
722 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
723 else {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
724 // may be a valid email address or domain name
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
725 char *st = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
726 if ((st == token_black) || (st == token_white) || (st == token_unknown)) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
727 me.add_from(have, st);
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 CONTEXTP con = me.find_from_context_name(st);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
731 if (con) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
732 me.add_from_context(have, con);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
733 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
734 else {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
735 tok.token_error("white/black/unknown or child context name", st);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
736 return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
737 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
738 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
739 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
740 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
741 return tsa(tok, token_semi);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
742 }
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 bool parse_context(TOKEN &tok, CONFIG &dc, CONTEXTP parent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
748 bool parse_context(TOKEN &tok, CONFIG &dc, CONTEXTP parent) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
749 char *name = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
750 if (!tsa(tok, token_lbrace)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
751 CONTEXTP con = new CONTEXT(parent, name);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
752
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
753 while (true) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
754 char *have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
755 if (!have) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
756 if (have == token_rbrace) break; // done
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
757 if (have == token_dnsbl) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
758 if (!parse_dnsbl(tok, dc, *con)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
759 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
760 else if (have == token_dnsbll) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
761 if (!parse_dnsbll(tok, dc, *con)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
762 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
763 else if (have == token_content) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
764 if (!parse_content(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_envto) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
767 if (!parse_envto(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_envfrom) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
770 if (!parse_envfrom(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_context) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
773 if (!parse_context(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 {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
776 tok.token_error("context keyword", have);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
777 return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
778 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
779 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
780
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
781 if (!tsa(tok, token_semi)) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
782 delete con;
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 dc.add_context(con);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
786 if (parent) parent->add_context(con);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
787 return true;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
788 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
789
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
790
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
791 ////////////////////////////////////////////////
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
792 // parse a config file
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
793 //
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
794 bool load_conf(CONFIG &dc, char *fn) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
795 TOKEN tok(fn, &dc.config_files);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
796 while (true) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
797 char *have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
798 if (!have) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
799 if (have == token_context) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
800 if (!parse_context(tok, dc, NULL)) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
801 return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
802 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
803 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
804 else {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
805 tok.token_error(token_context, have);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
806 return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
807 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
808 }
72
e6a2d0be7c5e start coding on new config syntax
carl
parents: 71
diff changeset
809 return (dc.default_context) ? true : false;
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
810 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
811
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
812
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
813 ////////////////////////////////////////////////
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
814 // init the tokens
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
815 //
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
816 void token_init() {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
817 token_black = register_string("black");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
818 token_content = register_string("content");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
819 token_context = register_string("context");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
820 token_dccfrom = register_string("dcc_from");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
821 token_dccto = register_string("dcc_to");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
822 token_default = register_string("default");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
823 token_dnsbl = register_string("dnsbl");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
824 token_dnsbll = register_string("dnsbl_list");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
825 token_envfrom = register_string("env_from");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
826 token_envto = register_string("env_to");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
827 token_filter = register_string("filter");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
828 token_host_limit = register_string("host_limit");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
829 token_html_limit = register_string("html_limit");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
830 token_html_tags = register_string("html_tags");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
831 token_ignore = register_string("ignore");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
832 token_include = register_string("include");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
833 token_inherit = register_string("inherit");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
834 token_lbrace = register_string("{");
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
835 token_mailhost = register_string("mail_host");
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
836 token_many = register_string("many");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
837 token_off = register_string("off");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
838 token_ok = register_string("ok");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
839 token_ok2 = register_string("ok2");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
840 token_on = register_string("on");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
841 token_rbrace = register_string("}");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
842 token_semi = register_string(";");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
843 token_soft = register_string("soft");
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
844 token_substitute = register_string("substitute");
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
845 token_tld = register_string("tld");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
846 token_unknown = register_string("unknown");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
847 token_white = register_string("white");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
848 }