]>
Commit | Line | Data |
---|---|---|
be335c22 | 1 | |
30a4f2a8 | 2 | /* |
2b6662ba | 3 | * $Id: cache_cf.cc,v 1.369 2001/01/12 00:37:14 wessels Exp $ |
30a4f2a8 | 4 | * |
5 | * DEBUG: section 3 Configuration File Parsing | |
6 | * AUTHOR: Harvest Derived | |
7 | * | |
2b6662ba | 8 | * SQUID Web Proxy Cache http://www.squid-cache.org/ |
e25c139f | 9 | * ---------------------------------------------------------- |
30a4f2a8 | 10 | * |
2b6662ba | 11 | * Squid is the result of efforts by numerous individuals from |
12 | * the Internet community; see the CONTRIBUTORS file for full | |
13 | * details. Many organizations have provided support for Squid's | |
14 | * development; see the SPONSORS file for full details. Squid is | |
15 | * Copyrighted (C) 2001 by the Regents of the University of | |
16 | * California; see the COPYRIGHT file for full details. Squid | |
17 | * incorporates software developed and/or copyrighted by other | |
18 | * sources; see the CREDITS file for full details. | |
30a4f2a8 | 19 | * |
20 | * This program is free software; you can redistribute it and/or modify | |
21 | * it under the terms of the GNU General Public License as published by | |
22 | * the Free Software Foundation; either version 2 of the License, or | |
23 | * (at your option) any later version. | |
24 | * | |
25 | * This program is distributed in the hope that it will be useful, | |
26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28 | * GNU General Public License for more details. | |
29 | * | |
30 | * You should have received a copy of the GNU General Public License | |
31 | * along with this program; if not, write to the Free Software | |
cbdec147 | 32 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. |
e25c139f | 33 | * |
30a4f2a8 | 34 | */ |
cf5fd929 | 35 | |
44a47c6e | 36 | #include "squid.h" |
1df370e3 | 37 | |
38 | #if SQUID_SNMP | |
a97cfa48 | 39 | #include "snmp.h" |
1df370e3 | 40 | #endif |
090089c4 | 41 | |
8813e606 | 42 | static const char *const T_SECOND_STR = "second"; |
43 | static const char *const T_MINUTE_STR = "minute"; | |
44 | static const char *const T_HOUR_STR = "hour"; | |
45 | static const char *const T_DAY_STR = "day"; | |
46 | static const char *const T_WEEK_STR = "week"; | |
47 | static const char *const T_FORTNIGHT_STR = "fortnight"; | |
48 | static const char *const T_MONTH_STR = "month"; | |
49 | static const char *const T_YEAR_STR = "year"; | |
50 | static const char *const T_DECADE_STR = "decade"; | |
aa0a0c7c | 51 | |
9906e724 | 52 | static const char *const B_BYTES_STR = "bytes"; |
53 | static const char *const B_KBYTES_STR = "KB"; | |
54 | static const char *const B_MBYTES_STR = "MB"; | |
55 | static const char *const B_GBYTES_STR = "GB"; | |
56 | ||
4db43fab | 57 | static const char *const list_sep = ", \t\n\r"; |
97474590 | 58 | |
cd748f27 | 59 | static void update_maxobjsize(void); |
f5b8bbc4 | 60 | static void configDoConfigure(void); |
61 | static void parse_refreshpattern(refresh_t **); | |
62 | static int parseTimeUnits(const char *unit); | |
63 | static void parseTimeLine(time_t * tptr, const char *units); | |
59715b38 | 64 | static void parse_ushort(u_short * var); |
f5b8bbc4 | 65 | static void parse_string(char **); |
94439e4e | 66 | void parse_wordlist(wordlist **); |
f5b8bbc4 | 67 | static void default_all(void); |
68 | static void defaults_if_none(void); | |
69 | static int parse_line(char *); | |
70 | static void parseBytesLine(size_t * bptr, const char *units); | |
71 | static size_t parseBytesUnits(const char *unit); | |
f5b8bbc4 | 72 | static void free_all(void); |
94439e4e | 73 | void requirePathnameExists(const char *name, const char *path); |
ed7f5615 | 74 | static OBJH dump_config; |
6bccf575 | 75 | static void dump_http_header_access(StoreEntry * entry, const char *name, header_mangler header[]); |
76 | static void parse_http_header_access(header_mangler header[]); | |
77 | static void free_http_header_access(header_mangler header[]); | |
78 | static void dump_http_header_replace(StoreEntry * entry, const char *name, header_mangler header[]); | |
79 | static void parse_http_header_replace(header_mangler * header); | |
80 | static void free_http_header_replace(header_mangler * header); | |
81 | static void parse_denyinfo(acl_deny_info_list ** var); | |
82 | static void dump_denyinfo(StoreEntry * entry, const char *name, acl_deny_info_list * var); | |
83 | static void free_denyinfo(acl_deny_info_list ** var); | |
7e3ce7b9 | 84 | static void parse_sockaddr_in_list(sockaddr_in_list **); |
85 | static void dump_sockaddr_in_list(StoreEntry *, const char *, const sockaddr_in_list *); | |
86 | static void free_sockaddr_in_list(sockaddr_in_list **); | |
87 | static int check_null_sockaddr_in_list(const sockaddr_in_list *); | |
270b86af | 88 | |
0e4e0e7d | 89 | void |
0673c0ba | 90 | self_destruct(void) |
090089c4 | 91 | { |
137ee196 | 92 | fatalf("Bungled %s line %d: %s", |
b8de7ebe | 93 | cfg_filename, config_lineno, config_input_line); |
090089c4 | 94 | } |
95 | ||
8203a132 | 96 | void |
97 | wordlistDestroy(wordlist ** list) | |
0ffd22bc | 98 | { |
99 | wordlist *w = NULL; | |
79d39a72 | 100 | while ((w = *list) != NULL) { |
b5639035 | 101 | *list = w->next; |
0ffd22bc | 102 | safe_free(w->key); |
db1cd23c | 103 | memFree(w, MEM_WORDLIST); |
0ffd22bc | 104 | } |
105 | *list = NULL; | |
106 | } | |
107 | ||
858783c9 | 108 | const char * |
fe4e214f | 109 | wordlistAdd(wordlist ** list, const char *key) |
090089c4 | 110 | { |
c68e9c6b | 111 | while (*list) |
112 | list = &(*list)->next; | |
113 | *list = memAllocate(MEM_WORDLIST); | |
114 | (*list)->key = xstrdup(key); | |
115 | (*list)->next = NULL; | |
858783c9 | 116 | return (*list)->key; |
117 | } | |
118 | ||
119 | void | |
a4b8110e | 120 | wordlistJoin(wordlist ** list, wordlist ** wl) |
858783c9 | 121 | { |
122 | while (*list) | |
123 | list = &(*list)->next; | |
124 | *list = *wl; | |
125 | *wl = NULL; | |
126 | } | |
127 | ||
128 | void | |
a4b8110e | 129 | wordlistAddWl(wordlist ** list, wordlist * wl) |
858783c9 | 130 | { |
131 | while (*list) | |
132 | list = &(*list)->next; | |
a4b8110e | 133 | for (; wl; wl = wl->next, list = &(*list)->next) { |
858783c9 | 134 | *list = memAllocate(MEM_WORDLIST); |
135 | (*list)->key = xstrdup(wl->key); | |
a4b8110e | 136 | (*list)->next = NULL; |
858783c9 | 137 | } |
090089c4 | 138 | } |
139 | ||
137ee196 | 140 | void |
eeb423fb | 141 | wordlistCat(const wordlist * w, MemBuf * mb) |
5da06f20 | 142 | { |
5da06f20 | 143 | while (NULL != w) { |
137ee196 | 144 | memBufPrintf(mb, "%s\n", w->key); |
5da06f20 | 145 | w = w->next; |
146 | } | |
5da06f20 | 147 | } |
148 | ||
6b8e7481 | 149 | wordlist * |
150 | wordlistDup(const wordlist * w) | |
151 | { | |
152 | wordlist *D = NULL; | |
153 | while (NULL != w) { | |
154 | wordlistAdd(&D, w->key); | |
155 | w = w->next; | |
156 | } | |
157 | return D; | |
158 | } | |
159 | ||
8203a132 | 160 | void |
161 | intlistDestroy(intlist ** list) | |
92a6f4b1 | 162 | { |
163 | intlist *w = NULL; | |
164 | intlist *n = NULL; | |
92a6f4b1 | 165 | for (w = *list; w; w = n) { |
166 | n = w->next; | |
db1cd23c | 167 | memFree(w, MEM_INTLIST); |
92a6f4b1 | 168 | } |
169 | *list = NULL; | |
170 | } | |
171 | ||
5db53b8f | 172 | int |
173 | intlistFind(intlist * list, int i) | |
174 | { | |
175 | intlist *w = NULL; | |
176 | for (w = list; w; w = w->next) | |
177 | if (w->i == i) | |
178 | return 1; | |
179 | return 0; | |
180 | } | |
181 | ||
403279e0 | 182 | |
3c5557f9 | 183 | /* |
184 | * Use this #define in all the parse*() functions. Assumes char *token is | |
185 | * defined | |
186 | */ | |
090089c4 | 187 | |
0e4e0e7d | 188 | int |
189 | GetInteger(void) | |
190 | { | |
191 | char *token = strtok(NULL, w_space); | |
192 | int i; | |
193 | if (token == NULL) | |
194 | self_destruct(); | |
195 | if (sscanf(token, "%d", &i) != 1) | |
196 | self_destruct(); | |
197 | return i; | |
198 | } | |
090089c4 | 199 | |
cd748f27 | 200 | static void |
201 | update_maxobjsize(void) | |
202 | { | |
203 | int i; | |
e8dbac8b | 204 | ssize_t ms = -1; |
cd748f27 | 205 | |
206 | for (i = 0; i < Config.cacheSwap.n_configured; i++) { | |
a4b8110e | 207 | if (Config.cacheSwap.swapDirs[i].max_objsize > ms) |
208 | ms = Config.cacheSwap.swapDirs[i].max_objsize; | |
cd748f27 | 209 | } |
210 | store_maxobjsize = ms; | |
211 | } | |
212 | ||
270b86af | 213 | int |
214 | parseConfigFile(const char *file_name) | |
2546fcb3 | 215 | { |
270b86af | 216 | FILE *fp = NULL; |
217 | char *token = NULL; | |
72121e8b | 218 | char *tmp_line; |
e13ee7ad | 219 | int err_count = 0; |
0153d498 | 220 | free_all(); |
221 | default_all(); | |
137ee196 | 222 | if ((fp = fopen(file_name, "r")) == NULL) |
223 | fatalf("Unable to open configuration file: %s: %s", | |
270b86af | 224 | file_name, xstrerror()); |
c4aefe96 | 225 | #if defined(_SQUID_CYGWIN_) |
226 | setmode(fileno(fp), O_TEXT); | |
227 | #endif | |
270b86af | 228 | cfg_filename = file_name; |
229 | if ((token = strrchr(cfg_filename, '/'))) | |
230 | cfg_filename = token + 1; | |
231 | memset(config_input_line, '\0', BUFSIZ); | |
232 | config_lineno = 0; | |
233 | while (fgets(config_input_line, BUFSIZ, fp)) { | |
234 | config_lineno++; | |
235 | if ((token = strchr(config_input_line, '\n'))) | |
236 | *token = '\0'; | |
237 | if (config_input_line[0] == '#') | |
238 | continue; | |
239 | if (config_input_line[0] == '\0') | |
240 | continue; | |
241 | debug(3, 5) ("Processing: '%s'\n", config_input_line); | |
72121e8b | 242 | tmp_line = xstrdup(config_input_line); |
270b86af | 243 | if (!parse_line(tmp_line)) { |
244 | debug(3, 0) ("parseConfigFile: line %d unrecognized: '%s'\n", | |
245 | config_lineno, | |
246 | config_input_line); | |
e13ee7ad | 247 | err_count++; |
270b86af | 248 | } |
72121e8b | 249 | safe_free(tmp_line); |
270b86af | 250 | } |
f0b19334 | 251 | fclose(fp); |
252 | defaults_if_none(); | |
253 | configDoConfigure(); | |
22f3fd98 | 254 | cachemgrRegister("config", |
255 | "Current Squid Configuration", | |
256 | dump_config, | |
1da3b90b | 257 | 1, 1); |
e13ee7ad | 258 | return err_count; |
f0b19334 | 259 | } |
270b86af | 260 | |
f0b19334 | 261 | static void |
262 | configDoConfigure(void) | |
263 | { | |
264 | LOCAL_ARRAY(char, buf, BUFSIZ); | |
265 | memset(&Config2, '\0', sizeof(SquidConfig2)); | |
7021844c | 266 | /* init memory as early as possible */ |
267 | memConfigure(); | |
270b86af | 268 | /* Sanity checks */ |
a95856a0 | 269 | if (Config.cacheSwap.swapDirs == NULL) |
270 | fatal("No cache_dir's specified in config file"); | |
9fa8263f | 271 | /* calculate Config.Swap.maxSize */ |
f4e3fa54 | 272 | storeDirConfigure(); |
82e2afd9 | 273 | if (0 == Config.Swap.maxSize) |
274 | /* people might want a zero-sized cache on purpose */ | |
275 | (void) 0; | |
276 | else if (Config.Swap.maxSize < (Config.memMaxSize >> 10)) | |
f0b19334 | 277 | fatal("cache_swap is lower than cache_mem"); |
84f42bac | 278 | if (Config.Announce.period > 0) { |
279 | Config.onoff.announce = 1; | |
280 | } else if (Config.Announce.period < 1) { | |
f1dc9b30 | 281 | Config.Announce.period = 86400 * 365; /* one year */ |
17a0a4ee | 282 | Config.onoff.announce = 0; |
270b86af | 283 | } |
6b53c392 | 284 | #if USE_DNSSERVERS |
f0b19334 | 285 | if (Config.dnsChildren < 1) |
286 | fatal("No dnsservers allocated"); | |
287 | if (Config.dnsChildren > DefaultDnsChildrenMax) { | |
288 | debug(3, 0) ("WARNING: dns_children was set to a bad value: %d\n", | |
270b86af | 289 | Config.dnsChildren); |
f0b19334 | 290 | debug(3, 0) ("Setting it to the maximum (%d).\n", |
291 | DefaultDnsChildrenMax); | |
270b86af | 292 | Config.dnsChildren = DefaultDnsChildrenMax; |
293 | } | |
efd900cb | 294 | #endif |
270b86af | 295 | if (Config.Program.redirect) { |
296 | if (Config.redirectChildren < 1) { | |
297 | Config.redirectChildren = 0; | |
c6d5b87b | 298 | wordlistDestroy(&Config.Program.redirect); |
270b86af | 299 | } else if (Config.redirectChildren > DefaultRedirectChildrenMax) { |
f0b19334 | 300 | debug(3, 0) ("WARNING: redirect_children was set to a bad value: %d\n", |
270b86af | 301 | Config.redirectChildren); |
f0b19334 | 302 | debug(3, 0) ("Setting it to the maximum (%d).\n", DefaultRedirectChildrenMax); |
270b86af | 303 | Config.redirectChildren = DefaultRedirectChildrenMax; |
304 | } | |
fea2e6e0 | 305 | } |
f1dc9b30 | 306 | if (Config.Accel.host) { |
a47b9029 | 307 | snprintf(buf, BUFSIZ, "http://%s:%d", Config.Accel.host, Config.Accel.port); |
308 | Config2.Accel.prefix = xstrdup(buf); | |
309 | Config2.Accel.on = 1; | |
f1dc9b30 | 310 | } |
311 | if (Config.appendDomain) | |
312 | if (*Config.appendDomain != '.') | |
313 | fatal("append_domain must begin with a '.'"); | |
270b86af | 314 | if (Config.errHtmlText == NULL) |
315 | Config.errHtmlText = xstrdup(null_string); | |
316 | storeConfigure(); | |
42b51993 | 317 | if (Config2.Accel.on && !strcmp(Config.Accel.host, "virtual")) { |
270b86af | 318 | vhost_mode = 1; |
42b51993 | 319 | if (Config.Accel.port == 0) |
320 | vport_mode = 1; | |
321 | } | |
7e3ce7b9 | 322 | if (Config.Sockaddr.http == NULL) |
270b86af | 323 | fatal("No http_port specified!"); |
137ee196 | 324 | snprintf(ThisCache, sizeof(ThisCache), "%s:%d (%s)", |
98829f69 | 325 | uniqueHostname(), |
7e3ce7b9 | 326 | (int) ntohs(Config.Sockaddr.http->s.sin_port), |
137ee196 | 327 | full_appname_string); |
38a6c74e | 328 | /* |
329 | * the extra space is for loop detection in client_side.c -- we search | |
330 | * for substrings in the Via header. | |
331 | */ | |
332 | snprintf(ThisCache2, sizeof(ThisCache), " %s:%d (%s)", | |
333 | uniqueHostname(), | |
7e3ce7b9 | 334 | (int) ntohs(Config.Sockaddr.http->s.sin_port), |
38a6c74e | 335 | full_appname_string); |
270b86af | 336 | if (!Config.udpMaxHitObjsz || Config.udpMaxHitObjsz > SQUID_UDP_SO_SNDBUF) |
337 | Config.udpMaxHitObjsz = SQUID_UDP_SO_SNDBUF; | |
338 | if (Config.appendDomain) | |
339 | Config.appendDomainLen = strlen(Config.appendDomain); | |
340 | else | |
341 | Config.appendDomainLen = 0; | |
f1dc9b30 | 342 | safe_free(debug_options) |
343 | debug_options = xstrdup(Config.debugOptions); | |
22c653cd | 344 | if (Config.retry.timeout < 5) |
345 | fatal("minimum_retry_timeout must be at least 5 seconds"); | |
346 | if (Config.retry.maxtries > 10) | |
347 | fatal("maximum_single_addr_tries cannot be larger than 10"); | |
348 | if (Config.retry.maxtries < 1) { | |
22c653cd | 349 | debug(3, 0) ("WARNING: resetting 'maximum_single_addr_tries to 1\n"); |
5210854d | 350 | Config.retry.maxtries = 1; |
351 | } | |
f0b19334 | 352 | requirePathnameExists("MIME Config Table", Config.mimeTablePathname); |
6b53c392 | 353 | #if USE_DNSSERVERS |
f0b19334 | 354 | requirePathnameExists("cache_dns_program", Config.Program.dnsserver); |
efd900cb | 355 | #endif |
a3d0a19d | 356 | #if USE_UNLINKD |
f0b19334 | 357 | requirePathnameExists("unlinkd_program", Config.Program.unlinkd); |
a3d0a19d | 358 | #endif |
f0b19334 | 359 | if (Config.Program.redirect) |
c6d5b87b | 360 | requirePathnameExists("redirect_program", Config.Program.redirect->key); |
f0b19334 | 361 | requirePathnameExists("Icon Directory", Config.icons.directory); |
362 | requirePathnameExists("Error Directory", Config.errorDirectory); | |
9f60cfdf | 363 | #if HTTP_VIOLATIONS |
364 | { | |
49c0f46d | 365 | const refresh_t *R; |
366 | for (R = Config.Refresh; R; R = R->next) { | |
367 | if (!R->flags.override_expire) | |
368 | continue; | |
369 | debug(22, 1) ("WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP\n"); | |
370 | break; | |
371 | } | |
372 | for (R = Config.Refresh; R; R = R->next) { | |
373 | if (!R->flags.override_lastmod) | |
374 | continue; | |
375 | debug(22, 1) ("WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP\n"); | |
376 | break; | |
377 | } | |
9f60cfdf | 378 | } |
379 | #endif | |
db1cd23c | 380 | if (Config.Wais.relayHost) { |
381 | if (Config.Wais.peer) | |
382 | cbdataFree(Config.Wais.peer); | |
28c60158 | 383 | Config.Wais.peer = CBDATA_ALLOC(peer, peerDestroy); |
b6a2f15e | 384 | Config.Wais.peer->host = xstrdup(Config.Wais.relayHost); |
db1cd23c | 385 | Config.Wais.peer->http_port = Config.Wais.relayPort; |
386 | } | |
53cb32a9 | 387 | if (aclPurgeMethodInUse(Config.accessList.http)) |
388 | Config2.onoff.enable_purge = 1; | |
d20b1cd0 | 389 | if (NULL != Config.effectiveUser) { |
390 | struct passwd *pwd = getpwnam(Config.effectiveUser); | |
391 | if (NULL == pwd) | |
392 | /* | |
393 | * Andres Kroonmaa <andre@online.ee>: | |
394 | * Some getpwnam() implementations (Solaris?) require | |
395 | * an available FD < 256 for opening a FILE* to the | |
396 | * passwd file. | |
397 | * DW: | |
398 | * This should be safe at startup, but might still fail | |
399 | * during reconfigure. | |
400 | */ | |
401 | fatalf("getpwnam failed to find userid for effective user '%s'", | |
402 | Config.effectiveUser, | |
403 | xstrerror()); | |
404 | Config2.effectiveUserID = pwd->pw_uid; | |
405 | } | |
406 | if (NULL != Config.effectiveGroup) { | |
407 | struct group *grp = getgrnam(Config.effectiveGroup); | |
408 | if (NULL == grp) | |
409 | fatalf("getgrnam failed to find groupid for effective group '%s'", | |
410 | Config.effectiveGroup, | |
411 | xstrerror()); | |
412 | Config2.effectiveGroupID = grp->gr_gid; | |
413 | } | |
56fe752e | 414 | urlExtMethodConfigure(); |
090089c4 | 415 | } |
416 | ||
270b86af | 417 | /* Parse a time specification from the config file. Store the |
f1dc9b30 | 418 | * result in 'tptr', after converting it to 'units' */ |
8203a132 | 419 | static void |
a47b9029 | 420 | parseTimeLine(time_t * tptr, const char *units) |
090089c4 | 421 | { |
422 | char *token; | |
270b86af | 423 | double d; |
f1dc9b30 | 424 | time_t m; |
425 | time_t u; | |
270b86af | 426 | if ((u = parseTimeUnits(units)) == 0) |
3003c0f3 | 427 | self_destruct(); |
270b86af | 428 | if ((token = strtok(NULL, w_space)) == NULL) |
3003c0f3 | 429 | self_destruct(); |
270b86af | 430 | d = atof(token); |
431 | m = u; /* default to 'units' if none specified */ | |
10738561 | 432 | if (0 == d) |
433 | (void) 0; | |
434 | else if ((token = strtok(NULL, w_space)) == NULL) | |
a47b9029 | 435 | debug(3, 0) ("WARNING: No units on '%s', assuming %f %s\n", |
436 | config_input_line, d, units); | |
9e975e4e | 437 | else if ((m = parseTimeUnits(token)) == 0) |
a47b9029 | 438 | self_destruct(); |
f1dc9b30 | 439 | *tptr = m * d / u; |
090089c4 | 440 | } |
441 | ||
270b86af | 442 | static int |
443 | parseTimeUnits(const char *unit) | |
444 | { | |
445 | if (!strncasecmp(unit, T_SECOND_STR, strlen(T_SECOND_STR))) | |
446 | return 1; | |
447 | if (!strncasecmp(unit, T_MINUTE_STR, strlen(T_MINUTE_STR))) | |
448 | return 60; | |
449 | if (!strncasecmp(unit, T_HOUR_STR, strlen(T_HOUR_STR))) | |
450 | return 3600; | |
451 | if (!strncasecmp(unit, T_DAY_STR, strlen(T_DAY_STR))) | |
452 | return 86400; | |
453 | if (!strncasecmp(unit, T_WEEK_STR, strlen(T_WEEK_STR))) | |
454 | return 86400 * 7; | |
455 | if (!strncasecmp(unit, T_FORTNIGHT_STR, strlen(T_FORTNIGHT_STR))) | |
456 | return 86400 * 14; | |
457 | if (!strncasecmp(unit, T_MONTH_STR, strlen(T_MONTH_STR))) | |
458 | return 86400 * 30; | |
459 | if (!strncasecmp(unit, T_YEAR_STR, strlen(T_YEAR_STR))) | |
460 | return 86400 * 365.2522; | |
461 | if (!strncasecmp(unit, T_DECADE_STR, strlen(T_DECADE_STR))) | |
462 | return 86400 * 365.2522 * 10; | |
463 | debug(3, 1) ("parseTimeUnits: unknown time unit '%s'\n", unit); | |
464 | return 0; | |
465 | } | |
466 | ||
9906e724 | 467 | static void |
9e975e4e | 468 | parseBytesLine(size_t * bptr, const char *units) |
9906e724 | 469 | { |
470 | char *token; | |
471 | double d; | |
472 | size_t m; | |
473 | size_t u; | |
474 | if ((u = parseBytesUnits(units)) == 0) | |
475 | self_destruct(); | |
476 | if ((token = strtok(NULL, w_space)) == NULL) | |
477 | self_destruct(); | |
478 | d = atof(token); | |
479 | m = u; /* default to 'units' if none specified */ | |
343f47a3 | 480 | if (0.0 == d) |
10738561 | 481 | (void) 0; |
4860dc1b | 482 | else if ((token = strtok(NULL, w_space)) == NULL) |
9e975e4e | 483 | debug(3, 0) ("WARNING: No units on '%s', assuming %f %s\n", |
484 | config_input_line, d, units); | |
485 | else if ((m = parseBytesUnits(token)) == 0) | |
486 | self_destruct(); | |
9906e724 | 487 | *bptr = m * d / u; |
488 | } | |
489 | ||
490 | static size_t | |
491 | parseBytesUnits(const char *unit) | |
492 | { | |
493 | if (!strncasecmp(unit, B_BYTES_STR, strlen(B_BYTES_STR))) | |
494 | return 1; | |
495 | if (!strncasecmp(unit, B_KBYTES_STR, strlen(B_KBYTES_STR))) | |
a47b9029 | 496 | return 1 << 10; |
9906e724 | 497 | if (!strncasecmp(unit, B_MBYTES_STR, strlen(B_MBYTES_STR))) |
a47b9029 | 498 | return 1 << 20; |
9906e724 | 499 | if (!strncasecmp(unit, B_GBYTES_STR, strlen(B_GBYTES_STR))) |
a47b9029 | 500 | return 1 << 30; |
9906e724 | 501 | debug(3, 1) ("parseBytesUnits: unknown bytes unit '%s'\n", unit); |
502 | return 0; | |
503 | } | |
504 | ||
270b86af | 505 | /***************************************************************************** |
506 | * Max | |
507 | *****************************************************************************/ | |
508 | ||
8203a132 | 509 | static void |
9ef28b60 | 510 | dump_acl(StoreEntry * entry, const char *name, acl * ae) |
090089c4 | 511 | { |
56b63fa1 | 512 | wordlist *w; |
513 | wordlist *v; | |
9ef28b60 | 514 | while (ae != NULL) { |
c68e9c6b | 515 | debug(3, 3) ("dump_acl: %s %s\n", name, ae->name); |
9ef28b60 | 516 | v = w = aclDumpGeneric(ae); |
56b63fa1 | 517 | while (v != NULL) { |
c68e9c6b | 518 | debug(3, 3) ("dump_acl: %s %s %s\n", name, ae->name, v->key); |
16300b58 | 519 | storeAppendPrintf(entry, "%s %s %s %s\n", |
520 | name, | |
9ef28b60 | 521 | ae->name, |
522 | aclTypeToStr(ae->type), | |
16300b58 | 523 | v->key); |
56b63fa1 | 524 | v = v->next; |
525 | } | |
526 | wordlistDestroy(&w); | |
9ef28b60 | 527 | ae = ae->next; |
56b63fa1 | 528 | } |
090089c4 | 529 | } |
530 | ||
8203a132 | 531 | static void |
9ef28b60 | 532 | parse_acl(acl ** ae) |
090089c4 | 533 | { |
9ef28b60 | 534 | aclParseAclLine(ae); |
f1dc9b30 | 535 | } |
536 | ||
537 | static void | |
9ef28b60 | 538 | free_acl(acl ** ae) |
f1dc9b30 | 539 | { |
9ef28b60 | 540 | aclDestroyAcls(ae); |
090089c4 | 541 | } |
542 | ||
8203a132 | 543 | static void |
16300b58 | 544 | dump_acl_access(StoreEntry * entry, const char *name, acl_access * head) |
30a4f2a8 | 545 | { |
56b63fa1 | 546 | acl_list *l; |
547 | while (head != NULL) { | |
505e35db | 548 | storeAppendPrintf(entry, "%s %s", |
0cdcddb9 | 549 | name, |
505e35db | 550 | head->allow ? "Allow" : "Deny"); |
551 | for (l = head->acl_list; l != NULL; l = l->next) { | |
552 | storeAppendPrintf(entry, " %s%s", | |
553 | l->op ? null_string : "!", | |
56b63fa1 | 554 | l->acl->name); |
16300b58 | 555 | } |
505e35db | 556 | storeAppendPrintf(entry, "\n"); |
56b63fa1 | 557 | head = head->next; |
558 | } | |
30a4f2a8 | 559 | } |
090089c4 | 560 | |
8203a132 | 561 | static void |
16300b58 | 562 | parse_acl_access(acl_access ** head) |
090089c4 | 563 | { |
270b86af | 564 | aclParseAccessLine(head); |
090089c4 | 565 | } |
566 | ||
0153d498 | 567 | static void |
16300b58 | 568 | free_acl_access(acl_access ** head) |
0153d498 | 569 | { |
a47b9029 | 570 | aclDestroyAccessList(head); |
0153d498 | 571 | } |
572 | ||
8203a132 | 573 | static void |
a7d59104 | 574 | dump_address(StoreEntry * entry, const char *name, struct in_addr addr) |
270b86af | 575 | { |
f53b06f9 | 576 | storeAppendPrintf(entry, "%s %s\n", name, inet_ntoa(addr)); |
270b86af | 577 | } |
578 | ||
579 | static void | |
580 | parse_address(struct in_addr *addr) | |
090089c4 | 581 | { |
0ee4272b | 582 | const struct hostent *hp; |
270b86af | 583 | char *token = strtok(NULL, w_space); |
584 | ||
30a4f2a8 | 585 | if (token == NULL) |
586 | self_destruct(); | |
429fdbec | 587 | if (safe_inet_addr(token, addr) == 1) |
588 | (void) 0; | |
ceb8994e | 589 | else if ((hp = gethostbyname(token))) /* dont use ipcache */ |
1d73e33a | 590 | *addr = inaddrFromHostent(hp); |
30a4f2a8 | 591 | else |
3003c0f3 | 592 | self_destruct(); |
090089c4 | 593 | } |
594 | ||
0153d498 | 595 | static void |
596 | free_address(struct in_addr *addr) | |
597 | { | |
a47b9029 | 598 | memset(addr, '\0', sizeof(struct in_addr)); |
0153d498 | 599 | } |
600 | ||
59715b38 | 601 | #if DELAY_POOLS |
602 | ||
603 | /* do nothing - free_delay_pool_count is the magic free function. | |
604 | * this is why delay_pool_count isn't just marked TYPE: ushort | |
605 | */ | |
606 | #define free_delay_pool_class(X) | |
607 | #define free_delay_pool_access(X) | |
608 | #define free_delay_pool_rates(X) | |
609 | #define dump_delay_pool_class(X, Y, Z) | |
610 | #define dump_delay_pool_access(X, Y, Z) | |
611 | #define dump_delay_pool_rates(X, Y, Z) | |
612 | ||
613 | static void | |
614 | free_delay_pool_count(delayConfig * cfg) | |
615 | { | |
616 | int i; | |
617 | ||
618 | if (!cfg->pools) | |
619 | return; | |
620 | for (i = 0; i < cfg->pools; i++) { | |
621 | if (cfg->class[i]) { | |
622 | delayFreeDelayPool(i); | |
623 | safe_free(cfg->rates[i]); | |
624 | } | |
625 | aclDestroyAccessList(&cfg->access[i]); | |
626 | } | |
627 | delayFreeDelayData(); | |
628 | xfree(cfg->class); | |
629 | xfree(cfg->rates); | |
630 | xfree(cfg->access); | |
631 | memset(cfg, 0, sizeof(*cfg)); | |
632 | } | |
633 | ||
634 | static void | |
635 | dump_delay_pool_count(StoreEntry * entry, const char *name, delayConfig cfg) | |
636 | { | |
637 | int i; | |
638 | LOCAL_ARRAY(char, nom, 32); | |
639 | ||
640 | if (!cfg.pools) { | |
641 | storeAppendPrintf(entry, "%s 0\n", name); | |
642 | return; | |
643 | } | |
644 | storeAppendPrintf(entry, "%s %d\n", name, cfg.pools); | |
645 | for (i = 0; i < cfg.pools; i++) { | |
646 | storeAppendPrintf(entry, "delay_class %d %d\n", i + 1, cfg.class[i]); | |
647 | snprintf(nom, 32, "delay_access %d", i + 1); | |
648 | dump_acl_access(entry, nom, cfg.access[i]); | |
649 | if (cfg.class[i] >= 1) | |
650 | storeAppendPrintf(entry, "delay_parameters %d %d/%d", i + 1, | |
651 | cfg.rates[i]->aggregate.restore_bps, | |
652 | cfg.rates[i]->aggregate.max_bytes); | |
653 | if (cfg.class[i] >= 3) | |
654 | storeAppendPrintf(entry, " %d/%d", | |
655 | cfg.rates[i]->network.restore_bps, | |
656 | cfg.rates[i]->network.max_bytes); | |
657 | if (cfg.class[i] >= 2) | |
658 | storeAppendPrintf(entry, " %d/%d", | |
659 | cfg.rates[i]->individual.restore_bps, | |
660 | cfg.rates[i]->individual.max_bytes); | |
661 | if (cfg.class[i] >= 1) | |
662 | storeAppendPrintf(entry, "\n"); | |
663 | } | |
664 | } | |
665 | ||
666 | static void | |
667 | parse_delay_pool_count(delayConfig * cfg) | |
668 | { | |
669 | if (cfg->pools) { | |
670 | debug(3, 0) ("parse_delay_pool_count: multiple delay_pools lines, aborting all previous delay_pools config\n"); | |
671 | free_delay_pool_count(cfg); | |
672 | } | |
673 | parse_ushort(&cfg->pools); | |
674 | delayInitDelayData(cfg->pools); | |
675 | cfg->class = xcalloc(cfg->pools, sizeof(u_char)); | |
676 | cfg->rates = xcalloc(cfg->pools, sizeof(delaySpecSet *)); | |
677 | cfg->access = xcalloc(cfg->pools, sizeof(acl_access *)); | |
678 | } | |
679 | ||
680 | static void | |
681 | parse_delay_pool_class(delayConfig * cfg) | |
682 | { | |
683 | ushort pool, class; | |
684 | ||
685 | parse_ushort(&pool); | |
686 | if (pool < 1 || pool > cfg->pools) { | |
687 | debug(3, 0) ("parse_delay_pool_class: Ignoring pool %d not in 1 .. %d\n", pool, cfg->pools); | |
688 | return; | |
689 | } | |
690 | parse_ushort(&class); | |
691 | if (class < 1 || class > 3) { | |
692 | debug(3, 0) ("parse_delay_pool_class: Ignoring pool %d class %d not in 1 .. 3\n", pool, class); | |
693 | return; | |
694 | } | |
695 | pool--; | |
696 | if (cfg->class[pool]) { | |
697 | delayFreeDelayPool(pool); | |
698 | safe_free(cfg->rates[pool]); | |
699 | } | |
700 | cfg->rates[pool] = xmalloc(class * sizeof(delaySpec)); | |
701 | cfg->class[pool] = class; | |
702 | cfg->rates[pool]->aggregate.restore_bps = cfg->rates[pool]->aggregate.max_bytes = -1; | |
703 | if (cfg->class[pool] >= 3) | |
704 | cfg->rates[pool]->network.restore_bps = cfg->rates[pool]->network.max_bytes = -1; | |
705 | if (cfg->class[pool] >= 2) | |
706 | cfg->rates[pool]->individual.restore_bps = cfg->rates[pool]->individual.max_bytes = -1; | |
707 | delayCreateDelayPool(pool, class); | |
708 | } | |
709 | ||
710 | static void | |
711 | parse_delay_pool_rates(delayConfig * cfg) | |
712 | { | |
713 | ushort pool, class; | |
714 | int i; | |
715 | delaySpec *ptr; | |
716 | char *token; | |
717 | ||
718 | parse_ushort(&pool); | |
719 | if (pool < 1 || pool > cfg->pools) { | |
720 | debug(3, 0) ("parse_delay_pool_rates: Ignoring pool %d not in 1 .. %d\n", pool, cfg->pools); | |
721 | return; | |
722 | } | |
723 | pool--; | |
724 | class = cfg->class[pool]; | |
725 | if (class == 0) { | |
726 | debug(3, 0) ("parse_delay_pool_rates: Ignoring pool %d attempt to set rates with class not set\n", pool + 1); | |
727 | return; | |
728 | } | |
729 | ptr = (delaySpec *) cfg->rates[pool]; | |
730 | /* read in "class" sets of restore,max pairs */ | |
731 | while (class--) { | |
732 | token = strtok(NULL, "/"); | |
733 | if (token == NULL) | |
734 | self_destruct(); | |
735 | if (sscanf(token, "%d", &i) != 1) | |
736 | self_destruct(); | |
737 | ptr->restore_bps = i; | |
0e4e0e7d | 738 | i = GetInteger(); |
59715b38 | 739 | ptr->max_bytes = i; |
740 | ptr++; | |
741 | } | |
742 | class = cfg->class[pool]; | |
743 | /* if class is 3, swap around network and individual */ | |
744 | if (class == 3) { | |
745 | delaySpec tmp; | |
746 | ||
747 | tmp = cfg->rates[pool]->individual; | |
748 | cfg->rates[pool]->individual = cfg->rates[pool]->network; | |
749 | cfg->rates[pool]->network = tmp; | |
750 | } | |
751 | /* initialize the delay pools */ | |
752 | delayInitDelayPool(pool, class, cfg->rates[pool]); | |
753 | } | |
754 | ||
755 | static void | |
756 | parse_delay_pool_access(delayConfig * cfg) | |
757 | { | |
758 | ushort pool; | |
759 | ||
760 | parse_ushort(&pool); | |
761 | if (pool < 1 || pool > cfg->pools) { | |
762 | debug(3, 0) ("parse_delay_pool_rates: Ignoring pool %d not in 1 .. %d\n", pool, cfg->pools); | |
763 | return; | |
764 | } | |
765 | aclParseAccessLine(&cfg->access[pool - 1]); | |
766 | } | |
767 | #endif | |
768 | ||
97474590 | 769 | static void |
6bccf575 | 770 | dump_http_header_access(StoreEntry * entry, const char *name, header_mangler header[]) |
e3dd531e | 771 | { |
efd900cb | 772 | int i; |
6bccf575 | 773 | storeAppendPrintf(entry, "%s:", name); |
774 | for (i = 0; i < HDR_ENUM_END; i++) { | |
775 | if (header[i].access_list != NULL) { | |
776 | storeAppendPrintf(entry, "\t"); | |
777 | dump_acl_access(entry, httpHeaderNameById(i), | |
778 | header[i].access_list); | |
779 | } | |
efd900cb | 780 | } |
97474590 | 781 | } |
e3dd531e | 782 | |
97474590 | 783 | static void |
6bccf575 | 784 | parse_http_header_access(header_mangler header[]) |
97474590 | 785 | { |
6bccf575 | 786 | int id, i; |
97474590 | 787 | char *t = NULL; |
97474590 | 788 | if ((t = strtok(NULL, w_space)) == NULL) { |
789 | debug(3, 0) ("%s line %d: %s\n", | |
790 | cfg_filename, config_lineno, config_input_line); | |
6bccf575 | 791 | debug(3, 0) ("parse_http_header_access: missing header name.\n"); |
97474590 | 792 | return; |
793 | } | |
6bccf575 | 794 | /* Now lookup index of header. */ |
795 | id = httpHeaderIdByNameDef(t, strlen(t)); | |
796 | if (strcmp(t, "All") == 0) | |
797 | id = HDR_ENUM_END; | |
798 | else if (strcmp(t, "Other") == 0) | |
799 | id = HDR_OTHER; | |
800 | else if (id == -1) { | |
97474590 | 801 | debug(3, 0) ("%s line %d: %s\n", |
802 | cfg_filename, config_lineno, config_input_line); | |
6bccf575 | 803 | debug(3, 0) ("parse_http_header_access: unknown header name %s.\n", t); |
97474590 | 804 | return; |
805 | } | |
6bccf575 | 806 | if (id != HDR_ENUM_END) { |
807 | parse_acl_access(&header[id].access_list); | |
808 | } else { | |
809 | char *next_string = t + strlen(t); | |
810 | *next_string = ' '; | |
811 | for (i = 0; i < HDR_ENUM_END; i++) { | |
812 | char *new_string = xstrdup(next_string); | |
813 | strtok(new_string, " "); | |
814 | parse_acl_access(&header[i].access_list); | |
815 | safe_free(new_string); | |
efd900cb | 816 | } |
97474590 | 817 | } |
6bccf575 | 818 | } |
819 | ||
820 | static void | |
821 | free_http_header_access(header_mangler header[]) | |
822 | { | |
823 | int i; | |
824 | for (i = 0; i < HDR_ENUM_END; i++) { | |
825 | free_acl_access(&header[i].access_list); | |
826 | } | |
827 | } | |
828 | ||
829 | static void | |
830 | dump_http_header_replace(StoreEntry * entry, const char *name, header_mangler | |
831 | header[]) | |
832 | { | |
833 | int i; | |
834 | storeAppendPrintf(entry, "%s:", name); | |
835 | for (i = 0; i < HDR_ENUM_END; i++) { | |
836 | if (NULL == header[i].replacement) | |
837 | continue; | |
838 | storeAppendPrintf(entry, "\t%s: %s", httpHeaderNameById(i), | |
839 | header[i].replacement); | |
97474590 | 840 | } |
841 | } | |
e3dd531e | 842 | |
97474590 | 843 | static void |
6bccf575 | 844 | parse_http_header_replace(header_mangler header[]) |
e3dd531e | 845 | { |
6bccf575 | 846 | int id, i; |
847 | char *t = NULL; | |
848 | if ((t = strtok(NULL, w_space)) == NULL) { | |
849 | debug(3, 0) ("%s line %d: %s\n", | |
850 | cfg_filename, config_lineno, config_input_line); | |
851 | debug(3, 0) ("parse_http_header_replace: missing header name.\n"); | |
852 | return; | |
853 | } | |
854 | /* Now lookup index of header. */ | |
855 | id = httpHeaderIdByNameDef(t, strlen(t)); | |
856 | if (strcmp(t, "All") == 0) | |
857 | id = HDR_ENUM_END; | |
858 | else if (strcmp(t, "Other") == 0) | |
859 | id = HDR_OTHER; | |
860 | else if (id == -1) { | |
861 | debug(3, 0) ("%s line %d: %s\n", | |
862 | cfg_filename, config_lineno, config_input_line); | |
863 | debug(3, 0) ("parse_http_header_replace: unknown header name %s.\n", | |
864 | t); | |
865 | return; | |
866 | } | |
867 | if (id != HDR_ENUM_END) { | |
868 | if (header[id].replacement != NULL) | |
869 | safe_free(header[id].replacement); | |
870 | header[id].replacement = xstrdup(t + strlen(t) + 1); | |
871 | } else { | |
872 | for (i = 0; i < HDR_ENUM_END; i++) { | |
873 | if (header[i].replacement != NULL) | |
874 | safe_free(header[i].replacement); | |
875 | header[i].replacement = xstrdup(t + strlen(t) + 1); | |
876 | } | |
877 | } | |
878 | } | |
879 | ||
880 | static void | |
881 | free_http_header_replace(header_mangler header[]) | |
882 | { | |
883 | int i; | |
884 | for (i = 0; i < HDR_ENUM_END; i++) { | |
885 | if (header[i].replacement != NULL) | |
886 | safe_free(header[i].replacement); | |
887 | } | |
97474590 | 888 | } |
889 | ||
e90100aa | 890 | static void |
56b63fa1 | 891 | dump_cachedir(StoreEntry * entry, const char *name, cacheSwap swap) |
e90100aa | 892 | { |
f53b06f9 | 893 | SwapDir *s; |
894 | int i; | |
a7d59104 | 895 | for (i = 0; i < swap.n_configured; i++) { |
896 | s = swap.swapDirs + i; | |
a4b8110e | 897 | s->dump(entry, name, s); |
f53b06f9 | 898 | } |
899 | } | |
900 | ||
901 | static int | |
56b63fa1 | 902 | check_null_cachedir(cacheSwap swap) |
f53b06f9 | 903 | { |
904 | return swap.swapDirs == NULL; | |
e90100aa | 905 | } |
906 | ||
53ad48e6 | 907 | static int |
908 | check_null_string(char *s) | |
909 | { | |
910 | return s == NULL; | |
911 | } | |
912 | ||
94439e4e | 913 | void |
914 | allocate_new_authScheme(authConfig * cfg) | |
915 | { | |
916 | if (cfg->schemes == NULL) { | |
917 | cfg->n_allocated = 4; | |
918 | cfg->schemes = xcalloc(cfg->n_allocated, sizeof(authScheme)); | |
919 | } | |
920 | if (cfg->n_allocated == cfg->n_configured) { | |
921 | authScheme *tmp; | |
922 | cfg->n_allocated <<= 1; | |
923 | tmp = xcalloc(cfg->n_allocated, sizeof(authScheme)); | |
924 | xmemcpy(tmp, cfg->schemes, cfg->n_configured * sizeof(authScheme)); | |
925 | xfree(cfg->schemes); | |
926 | cfg->schemes = tmp; | |
927 | } | |
928 | } | |
929 | ||
930 | static void | |
931 | parse_authparam(authConfig * config) | |
932 | { | |
933 | char *type_str; | |
934 | char *param_str; | |
935 | authScheme *scheme = NULL; | |
936 | int type, i; | |
937 | ||
938 | if ((type_str = strtok(NULL, w_space)) == NULL) | |
939 | self_destruct(); | |
940 | ||
941 | if ((param_str = strtok(NULL, w_space)) == NULL) | |
942 | self_destruct(); | |
943 | ||
944 | if ((type = authenticateAuthSchemeId(type_str)) == -1) { | |
945 | debug(3, 0) ("Parsing Config File: Unknown authentication scheme '%s'.\n", type_str); | |
946 | return; | |
947 | } | |
948 | for (i = 0; i < config->n_configured; i++) { | |
949 | if (config->schemes[i].Id == type) { | |
950 | scheme = config->schemes + i; | |
951 | } | |
952 | } | |
953 | ||
954 | if (scheme == NULL) { | |
955 | allocate_new_authScheme(config); | |
956 | scheme = config->schemes + config->n_configured; | |
957 | config->n_configured++; | |
958 | scheme->Id = type; | |
959 | scheme->typestr = authscheme_list[type].typestr; | |
960 | } | |
961 | authscheme_list[type].parse(scheme, config->n_configured, param_str); | |
962 | } | |
963 | ||
964 | static void | |
965 | free_authparam(authConfig * cfg) | |
966 | { | |
967 | authScheme *scheme; | |
968 | int i; | |
969 | /* DON'T FREE THESE FOR RECONFIGURE */ | |
970 | if (reconfiguring) | |
971 | return; | |
972 | for (i = 0; i < cfg->n_configured; i++) { | |
973 | scheme = cfg->schemes + i; | |
974 | authscheme_list[scheme->Id].freeconfig(scheme); | |
975 | } | |
976 | safe_free(cfg->schemes); | |
977 | cfg->schemes = NULL; | |
978 | cfg->n_allocated = 0; | |
979 | cfg->n_configured = 0; | |
980 | } | |
981 | ||
982 | static void | |
983 | dump_authparam(StoreEntry * entry, const char *name, authConfig cfg) | |
984 | { | |
985 | authScheme *scheme; | |
986 | int i; | |
987 | for (i = 0; i < cfg.n_configured; i++) { | |
988 | scheme = cfg.schemes + i; | |
989 | authscheme_list[scheme->Id].dump(entry, name, scheme); | |
990 | } | |
991 | } | |
992 | ||
0e4e0e7d | 993 | void |
994 | allocate_new_swapdir(cacheSwap * swap) | |
090089c4 | 995 | { |
f1dc9b30 | 996 | if (swap->swapDirs == NULL) { |
997 | swap->n_allocated = 4; | |
998 | swap->swapDirs = xcalloc(swap->n_allocated, sizeof(SwapDir)); | |
999 | } | |
1000 | if (swap->n_allocated == swap->n_configured) { | |
0e4e0e7d | 1001 | SwapDir *tmp; |
f1dc9b30 | 1002 | swap->n_allocated <<= 1; |
1003 | tmp = xcalloc(swap->n_allocated, sizeof(SwapDir)); | |
1004 | xmemcpy(tmp, swap->swapDirs, swap->n_configured * sizeof(SwapDir)); | |
1005 | xfree(swap->swapDirs); | |
1006 | swap->swapDirs = tmp; | |
1007 | } | |
0e4e0e7d | 1008 | } |
1009 | ||
cd748f27 | 1010 | static int |
1011 | find_fstype(char *type) | |
1012 | { | |
1013 | int i; | |
1014 | for (i = 0; storefs_list[i].typestr != NULL; i++) { | |
a4b8110e | 1015 | if (strcasecmp(type, storefs_list[i].typestr) == 0) { |
cd748f27 | 1016 | return i; |
1017 | } | |
1018 | } | |
1019 | return (-1); | |
1020 | } | |
1021 | ||
0e4e0e7d | 1022 | static void |
1023 | parse_cachedir(cacheSwap * swap) | |
1024 | { | |
1025 | char *type_str; | |
cd748f27 | 1026 | char *path_str; |
1027 | SwapDir *sd; | |
1028 | int i; | |
1029 | int fs; | |
e8dbac8b | 1030 | ssize_t maxobjsize; |
cd748f27 | 1031 | |
0e4e0e7d | 1032 | if ((type_str = strtok(NULL, w_space)) == NULL) |
1033 | self_destruct(); | |
cd748f27 | 1034 | |
e8dbac8b | 1035 | maxobjsize = (ssize_t) GetInteger(); |
cd748f27 | 1036 | |
1037 | if ((path_str = strtok(NULL, w_space)) == NULL) | |
1038 | self_destruct(); | |
1039 | ||
1040 | /* | |
1041 | * This bit of code is a little strange. | |
1042 | * See, if we find a path and type match for a given line, then | |
1043 | * as long as we're reconfiguring, we can just call its reconfigure | |
1044 | * function. No harm there. | |
1045 | * | |
1046 | * Trouble is, if we find a path match, but not a type match, we have | |
1047 | * a dilemma - we could gracefully shut down the fs, kill it, and | |
1048 | * create a new one of a new type in its place, BUT at this stage the | |
1049 | * fs is meant to be the *NEW* one, and so things go very strange. :-) | |
1050 | * | |
1051 | * So, we'll assume the person isn't going to change the fs type for now, | |
1052 | * and XXX later on we will make sure that its picked up. | |
1053 | * | |
1054 | * (moving around cache_dir lines will be looked at later in a little | |
1055 | * more sane detail..) | |
1056 | */ | |
1057 | ||
1058 | for (i = 0; i < swap->n_configured; i++) { | |
a4b8110e | 1059 | if (0 == strcasecmp(path_str, swap->swapDirs[i].path)) { |
cd748f27 | 1060 | /* This is a little weird, you'll appreciate it later */ |
1061 | fs = find_fstype(type_str); | |
1062 | if (fs < 0) { | |
a4b8110e | 1063 | fatalf("Unknown cache_dir type '%s'\n", type_str); |
cd748f27 | 1064 | } |
1065 | sd = swap->swapDirs + i; | |
1066 | storefs_list[fs].reconfigurefunc(sd, i, path_str); | |
a4b8110e | 1067 | sd->max_objsize = maxobjsize; |
1068 | update_maxobjsize(); | |
1069 | return; | |
cd748f27 | 1070 | } |
1071 | } | |
1072 | ||
2b6662ba | 1073 | assert(swap->n_configured < 63); /* 7 bits, signed */ |
dc986280 | 1074 | |
cd748f27 | 1075 | fs = find_fstype(type_str); |
1076 | if (fs < 0) { | |
a4b8110e | 1077 | /* If we get here, we didn't find a matching cache_dir type */ |
1078 | fatalf("Unknown cache_dir type '%s'\n", type_str); | |
0e4e0e7d | 1079 | } |
cd748f27 | 1080 | allocate_new_swapdir(swap); |
1081 | sd = swap->swapDirs + swap->n_configured; | |
1082 | storefs_list[fs].parsefunc(sd, swap->n_configured, path_str); | |
1083 | /* XXX should we dupe the string here, in case it gets trodden on? */ | |
1084 | sd->type = storefs_list[fs].typestr; | |
1085 | sd->max_objsize = maxobjsize; | |
90d42c28 | 1086 | /* defaults in case fs implementation fails to set these */ |
1087 | sd->fs.blksize = 1024; | |
cd748f27 | 1088 | swap->n_configured++; |
1089 | /* Update the max object size */ | |
1090 | update_maxobjsize(); | |
752c3b27 | 1091 | } |
1092 | ||
8203a132 | 1093 | static void |
16300b58 | 1094 | free_cachedir(cacheSwap * swap) |
f1dc9b30 | 1095 | { |
a47b9029 | 1096 | SwapDir *s; |
1097 | int i; | |
860ee7e3 | 1098 | /* DON'T FREE THESE FOR RECONFIGURE */ |
5cd39a10 | 1099 | if (reconfiguring) |
860ee7e3 | 1100 | return; |
a47b9029 | 1101 | for (i = 0; i < swap->n_configured; i++) { |
1102 | s = swap->swapDirs + i; | |
cd748f27 | 1103 | s->freefs(s); |
a47b9029 | 1104 | xfree(s->path); |
a47b9029 | 1105 | } |
1106 | safe_free(swap->swapDirs); | |
1107 | swap->swapDirs = NULL; | |
1108 | swap->n_allocated = 0; | |
1109 | swap->n_configured = 0; | |
f1dc9b30 | 1110 | } |
1111 | ||
505e35db | 1112 | const char * |
1113 | peer_type_str(const peer_t type) | |
1114 | { | |
0cdcddb9 | 1115 | switch (type) { |
505e35db | 1116 | case PEER_PARENT: |
1117 | return "parent"; | |
1118 | break; | |
1119 | case PEER_SIBLING: | |
1120 | return "sibling"; | |
1121 | break; | |
1122 | case PEER_MULTICAST: | |
1123 | return "multicast"; | |
1124 | break; | |
1125 | default: | |
1126 | return "unknown"; | |
1127 | break; | |
1128 | } | |
1129 | } | |
1130 | ||
f1dc9b30 | 1131 | static void |
a7d59104 | 1132 | dump_peer(StoreEntry * entry, const char *name, peer * p) |
98ffb7e4 | 1133 | { |
505e35db | 1134 | domain_ping *d; |
1135 | acl_access *a; | |
1136 | domain_type *t; | |
1137 | LOCAL_ARRAY(char, xname, 128); | |
d41de3c1 | 1138 | while (p != NULL) { |
1139 | storeAppendPrintf(entry, "%s %s %s %d %d", | |
1140 | name, | |
1141 | p->host, | |
1142 | neighborTypeStr(p), | |
1143 | p->http_port, | |
399cabec | 1144 | p->icp.port); |
a369131d | 1145 | dump_peer_options(entry, p); |
b6a2f15e | 1146 | for (d = p->peer_domain; d; d = d->next) { |
505e35db | 1147 | storeAppendPrintf(entry, "cache_peer_domain %s %s%s\n", |
1148 | p->host, | |
1149 | d->do_ping ? null_string : "!", | |
1150 | d->domain); | |
1151 | } | |
1152 | if ((a = p->access)) { | |
1153 | snprintf(xname, 128, "cache_peer_access %s", p->host); | |
1154 | dump_acl_access(entry, xname, p->access); | |
1155 | } | |
1156 | for (t = p->typelist; t; t = t->next) { | |
1157 | storeAppendPrintf(entry, "neighbor_type_domain %s %s %s\n", | |
1158 | p->host, | |
1159 | peer_type_str(t->type), | |
1160 | t->domain); | |
1161 | } | |
d41de3c1 | 1162 | p = p->next; |
1163 | } | |
98ffb7e4 | 1164 | } |
1165 | ||
8203a132 | 1166 | static void |
40a1495e | 1167 | parse_peer(peer ** head) |
7813c6d5 | 1168 | { |
270b86af | 1169 | char *token = NULL; |
40a1495e | 1170 | peer *p; |
7813c6d5 | 1171 | int i; |
28c60158 | 1172 | p = CBDATA_ALLOC(peer, peerDestroy); |
40a1495e | 1173 | p->http_port = CACHE_HTTP_PORT; |
399cabec | 1174 | p->icp.port = CACHE_ICP_PORT; |
40a1495e | 1175 | p->weight = 1; |
dc835977 | 1176 | p->stats.logged_state = PEER_ALIVE; |
e481c2dc | 1177 | if ((token = strtok(NULL, w_space)) == NULL) |
270b86af | 1178 | self_destruct(); |
40a1495e | 1179 | p->host = xstrdup(token); |
e481c2dc | 1180 | if ((token = strtok(NULL, w_space)) == NULL) |
270b86af | 1181 | self_destruct(); |
40a1495e | 1182 | p->type = parseNeighborType(token); |
0e4e0e7d | 1183 | i = GetInteger(); |
40a1495e | 1184 | p->http_port = (u_short) i; |
0e4e0e7d | 1185 | i = GetInteger(); |
399cabec | 1186 | p->icp.port = (u_short) i; |
270b86af | 1187 | while ((token = strtok(NULL, w_space))) { |
1188 | if (!strcasecmp(token, "proxy-only")) { | |
cd196bc8 | 1189 | p->options.proxy_only = 1; |
270b86af | 1190 | } else if (!strcasecmp(token, "no-query")) { |
cd196bc8 | 1191 | p->options.no_query = 1; |
8638fc66 | 1192 | } else if (!strcasecmp(token, "no-digest")) { |
cd196bc8 | 1193 | p->options.no_digest = 1; |
270b86af | 1194 | } else if (!strcasecmp(token, "multicast-responder")) { |
cd196bc8 | 1195 | p->options.mcast_responder = 1; |
270b86af | 1196 | } else if (!strncasecmp(token, "weight=", 7)) { |
40a1495e | 1197 | p->weight = atoi(token + 7); |
0103c4c1 | 1198 | } else if (!strcasecmp(token, "closest-only")) { |
cd196bc8 | 1199 | p->options.closest_only = 1; |
270b86af | 1200 | } else if (!strncasecmp(token, "ttl=", 4)) { |
40a1495e | 1201 | p->mcast.ttl = atoi(token + 4); |
1202 | if (p->mcast.ttl < 0) | |
1203 | p->mcast.ttl = 0; | |
1204 | if (p->mcast.ttl > 128) | |
1205 | p->mcast.ttl = 128; | |
0103c4c1 | 1206 | } else if (!strcasecmp(token, "default")) { |
cd196bc8 | 1207 | p->options.default_parent = 1; |
0103c4c1 | 1208 | } else if (!strcasecmp(token, "round-robin")) { |
cd196bc8 | 1209 | p->options.roundrobin = 1; |
dc9d133b | 1210 | #if USE_HTCP |
0103c4c1 | 1211 | } else if (!strcasecmp(token, "htcp")) { |
cd196bc8 | 1212 | p->options.htcp = 1; |
dc9d133b | 1213 | #endif |
0103c4c1 | 1214 | } else if (!strcasecmp(token, "no-netdb-exchange")) { |
cd196bc8 | 1215 | p->options.no_netdb_exchange = 1; |
afd88fbe | 1216 | #if USE_CARP |
1217 | } else if (!strncasecmp(token, "carp-load-factor=", 17)) { | |
1218 | if (p->type != PEER_PARENT) | |
0cdcddb9 | 1219 | debug(3, 0) ("parse_peer: Ignoring carp-load-factor for non-parent %s/%d\n", p->host, p->http_port); |
1220 | else | |
1221 | p->carp.load_factor = atof(token + 17); | |
95e36d02 | 1222 | #endif |
1223 | #if DELAY_POOLS | |
1224 | } else if (!strcasecmp(token, "no-delay")) { | |
cd196bc8 | 1225 | p->options.no_delay = 1; |
afd88fbe | 1226 | #endif |
c68e9c6b | 1227 | } else if (!strncasecmp(token, "login=", 6)) { |
1228 | p->login = xstrdup(token + 6); | |
3f62decd | 1229 | } else if (!strncasecmp(token, "connect-timeout=", 16)) { |
1230 | p->connect_timeout = atoi(token + 16); | |
7e3ce7b9 | 1231 | #if USE_CACHE_DIGESTS |
1232 | } else if (!strncasecmp(token, "digest-url=", 11)) { | |
1233 | p->digest_url = xstrdup(token + 11); | |
1234 | #endif | |
987de783 | 1235 | } else if (!strcasecmp(token, "allow-miss")) { |
1236 | p->options.allow_miss = 1; | |
c7f9eb6d | 1237 | } else if (!strcasecmp(token, "max-conn=")) { |
1238 | p->max_conn = atoi(token + 9); | |
270b86af | 1239 | } else { |
40a1495e | 1240 | debug(3, 0) ("parse_peer: token='%s'\n", token); |
270b86af | 1241 | self_destruct(); |
1242 | } | |
1243 | } | |
40a1495e | 1244 | if (p->weight < 1) |
1245 | p->weight = 1; | |
399cabec | 1246 | p->icp.version = ICP_VERSION_CURRENT; |
98829f69 | 1247 | p->tcp_up = PEER_TCP_MAGIC_COUNT; |
eb406bb7 | 1248 | p->test_fd = -1; |
afd88fbe | 1249 | #if USE_CARP |
8ee9b49f | 1250 | #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) |
afd88fbe | 1251 | if (p->carp.load_factor) { |
e13ee7ad | 1252 | /* calculate this peers hash for use in CARP */ |
0cdcddb9 | 1253 | p->carp.hash = 0; |
1254 | for (token = p->host; *token != 0; token++) | |
8ee9b49f | 1255 | p->carp.hash += ROTATE_LEFT(p->carp.hash, 19) + (unsigned int) *token; |
d20b1cd0 | 1256 | p->carp.hash += p->carp.hash * 0x62531965; |
8ee9b49f | 1257 | p->carp.hash = ROTATE_LEFT(p->carp.hash, 21); |
afd88fbe | 1258 | } |
1259 | #endif | |
e13ee7ad | 1260 | #if USE_CACHE_DIGESTS |
1261 | if (!p->options.no_digest) { | |
1262 | p->digest = peerDigestCreate(p); | |
8a6218c6 | 1263 | cbdataLock(p->digest); /* so we know when/if digest disappears */ |
1264 | } | |
e13ee7ad | 1265 | #endif |
0153d498 | 1266 | while (*head != NULL) |
1267 | head = &(*head)->next; | |
1268 | *head = p; | |
40a1495e | 1269 | Config.npeers++; |
82056f1e | 1270 | peerClearRR(p); |
0153d498 | 1271 | } |
1272 | ||
1273 | static void | |
40a1495e | 1274 | free_peer(peer ** P) |
0153d498 | 1275 | { |
40a1495e | 1276 | peer *p; |
79d39a72 | 1277 | while ((p = *P) != NULL) { |
a47b9029 | 1278 | *P = p->next; |
3855c318 | 1279 | #if USE_CACHE_DIGESTS |
1280 | if (p->digest) | |
1281 | cbdataUnlock(p->digest); | |
1282 | p->digest = NULL; | |
1283 | #endif | |
41042c81 | 1284 | cbdataFree(p); |
a47b9029 | 1285 | } |
987c67d1 | 1286 | Config.npeers = 0; |
270b86af | 1287 | } |
1288 | ||
1289 | static void | |
a7d59104 | 1290 | dump_cachemgrpasswd(StoreEntry * entry, const char *name, cachemgr_passwd * list) |
270b86af | 1291 | { |
d41de3c1 | 1292 | wordlist *w; |
1293 | while (list != NULL) { | |
74aa8456 | 1294 | if (strcmp(list->passwd, "none") && strcmp(list->passwd, "disable")) |
1295 | storeAppendPrintf(entry, "%s XXXXXXXXXX", name); | |
1296 | else | |
1297 | storeAppendPrintf(entry, "%s %s", name, list->passwd); | |
d41de3c1 | 1298 | for (w = list->actions; w != NULL; w = w->next) { |
1299 | storeAppendPrintf(entry, " %s", w->key); | |
1300 | } | |
1301 | storeAppendPrintf(entry, "\n"); | |
1302 | list = list->next; | |
1303 | } | |
270b86af | 1304 | } |
1305 | ||
1306 | static void | |
a47b9029 | 1307 | parse_cachemgrpasswd(cachemgr_passwd ** head) |
270b86af | 1308 | { |
1309 | char *passwd = NULL; | |
1310 | wordlist *actions = NULL; | |
22f3fd98 | 1311 | cachemgr_passwd *p; |
1312 | cachemgr_passwd **P; | |
270b86af | 1313 | parse_string(&passwd); |
1314 | parse_wordlist(&actions); | |
22f3fd98 | 1315 | p = xcalloc(1, sizeof(cachemgr_passwd)); |
1316 | p->passwd = passwd; | |
1317 | p->actions = actions; | |
1318 | for (P = head; *P; P = &(*P)->next); | |
1319 | *P = p; | |
270b86af | 1320 | } |
1321 | ||
1322 | static void | |
a47b9029 | 1323 | free_cachemgrpasswd(cachemgr_passwd ** head) |
270b86af | 1324 | { |
a47b9029 | 1325 | cachemgr_passwd *p; |
79d39a72 | 1326 | while ((p = *head) != NULL) { |
a47b9029 | 1327 | *head = p->next; |
1328 | xfree(p->passwd); | |
22f3fd98 | 1329 | wordlistDestroy(&p->actions); |
a47b9029 | 1330 | xfree(p); |
1331 | } | |
270b86af | 1332 | } |
1333 | ||
8203a132 | 1334 | static void |
16300b58 | 1335 | dump_denyinfo(StoreEntry * entry, const char *name, acl_deny_info_list * var) |
270b86af | 1336 | { |
d41de3c1 | 1337 | acl_name_list *a; |
1338 | while (var != NULL) { | |
02922e76 | 1339 | storeAppendPrintf(entry, "%s %s", name, var->err_page_name); |
d41de3c1 | 1340 | for (a = var->acl_list; a != NULL; a = a->next) |
1341 | storeAppendPrintf(entry, " %s", a->name); | |
1342 | storeAppendPrintf(entry, "\n"); | |
1343 | var = var->next; | |
1344 | } | |
270b86af | 1345 | } |
1346 | ||
1347 | static void | |
16300b58 | 1348 | parse_denyinfo(acl_deny_info_list ** var) |
6e40f263 | 1349 | { |
f1dc9b30 | 1350 | aclParseDenyInfoLine(var); |
6e40f263 | 1351 | } |
403279e0 | 1352 | |
1273d501 | 1353 | void |
a47b9029 | 1354 | free_denyinfo(acl_deny_info_list ** list) |
3c5557f9 | 1355 | { |
56b63fa1 | 1356 | acl_deny_info_list *a = NULL; |
1357 | acl_deny_info_list *a_next = NULL; | |
1358 | acl_name_list *l = NULL; | |
1359 | acl_name_list *l_next = NULL; | |
1273d501 | 1360 | for (a = *list; a; a = a_next) { |
a47b9029 | 1361 | for (l = a->acl_list; l; l = l_next) { |
1362 | l_next = l->next; | |
3314e65b | 1363 | memFree(l, MEM_ACL_NAME_LIST); |
eeda4c4d | 1364 | l = NULL; |
a47b9029 | 1365 | } |
1366 | a_next = a->next; | |
eeda4c4d | 1367 | memFree(a, MEM_ACL_DENY_INFO_LIST); |
1368 | a = NULL; | |
1273d501 | 1369 | } |
1370 | *list = NULL; | |
270b86af | 1371 | } |
1372 | ||
1373 | static void | |
505e35db | 1374 | parse_peer_access(void) |
270b86af | 1375 | { |
1376 | char *host = NULL; | |
505e35db | 1377 | peer *p; |
270b86af | 1378 | if (!(host = strtok(NULL, w_space))) |
1379 | self_destruct(); | |
0cdcddb9 | 1380 | if ((p = peerFindByName(host)) == NULL) { |
1381 | debug(15, 0) ("%s, line %d: No cache_peer '%s'\n", | |
1382 | cfg_filename, config_lineno, host); | |
1383 | return; | |
1384 | } | |
505e35db | 1385 | aclParseAccessLine(&p->access); |
270b86af | 1386 | } |
1387 | ||
270b86af | 1388 | static void |
1389 | parse_hostdomain(void) | |
1390 | { | |
1391 | char *host = NULL; | |
1392 | char *domain = NULL; | |
1393 | if (!(host = strtok(NULL, w_space))) | |
1394 | self_destruct(); | |
f1dc9b30 | 1395 | while ((domain = strtok(NULL, list_sep))) { |
1396 | domain_ping *l = NULL; | |
1397 | domain_ping **L = NULL; | |
40a1495e | 1398 | peer *p; |
1399 | if ((p = peerFindByName(host)) == NULL) { | |
43c3424b | 1400 | debug(15, 0) ("%s, line %d: No cache_peer '%s'\n", |
f1dc9b30 | 1401 | cfg_filename, config_lineno, host); |
1402 | continue; | |
1403 | } | |
56b63fa1 | 1404 | l = xcalloc(1, sizeof(domain_ping)); |
f1dc9b30 | 1405 | l->do_ping = 1; |
1406 | if (*domain == '!') { /* check for !.edu */ | |
1407 | l->do_ping = 0; | |
1408 | domain++; | |
1409 | } | |
1410 | l->domain = xstrdup(domain); | |
b6a2f15e | 1411 | for (L = &(p->peer_domain); *L; L = &((*L)->next)); |
f1dc9b30 | 1412 | *L = l; |
1413 | } | |
270b86af | 1414 | } |
1415 | ||
1416 | static void | |
1417 | parse_hostdomaintype(void) | |
1418 | { | |
1419 | char *host = NULL; | |
1420 | char *type = NULL; | |
1421 | char *domain = NULL; | |
1422 | if (!(host = strtok(NULL, w_space))) | |
1423 | self_destruct(); | |
1424 | if (!(type = strtok(NULL, w_space))) | |
1425 | self_destruct(); | |
f1dc9b30 | 1426 | while ((domain = strtok(NULL, list_sep))) { |
1427 | domain_type *l = NULL; | |
1428 | domain_type **L = NULL; | |
40a1495e | 1429 | peer *p; |
1430 | if ((p = peerFindByName(host)) == NULL) { | |
43c3424b | 1431 | debug(15, 0) ("%s, line %d: No cache_peer '%s'\n", |
f1dc9b30 | 1432 | cfg_filename, config_lineno, host); |
1433 | return; | |
1434 | } | |
56b63fa1 | 1435 | l = xcalloc(1, sizeof(domain_type)); |
f1dc9b30 | 1436 | l->type = parseNeighborType(type); |
1437 | l->domain = xstrdup(domain); | |
1438 | for (L = &(p->typelist); *L; L = &((*L)->next)); | |
1439 | *L = l; | |
1440 | } | |
270b86af | 1441 | } |
1442 | ||
7e3ce7b9 | 1443 | #if UNUSED_CODE |
270b86af | 1444 | static void |
a7d59104 | 1445 | dump_ushortlist(StoreEntry * entry, const char *name, ushortlist * u) |
090089c4 | 1446 | { |
270b86af | 1447 | while (u) { |
f53b06f9 | 1448 | storeAppendPrintf(entry, "%s %d\n", name, (int) u->i); |
270b86af | 1449 | u = u->next; |
1450 | } | |
1451 | } | |
090089c4 | 1452 | |
f53b06f9 | 1453 | static int |
1454 | check_null_ushortlist(ushortlist * u) | |
1455 | { | |
1456 | return u == NULL; | |
1457 | } | |
1458 | ||
270b86af | 1459 | static void |
1460 | parse_ushortlist(ushortlist ** P) | |
1461 | { | |
1462 | char *token; | |
1463 | int i; | |
1464 | ushortlist *u; | |
1465 | ushortlist **U; | |
1466 | while ((token = strtok(NULL, w_space))) { | |
1467 | if (sscanf(token, "%d", &i) != 1) | |
1468 | self_destruct(); | |
1469 | if (i < 0) | |
1470 | i = 0; | |
1471 | u = xcalloc(1, sizeof(ushortlist)); | |
1472 | u->i = (u_short) i; | |
1473 | for (U = P; *U; U = &(*U)->next); | |
1474 | *U = u; | |
090089c4 | 1475 | } |
270b86af | 1476 | } |
090089c4 | 1477 | |
0153d498 | 1478 | static void |
a47b9029 | 1479 | free_ushortlist(ushortlist ** P) |
0153d498 | 1480 | { |
a47b9029 | 1481 | ushortlist *u; |
79d39a72 | 1482 | while ((u = *P) != NULL) { |
a47b9029 | 1483 | *P = u->next; |
1484 | xfree(u); | |
1485 | } | |
0153d498 | 1486 | } |
7e3ce7b9 | 1487 | #endif |
0153d498 | 1488 | |
270b86af | 1489 | static void |
a7d59104 | 1490 | dump_int(StoreEntry * entry, const char *name, int var) |
270b86af | 1491 | { |
f53b06f9 | 1492 | storeAppendPrintf(entry, "%s %d\n", name, var); |
270b86af | 1493 | } |
c1c29eb6 | 1494 | |
94439e4e | 1495 | void |
270b86af | 1496 | parse_int(int *var) |
1497 | { | |
270b86af | 1498 | int i; |
0e4e0e7d | 1499 | i = GetInteger(); |
270b86af | 1500 | *var = i; |
1501 | } | |
090089c4 | 1502 | |
0153d498 | 1503 | static void |
1504 | free_int(int *var) | |
1505 | { | |
a47b9029 | 1506 | *var = 0; |
0153d498 | 1507 | } |
1508 | ||
270b86af | 1509 | static void |
a7d59104 | 1510 | dump_onoff(StoreEntry * entry, const char *name, int var) |
270b86af | 1511 | { |
f53b06f9 | 1512 | storeAppendPrintf(entry, "%s %s\n", name, var ? "on" : "off"); |
270b86af | 1513 | } |
090089c4 | 1514 | |
270b86af | 1515 | static void |
1516 | parse_onoff(int *var) | |
1517 | { | |
1518 | char *token = strtok(NULL, w_space); | |
090089c4 | 1519 | |
270b86af | 1520 | if (token == NULL) |
1521 | self_destruct(); | |
1522 | if (!strcasecmp(token, "on") || !strcasecmp(token, "enable")) | |
1523 | *var = 1; | |
1524 | else | |
1525 | *var = 0; | |
1526 | } | |
e90100aa | 1527 | |
0153d498 | 1528 | #define free_onoff free_int |
f1dc9b30 | 1529 | #define dump_eol dump_string |
1530 | #define free_eol free_string | |
30a4f2a8 | 1531 | |
270b86af | 1532 | static void |
a7d59104 | 1533 | dump_refreshpattern(StoreEntry * entry, const char *name, refresh_t * head) |
270b86af | 1534 | { |
d41de3c1 | 1535 | while (head != NULL) { |
9f60cfdf | 1536 | storeAppendPrintf(entry, "%s%s %s %d %d%% %d\n", |
c3f6d204 | 1537 | name, |
1538 | head->flags.icase ? " -i" : null_string, | |
1539 | head->pattern, | |
1540 | (int) head->min / 60, | |
1541 | (int) (100.0 * head->pct + 0.5), | |
9f60cfdf | 1542 | (int) head->max / 60); |
1543 | #if HTTP_VIOLATIONS | |
1544 | if (head->flags.override_expire) | |
1545 | storeAppendPrintf(entry, " override-expire"); | |
1546 | if (head->flags.override_lastmod) | |
1547 | storeAppendPrintf(entry, " override-lastmod"); | |
1548 | if (head->flags.reload_into_ims) | |
1549 | storeAppendPrintf(entry, " reload-into-ims"); | |
1550 | if (head->flags.ignore_reload) | |
1551 | storeAppendPrintf(entry, " ignore-reload"); | |
1552 | #endif | |
1553 | storeAppendPrintf(entry, "\n"); | |
d41de3c1 | 1554 | head = head->next; |
1555 | } | |
270b86af | 1556 | } |
090089c4 | 1557 | |
270b86af | 1558 | static void |
f1dc9b30 | 1559 | parse_refreshpattern(refresh_t ** head) |
270b86af | 1560 | { |
f1dc9b30 | 1561 | char *token; |
1562 | char *pattern; | |
1563 | time_t min = 0; | |
c3f6d204 | 1564 | double pct = 0.0; |
f1dc9b30 | 1565 | time_t max = 0; |
9f60cfdf | 1566 | #if HTTP_VIOLATIONS |
1dfa1d81 | 1567 | int override_expire = 0; |
1568 | int override_lastmod = 0; | |
cbe3a719 | 1569 | int reload_into_ims = 0; |
1570 | int ignore_reload = 0; | |
9f60cfdf | 1571 | #endif |
f1dc9b30 | 1572 | int i; |
1573 | refresh_t *t; | |
1574 | regex_t comp; | |
1575 | int errcode; | |
1576 | int flags = REG_EXTENDED | REG_NOSUB; | |
1577 | if ((token = strtok(NULL, w_space)) == NULL) | |
1578 | self_destruct(); | |
1579 | if (strcmp(token, "-i") == 0) { | |
1580 | flags |= REG_ICASE; | |
1581 | token = strtok(NULL, w_space); | |
1582 | } else if (strcmp(token, "+i") == 0) { | |
1583 | flags &= ~REG_ICASE; | |
1584 | token = strtok(NULL, w_space); | |
1585 | } | |
1586 | if (token == NULL) | |
1587 | self_destruct(); | |
1588 | pattern = xstrdup(token); | |
0e4e0e7d | 1589 | i = GetInteger(); /* token: min */ |
f1dc9b30 | 1590 | min = (time_t) (i * 60); /* convert minutes to seconds */ |
0e4e0e7d | 1591 | i = GetInteger(); /* token: pct */ |
c3f6d204 | 1592 | pct = (double) i / 100.0; |
0e4e0e7d | 1593 | i = GetInteger(); /* token: max */ |
f1dc9b30 | 1594 | max = (time_t) (i * 60); /* convert minutes to seconds */ |
1dfa1d81 | 1595 | /* Options */ |
1596 | while ((token = strtok(NULL, w_space)) != NULL) { | |
9f60cfdf | 1597 | #if HTTP_VIOLATIONS |
1dfa1d81 | 1598 | if (!strcmp(token, "override-expire")) |
1599 | override_expire = 1; | |
255d6021 | 1600 | else if (!strcmp(token, "override-lastmod")) |
1dfa1d81 | 1601 | override_lastmod = 1; |
cbe3a719 | 1602 | else if (!strcmp(token, "reload-into-ims")) { |
1603 | reload_into_ims = 1; | |
1604 | refresh_nocache_hack = 1; | |
1605 | /* tell client_side.c that this is used */ | |
1606 | } else if (!strcmp(token, "ignore-reload")) { | |
1607 | ignore_reload = 1; | |
1608 | refresh_nocache_hack = 1; | |
1609 | /* tell client_side.c that this is used */ | |
1610 | } else | |
9f60cfdf | 1611 | #endif |
cbe3a719 | 1612 | debug(22, 0) ("redreshAddToList: Unknown option '%s': %s\n", |
1dfa1d81 | 1613 | pattern, token); |
1614 | } | |
f1dc9b30 | 1615 | if ((errcode = regcomp(&comp, pattern, flags)) != 0) { |
1616 | char errbuf[256]; | |
1617 | regerror(errcode, &comp, errbuf, sizeof errbuf); | |
1618 | debug(22, 0) ("%s line %d: %s\n", | |
1619 | cfg_filename, config_lineno, config_input_line); | |
1620 | debug(22, 0) ("refreshAddToList: Invalid regular expression '%s': %s\n", | |
1621 | pattern, errbuf); | |
1622 | return; | |
1623 | } | |
c3f6d204 | 1624 | pct = pct < 0.0 ? 0.0 : pct; |
f1dc9b30 | 1625 | max = max < 0 ? 0 : max; |
1626 | t = xcalloc(1, sizeof(refresh_t)); | |
1627 | t->pattern = (char *) xstrdup(pattern); | |
1628 | t->compiled_pattern = comp; | |
1629 | t->min = min; | |
c3f6d204 | 1630 | t->pct = pct; |
f1dc9b30 | 1631 | t->max = max; |
c3f6d204 | 1632 | if (flags & REG_ICASE) |
1633 | t->flags.icase = 1; | |
9f60cfdf | 1634 | #if HTTP_VIOLATIONS |
1dfa1d81 | 1635 | if (override_expire) |
1636 | t->flags.override_expire = 1; | |
1637 | if (override_lastmod) | |
1638 | t->flags.override_lastmod = 1; | |
cbe3a719 | 1639 | if (reload_into_ims) |
1640 | t->flags.reload_into_ims = 1; | |
1641 | if (ignore_reload) | |
1642 | t->flags.ignore_reload = 1; | |
9f60cfdf | 1643 | #endif |
f1dc9b30 | 1644 | t->next = NULL; |
1645 | while (*head) | |
1646 | head = &(*head)->next; | |
1647 | *head = t; | |
1648 | safe_free(pattern); | |
270b86af | 1649 | } |
090089c4 | 1650 | |
6b53c392 | 1651 | static int |
a4b8110e | 1652 | check_null_refreshpattern(refresh_t * data) |
6b53c392 | 1653 | { |
1654 | return data != NULL; | |
1655 | } | |
1656 | ||
270b86af | 1657 | static void |
a47b9029 | 1658 | free_refreshpattern(refresh_t ** head) |
270b86af | 1659 | { |
f1dc9b30 | 1660 | refresh_t *t; |
79d39a72 | 1661 | while ((t = *head) != NULL) { |
f1dc9b30 | 1662 | *head = t->next; |
1663 | safe_free(t->pattern); | |
1664 | regfree(&t->compiled_pattern); | |
1665 | safe_free(t); | |
1666 | } | |
270b86af | 1667 | } |
12b9e9b1 | 1668 | |
270b86af | 1669 | static void |
a7d59104 | 1670 | dump_string(StoreEntry * entry, const char *name, char *var) |
270b86af | 1671 | { |
f53b06f9 | 1672 | if (var != NULL) |
a7d59104 | 1673 | storeAppendPrintf(entry, "%s %s\n", name, var); |
270b86af | 1674 | } |
98ffb7e4 | 1675 | |
270b86af | 1676 | static void |
0153d498 | 1677 | parse_string(char **var) |
270b86af | 1678 | { |
1679 | char *token = strtok(NULL, w_space); | |
270b86af | 1680 | safe_free(*var); |
1681 | if (token == NULL) | |
1682 | self_destruct(); | |
1683 | *var = xstrdup(token); | |
1684 | } | |
b15e6857 | 1685 | |
0153d498 | 1686 | static void |
1687 | free_string(char **var) | |
1688 | { | |
027acbaf | 1689 | safe_free(*var); |
0153d498 | 1690 | } |
caebbe00 | 1691 | |
94439e4e | 1692 | void |
f1dc9b30 | 1693 | parse_eol(char *volatile *var) |
270b86af | 1694 | { |
1695 | char *token = strtok(NULL, null_string); | |
270b86af | 1696 | safe_free(*var); |
f1dc9b30 | 1697 | if (token == NULL) |
1698 | self_destruct(); | |
270b86af | 1699 | *var = xstrdup(token); |
1700 | } | |
090089c4 | 1701 | |
270b86af | 1702 | static void |
a7d59104 | 1703 | dump_time_t(StoreEntry * entry, const char *name, time_t var) |
090089c4 | 1704 | { |
f53b06f9 | 1705 | storeAppendPrintf(entry, "%s %d seconds\n", name, (int) var); |
090089c4 | 1706 | } |
1707 | ||
94439e4e | 1708 | void |
a47b9029 | 1709 | parse_time_t(time_t * var) |
0ffd22bc | 1710 | { |
f1dc9b30 | 1711 | parseTimeLine(var, T_SECOND_STR); |
0ffd22bc | 1712 | } |
1713 | ||
270b86af | 1714 | static void |
a47b9029 | 1715 | free_time_t(time_t * var) |
270b86af | 1716 | { |
a47b9029 | 1717 | *var = 0; |
270b86af | 1718 | } |
9906e724 | 1719 | |
1720 | static void | |
a7d59104 | 1721 | dump_size_t(StoreEntry * entry, const char *name, size_t var) |
1b635117 | 1722 | { |
f53b06f9 | 1723 | storeAppendPrintf(entry, "%s %d\n", name, (int) var); |
1b635117 | 1724 | } |
1725 | ||
1726 | static void | |
a7d59104 | 1727 | dump_b_size_t(StoreEntry * entry, const char *name, size_t var) |
9906e724 | 1728 | { |
f53b06f9 | 1729 | storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_BYTES_STR); |
9906e724 | 1730 | } |
1731 | ||
1732 | static void | |
a7d59104 | 1733 | dump_kb_size_t(StoreEntry * entry, const char *name, size_t var) |
9906e724 | 1734 | { |
f53b06f9 | 1735 | storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_KBYTES_STR); |
9906e724 | 1736 | } |
1737 | ||
1738 | static void | |
a47b9029 | 1739 | parse_size_t(size_t * var) |
1b635117 | 1740 | { |
1b635117 | 1741 | int i; |
0e4e0e7d | 1742 | i = GetInteger(); |
1b635117 | 1743 | *var = (size_t) i; |
1744 | } | |
1745 | ||
1746 | static void | |
1747 | parse_b_size_t(size_t * var) | |
9906e724 | 1748 | { |
1749 | parseBytesLine(var, B_BYTES_STR); | |
1750 | } | |
1751 | ||
1752 | static void | |
a47b9029 | 1753 | parse_kb_size_t(size_t * var) |
9906e724 | 1754 | { |
1755 | parseBytesLine(var, B_KBYTES_STR); | |
1756 | } | |
1757 | ||
1758 | static void | |
a47b9029 | 1759 | free_size_t(size_t * var) |
9906e724 | 1760 | { |
a47b9029 | 1761 | *var = 0; |
9906e724 | 1762 | } |
1763 | ||
1b635117 | 1764 | #define free_b_size_t free_size_t |
9906e724 | 1765 | #define free_kb_size_t free_size_t |
1766 | #define free_mb_size_t free_size_t | |
1767 | #define free_gb_size_t free_size_t | |
090089c4 | 1768 | |
8203a132 | 1769 | static void |
a7d59104 | 1770 | dump_ushort(StoreEntry * entry, const char *name, u_short var) |
090089c4 | 1771 | { |
f53b06f9 | 1772 | storeAppendPrintf(entry, "%s %d\n", name, var); |
270b86af | 1773 | } |
090089c4 | 1774 | |
0153d498 | 1775 | static void |
a47b9029 | 1776 | free_ushort(u_short * u) |
0153d498 | 1777 | { |
1778 | *u = 0; | |
1779 | } | |
1780 | ||
270b86af | 1781 | static void |
1782 | parse_ushort(u_short * var) | |
1783 | { | |
270b86af | 1784 | int i; |
090089c4 | 1785 | |
0e4e0e7d | 1786 | i = GetInteger(); |
270b86af | 1787 | if (i < 0) |
1788 | i = 0; | |
1789 | *var = (u_short) i; | |
090089c4 | 1790 | } |
1791 | ||
270b86af | 1792 | static void |
a7d59104 | 1793 | dump_wordlist(StoreEntry * entry, const char *name, wordlist * list) |
270b86af | 1794 | { |
270b86af | 1795 | while (list != NULL) { |
f53b06f9 | 1796 | storeAppendPrintf(entry, "%s %s\n", name, list->key); |
270b86af | 1797 | list = list->next; |
429fdbec | 1798 | } |
429fdbec | 1799 | } |
1800 | ||
94439e4e | 1801 | void |
270b86af | 1802 | parse_wordlist(wordlist ** list) |
429fdbec | 1803 | { |
270b86af | 1804 | char *token; |
270b86af | 1805 | while ((token = strtok(NULL, w_space))) |
1806 | wordlistAdd(list, token); | |
429fdbec | 1807 | } |
270b86af | 1808 | |
f8d9f54a | 1809 | static int |
5da06f20 | 1810 | check_null_wordlist(wordlist * w) |
f8d9f54a | 1811 | { |
1812 | return w == NULL; | |
1813 | } | |
1814 | ||
63e9d884 | 1815 | static int |
c6d5b87b | 1816 | check_null_acl_access(acl_access * a) |
63e9d884 | 1817 | { |
1818 | return a == NULL; | |
1819 | } | |
1820 | ||
0153d498 | 1821 | #define free_wordlist wordlistDestroy |
270b86af | 1822 | |
d548ee64 | 1823 | #define free_uri_whitespace free_int |
1824 | ||
1825 | static void | |
1826 | parse_uri_whitespace(int *var) | |
1827 | { | |
1828 | char *token = strtok(NULL, w_space); | |
1829 | if (token == NULL) | |
1830 | self_destruct(); | |
7e3ce7b9 | 1831 | if (!strcasecmp(token, "strip")) |
1832 | *var = URI_WHITESPACE_STRIP; | |
1833 | else if (!strcasecmp(token, "deny")) | |
d548ee64 | 1834 | *var = URI_WHITESPACE_DENY; |
1835 | else if (!strcasecmp(token, "allow")) | |
1836 | *var = URI_WHITESPACE_ALLOW; | |
1837 | else if (!strcasecmp(token, "encode")) | |
1838 | *var = URI_WHITESPACE_ENCODE; | |
1839 | else if (!strcasecmp(token, "chop")) | |
1840 | *var = URI_WHITESPACE_CHOP; | |
1841 | else | |
1842 | self_destruct(); | |
1843 | } | |
1844 | ||
1845 | ||
1846 | static void | |
1847 | dump_uri_whitespace(StoreEntry * entry, const char *name, int var) | |
1848 | { | |
1849 | char *s; | |
1850 | if (var == URI_WHITESPACE_ALLOW) | |
1851 | s = "allow"; | |
1852 | else if (var == URI_WHITESPACE_ENCODE) | |
1853 | s = "encode"; | |
1854 | else if (var == URI_WHITESPACE_CHOP) | |
1855 | s = "chop"; | |
7e3ce7b9 | 1856 | else if (var == URI_WHITESPACE_DENY) |
d548ee64 | 1857 | s = "deny"; |
7e3ce7b9 | 1858 | else |
1859 | s = "strip"; | |
d548ee64 | 1860 | storeAppendPrintf(entry, "%s %s\n", name, s); |
1861 | } | |
1862 | ||
6a566b9c | 1863 | static void |
c1dd71ae | 1864 | free_removalpolicy(RemovalPolicySettings ** settings) |
6a566b9c | 1865 | { |
1866 | if (!*settings) | |
1867 | return; | |
1868 | free_string(&(*settings)->type); | |
1869 | free_wordlist(&(*settings)->args); | |
1870 | xfree(*settings); | |
1871 | *settings = NULL; | |
1872 | } | |
1873 | ||
1874 | static void | |
c1dd71ae | 1875 | parse_removalpolicy(RemovalPolicySettings ** settings) |
6a566b9c | 1876 | { |
1877 | if (*settings) | |
1878 | free_removalpolicy(settings); | |
1879 | *settings = xcalloc(1, sizeof(**settings)); | |
1880 | parse_string(&(*settings)->type); | |
1881 | parse_wordlist(&(*settings)->args); | |
1882 | } | |
1883 | ||
1884 | static void | |
c1dd71ae | 1885 | dump_removalpolicy(StoreEntry * entry, const char *name, RemovalPolicySettings * settings) |
6a566b9c | 1886 | { |
1887 | wordlist *args; | |
1888 | storeAppendPrintf(entry, "%s %s", name, settings->type); | |
1889 | args = settings->args; | |
1890 | while (args) { | |
1891 | storeAppendPrintf(entry, " %s", args->key); | |
1892 | args = args->next; | |
1893 | } | |
be58afb5 | 1894 | storeAppendPrintf(entry, "\n"); |
6a566b9c | 1895 | } |
c1dd71ae | 1896 | |
6a566b9c | 1897 | |
270b86af | 1898 | #include "cf_parser.c" |
f1dc9b30 | 1899 | |
1900 | peer_t | |
1901 | parseNeighborType(const char *s) | |
1902 | { | |
1903 | if (!strcasecmp(s, "parent")) | |
1904 | return PEER_PARENT; | |
1905 | if (!strcasecmp(s, "neighbor")) | |
1906 | return PEER_SIBLING; | |
1907 | if (!strcasecmp(s, "neighbour")) | |
1908 | return PEER_SIBLING; | |
1909 | if (!strcasecmp(s, "sibling")) | |
1910 | return PEER_SIBLING; | |
1911 | if (!strcasecmp(s, "multicast")) | |
1912 | return PEER_MULTICAST; | |
1913 | debug(15, 0) ("WARNING: Unknown neighbor type: %s\n", s); | |
1914 | return PEER_SIBLING; | |
1915 | } | |
f150dd4b | 1916 | |
7e3ce7b9 | 1917 | static void |
1918 | parse_sockaddr_in_list(sockaddr_in_list ** head) | |
1919 | { | |
1920 | char *token; | |
1921 | char *t; | |
efd900cb | 1922 | char *host; |
7e3ce7b9 | 1923 | const struct hostent *hp; |
efd900cb | 1924 | unsigned short port; |
7e3ce7b9 | 1925 | sockaddr_in_list *s; |
1926 | while ((token = strtok(NULL, w_space))) { | |
efd900cb | 1927 | host = NULL; |
1928 | port = 0; | |
7e3ce7b9 | 1929 | if ((t = strchr(token, ':'))) { |
1930 | /* host:port */ | |
1931 | host = token; | |
1932 | *t = '\0'; | |
efd900cb | 1933 | port = (unsigned short) atoi(t + 1); |
1934 | if (0 == port) | |
7e3ce7b9 | 1935 | self_destruct(); |
efd900cb | 1936 | } else if ((port = atoi(token)) > 0) { |
7e3ce7b9 | 1937 | /* port */ |
1938 | } else { | |
1939 | self_destruct(); | |
1940 | } | |
1941 | s = xcalloc(1, sizeof(*s)); | |
efd900cb | 1942 | s->s.sin_port = htons(port); |
7e3ce7b9 | 1943 | if (NULL == host) |
1944 | s->s.sin_addr = any_addr; | |
1945 | else if (1 == safe_inet_addr(host, &s->s.sin_addr)) | |
1946 | (void) 0; | |
efd900cb | 1947 | else if ((hp = gethostbyname(host))) /* dont use ipcache */ |
7e3ce7b9 | 1948 | s->s.sin_addr = inaddrFromHostent(hp); |
1949 | else | |
1950 | self_destruct(); | |
1951 | while (*head) | |
1952 | head = &(*head)->next; | |
1953 | *head = s; | |
1954 | } | |
1955 | } | |
1956 | ||
1957 | static void | |
1958 | dump_sockaddr_in_list(StoreEntry * e, const char *n, const sockaddr_in_list * s) | |
1959 | { | |
1960 | while (s) { | |
1961 | storeAppendPrintf(e, "%s %s:%d\n", | |
1962 | n, | |
1963 | inet_ntoa(s->s.sin_addr), | |
1964 | ntohs(s->s.sin_port)); | |
1965 | s = s->next; | |
1966 | } | |
1967 | } | |
1968 | ||
1969 | static void | |
1970 | free_sockaddr_in_list(sockaddr_in_list ** head) | |
1971 | { | |
1972 | sockaddr_in_list *s; | |
1973 | while ((s = *head) != NULL) { | |
1974 | *head = s->next; | |
1975 | xfree(s); | |
1976 | } | |
1977 | } | |
1978 | ||
1979 | static int | |
1980 | check_null_sockaddr_in_list(const sockaddr_in_list * s) | |
1981 | { | |
1982 | return NULL == s; | |
1983 | } | |
1984 | ||
f150dd4b | 1985 | void |
1986 | configFreeMemory(void) | |
1987 | { | |
23ff6968 | 1988 | free_all(); |
f150dd4b | 1989 | } |
f0b19334 | 1990 | |
94439e4e | 1991 | void |
f0b19334 | 1992 | requirePathnameExists(const char *name, const char *path) |
1993 | { | |
1994 | struct stat sb; | |
f0b19334 | 1995 | assert(path != NULL); |
137ee196 | 1996 | if (stat(path, &sb) < 0) |
1997 | fatalf("%s: %s", path, xstrerror()); | |
f0b19334 | 1998 | } |