annotate src/context.cpp @ 73:2b369f7db7bf

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