annotate src/context.cpp @ 75:1142e46be550

start coding on new config syntax
author carl
date Wed, 13 Jul 2005 23:04:14 -0700
parents b7449114ebb0
children 81f1e400e8ab
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()) {
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
83 CONTEXTP c = (*i).second;
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
84 if ((c != con) && (c != con->get_parent())) {
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
85 char oldname[maxlen];
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
86 char newname[maxlen];
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
87 char *oldn = c->get_full_name(oldname, maxlen);
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
88 char *newn = con->get_full_name(newname, maxlen);
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
89 char buf[maxlen*3];
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
90 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
91 my_syslog(buf);
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
92 }
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
93 }
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
94 env_to[to] = con;
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
95 }
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
96
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
97
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
98 CONTEXTP CONFIG::find_context(char *to) {
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
99 context_map::iterator i = env_to.find(to);
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
100 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
101 char *x = strchr(to, '@');
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
102 if (x) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
103 x++;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
104 i = env_to.find(x);
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
105 if (i != env_to.end()) return (*i).second; // found domain.tld key
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
106 char y = *x;
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
107 *x = '\0';
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
108 i = env_to.find(to);
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
109 *x = y;
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
110 if (i != env_to.end()) return (*i).second; // found user@ key
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
111 }
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
112 return default_context;
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
113 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
114
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
115
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
116 void CONFIG::dump() {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
117 if (default_context) default_context->dump();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
118 for (context_list::iterator i=contexts.begin(); i!=contexts.end(); i++) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
119 CONTEXTP c = *i;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
120 CONTEXTP p = c->get_parent();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
121 if (!p && (c != default_context)) c->dump();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
122 }
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
123 char buf[maxlen];
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
124 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
125 char *to = (*i).first;
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
126 CONTEXTP con = (*i).second;
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
127 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
128 }
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
129 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
130
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
131
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
132 CONTEXT::CONTEXT(CONTEXTP parent_, char *name_) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
133 parent = parent_;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
134 name = name_;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
135 env_from_default = (parent) ? token_inherit : token_unknown;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
136 content_filtering = (parent) ? parent->content_filtering : false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
137 content_suffix = NULL;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
138 content_message = NULL;
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
139 host_limit = (parent) ? parent->host_limit : 0;
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
140 host_limit_message = NULL;
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
141 host_random = (parent) ? parent->host_random : false;
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
142 tag_limit = (parent) ? parent->tag_limit : 0;
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
143 tag_limit_message = NULL;
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
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
147 CONTEXT::~CONTEXT() {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
148 for (dnsblp_map::iterator i=dnsbl_names.begin(); i!=dnsbl_names.end(); i++) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
149 DNSBLP d = (*i).second;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
150 // delete the underlying DNSBL objects.
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
151 delete d;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
152 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
153 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
154
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
155
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
156 char *CONTEXT::get_full_name(char *buffer, int size) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
157 if (!parent) return name;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
158 char buf[maxlen];
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
159 snprintf(buffer, size, "%s.%s", parent->get_full_name(buf, maxlen), name);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
160 return buffer;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
161 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
162
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
163
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
164 bool CONTEXT::cover_env_to(char *to) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
165 char buffer[maxlen];
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
166 char *x = strchr(to, '@');
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
167 if (x) x++;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
168 else x = to;
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
169 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
170 string_set::iterator i = env_to.find(x);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
171 if (i != env_to.end()) return true;
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
172 return false;
71
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
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
176 char *CONTEXT::find_from(char *from) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
177 string_map::iterator i = env_from.find(from);
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
178 if (i != env_from.end()) return (*i).second; // found user@domain.tld key
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
179 char *x = strchr(from, '@');
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
180 if (x) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
181 x++;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
182 i = env_from.find(x);
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
183 if (i != env_from.end()) return (*i).second; // found domain.tld key
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
184 char y = *x;
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
185 *x = '\0';
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
186 i = env_from.find(from);
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
187 *x = y;
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
188 if (i != env_from.end()) return (*i).second; // found user@ key
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
189 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
190 if ((env_from_default == token_inherit) && parent) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
191 return parent->find_from(from);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
192 }
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
193 return (env_from_default == token_inherit) ? token_unknown : env_from_default;
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
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
197 CONTEXTP CONTEXT::find_context(char *from) {
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
198 context_map::iterator i = env_from_context.find(from);
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
199 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
200 char *x = strchr(from, '@');
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
201 if (x) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
202 x++;
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
203 i = env_from_context.find(x);
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
204 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
205 char y = *x;
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
206 *x = '\0';
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
207 i = env_from_context.find(from);
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
208 *x = y;
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
209 if (i != env_from_context.end()) return (*i).second; // found user@ key
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
210 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
211 return this;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
212 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
213
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
214
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
215 CONTEXTP CONTEXT::find_from_context_name(char *name) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
216 context_map::iterator i = children.find(name);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
217 if (i != children.end()) return (*i).second;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
218 return NULL;
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
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
222 DNSBLP CONTEXT::find_dnsbl(char *name) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
223 dnsblp_map::iterator i = dnsbl_names.find(name);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
224 if (i != dnsbl_names.end()) return (*i).second;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
225 if (parent) return parent->find_dnsbl(name);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
226 return NULL;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
227 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
228
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
229
72
e6a2d0be7c5e start coding on new config syntax
carl
parents: 71
diff changeset
230 bool CONTEXT::acceptable_content(recorder &memory, char *&msg) {
e6a2d0be7c5e start coding on new config syntax
carl
parents: 71
diff changeset
231 if (memory.excessive_bad_tags(tag_limit)) {
e6a2d0be7c5e start coding on new config syntax
carl
parents: 71
diff changeset
232 msg = tag_limit_message;
e6a2d0be7c5e start coding on new config syntax
carl
parents: 71
diff changeset
233 return false;
e6a2d0be7c5e start coding on new config syntax
carl
parents: 71
diff changeset
234 }
e6a2d0be7c5e start coding on new config syntax
carl
parents: 71
diff changeset
235 if (!host_random && memory.excessive_hosts(host_limit)) {
e6a2d0be7c5e start coding on new config syntax
carl
parents: 71
diff changeset
236 msg = host_limit_message;
e6a2d0be7c5e start coding on new config syntax
carl
parents: 71
diff changeset
237 return false;
e6a2d0be7c5e start coding on new config syntax
carl
parents: 71
diff changeset
238 }
e6a2d0be7c5e start coding on new config syntax
carl
parents: 71
diff changeset
239 }
e6a2d0be7c5e start coding on new config syntax
carl
parents: 71
diff changeset
240
e6a2d0be7c5e start coding on new config syntax
carl
parents: 71
diff changeset
241
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
242 void CONTEXT::dump(int level) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
243 char indent[maxlen];
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
244 int i = min(maxlen-1, level*4);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
245 memset(indent, ' ', i);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
246 indent[i] = '\0';
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
247 char buf[maxlen];
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
248 char *fullname = get_full_name(buf,maxlen);
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
249 printf("%s context %s { \t// %s\n", indent, name, fullname);
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
250
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
251 for (dnsblp_map::iterator i=dnsbl_names.begin(); i!=dnsbl_names.end(); i++) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
252 char *n = (*i).first;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
253 DNSBL &d = *(*i).second;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
254 printf("%s dnsbl %s %s \"%s\"; \n", indent, n, d.suffix, d.message);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
255 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
256
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
257 if (!dnsbl_list.empty()) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
258 printf("%s dnsbl_list", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
259 for (dnsblp_list::iterator i=dnsbl_list.begin(); i!=dnsbl_list.end(); i++) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
260 DNSBL &d = *(*i);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
261 printf(" %s", d.name);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
262 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
263 printf("; \n");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
264 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
265
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
266 if (content_filtering) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
267 printf("%s content on { \n", indent, env_from_default);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
268 if (content_suffix) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
269 printf("%s filter %s \"%s\"; \n", indent, content_suffix, content_message);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
270 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
271 if (!content_host_ignore.empty()) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
272 printf("%s ignore { \n", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
273 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
274 printf("%s %s; \n", indent, *i);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
275 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
276 printf("%s }; \n", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
277 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
278 if (!content_tlds.empty()) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
279 printf("%s tld { \n", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
280 printf("%s ", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
281 for (string_set::iterator i=content_tlds.begin(); i!=content_tlds.end(); i++) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
282 printf("%s; ", *i);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
283 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
284 printf("\n%s }; \n", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
285 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
286 if (!html_tags.empty()) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
287 printf("%s html_tags { \n", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
288 printf("%s ", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
289 for (string_set::iterator i=html_tags.begin(); i!=html_tags.end(); i++) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
290 printf("%s; ", *i);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
291 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
292 printf("\n%s }; \n", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
293 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
294 if (host_limit_message) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
295 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
296 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
297 else if (host_random) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
298 printf("%s host_limit soft %d; \n", indent, host_limit);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
299 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
300 else {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
301 printf("%s host_limit off; \n", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
302 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
303 if (tag_limit_message) {
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
304 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
305 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
306 else {
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
307 printf("%s html_limit off; \n", indent);
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
308 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
309 printf("%s }; \n", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
310 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
311 else {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
312 printf("%s content off {}; \n", indent, env_from_default);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
313 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
314
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
315 printf("%s env_to { \t// %s\n", indent, fullname);
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
316 for (string_set::iterator i=env_to.begin(); i!=env_to.end(); i++) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
317 printf("%s %s; \n", indent, *i);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
318 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
319 printf("%s }; \n", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
320
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
321 for (context_map::iterator i=children.begin(); i!=children.end(); i++) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
322 CONTEXTP c = (*i).second;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
323 c->dump(level+1);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
324 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
325
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
326 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
327 if (!env_from.empty()) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
328 printf("%s // white/black/unknown \n", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
329 for (string_map::iterator i=env_from.begin(); i!=env_from.end(); i++) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
330 char *f = (*i).first;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
331 char *t = (*i).second;
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
332 printf("%s %s \t%s; \n", indent, f, t);
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
333 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
334 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
335 if (!env_from_context.empty()) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
336 printf("%s // child contexts \n", indent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
337 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
338 char *f = (*j).first;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
339 CONTEXTP t = (*j).second;
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
340 printf("%s %s \t%s; \n", indent, f, t->name);
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
341 }
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 printf("%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
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
348
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
349 ////////////////////////////////////////////////
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
350 // helper to discard the strings held by a string_set
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
351 //
74
b7449114ebb0 start coding on new config syntax
carl
parents: 73
diff changeset
352 void discard(string_set &s) {
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
353 for (string_set::iterator i=s.begin(); i!=s.end(); i++) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
354 free(*i);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
355 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
356 s.clear();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
357 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
358
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
359
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
360 ////////////////////////////////////////////////
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
361 // helper to register a string in a string set
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
362 //
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
363 char* register_string(string_set &s, char *name) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
364 string_set::iterator i = s.find(name);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
365 if (i != s.end()) return *i;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
366 char *x = strdup(name);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
367 s.insert(x);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
368 return x;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
369 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
370
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
371
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
372 ////////////////////////////////////////////////
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
373 // register a global string
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
374 //
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
375 char* register_string(char *name) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
376 return register_string(all_strings, name);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
377 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
378
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
379
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
380 ////////////////////////////////////////////////
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
381 //
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
382 bool tsa(TOKEN &tok, char *token);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
383 bool tsa(TOKEN &tok, char *token) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
384 char *have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
385 if (have == token) return true;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
386 tok.token_error(token, have);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
387 return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
388 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
389
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
390
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
391 ////////////////////////////////////////////////
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
392 //
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
393 bool parse_dnsbl(TOKEN &tok, CONFIG &dc, CONTEXT &me);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
394 bool parse_dnsbl(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
395 char *name = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
396 char *suf = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
397 char *msg = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
398 if (!tsa(tok, token_semi)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
399 DNSBLP dns = new DNSBL(name, suf, msg);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
400 me.add_dnsbl(name, dns);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
401 return true;
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
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
405 ////////////////////////////////////////////////
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
406 //
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
407 bool parse_dnsbll(TOKEN &tok, CONFIG &dc, CONTEXT &me);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
408 bool parse_dnsbll(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
409 while (true) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
410 char *have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
411 if (!have) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
412 if (have == token_semi) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
413 DNSBLP dns = me.find_dnsbl(have);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
414 if (dns) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
415 me.add_dnsbl(dns);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
416 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
417 else {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
418 tok.token_error("dnsbl name", have);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
419 return false;
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 return true;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
423 }
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 bool parse_content(TOKEN &tok, CONFIG &dc, CONTEXT &me);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
429 bool parse_content(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
430 bool topdefault = (!me.get_parent()) && (!dc.default_context);
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
431 char *setting = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
432 if (setting == token_on) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
433 me.set_content_filtering(true);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
434 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
435 else if (setting == token_off) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
436 me.set_content_filtering(false);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
437 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
438 else {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
439 tok.token_error("on/off", setting);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
440 return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
441 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
442 if (!tsa(tok, token_lbrace)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
443 while (true) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
444 char *have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
445 if (!have) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
446 if (have == token_filter) {
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
447 char *suffix = tok.next();
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
448 char *messag = tok.next();
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
449 if (topdefault) {
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
450 me.set_content_suffix(suffix);
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
451 me.set_content_message(messag);
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
452 }
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
453 if (!tsa(tok, token_semi)) return false;
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
454 if (!topdefault) tok.token_error("content filters may only be speciried in the top default context");
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
455 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
456 else if (have == token_ignore) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
457 if (!tsa(tok, token_lbrace)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
458 while (true) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
459 if (!have) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
460 char *have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
461 if (have == token_rbrace) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
462 break; // done
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
463 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
464 else {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
465 me.add_ignore(have);
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 if (!tsa(tok, token_semi)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
469 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
470 else if (have == token_tld) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
471 if (!tsa(tok, token_lbrace)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
472 while (true) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
473 char *have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
474 if (!have) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
475 if (have == token_rbrace) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
476 break; // done
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 {
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
479 if (topdefault) me.add_tld(have);
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
480 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
481 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
482 if (!tsa(tok, token_semi)) return false;
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
483 if (!topdefault) tok.token_error("tld values may only be specified in the top default context");
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
484 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
485 else if (have == token_html_limit) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
486 have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
487 if (have == token_on) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
488 me.set_tag_limit(tok.nextint());
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
489 me.set_tag_message(tok.next());
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
490 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
491 else if (have == token_off) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
492 me.set_tag_limit(0);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
493 me.set_tag_message(NULL);
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 {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
496 tok.token_error("on/off", have);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
497 return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
498 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
499 if (!tsa(tok, token_semi)) return false;
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 (have == token_html_tags) {
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_rbrace) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
507 break; // done
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
508 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
509 else {
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
510 if (topdefault) me.add_tag(have);
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
511 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
512 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
513 if (!tsa(tok, token_semi)) return false;
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
514 if (!topdefault) tok.token_error("html tags may only be specified in the top default context");
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
515 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
516 else if (have == token_host_limit) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
517 have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
518 if (have == token_on) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
519 me.set_host_limit(tok.nextint());
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
520 me.set_host_message(tok.next());
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
521 me.set_host_random(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_off) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
524 me.set_host_limit(0);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
525 me.set_host_message(NULL);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
526 me.set_host_random(false);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
527 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
528 else if (have == token_soft) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
529 me.set_host_limit(tok.nextint());
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
530 me.set_host_message(NULL);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
531 me.set_host_random(true);
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 {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
534 tok.token_error("on/off/soft", have);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
535 return false;
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_rbrace) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
540 break; // done
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
541 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
542 else {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
543 tok.token_error("content keyword", have);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
544 return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
545 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
546 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
547 return tsa(tok, token_semi);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
548 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
549
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
550
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
551 ////////////////////////////////////////////////
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
552 //
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
553 bool parse_envto(TOKEN &tok, CONFIG &dc, CONTEXT &me);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
554 bool parse_envto(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
555 if (!tsa(tok, token_lbrace)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
556 while (true) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
557 char *have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
558 if (!have) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
559 if (have == token_rbrace) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
560 if (have == token_semi) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
561 // optional separators
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 if (have == token_dccto) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
564 char *flavor = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
565 if (!tsa(tok, token_lbrace)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
566 bool keeping = false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
567 while (true) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
568 char *have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
569 if (!have) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
570 if (have == token_rbrace) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
571 if (have == flavor) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
572 keeping = true;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
573 continue;
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_ok) || (have == token_ok2) || (have == token_many)) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
576 keeping = false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
577 continue;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
578 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
579 if (have == token_envto) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
580 have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
581 if (keeping) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
582 if (me.allow_env_to(have)) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
583 me.add_to(have);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
584 dc.add_to(have, &me);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
585 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
586 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
587 }
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
588 else if (have == token_substitute) {
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
589 if (tok.next() == token_mailhost) {
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
590 have = tok.next();
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
591 if (keeping) {
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
592 if (me.allow_env_to(have)) {
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
593 me.add_to(have);
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
594 dc.add_to(have, &me);
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
595 }
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
596 }
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
597 }
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
598 }
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
599 tok.skipeol();
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 else if (me.allow_env_to(have)) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
603 me.add_to(have);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
604 dc.add_to(have, &me);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
605 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
606 else {
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
607 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
608 return false;
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 return tsa(tok, token_semi);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
612 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
613
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
614
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
615 ////////////////////////////////////////////////
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
616 //
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
617 bool parse_envfrom(TOKEN &tok, CONFIG &dc, CONTEXT &me);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
618 bool parse_envfrom(TOKEN &tok, CONFIG &dc, CONTEXT &me) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
619 char *st = tok.next();
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
620 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
621 me.set_from_default(st);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
622 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
623 else {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
624 tok.push(st);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
625 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
626 if (!tsa(tok, token_lbrace)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
627 while (true) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
628 char *have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
629 if (!have) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
630 if (have == token_rbrace) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
631 if (have == token_semi) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
632 // optional separators
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
633 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
634 else if (have == token_dccfrom) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
635 if (!tsa(tok, token_lbrace)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
636 bool keeping = false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
637 bool many = false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
638 while (true) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
639 char *have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
640 if (!have) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
641 if (have == token_rbrace) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
642 if (have == token_ok) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
643 keeping = true;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
644 many = false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
645 continue;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
646 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
647 else if (have == token_many) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
648 keeping = true;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
649 many = true;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
650 continue;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
651 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
652 else if (have == token_ok2) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
653 keeping = false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
654 continue;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
655 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
656 if (have == token_envfrom) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
657 have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
658 if (keeping) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
659 me.add_from(have, (many) ? token_black : token_white);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
660 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
661 }
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
662 else if (have == token_substitute) {
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
663 if (tok.next() == token_mailhost) {
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
664 have = tok.next();
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
665 me.add_from(have, (many) ? token_black : token_white);
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
666 }
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
667 }
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
668 tok.skipeol();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
669 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
670 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
671 else {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
672 // may be a valid email address or domain name
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
673 char *st = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
674 if ((st == token_black) || (st == token_white) || (st == token_unknown)) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
675 me.add_from(have, st);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
676 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
677 else {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
678 CONTEXTP con = me.find_from_context_name(st);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
679 if (con) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
680 me.add_from_context(have, con);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
681 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
682 else {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
683 tok.token_error("white/black/unknown or child context name", st);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
684 return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
685 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
686 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
687 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
688 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
689 return tsa(tok, token_semi);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
690 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
691
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
692
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
693 ////////////////////////////////////////////////
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
694 //
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
695 bool parse_context(TOKEN &tok, CONFIG &dc, CONTEXTP parent);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
696 bool parse_context(TOKEN &tok, CONFIG &dc, CONTEXTP parent) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
697 char *name = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
698 if (!tsa(tok, token_lbrace)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
699 CONTEXTP con = new CONTEXT(parent, name);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
700
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
701 while (true) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
702 char *have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
703 if (!have) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
704 if (have == token_rbrace) break; // done
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
705 if (have == token_dnsbl) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
706 if (!parse_dnsbl(tok, dc, *con)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
707 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
708 else if (have == token_dnsbll) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
709 if (!parse_dnsbll(tok, dc, *con)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
710 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
711 else if (have == token_content) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
712 if (!parse_content(tok, dc, *con)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
713 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
714 else if (have == token_envto) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
715 if (!parse_envto(tok, dc, *con)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
716 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
717 else if (have == token_envfrom) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
718 if (!parse_envfrom(tok, dc, *con)) return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
719 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
720 else if (have == token_context) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
721 if (!parse_context(tok, dc, con)) return false;
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 tok.token_error("context keyword", have);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
725 return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
726 }
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 if (!tsa(tok, token_semi)) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
730 delete con;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
731 return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
732 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
733 dc.add_context(con);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
734 if (parent) parent->add_context(con);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
735 return true;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
736 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
737
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
738
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
739 ////////////////////////////////////////////////
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
740 // parse a config file
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
741 //
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
742 bool load_conf(CONFIG &dc, char *fn) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
743 TOKEN tok(fn, &dc.config_files);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
744 while (true) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
745 char *have = tok.next();
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
746 if (!have) break;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
747 if (have == token_context) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
748 if (!parse_context(tok, dc, NULL)) {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
749 return false;
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 else {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
753 tok.token_error(token_context, have);
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
754 return false;
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
755 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
756 }
72
e6a2d0be7c5e start coding on new config syntax
carl
parents: 71
diff changeset
757 return (dc.default_context) ? true : false;
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
758 }
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
759
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
760
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
761 ////////////////////////////////////////////////
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
762 // init the tokens
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
763 //
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
764 void token_init() {
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
765 token_black = register_string("black");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
766 token_content = register_string("content");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
767 token_context = register_string("context");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
768 token_dccfrom = register_string("dcc_from");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
769 token_dccto = register_string("dcc_to");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
770 token_default = register_string("default");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
771 token_dnsbl = register_string("dnsbl");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
772 token_dnsbll = register_string("dnsbl_list");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
773 token_envfrom = register_string("env_from");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
774 token_envto = register_string("env_to");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
775 token_filter = register_string("filter");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
776 token_host_limit = register_string("host_limit");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
777 token_html_limit = register_string("html_limit");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
778 token_html_tags = register_string("html_tags");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
779 token_ignore = register_string("ignore");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
780 token_include = register_string("include");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
781 token_inherit = register_string("inherit");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
782 token_lbrace = register_string("{");
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
783 token_mailhost = register_string("mail_host");
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
784 token_many = register_string("many");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
785 token_off = register_string("off");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
786 token_ok = register_string("ok");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
787 token_ok2 = register_string("ok2");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
788 token_on = register_string("on");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
789 token_rbrace = register_string("}");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
790 token_semi = register_string(";");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
791 token_soft = register_string("soft");
75
1142e46be550 start coding on new config syntax
carl
parents: 74
diff changeset
792 token_substitute = register_string("substitute");
71
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
793 token_tld = register_string("tld");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
794 token_unknown = register_string("unknown");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
795 token_white = register_string("white");
dd21c8e13074 start coding on new config syntax
carl
parents:
diff changeset
796 }