]> git.ipfire.org Git - thirdparty/squid.git/blame - src/cache_cf.cc
remove squid.conf.pre.in
[thirdparty/squid.git] / src / cache_cf.cc
CommitLineData
30a4f2a8 1/*
88738790 2 * $Id: cache_cf.cc,v 1.210 1997/07/16 20:31:57 wessels Exp $
30a4f2a8 3 *
4 * DEBUG: section 3 Configuration File Parsing
5 * AUTHOR: Harvest Derived
6 *
42c04c16 7 * SQUID Internet Object Cache http://squid.nlanr.net/Squid/
30a4f2a8 8 * --------------------------------------------------------
9 *
10 * Squid is the result of efforts by numerous individuals from the
11 * Internet community. Development is led by Duane Wessels of the
12 * National Laboratory for Applied Network Research and funded by
13 * the National Science Foundation.
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 *
29 */
cf5fd929 30
44a47c6e 31#include "squid.h"
090089c4 32
8813e606 33static const char *const T_SECOND_STR = "second";
34static const char *const T_MINUTE_STR = "minute";
35static const char *const T_HOUR_STR = "hour";
36static const char *const T_DAY_STR = "day";
37static const char *const T_WEEK_STR = "week";
38static const char *const T_FORTNIGHT_STR = "fortnight";
39static const char *const T_MONTH_STR = "month";
40static const char *const T_YEAR_STR = "year";
41static const char *const T_DECADE_STR = "decade";
aa0a0c7c 42
9906e724 43static const char *const B_BYTES_STR = "bytes";
44static const char *const B_KBYTES_STR = "KB";
45static const char *const B_MBYTES_STR = "MB";
46static const char *const B_GBYTES_STR = "GB";
47
4db43fab 48static const char *const list_sep = ", \t\n\r";
090089c4 49
24382924 50static char fatal_str[BUFSIZ];
24382924 51static void self_destruct _PARAMS((void));
0ee4272b 52static void wordlistAdd _PARAMS((wordlist **, const char *));
caebbe00 53
67508012 54static void configDoConfigure _PARAMS((void));
f1dc9b30 55static void parse_refreshpattern _PARAMS((refresh_t **));
429fdbec 56static int parseTimeUnits _PARAMS((const char *unit));
a47b9029 57static void parseTimeLine _PARAMS((time_t * tptr, const char *units));
270b86af 58static void parse_string _PARAMS((char **));
59static void parse_wordlist _PARAMS((wordlist **));
270b86af 60static void default_all _PARAMS((void));
0153d498 61static int parse_line _PARAMS((char *));
a47b9029 62static void parseBytesLine _PARAMS((size_t * bptr, const char *units));
9906e724 63static size_t parseBytesUnits _PARAMS((const char *unit));
0153d498 64
65/* These come from cf_gen.c */
66static void default_all _PARAMS((void));
0153d498 67static void free_all _PARAMS((void));
270b86af 68
24382924 69static void
0673c0ba 70self_destruct(void)
090089c4 71{
b8de7ebe 72 sprintf(fatal_str, "Bungled %s line %d: %s",
73 cfg_filename, config_lineno, config_input_line);
090089c4 74 fatal(fatal_str);
75}
76
8203a132 77void
78wordlistDestroy(wordlist ** list)
0ffd22bc 79{
80 wordlist *w = NULL;
b5639035 81 while ((w = *list)) {
82 *list = w->next;
0ffd22bc 83 safe_free(w->key);
84 safe_free(w);
85 }
86 *list = NULL;
87}
88
24382924 89static void
fe4e214f 90wordlistAdd(wordlist ** list, const char *key)
090089c4 91{
0ffd22bc 92 wordlist *p = NULL;
93 wordlist *q = NULL;
090089c4 94
95 if (!(*list)) {
96 /* empty list */
30a4f2a8 97 *list = xcalloc(1, sizeof(wordlist));
090089c4 98 (*list)->key = xstrdup(key);
99 (*list)->next = NULL;
100 } else {
101 p = *list;
102 while (p->next)
103 p = p->next;
30a4f2a8 104 q = xcalloc(1, sizeof(wordlist));
090089c4 105 q->key = xstrdup(key);
106 q->next = NULL;
107 p->next = q;
108 }
109}
110
8203a132 111void
112intlistDestroy(intlist ** list)
92a6f4b1 113{
114 intlist *w = NULL;
115 intlist *n = NULL;
116
117 for (w = *list; w; w = n) {
118 n = w->next;
119 safe_free(w);
120 }
121 *list = NULL;
122}
123
403279e0 124
3c5557f9 125/*
126 * Use this #define in all the parse*() functions. Assumes char *token is
127 * defined
128 */
090089c4 129
130#define GetInteger(var) \
131 token = strtok(NULL, w_space); \
30a4f2a8 132 if( token == NULL) \
3003c0f3 133 self_destruct(); \
090089c4 134 if (sscanf(token, "%d", &var) != 1) \
3003c0f3 135 self_destruct();
090089c4 136
270b86af 137int
138parseConfigFile(const char *file_name)
2546fcb3 139{
270b86af 140 FILE *fp = NULL;
141 char *token = NULL;
72121e8b 142 char *tmp_line;
0153d498 143 free_all();
144 default_all();
270b86af 145 if ((fp = fopen(file_name, "r")) == NULL) {
146 sprintf(fatal_str, "Unable to open configuration file: %s: %s",
147 file_name, xstrerror());
148 fatal(fatal_str);
149 }
150 cfg_filename = file_name;
151 if ((token = strrchr(cfg_filename, '/')))
152 cfg_filename = token + 1;
153 memset(config_input_line, '\0', BUFSIZ);
154 config_lineno = 0;
155 while (fgets(config_input_line, BUFSIZ, fp)) {
156 config_lineno++;
157 if ((token = strchr(config_input_line, '\n')))
158 *token = '\0';
159 if (config_input_line[0] == '#')
160 continue;
161 if (config_input_line[0] == '\0')
162 continue;
163 debug(3, 5) ("Processing: '%s'\n", config_input_line);
72121e8b 164 tmp_line = xstrdup(config_input_line);
270b86af 165 if (!parse_line(tmp_line)) {
166 debug(3, 0) ("parseConfigFile: line %d unrecognized: '%s'\n",
167 config_lineno,
168 config_input_line);
169 }
72121e8b 170 safe_free(tmp_line);
270b86af 171 }
172
270b86af 173 /* Sanity checks */
174 if (Config.Swap.maxSize < (Config.Mem.maxSize >> 10)) {
175 printf("WARNING: cache_swap (%d kbytes) is less than cache_mem (%d bytes).\n", Config.Swap.maxSize, Config.Mem.maxSize);
176 printf(" This will cause serious problems with your cache!!!\n");
177 printf(" Change your configuration file.\n");
178 fflush(stdout); /* print message */
179 }
f1dc9b30 180 if (Config.Announce.period < 1) {
181 Config.Announce.period = 86400 * 365; /* one year */
270b86af 182 Config.Announce.on = 0;
183 }
184 if (Config.dnsChildren < 0)
185 Config.dnsChildren = 0;
186 if (Config.dnsChildren < 1) {
187 printf("WARNING: dnsservers are disabled!\n");
188 printf("WARNING: Cache performance may be very poor\n");
189 } else if (Config.dnsChildren > DefaultDnsChildrenMax) {
190 printf("WARNING: dns_children was set to a bad value: %d\n",
191 Config.dnsChildren);
192 printf("Setting it to the maximum (%d).\n", DefaultDnsChildrenMax);
193 Config.dnsChildren = DefaultDnsChildrenMax;
194 }
195 if (Config.Program.redirect) {
196 if (Config.redirectChildren < 1) {
197 Config.redirectChildren = 0;
198 safe_free(Config.Program.redirect);
199 } else if (Config.redirectChildren > DefaultRedirectChildrenMax) {
200 printf("WARNING: redirect_children was set to a bad value: %d\n",
201 Config.redirectChildren);
202 printf("Setting it to the maximum (%d).\n", DefaultRedirectChildrenMax);
203 Config.redirectChildren = DefaultRedirectChildrenMax;
204 }
fea2e6e0 205 }
270b86af 206 fclose(fp);
207 configDoConfigure();
270b86af 208 return 0;
2546fcb3 209}
210
8203a132 211static void
270b86af 212configDoConfigure(void)
090089c4 213{
f1dc9b30 214 LOCAL_ARRAY(char, buf, BUFSIZ);
215 memset(&Config2, '\0', sizeof(SquidConfig2));
216 if (Config.Accel.host) {
a47b9029 217 snprintf(buf, BUFSIZ, "http://%s:%d", Config.Accel.host, Config.Accel.port);
218 Config2.Accel.prefix = xstrdup(buf);
219 Config2.Accel.on = 1;
f1dc9b30 220 }
221 if (Config.appendDomain)
222 if (*Config.appendDomain != '.')
223 fatal("append_domain must begin with a '.'");
270b86af 224 if (Config.errHtmlText == NULL)
225 Config.errHtmlText = xstrdup(null_string);
226 storeConfigure();
f1dc9b30 227 if (Config2.Accel.on && !strcmp(Config.Accel.host, "virtual"))
270b86af 228 vhost_mode = 1;
229 if (Config.Port.http == NULL)
230 fatal("No http_port specified!");
231 sprintf(ThisCache, "%s:%d (Squid/%s)",
232 getMyHostname(),
233 (int) Config.Port.http->i,
234 SQUID_VERSION);
235 if (!Config.udpMaxHitObjsz || Config.udpMaxHitObjsz > SQUID_UDP_SO_SNDBUF)
236 Config.udpMaxHitObjsz = SQUID_UDP_SO_SNDBUF;
237 if (Config.appendDomain)
238 Config.appendDomainLen = strlen(Config.appendDomain);
239 else
240 Config.appendDomainLen = 0;
f1dc9b30 241 safe_free(debug_options)
242 debug_options = xstrdup(Config.debugOptions);
090089c4 243}
244
270b86af 245/* Parse a time specification from the config file. Store the
f1dc9b30 246 * result in 'tptr', after converting it to 'units' */
8203a132 247static void
a47b9029 248parseTimeLine(time_t * tptr, const char *units)
090089c4 249{
250 char *token;
270b86af 251 double d;
f1dc9b30 252 time_t m;
253 time_t u;
270b86af 254 if ((u = parseTimeUnits(units)) == 0)
3003c0f3 255 self_destruct();
270b86af 256 if ((token = strtok(NULL, w_space)) == NULL)
3003c0f3 257 self_destruct();
270b86af 258 d = atof(token);
259 m = u; /* default to 'units' if none specified */
9e975e4e 260 if ((token = strtok(NULL, w_space)) == NULL)
a47b9029 261 debug(3, 0) ("WARNING: No units on '%s', assuming %f %s\n",
262 config_input_line, d, units);
9e975e4e 263 else if ((m = parseTimeUnits(token)) == 0)
a47b9029 264 self_destruct();
f1dc9b30 265 *tptr = m * d / u;
090089c4 266}
267
270b86af 268static int
269parseTimeUnits(const char *unit)
270{
271 if (!strncasecmp(unit, T_SECOND_STR, strlen(T_SECOND_STR)))
272 return 1;
273 if (!strncasecmp(unit, T_MINUTE_STR, strlen(T_MINUTE_STR)))
274 return 60;
275 if (!strncasecmp(unit, T_HOUR_STR, strlen(T_HOUR_STR)))
276 return 3600;
277 if (!strncasecmp(unit, T_DAY_STR, strlen(T_DAY_STR)))
278 return 86400;
279 if (!strncasecmp(unit, T_WEEK_STR, strlen(T_WEEK_STR)))
280 return 86400 * 7;
281 if (!strncasecmp(unit, T_FORTNIGHT_STR, strlen(T_FORTNIGHT_STR)))
282 return 86400 * 14;
283 if (!strncasecmp(unit, T_MONTH_STR, strlen(T_MONTH_STR)))
284 return 86400 * 30;
285 if (!strncasecmp(unit, T_YEAR_STR, strlen(T_YEAR_STR)))
286 return 86400 * 365.2522;
287 if (!strncasecmp(unit, T_DECADE_STR, strlen(T_DECADE_STR)))
288 return 86400 * 365.2522 * 10;
289 debug(3, 1) ("parseTimeUnits: unknown time unit '%s'\n", unit);
290 return 0;
291}
292
9906e724 293static void
9e975e4e 294parseBytesLine(size_t * bptr, const char *units)
9906e724 295{
296 char *token;
297 double d;
298 size_t m;
299 size_t u;
300 if ((u = parseBytesUnits(units)) == 0)
301 self_destruct();
302 if ((token = strtok(NULL, w_space)) == NULL)
303 self_destruct();
304 d = atof(token);
305 m = u; /* default to 'units' if none specified */
9e975e4e 306 if ((token = strtok(NULL, w_space)) == NULL)
307 debug(3, 0) ("WARNING: No units on '%s', assuming %f %s\n",
308 config_input_line, d, units);
309 else if ((m = parseBytesUnits(token)) == 0)
310 self_destruct();
9906e724 311 *bptr = m * d / u;
312}
313
314static size_t
315parseBytesUnits(const char *unit)
316{
317 if (!strncasecmp(unit, B_BYTES_STR, strlen(B_BYTES_STR)))
318 return 1;
319 if (!strncasecmp(unit, B_KBYTES_STR, strlen(B_KBYTES_STR)))
a47b9029 320 return 1 << 10;
9906e724 321 if (!strncasecmp(unit, B_MBYTES_STR, strlen(B_MBYTES_STR)))
a47b9029 322 return 1 << 20;
9906e724 323 if (!strncasecmp(unit, B_GBYTES_STR, strlen(B_GBYTES_STR)))
a47b9029 324 return 1 << 30;
9906e724 325 debug(3, 1) ("parseBytesUnits: unknown bytes unit '%s'\n", unit);
326 return 0;
327}
328
270b86af 329/*****************************************************************************
330 * Max
331 *****************************************************************************/
332
8203a132 333static void
a47b9029 334dump_acl(acl * acl)
090089c4 335{
b556b1e9 336 assert(0);
090089c4 337}
338
8203a132 339static void
a47b9029 340parse_acl(acl ** acl)
090089c4 341{
f1dc9b30 342 aclParseAclLine(acl);
343}
344
345static void
a47b9029 346free_acl(acl ** acl)
f1dc9b30 347{
348 aclDestroyAcls(acl);
090089c4 349}
350
8203a132 351static void
270b86af 352dump_acl_access(struct _acl_access *head)
30a4f2a8 353{
b556b1e9 354 assert(0);
30a4f2a8 355}
090089c4 356
8203a132 357static void
270b86af 358parse_acl_access(struct _acl_access **head)
090089c4 359{
270b86af 360 aclParseAccessLine(head);
090089c4 361}
362
0153d498 363static void
364free_acl_access(struct _acl_access **head)
365{
a47b9029 366 aclDestroyAccessList(head);
0153d498 367}
368
8203a132 369static void
270b86af 370dump_address(struct in_addr addr)
371{
372 printf("%s", inet_ntoa(addr));
373}
374
375static void
376parse_address(struct in_addr *addr)
090089c4 377{
0ee4272b 378 const struct hostent *hp;
270b86af 379 char *token = strtok(NULL, w_space);
380
30a4f2a8 381 if (token == NULL)
382 self_destruct();
429fdbec 383 if (safe_inet_addr(token, addr) == 1)
384 (void) 0;
ceb8994e 385 else if ((hp = gethostbyname(token))) /* dont use ipcache */
1d73e33a 386 *addr = inaddrFromHostent(hp);
30a4f2a8 387 else
3003c0f3 388 self_destruct();
090089c4 389}
390
0153d498 391static void
392free_address(struct in_addr *addr)
393{
a47b9029 394 memset(addr, '\0', sizeof(struct in_addr));
0153d498 395}
396
e90100aa 397static void
f1dc9b30 398dump_cachedir(struct _cacheSwap swap)
e90100aa 399{
b556b1e9 400 assert(0);
e90100aa 401}
402
8203a132 403static void
f1dc9b30 404parse_cachedir(struct _cacheSwap *swap)
090089c4 405{
406 char *token;
f1dc9b30 407 char *path;
752c3b27 408 int i;
270b86af 409 int size;
410 int l1;
411 int l2;
412 int readonly = 0;
f1dc9b30 413 SwapDir *tmp = NULL;
414 if ((path = strtok(NULL, w_space)) == NULL)
752c3b27 415 self_destruct();
f1dc9b30 416 if (strlen(path) > (SQUID_MAXPATHLEN - 32))
417 fatal_dump("cache_dir pathname is too long");
270b86af 418 GetInteger(i);
419 size = i << 10; /* Mbytes to kbytes */
270b86af 420 GetInteger(i);
421 l1 = i;
422 GetInteger(i);
423 l2 = i;
424 if ((token = strtok(NULL, w_space)))
425 if (!strcasecmp(token, "read-only"))
426 readonly = 1;
f1dc9b30 427 for (i = 0; i < swap->n_configured; i++) {
a47b9029 428 tmp = swap->swapDirs + i;
f1dc9b30 429 if (!strcmp(path, tmp->path)) {
430 /* just reconfigure it */
a47b9029 431 tmp->max_size = size;
432 tmp->read_only = readonly;
f1dc9b30 433 return;
434 }
435 }
436 if (swap->swapDirs == NULL) {
437 swap->n_allocated = 4;
438 swap->swapDirs = xcalloc(swap->n_allocated, sizeof(SwapDir));
439 }
440 if (swap->n_allocated == swap->n_configured) {
441 swap->n_allocated <<= 1;
442 tmp = xcalloc(swap->n_allocated, sizeof(SwapDir));
443 xmemcpy(tmp, swap->swapDirs, swap->n_configured * sizeof(SwapDir));
444 xfree(swap->swapDirs);
445 swap->swapDirs = tmp;
446 }
447 debug(20, 1) ("Creating Swap Dir #%d in %s\n", swap->n_configured + 1, path);
448 tmp = swap->swapDirs + swap->n_configured;
449 tmp->path = xstrdup(path);
450 tmp->max_size = size;
451 tmp->l1 = l1;
452 tmp->l2 = l2;
453 tmp->read_only = readonly;
454 tmp->map = file_map_create(MAX_FILES_PER_DIR);
455 tmp->swaplog_fd = -1;
62607543 456 swap->n_configured++;
9906e724 457 Config.Swap.maxSize += size;
752c3b27 458}
459
8203a132 460static void
f1dc9b30 461free_cachedir(struct _cacheSwap *swap)
462{
a47b9029 463 SwapDir *s;
464 int i;
465 for (i = 0; i < swap->n_configured; i++) {
466 s = swap->swapDirs + i;
467 xfree(s->path);
468 filemapFreeMemory(s->map);
469 }
470 safe_free(swap->swapDirs);
471 swap->swapDirs = NULL;
472 swap->n_allocated = 0;
473 swap->n_configured = 0;
f1dc9b30 474}
475
476static void
40a1495e 477dump_peer(peer * p)
98ffb7e4 478{
b556b1e9 479 assert(0);
98ffb7e4 480}
481
8203a132 482static void
40a1495e 483parse_peer(peer ** head)
7813c6d5 484{
270b86af 485 char *token = NULL;
40a1495e 486 peer *p;
7813c6d5 487 int i;
40a1495e 488 ushortlist *u;
489 const char *me = getMyHostname();
72121e8b 490debug(0,0)("this be cache_peer()\n");
491debug(0,0)("%s\n", strtok(NULL, null_string));
40a1495e 492 p = xcalloc(1, sizeof(peer));
493 p->http_port = CACHE_HTTP_PORT;
494 p->icp_port = CACHE_ICP_PORT;
495 p->weight = 1;
72121e8b 496 token = strtok(NULL, w_space);
497debug(0,0)("token = %p\n", token);
498 if (token == NULL) {
40a1495e 499 debug(0,0)("bad hostname\n");
270b86af 500 self_destruct();
40a1495e 501 }
502 p->host = xstrdup(token);
503 if ((token = strtok(NULL, w_space)) == NULL) {
88738790 504 debug(0, 0) ("bad type\n");
270b86af 505 self_destruct();
40a1495e 506 }
507 p->type = parseNeighborType(token);
270b86af 508 GetInteger(i);
40a1495e 509 p->http_port = (u_short) i;
7813c6d5 510 GetInteger(i);
40a1495e 511 p->icp_port = (u_short) i;
512 if (strcmp(p->host, me) == 0) {
513 for (u = Config.Port.http; u; u = u->next) {
514 if (p->http_port != u->i)
515 continue;
516 debug(15, 0) ("parse_peer: Peer looks like myself: %s %s/%d/%d\n",
517 p->type, p->host, p->http_port, p->icp_port);
518 self_destruct();
519 }
520 }
270b86af 521 while ((token = strtok(NULL, w_space))) {
522 if (!strcasecmp(token, "proxy-only")) {
40a1495e 523 p->options |= NEIGHBOR_PROXY_ONLY;
270b86af 524 } else if (!strcasecmp(token, "no-query")) {
40a1495e 525 p->options |= NEIGHBOR_NO_QUERY;
270b86af 526 } else if (!strcasecmp(token, "multicast-responder")) {
40a1495e 527 p->options |= NEIGHBOR_MCAST_RESPONDER;
270b86af 528 } else if (!strncasecmp(token, "weight=", 7)) {
40a1495e 529 p->weight = atoi(token + 7);
270b86af 530 } else if (!strncasecmp(token, "ttl=", 4)) {
40a1495e 531 p->mcast.ttl = atoi(token + 4);
532 if (p->mcast.ttl < 0)
533 p->mcast.ttl = 0;
534 if (p->mcast.ttl > 128)
535 p->mcast.ttl = 128;
270b86af 536 } else if (!strncasecmp(token, "default", 7)) {
40a1495e 537 p->options |= NEIGHBOR_DEFAULT_PARENT;
270b86af 538 } else if (!strncasecmp(token, "round-robin", 11)) {
40a1495e 539 p->options |= NEIGHBOR_ROUNDROBIN;
270b86af 540 } else {
40a1495e 541 debug(3, 0) ("parse_peer: token='%s'\n", token);
270b86af 542 self_destruct();
543 }
544 }
40a1495e 545 if (p->weight < 1)
546 p->weight = 1;
547 p->icp_version = ICP_VERSION_CURRENT;
548 p->tcp_up = 1;
549 cbdataAdd(p);
0153d498 550 while (*head != NULL)
551 head = &(*head)->next;
552 *head = p;
40a1495e 553 Config.npeers++;
0153d498 554}
555
556static void
40a1495e 557free_peer(peer ** P)
0153d498 558{
40a1495e 559 peer *p;
a47b9029 560 while ((p = *P)) {
561 *P = p->next;
40a1495e 562 peerDestroy(p);
a47b9029 563 }
270b86af 564}
565
566static void
a47b9029 567dump_cachemgrpasswd(cachemgr_passwd * list)
270b86af 568{
b556b1e9 569 assert(0);
270b86af 570}
571
572static void
a47b9029 573parse_cachemgrpasswd(cachemgr_passwd ** head)
270b86af 574{
575 char *passwd = NULL;
576 wordlist *actions = NULL;
577 parse_string(&passwd);
578 parse_wordlist(&actions);
f1dc9b30 579 objcachePasswdAdd(head, passwd, actions);
270b86af 580 wordlistDestroy(&actions);
581}
582
583static void
a47b9029 584free_cachemgrpasswd(cachemgr_passwd ** head)
270b86af 585{
a47b9029 586 cachemgr_passwd *p;
587 while ((p = *head)) {
588 *head = p->next;
589 xfree(p->passwd);
590 xfree(p);
591 }
270b86af 592}
593
270b86af 594
8203a132 595static void
f1dc9b30 596dump_denyinfo(struct _acl_deny_info_list *var)
270b86af 597{
b556b1e9 598 assert(0);
270b86af 599}
600
601static void
f1dc9b30 602parse_denyinfo(struct _acl_deny_info_list **var)
6e40f263 603{
f1dc9b30 604 aclParseDenyInfoLine(var);
6e40f263 605}
403279e0 606
1273d501 607void
a47b9029 608free_denyinfo(acl_deny_info_list ** list)
3c5557f9 609{
1273d501 610 struct _acl_deny_info_list *a = NULL;
611 struct _acl_deny_info_list *a_next = NULL;
612 struct _acl_name_list *l = NULL;
613 struct _acl_name_list *l_next = NULL;
614 for (a = *list; a; a = a_next) {
a47b9029 615 for (l = a->acl_list; l; l = l_next) {
616 l_next = l->next;
617 safe_free(l);
618 }
619 a_next = a->next;
620 safe_free(a);
1273d501 621 }
622 *list = NULL;
270b86af 623}
624
625static void
f1dc9b30 626parse_peeracl(void)
270b86af 627{
628 char *host = NULL;
629 char *aclname = NULL;
630 if (!(host = strtok(NULL, w_space)))
631 self_destruct();
f1dc9b30 632 while ((aclname = strtok(NULL, list_sep))) {
40a1495e 633 peer *p;
f1dc9b30 634 acl_list *L = NULL;
635 acl_list **Tail = NULL;
636 acl *a = NULL;
40a1495e 637 if ((p = peerFindByName(host)) == NULL) {
f1dc9b30 638 debug(15, 0) ("%s, line %d: No cache_host '%s'\n",
639 cfg_filename, config_lineno, host);
640 return;
641 }
642 L = xcalloc(1, sizeof(struct _acl_list));
643 L->op = 1;
644 if (*aclname == '!') {
645 L->op = 0;
646 aclname++;
647 }
648 debug(15, 3) ("neighborAddAcl: looking for ACL name '%s'\n", aclname);
649 a = aclFindByName(aclname);
650 if (a == NULL) {
651 debug(15, 0) ("%s line %d: %s\n",
652 cfg_filename, config_lineno, config_input_line);
653 debug(15, 0) ("neighborAddAcl: ACL name '%s' not found.\n", aclname);
654 xfree(L);
655 return;
656 }
657 L->acl = a;
658 for (Tail = &p->acls; *Tail; Tail = &(*Tail)->next);
659 *Tail = L;
660 }
270b86af 661}
662
270b86af 663static void
664parse_hostdomain(void)
665{
666 char *host = NULL;
667 char *domain = NULL;
668 if (!(host = strtok(NULL, w_space)))
669 self_destruct();
f1dc9b30 670 while ((domain = strtok(NULL, list_sep))) {
671 domain_ping *l = NULL;
672 domain_ping **L = NULL;
40a1495e 673 peer *p;
674 if ((p = peerFindByName(host)) == NULL) {
f1dc9b30 675 debug(15, 0) ("%s, line %d: No cache_host '%s'\n",
676 cfg_filename, config_lineno, host);
677 continue;
678 }
679 l = xcalloc(1, sizeof(struct _domain_ping));
680 l->do_ping = 1;
681 if (*domain == '!') { /* check for !.edu */
682 l->do_ping = 0;
683 domain++;
684 }
685 l->domain = xstrdup(domain);
686 for (L = &(p->pinglist); *L; L = &((*L)->next));
687 *L = l;
688 }
270b86af 689}
690
691static void
692parse_hostdomaintype(void)
693{
694 char *host = NULL;
695 char *type = NULL;
696 char *domain = NULL;
697 if (!(host = strtok(NULL, w_space)))
698 self_destruct();
699 if (!(type = strtok(NULL, w_space)))
700 self_destruct();
f1dc9b30 701 while ((domain = strtok(NULL, list_sep))) {
702 domain_type *l = NULL;
703 domain_type **L = NULL;
40a1495e 704 peer *p;
705 if ((p = peerFindByName(host)) == NULL) {
f1dc9b30 706 debug(15, 0) ("%s, line %d: No cache_host '%s'\n",
707 cfg_filename, config_lineno, host);
708 return;
709 }
710 l = xcalloc(1, sizeof(struct _domain_type));
711 l->type = parseNeighborType(type);
712 l->domain = xstrdup(domain);
713 for (L = &(p->typelist); *L; L = &((*L)->next));
714 *L = l;
715 }
270b86af 716}
717
718static void
719dump_httpanonymizer(int var)
720{
721 switch (var) {
722 case ANONYMIZER_NONE:
723 printf("off");
724 break;
725 case ANONYMIZER_STANDARD:
726 printf("paranoid");
727 break;
728 case ANONYMIZER_PARANOID:
729 printf("standard");
730 break;
731 }
732}
733
734static void
735parse_httpanonymizer(int *var)
fa562c67 736{
737 char *token;
738 token = strtok(NULL, w_space);
739 if (token == NULL)
bba6fa8f 740 self_destruct();
fa562c67 741 if (!strcasecmp(token, "off"))
270b86af 742 *var = ANONYMIZER_NONE;
fa562c67 743 else if (!strcasecmp(token, "paranoid"))
270b86af 744 *var = ANONYMIZER_PARANOID;
fa562c67 745 else
270b86af 746 *var = ANONYMIZER_STANDARD;
747}
748
641941c0 749
270b86af 750static void
a47b9029 751dump_ushortlist(ushortlist * u)
090089c4 752{
270b86af 753 while (u) {
754 printf("%d ", (int) u->i);
755 u = u->next;
756 }
757}
090089c4 758
270b86af 759static void
760parse_ushortlist(ushortlist ** P)
761{
762 char *token;
763 int i;
764 ushortlist *u;
765 ushortlist **U;
766 while ((token = strtok(NULL, w_space))) {
767 if (sscanf(token, "%d", &i) != 1)
768 self_destruct();
769 if (i < 0)
770 i = 0;
771 u = xcalloc(1, sizeof(ushortlist));
772 u->i = (u_short) i;
773 for (U = P; *U; U = &(*U)->next);
774 *U = u;
090089c4 775 }
270b86af 776}
090089c4 777
0153d498 778static void
a47b9029 779free_ushortlist(ushortlist ** P)
0153d498 780{
a47b9029 781 ushortlist *u;
782 while ((u = *P)) {
783 *P = u->next;
784 xfree(u);
785 }
0153d498 786}
787
270b86af 788static void
789dump_int(int var)
790{
791 printf("%d", var);
792}
c1c29eb6 793
270b86af 794static void
795parse_int(int *var)
796{
797 char *token;
798 int i;
85034133 799
270b86af 800 GetInteger(i);
801 *var = i;
802}
090089c4 803
0153d498 804static void
805free_int(int *var)
806{
a47b9029 807 *var = 0;
0153d498 808}
809
270b86af 810static void
811dump_onoff(int var)
812{
813 printf(var ? "on" : "off");
814}
090089c4 815
270b86af 816static void
817parse_onoff(int *var)
818{
819 char *token = strtok(NULL, w_space);
090089c4 820
270b86af 821 if (token == NULL)
822 self_destruct();
823 if (!strcasecmp(token, "on") || !strcasecmp(token, "enable"))
824 *var = 1;
825 else
826 *var = 0;
827}
e90100aa 828
0153d498 829#define free_onoff free_int
f1dc9b30 830#define free_httpanonymizer free_int
0153d498 831#define dump_pathname_stat dump_string
832#define free_pathname_stat free_string
f1dc9b30 833#define dump_eol dump_string
834#define free_eol free_string
30a4f2a8 835
270b86af 836static void
0153d498 837parse_pathname_stat(char **path)
270b86af 838{
839 struct stat sb;
270b86af 840 parse_string(path);
270b86af 841 if (stat(*path, &sb) < 0) {
0153d498 842 debug(50, 1) ("parse_pathname_stat: %s: %s\n", *path, xstrerror());
270b86af 843 self_destruct();
844 }
845}
30a4f2a8 846
270b86af 847static void
a47b9029 848dump_refreshpattern(refresh_t * head)
270b86af 849{
b556b1e9 850 assert(0);
270b86af 851}
090089c4 852
270b86af 853static void
f1dc9b30 854parse_refreshpattern(refresh_t ** head)
270b86af 855{
f1dc9b30 856 char *token;
857 char *pattern;
858 time_t min = 0;
859 int pct = 0;
860 time_t max = 0;
861 int i;
862 refresh_t *t;
863 regex_t comp;
864 int errcode;
865 int flags = REG_EXTENDED | REG_NOSUB;
866 if ((token = strtok(NULL, w_space)) == NULL)
867 self_destruct();
868 if (strcmp(token, "-i") == 0) {
869 flags |= REG_ICASE;
870 token = strtok(NULL, w_space);
871 } else if (strcmp(token, "+i") == 0) {
872 flags &= ~REG_ICASE;
873 token = strtok(NULL, w_space);
874 }
875 if (token == NULL)
876 self_destruct();
877 pattern = xstrdup(token);
878 GetInteger(i); /* token: min */
879 min = (time_t) (i * 60); /* convert minutes to seconds */
880 GetInteger(i); /* token: pct */
881 pct = i;
882 GetInteger(i); /* token: max */
883 max = (time_t) (i * 60); /* convert minutes to seconds */
884 if ((errcode = regcomp(&comp, pattern, flags)) != 0) {
885 char errbuf[256];
886 regerror(errcode, &comp, errbuf, sizeof errbuf);
887 debug(22, 0) ("%s line %d: %s\n",
888 cfg_filename, config_lineno, config_input_line);
889 debug(22, 0) ("refreshAddToList: Invalid regular expression '%s': %s\n",
890 pattern, errbuf);
891 return;
892 }
893 pct = pct < 0 ? 0 : pct;
894 max = max < 0 ? 0 : max;
895 t = xcalloc(1, sizeof(refresh_t));
896 t->pattern = (char *) xstrdup(pattern);
897 t->compiled_pattern = comp;
898 t->min = min;
899 t->pct = pct;
900 t->max = max;
901 t->next = NULL;
902 while (*head)
903 head = &(*head)->next;
904 *head = t;
905 safe_free(pattern);
270b86af 906}
090089c4 907
270b86af 908static void
a47b9029 909free_refreshpattern(refresh_t ** head)
270b86af 910{
f1dc9b30 911 refresh_t *t;
912 while ((t = *head)) {
913 *head = t->next;
914 safe_free(t->pattern);
915 regfree(&t->compiled_pattern);
916 safe_free(t);
917 }
270b86af 918}
12b9e9b1 919
270b86af 920static void
921dump_regexlist(relist * var)
922{
b556b1e9 923 assert(0);
270b86af 924}
cf5fd929 925
270b86af 926static void
927parse_regexlist(relist ** var)
928{
0153d498 929 aclParseRegexList(var);
270b86af 930}
fb263c4c 931
270b86af 932static void
0153d498 933free_regexlist(relist ** var)
270b86af 934{
0153d498 935 aclDestroyRegexList(*var);
936 *var = NULL;
270b86af 937}
7d49daab 938
270b86af 939static void
0153d498 940dump_string(char *var)
270b86af 941{
942 printf("%s", var);
943}
98ffb7e4 944
270b86af 945static void
0153d498 946parse_string(char **var)
270b86af 947{
948 char *token = strtok(NULL, w_space);
270b86af 949 safe_free(*var);
950 if (token == NULL)
951 self_destruct();
952 *var = xstrdup(token);
953}
b15e6857 954
0153d498 955static void
956free_string(char **var)
957{
a47b9029 958 xfree(*var);
959 *var = NULL;
0153d498 960}
caebbe00 961
270b86af 962static void
f1dc9b30 963parse_eol(char *volatile *var)
270b86af 964{
965 char *token = strtok(NULL, null_string);
270b86af 966 safe_free(*var);
f1dc9b30 967 if (token == NULL)
968 self_destruct();
270b86af 969 *var = xstrdup(token);
970}
090089c4 971
270b86af 972static void
f1dc9b30 973dump_time_t(time_t var)
090089c4 974{
f1dc9b30 975 printf("%d", (int) var);
090089c4 976}
977
270b86af 978static void
a47b9029 979parse_time_t(time_t * var)
0ffd22bc 980{
f1dc9b30 981 parseTimeLine(var, T_SECOND_STR);
0ffd22bc 982}
983
270b86af 984static void
a47b9029 985free_time_t(time_t * var)
270b86af 986{
a47b9029 987 *var = 0;
270b86af 988}
9906e724 989
990static void
991dump_size_t(size_t var)
992{
993 printf("%d bytes", (int) var);
994}
995
996static void
997dump_kb_size_t(size_t var)
998{
999 printf("%d KB", (int) var);
1000}
1001
1002static void
a47b9029 1003parse_size_t(size_t * var)
9906e724 1004{
1005 parseBytesLine(var, B_BYTES_STR);
1006}
1007
1008static void
a47b9029 1009parse_kb_size_t(size_t * var)
9906e724 1010{
1011 parseBytesLine(var, B_KBYTES_STR);
1012}
1013
1014static void
a47b9029 1015free_size_t(size_t * var)
9906e724 1016{
a47b9029 1017 *var = 0;
9906e724 1018}
1019
1020#define free_kb_size_t free_size_t
1021#define free_mb_size_t free_size_t
1022#define free_gb_size_t free_size_t
090089c4 1023
8203a132 1024static void
270b86af 1025dump_ushort(u_short var)
090089c4 1026{
270b86af 1027 printf("%d", var);
1028}
090089c4 1029
0153d498 1030static void
a47b9029 1031free_ushort(u_short * u)
0153d498 1032{
1033 *u = 0;
1034}
1035
270b86af 1036static void
1037parse_ushort(u_short * var)
1038{
1039 char *token;
1040 int i;
090089c4 1041
270b86af 1042 GetInteger(i);
1043 if (i < 0)
1044 i = 0;
1045 *var = (u_short) i;
090089c4 1046}
1047
270b86af 1048static void
1049dump_wordlist(wordlist * list)
1050{
1051 printf("{");
1052 while (list != NULL) {
1053 printf("%s ", list->key);
1054 list = list->next;
429fdbec 1055 }
270b86af 1056 printf("}");
429fdbec 1057}
1058
270b86af 1059static void
1060parse_wordlist(wordlist ** list)
429fdbec 1061{
270b86af 1062 char *token;
1063
1064 while ((token = strtok(NULL, w_space)))
1065 wordlistAdd(list, token);
429fdbec 1066}
270b86af 1067
0153d498 1068#define free_wordlist wordlistDestroy
270b86af 1069
1070#include "cf_parser.c"
f1dc9b30 1071
1072peer_t
1073parseNeighborType(const char *s)
1074{
1075 if (!strcasecmp(s, "parent"))
1076 return PEER_PARENT;
1077 if (!strcasecmp(s, "neighbor"))
1078 return PEER_SIBLING;
1079 if (!strcasecmp(s, "neighbour"))
1080 return PEER_SIBLING;
1081 if (!strcasecmp(s, "sibling"))
1082 return PEER_SIBLING;
1083 if (!strcasecmp(s, "multicast"))
1084 return PEER_MULTICAST;
1085 debug(15, 0) ("WARNING: Unknown neighbor type: %s\n", s);
1086 return PEER_SIBLING;
1087}