]> git.ipfire.org Git - thirdparty/squid.git/blame - src/cache_cf.cc
Adjusted the sizes of swap_filen and swap_dirn to the old ones (24, 8). This
[thirdparty/squid.git] / src / cache_cf.cc
CommitLineData
be335c22 1
30a4f2a8 2/*
94439e4e 3 * $Id: cache_cf.cc,v 1.367 2001/01/07 23:36:37 hno Exp $
30a4f2a8 4 *
5 * DEBUG: section 3 Configuration File Parsing
6 * AUTHOR: Harvest Derived
7 *
42c04c16 8 * SQUID Internet Object Cache http://squid.nlanr.net/Squid/
e25c139f 9 * ----------------------------------------------------------
30a4f2a8 10 *
11 * Squid is the result of efforts by numerous individuals from the
12 * Internet community. Development is led by Duane Wessels of the
e25c139f 13 * National Laboratory for Applied Network Research and funded by the
14 * National Science Foundation. Squid is Copyrighted (C) 1998 by
efd900cb 15 * the Regents of the University of California. Please see the
16 * COPYRIGHT file for full details. Squid incorporates software
17 * developed and/or copyrighted by other sources. Please see the
18 * 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 42static const char *const T_SECOND_STR = "second";
43static const char *const T_MINUTE_STR = "minute";
44static const char *const T_HOUR_STR = "hour";
45static const char *const T_DAY_STR = "day";
46static const char *const T_WEEK_STR = "week";
47static const char *const T_FORTNIGHT_STR = "fortnight";
48static const char *const T_MONTH_STR = "month";
49static const char *const T_YEAR_STR = "year";
50static const char *const T_DECADE_STR = "decade";
aa0a0c7c 51
9906e724 52static const char *const B_BYTES_STR = "bytes";
53static const char *const B_KBYTES_STR = "KB";
54static const char *const B_MBYTES_STR = "MB";
55static const char *const B_GBYTES_STR = "GB";
56
4db43fab 57static const char *const list_sep = ", \t\n\r";
97474590 58
cd748f27 59static void update_maxobjsize(void);
f5b8bbc4 60static void configDoConfigure(void);
61static void parse_refreshpattern(refresh_t **);
62static int parseTimeUnits(const char *unit);
63static void parseTimeLine(time_t * tptr, const char *units);
59715b38 64static void parse_ushort(u_short * var);
f5b8bbc4 65static void parse_string(char **);
94439e4e 66void parse_wordlist(wordlist **);
f5b8bbc4 67static void default_all(void);
68static void defaults_if_none(void);
69static int parse_line(char *);
70static void parseBytesLine(size_t * bptr, const char *units);
71static size_t parseBytesUnits(const char *unit);
f5b8bbc4 72static void free_all(void);
94439e4e 73void requirePathnameExists(const char *name, const char *path);
ed7f5615 74static OBJH dump_config;
6bccf575 75static void dump_http_header_access(StoreEntry * entry, const char *name, header_mangler header[]);
76static void parse_http_header_access(header_mangler header[]);
77static void free_http_header_access(header_mangler header[]);
78static void dump_http_header_replace(StoreEntry * entry, const char *name, header_mangler header[]);
79static void parse_http_header_replace(header_mangler * header);
80static void free_http_header_replace(header_mangler * header);
81static void parse_denyinfo(acl_deny_info_list ** var);
82static void dump_denyinfo(StoreEntry * entry, const char *name, acl_deny_info_list * var);
83static void free_denyinfo(acl_deny_info_list ** var);
7e3ce7b9 84static void parse_sockaddr_in_list(sockaddr_in_list **);
85static void dump_sockaddr_in_list(StoreEntry *, const char *, const sockaddr_in_list *);
86static void free_sockaddr_in_list(sockaddr_in_list **);
87static int check_null_sockaddr_in_list(const sockaddr_in_list *);
270b86af 88
0e4e0e7d 89void
0673c0ba 90self_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 96void
97wordlistDestroy(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 108const char *
fe4e214f 109wordlistAdd(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
119void
a4b8110e 120wordlistJoin(wordlist ** list, wordlist ** wl)
858783c9 121{
122 while (*list)
123 list = &(*list)->next;
124 *list = *wl;
125 *wl = NULL;
126}
127
128void
a4b8110e 129wordlistAddWl(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 140void
eeb423fb 141wordlistCat(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 149wordlist *
150wordlistDup(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 160void
161intlistDestroy(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 172int
173intlistFind(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 188int
189GetInteger(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 200static void
201update_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 213int
214parseConfigFile(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 261static void
262configDoConfigure(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 419static void
a47b9029 420parseTimeLine(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 442static int
443parseTimeUnits(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 467static void
9e975e4e 468parseBytesLine(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
490static size_t
491parseBytesUnits(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 509static void
9ef28b60 510dump_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 531static void
9ef28b60 532parse_acl(acl ** ae)
090089c4 533{
9ef28b60 534 aclParseAclLine(ae);
f1dc9b30 535}
536
537static void
9ef28b60 538free_acl(acl ** ae)
f1dc9b30 539{
9ef28b60 540 aclDestroyAcls(ae);
090089c4 541}
542
8203a132 543static void
16300b58 544dump_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 561static void
16300b58 562parse_acl_access(acl_access ** head)
090089c4 563{
270b86af 564 aclParseAccessLine(head);
090089c4 565}
566
0153d498 567static void
16300b58 568free_acl_access(acl_access ** head)
0153d498 569{
a47b9029 570 aclDestroyAccessList(head);
0153d498 571}
572
8203a132 573static void
a7d59104 574dump_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
579static void
580parse_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 595static void
596free_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
613static void
614free_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
634static void
635dump_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
666static void
667parse_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
680static void
681parse_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
710static void
711parse_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
755static void
756parse_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 769static void
6bccf575 770dump_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 783static void
6bccf575 784parse_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
820static void
821free_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
829static void
830dump_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 843static void
6bccf575 844parse_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
880static void
881free_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 890static void
56b63fa1 891dump_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
901static int
56b63fa1 902check_null_cachedir(cacheSwap swap)
f53b06f9 903{
904 return swap.swapDirs == NULL;
e90100aa 905}
906
53ad48e6 907static int
908check_null_string(char *s)
909{
910 return s == NULL;
911}
912
94439e4e 913void
914allocate_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
930static void
931parse_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
964static void
965free_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
982static void
983dump_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 993void
994allocate_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 1010static int
1011find_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 1022static void
1023parse_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
1073 fs = find_fstype(type_str);
1074 if (fs < 0) {
a4b8110e 1075 /* If we get here, we didn't find a matching cache_dir type */
1076 fatalf("Unknown cache_dir type '%s'\n", type_str);
0e4e0e7d 1077 }
cd748f27 1078 allocate_new_swapdir(swap);
1079 sd = swap->swapDirs + swap->n_configured;
1080 storefs_list[fs].parsefunc(sd, swap->n_configured, path_str);
1081 /* XXX should we dupe the string here, in case it gets trodden on? */
1082 sd->type = storefs_list[fs].typestr;
1083 sd->max_objsize = maxobjsize;
90d42c28 1084 /* defaults in case fs implementation fails to set these */
1085 sd->fs.blksize = 1024;
cd748f27 1086 swap->n_configured++;
1087 /* Update the max object size */
1088 update_maxobjsize();
752c3b27 1089}
1090
8203a132 1091static void
16300b58 1092free_cachedir(cacheSwap * swap)
f1dc9b30 1093{
a47b9029 1094 SwapDir *s;
1095 int i;
860ee7e3 1096 /* DON'T FREE THESE FOR RECONFIGURE */
5cd39a10 1097 if (reconfiguring)
860ee7e3 1098 return;
a47b9029 1099 for (i = 0; i < swap->n_configured; i++) {
1100 s = swap->swapDirs + i;
cd748f27 1101 s->freefs(s);
a47b9029 1102 xfree(s->path);
a47b9029 1103 }
1104 safe_free(swap->swapDirs);
1105 swap->swapDirs = NULL;
1106 swap->n_allocated = 0;
1107 swap->n_configured = 0;
f1dc9b30 1108}
1109
505e35db 1110const char *
1111peer_type_str(const peer_t type)
1112{
0cdcddb9 1113 switch (type) {
505e35db 1114 case PEER_PARENT:
1115 return "parent";
1116 break;
1117 case PEER_SIBLING:
1118 return "sibling";
1119 break;
1120 case PEER_MULTICAST:
1121 return "multicast";
1122 break;
1123 default:
1124 return "unknown";
1125 break;
1126 }
1127}
1128
f1dc9b30 1129static void
a7d59104 1130dump_peer(StoreEntry * entry, const char *name, peer * p)
98ffb7e4 1131{
505e35db 1132 domain_ping *d;
1133 acl_access *a;
1134 domain_type *t;
1135 LOCAL_ARRAY(char, xname, 128);
d41de3c1 1136 while (p != NULL) {
1137 storeAppendPrintf(entry, "%s %s %s %d %d",
1138 name,
1139 p->host,
1140 neighborTypeStr(p),
1141 p->http_port,
399cabec 1142 p->icp.port);
a369131d 1143 dump_peer_options(entry, p);
b6a2f15e 1144 for (d = p->peer_domain; d; d = d->next) {
505e35db 1145 storeAppendPrintf(entry, "cache_peer_domain %s %s%s\n",
1146 p->host,
1147 d->do_ping ? null_string : "!",
1148 d->domain);
1149 }
1150 if ((a = p->access)) {
1151 snprintf(xname, 128, "cache_peer_access %s", p->host);
1152 dump_acl_access(entry, xname, p->access);
1153 }
1154 for (t = p->typelist; t; t = t->next) {
1155 storeAppendPrintf(entry, "neighbor_type_domain %s %s %s\n",
1156 p->host,
1157 peer_type_str(t->type),
1158 t->domain);
1159 }
d41de3c1 1160 p = p->next;
1161 }
98ffb7e4 1162}
1163
8203a132 1164static void
40a1495e 1165parse_peer(peer ** head)
7813c6d5 1166{
270b86af 1167 char *token = NULL;
40a1495e 1168 peer *p;
7813c6d5 1169 int i;
28c60158 1170 p = CBDATA_ALLOC(peer, peerDestroy);
40a1495e 1171 p->http_port = CACHE_HTTP_PORT;
399cabec 1172 p->icp.port = CACHE_ICP_PORT;
40a1495e 1173 p->weight = 1;
dc835977 1174 p->stats.logged_state = PEER_ALIVE;
e481c2dc 1175 if ((token = strtok(NULL, w_space)) == NULL)
270b86af 1176 self_destruct();
40a1495e 1177 p->host = xstrdup(token);
e481c2dc 1178 if ((token = strtok(NULL, w_space)) == NULL)
270b86af 1179 self_destruct();
40a1495e 1180 p->type = parseNeighborType(token);
0e4e0e7d 1181 i = GetInteger();
40a1495e 1182 p->http_port = (u_short) i;
0e4e0e7d 1183 i = GetInteger();
399cabec 1184 p->icp.port = (u_short) i;
270b86af 1185 while ((token = strtok(NULL, w_space))) {
1186 if (!strcasecmp(token, "proxy-only")) {
cd196bc8 1187 p->options.proxy_only = 1;
270b86af 1188 } else if (!strcasecmp(token, "no-query")) {
cd196bc8 1189 p->options.no_query = 1;
8638fc66 1190 } else if (!strcasecmp(token, "no-digest")) {
cd196bc8 1191 p->options.no_digest = 1;
270b86af 1192 } else if (!strcasecmp(token, "multicast-responder")) {
cd196bc8 1193 p->options.mcast_responder = 1;
270b86af 1194 } else if (!strncasecmp(token, "weight=", 7)) {
40a1495e 1195 p->weight = atoi(token + 7);
0103c4c1 1196 } else if (!strcasecmp(token, "closest-only")) {
cd196bc8 1197 p->options.closest_only = 1;
270b86af 1198 } else if (!strncasecmp(token, "ttl=", 4)) {
40a1495e 1199 p->mcast.ttl = atoi(token + 4);
1200 if (p->mcast.ttl < 0)
1201 p->mcast.ttl = 0;
1202 if (p->mcast.ttl > 128)
1203 p->mcast.ttl = 128;
0103c4c1 1204 } else if (!strcasecmp(token, "default")) {
cd196bc8 1205 p->options.default_parent = 1;
0103c4c1 1206 } else if (!strcasecmp(token, "round-robin")) {
cd196bc8 1207 p->options.roundrobin = 1;
dc9d133b 1208#if USE_HTCP
0103c4c1 1209 } else if (!strcasecmp(token, "htcp")) {
cd196bc8 1210 p->options.htcp = 1;
dc9d133b 1211#endif
0103c4c1 1212 } else if (!strcasecmp(token, "no-netdb-exchange")) {
cd196bc8 1213 p->options.no_netdb_exchange = 1;
afd88fbe 1214#if USE_CARP
1215 } else if (!strncasecmp(token, "carp-load-factor=", 17)) {
1216 if (p->type != PEER_PARENT)
0cdcddb9 1217 debug(3, 0) ("parse_peer: Ignoring carp-load-factor for non-parent %s/%d\n", p->host, p->http_port);
1218 else
1219 p->carp.load_factor = atof(token + 17);
95e36d02 1220#endif
1221#if DELAY_POOLS
1222 } else if (!strcasecmp(token, "no-delay")) {
cd196bc8 1223 p->options.no_delay = 1;
afd88fbe 1224#endif
c68e9c6b 1225 } else if (!strncasecmp(token, "login=", 6)) {
1226 p->login = xstrdup(token + 6);
3f62decd 1227 } else if (!strncasecmp(token, "connect-timeout=", 16)) {
1228 p->connect_timeout = atoi(token + 16);
7e3ce7b9 1229#if USE_CACHE_DIGESTS
1230 } else if (!strncasecmp(token, "digest-url=", 11)) {
1231 p->digest_url = xstrdup(token + 11);
1232#endif
987de783 1233 } else if (!strcasecmp(token, "allow-miss")) {
1234 p->options.allow_miss = 1;
c7f9eb6d 1235 } else if (!strcasecmp(token, "max-conn=")) {
1236 p->max_conn = atoi(token + 9);
270b86af 1237 } else {
40a1495e 1238 debug(3, 0) ("parse_peer: token='%s'\n", token);
270b86af 1239 self_destruct();
1240 }
1241 }
40a1495e 1242 if (p->weight < 1)
1243 p->weight = 1;
399cabec 1244 p->icp.version = ICP_VERSION_CURRENT;
98829f69 1245 p->tcp_up = PEER_TCP_MAGIC_COUNT;
eb406bb7 1246 p->test_fd = -1;
afd88fbe 1247#if USE_CARP
8ee9b49f 1248#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
afd88fbe 1249 if (p->carp.load_factor) {
e13ee7ad 1250 /* calculate this peers hash for use in CARP */
0cdcddb9 1251 p->carp.hash = 0;
1252 for (token = p->host; *token != 0; token++)
8ee9b49f 1253 p->carp.hash += ROTATE_LEFT(p->carp.hash, 19) + (unsigned int) *token;
d20b1cd0 1254 p->carp.hash += p->carp.hash * 0x62531965;
8ee9b49f 1255 p->carp.hash = ROTATE_LEFT(p->carp.hash, 21);
afd88fbe 1256 }
1257#endif
e13ee7ad 1258#if USE_CACHE_DIGESTS
1259 if (!p->options.no_digest) {
1260 p->digest = peerDigestCreate(p);
8a6218c6 1261 cbdataLock(p->digest); /* so we know when/if digest disappears */
1262 }
e13ee7ad 1263#endif
0153d498 1264 while (*head != NULL)
1265 head = &(*head)->next;
1266 *head = p;
40a1495e 1267 Config.npeers++;
82056f1e 1268 peerClearRR(p);
0153d498 1269}
1270
1271static void
40a1495e 1272free_peer(peer ** P)
0153d498 1273{
40a1495e 1274 peer *p;
79d39a72 1275 while ((p = *P) != NULL) {
a47b9029 1276 *P = p->next;
3855c318 1277#if USE_CACHE_DIGESTS
1278 if (p->digest)
1279 cbdataUnlock(p->digest);
1280 p->digest = NULL;
1281#endif
41042c81 1282 cbdataFree(p);
a47b9029 1283 }
987c67d1 1284 Config.npeers = 0;
270b86af 1285}
1286
1287static void
a7d59104 1288dump_cachemgrpasswd(StoreEntry * entry, const char *name, cachemgr_passwd * list)
270b86af 1289{
d41de3c1 1290 wordlist *w;
1291 while (list != NULL) {
74aa8456 1292 if (strcmp(list->passwd, "none") && strcmp(list->passwd, "disable"))
1293 storeAppendPrintf(entry, "%s XXXXXXXXXX", name);
1294 else
1295 storeAppendPrintf(entry, "%s %s", name, list->passwd);
d41de3c1 1296 for (w = list->actions; w != NULL; w = w->next) {
1297 storeAppendPrintf(entry, " %s", w->key);
1298 }
1299 storeAppendPrintf(entry, "\n");
1300 list = list->next;
1301 }
270b86af 1302}
1303
1304static void
a47b9029 1305parse_cachemgrpasswd(cachemgr_passwd ** head)
270b86af 1306{
1307 char *passwd = NULL;
1308 wordlist *actions = NULL;
22f3fd98 1309 cachemgr_passwd *p;
1310 cachemgr_passwd **P;
270b86af 1311 parse_string(&passwd);
1312 parse_wordlist(&actions);
22f3fd98 1313 p = xcalloc(1, sizeof(cachemgr_passwd));
1314 p->passwd = passwd;
1315 p->actions = actions;
1316 for (P = head; *P; P = &(*P)->next);
1317 *P = p;
270b86af 1318}
1319
1320static void
a47b9029 1321free_cachemgrpasswd(cachemgr_passwd ** head)
270b86af 1322{
a47b9029 1323 cachemgr_passwd *p;
79d39a72 1324 while ((p = *head) != NULL) {
a47b9029 1325 *head = p->next;
1326 xfree(p->passwd);
22f3fd98 1327 wordlistDestroy(&p->actions);
a47b9029 1328 xfree(p);
1329 }
270b86af 1330}
1331
8203a132 1332static void
16300b58 1333dump_denyinfo(StoreEntry * entry, const char *name, acl_deny_info_list * var)
270b86af 1334{
d41de3c1 1335 acl_name_list *a;
1336 while (var != NULL) {
02922e76 1337 storeAppendPrintf(entry, "%s %s", name, var->err_page_name);
d41de3c1 1338 for (a = var->acl_list; a != NULL; a = a->next)
1339 storeAppendPrintf(entry, " %s", a->name);
1340 storeAppendPrintf(entry, "\n");
1341 var = var->next;
1342 }
270b86af 1343}
1344
1345static void
16300b58 1346parse_denyinfo(acl_deny_info_list ** var)
6e40f263 1347{
f1dc9b30 1348 aclParseDenyInfoLine(var);
6e40f263 1349}
403279e0 1350
1273d501 1351void
a47b9029 1352free_denyinfo(acl_deny_info_list ** list)
3c5557f9 1353{
56b63fa1 1354 acl_deny_info_list *a = NULL;
1355 acl_deny_info_list *a_next = NULL;
1356 acl_name_list *l = NULL;
1357 acl_name_list *l_next = NULL;
1273d501 1358 for (a = *list; a; a = a_next) {
a47b9029 1359 for (l = a->acl_list; l; l = l_next) {
1360 l_next = l->next;
3314e65b 1361 memFree(l, MEM_ACL_NAME_LIST);
eeda4c4d 1362 l = NULL;
a47b9029 1363 }
1364 a_next = a->next;
eeda4c4d 1365 memFree(a, MEM_ACL_DENY_INFO_LIST);
1366 a = NULL;
1273d501 1367 }
1368 *list = NULL;
270b86af 1369}
1370
1371static void
505e35db 1372parse_peer_access(void)
270b86af 1373{
1374 char *host = NULL;
505e35db 1375 peer *p;
270b86af 1376 if (!(host = strtok(NULL, w_space)))
1377 self_destruct();
0cdcddb9 1378 if ((p = peerFindByName(host)) == NULL) {
1379 debug(15, 0) ("%s, line %d: No cache_peer '%s'\n",
1380 cfg_filename, config_lineno, host);
1381 return;
1382 }
505e35db 1383 aclParseAccessLine(&p->access);
270b86af 1384}
1385
270b86af 1386static void
1387parse_hostdomain(void)
1388{
1389 char *host = NULL;
1390 char *domain = NULL;
1391 if (!(host = strtok(NULL, w_space)))
1392 self_destruct();
f1dc9b30 1393 while ((domain = strtok(NULL, list_sep))) {
1394 domain_ping *l = NULL;
1395 domain_ping **L = NULL;
40a1495e 1396 peer *p;
1397 if ((p = peerFindByName(host)) == NULL) {
43c3424b 1398 debug(15, 0) ("%s, line %d: No cache_peer '%s'\n",
f1dc9b30 1399 cfg_filename, config_lineno, host);
1400 continue;
1401 }
56b63fa1 1402 l = xcalloc(1, sizeof(domain_ping));
f1dc9b30 1403 l->do_ping = 1;
1404 if (*domain == '!') { /* check for !.edu */
1405 l->do_ping = 0;
1406 domain++;
1407 }
1408 l->domain = xstrdup(domain);
b6a2f15e 1409 for (L = &(p->peer_domain); *L; L = &((*L)->next));
f1dc9b30 1410 *L = l;
1411 }
270b86af 1412}
1413
1414static void
1415parse_hostdomaintype(void)
1416{
1417 char *host = NULL;
1418 char *type = NULL;
1419 char *domain = NULL;
1420 if (!(host = strtok(NULL, w_space)))
1421 self_destruct();
1422 if (!(type = strtok(NULL, w_space)))
1423 self_destruct();
f1dc9b30 1424 while ((domain = strtok(NULL, list_sep))) {
1425 domain_type *l = NULL;
1426 domain_type **L = NULL;
40a1495e 1427 peer *p;
1428 if ((p = peerFindByName(host)) == NULL) {
43c3424b 1429 debug(15, 0) ("%s, line %d: No cache_peer '%s'\n",
f1dc9b30 1430 cfg_filename, config_lineno, host);
1431 return;
1432 }
56b63fa1 1433 l = xcalloc(1, sizeof(domain_type));
f1dc9b30 1434 l->type = parseNeighborType(type);
1435 l->domain = xstrdup(domain);
1436 for (L = &(p->typelist); *L; L = &((*L)->next));
1437 *L = l;
1438 }
270b86af 1439}
1440
7e3ce7b9 1441#if UNUSED_CODE
270b86af 1442static void
a7d59104 1443dump_ushortlist(StoreEntry * entry, const char *name, ushortlist * u)
090089c4 1444{
270b86af 1445 while (u) {
f53b06f9 1446 storeAppendPrintf(entry, "%s %d\n", name, (int) u->i);
270b86af 1447 u = u->next;
1448 }
1449}
090089c4 1450
f53b06f9 1451static int
1452check_null_ushortlist(ushortlist * u)
1453{
1454 return u == NULL;
1455}
1456
270b86af 1457static void
1458parse_ushortlist(ushortlist ** P)
1459{
1460 char *token;
1461 int i;
1462 ushortlist *u;
1463 ushortlist **U;
1464 while ((token = strtok(NULL, w_space))) {
1465 if (sscanf(token, "%d", &i) != 1)
1466 self_destruct();
1467 if (i < 0)
1468 i = 0;
1469 u = xcalloc(1, sizeof(ushortlist));
1470 u->i = (u_short) i;
1471 for (U = P; *U; U = &(*U)->next);
1472 *U = u;
090089c4 1473 }
270b86af 1474}
090089c4 1475
0153d498 1476static void
a47b9029 1477free_ushortlist(ushortlist ** P)
0153d498 1478{
a47b9029 1479 ushortlist *u;
79d39a72 1480 while ((u = *P) != NULL) {
a47b9029 1481 *P = u->next;
1482 xfree(u);
1483 }
0153d498 1484}
7e3ce7b9 1485#endif
0153d498 1486
270b86af 1487static void
a7d59104 1488dump_int(StoreEntry * entry, const char *name, int var)
270b86af 1489{
f53b06f9 1490 storeAppendPrintf(entry, "%s %d\n", name, var);
270b86af 1491}
c1c29eb6 1492
94439e4e 1493void
270b86af 1494parse_int(int *var)
1495{
270b86af 1496 int i;
0e4e0e7d 1497 i = GetInteger();
270b86af 1498 *var = i;
1499}
090089c4 1500
0153d498 1501static void
1502free_int(int *var)
1503{
a47b9029 1504 *var = 0;
0153d498 1505}
1506
270b86af 1507static void
a7d59104 1508dump_onoff(StoreEntry * entry, const char *name, int var)
270b86af 1509{
f53b06f9 1510 storeAppendPrintf(entry, "%s %s\n", name, var ? "on" : "off");
270b86af 1511}
090089c4 1512
270b86af 1513static void
1514parse_onoff(int *var)
1515{
1516 char *token = strtok(NULL, w_space);
090089c4 1517
270b86af 1518 if (token == NULL)
1519 self_destruct();
1520 if (!strcasecmp(token, "on") || !strcasecmp(token, "enable"))
1521 *var = 1;
1522 else
1523 *var = 0;
1524}
e90100aa 1525
0153d498 1526#define free_onoff free_int
f1dc9b30 1527#define dump_eol dump_string
1528#define free_eol free_string
30a4f2a8 1529
270b86af 1530static void
a7d59104 1531dump_refreshpattern(StoreEntry * entry, const char *name, refresh_t * head)
270b86af 1532{
d41de3c1 1533 while (head != NULL) {
9f60cfdf 1534 storeAppendPrintf(entry, "%s%s %s %d %d%% %d\n",
c3f6d204 1535 name,
1536 head->flags.icase ? " -i" : null_string,
1537 head->pattern,
1538 (int) head->min / 60,
1539 (int) (100.0 * head->pct + 0.5),
9f60cfdf 1540 (int) head->max / 60);
1541#if HTTP_VIOLATIONS
1542 if (head->flags.override_expire)
1543 storeAppendPrintf(entry, " override-expire");
1544 if (head->flags.override_lastmod)
1545 storeAppendPrintf(entry, " override-lastmod");
1546 if (head->flags.reload_into_ims)
1547 storeAppendPrintf(entry, " reload-into-ims");
1548 if (head->flags.ignore_reload)
1549 storeAppendPrintf(entry, " ignore-reload");
1550#endif
1551 storeAppendPrintf(entry, "\n");
d41de3c1 1552 head = head->next;
1553 }
270b86af 1554}
090089c4 1555
270b86af 1556static void
f1dc9b30 1557parse_refreshpattern(refresh_t ** head)
270b86af 1558{
f1dc9b30 1559 char *token;
1560 char *pattern;
1561 time_t min = 0;
c3f6d204 1562 double pct = 0.0;
f1dc9b30 1563 time_t max = 0;
9f60cfdf 1564#if HTTP_VIOLATIONS
1dfa1d81 1565 int override_expire = 0;
1566 int override_lastmod = 0;
cbe3a719 1567 int reload_into_ims = 0;
1568 int ignore_reload = 0;
9f60cfdf 1569#endif
f1dc9b30 1570 int i;
1571 refresh_t *t;
1572 regex_t comp;
1573 int errcode;
1574 int flags = REG_EXTENDED | REG_NOSUB;
1575 if ((token = strtok(NULL, w_space)) == NULL)
1576 self_destruct();
1577 if (strcmp(token, "-i") == 0) {
1578 flags |= REG_ICASE;
1579 token = strtok(NULL, w_space);
1580 } else if (strcmp(token, "+i") == 0) {
1581 flags &= ~REG_ICASE;
1582 token = strtok(NULL, w_space);
1583 }
1584 if (token == NULL)
1585 self_destruct();
1586 pattern = xstrdup(token);
0e4e0e7d 1587 i = GetInteger(); /* token: min */
f1dc9b30 1588 min = (time_t) (i * 60); /* convert minutes to seconds */
0e4e0e7d 1589 i = GetInteger(); /* token: pct */
c3f6d204 1590 pct = (double) i / 100.0;
0e4e0e7d 1591 i = GetInteger(); /* token: max */
f1dc9b30 1592 max = (time_t) (i * 60); /* convert minutes to seconds */
1dfa1d81 1593 /* Options */
1594 while ((token = strtok(NULL, w_space)) != NULL) {
9f60cfdf 1595#if HTTP_VIOLATIONS
1dfa1d81 1596 if (!strcmp(token, "override-expire"))
1597 override_expire = 1;
255d6021 1598 else if (!strcmp(token, "override-lastmod"))
1dfa1d81 1599 override_lastmod = 1;
cbe3a719 1600 else if (!strcmp(token, "reload-into-ims")) {
1601 reload_into_ims = 1;
1602 refresh_nocache_hack = 1;
1603 /* tell client_side.c that this is used */
1604 } else if (!strcmp(token, "ignore-reload")) {
1605 ignore_reload = 1;
1606 refresh_nocache_hack = 1;
1607 /* tell client_side.c that this is used */
1608 } else
9f60cfdf 1609#endif
cbe3a719 1610 debug(22, 0) ("redreshAddToList: Unknown option '%s': %s\n",
1dfa1d81 1611 pattern, token);
1612 }
f1dc9b30 1613 if ((errcode = regcomp(&comp, pattern, flags)) != 0) {
1614 char errbuf[256];
1615 regerror(errcode, &comp, errbuf, sizeof errbuf);
1616 debug(22, 0) ("%s line %d: %s\n",
1617 cfg_filename, config_lineno, config_input_line);
1618 debug(22, 0) ("refreshAddToList: Invalid regular expression '%s': %s\n",
1619 pattern, errbuf);
1620 return;
1621 }
c3f6d204 1622 pct = pct < 0.0 ? 0.0 : pct;
f1dc9b30 1623 max = max < 0 ? 0 : max;
1624 t = xcalloc(1, sizeof(refresh_t));
1625 t->pattern = (char *) xstrdup(pattern);
1626 t->compiled_pattern = comp;
1627 t->min = min;
c3f6d204 1628 t->pct = pct;
f1dc9b30 1629 t->max = max;
c3f6d204 1630 if (flags & REG_ICASE)
1631 t->flags.icase = 1;
9f60cfdf 1632#if HTTP_VIOLATIONS
1dfa1d81 1633 if (override_expire)
1634 t->flags.override_expire = 1;
1635 if (override_lastmod)
1636 t->flags.override_lastmod = 1;
cbe3a719 1637 if (reload_into_ims)
1638 t->flags.reload_into_ims = 1;
1639 if (ignore_reload)
1640 t->flags.ignore_reload = 1;
9f60cfdf 1641#endif
f1dc9b30 1642 t->next = NULL;
1643 while (*head)
1644 head = &(*head)->next;
1645 *head = t;
1646 safe_free(pattern);
270b86af 1647}
090089c4 1648
6b53c392 1649static int
a4b8110e 1650check_null_refreshpattern(refresh_t * data)
6b53c392 1651{
1652 return data != NULL;
1653}
1654
270b86af 1655static void
a47b9029 1656free_refreshpattern(refresh_t ** head)
270b86af 1657{
f1dc9b30 1658 refresh_t *t;
79d39a72 1659 while ((t = *head) != NULL) {
f1dc9b30 1660 *head = t->next;
1661 safe_free(t->pattern);
1662 regfree(&t->compiled_pattern);
1663 safe_free(t);
1664 }
270b86af 1665}
12b9e9b1 1666
270b86af 1667static void
a7d59104 1668dump_string(StoreEntry * entry, const char *name, char *var)
270b86af 1669{
f53b06f9 1670 if (var != NULL)
a7d59104 1671 storeAppendPrintf(entry, "%s %s\n", name, var);
270b86af 1672}
98ffb7e4 1673
270b86af 1674static void
0153d498 1675parse_string(char **var)
270b86af 1676{
1677 char *token = strtok(NULL, w_space);
270b86af 1678 safe_free(*var);
1679 if (token == NULL)
1680 self_destruct();
1681 *var = xstrdup(token);
1682}
b15e6857 1683
0153d498 1684static void
1685free_string(char **var)
1686{
027acbaf 1687 safe_free(*var);
0153d498 1688}
caebbe00 1689
94439e4e 1690void
f1dc9b30 1691parse_eol(char *volatile *var)
270b86af 1692{
1693 char *token = strtok(NULL, null_string);
270b86af 1694 safe_free(*var);
f1dc9b30 1695 if (token == NULL)
1696 self_destruct();
270b86af 1697 *var = xstrdup(token);
1698}
090089c4 1699
270b86af 1700static void
a7d59104 1701dump_time_t(StoreEntry * entry, const char *name, time_t var)
090089c4 1702{
f53b06f9 1703 storeAppendPrintf(entry, "%s %d seconds\n", name, (int) var);
090089c4 1704}
1705
94439e4e 1706void
a47b9029 1707parse_time_t(time_t * var)
0ffd22bc 1708{
f1dc9b30 1709 parseTimeLine(var, T_SECOND_STR);
0ffd22bc 1710}
1711
270b86af 1712static void
a47b9029 1713free_time_t(time_t * var)
270b86af 1714{
a47b9029 1715 *var = 0;
270b86af 1716}
9906e724 1717
1718static void
a7d59104 1719dump_size_t(StoreEntry * entry, const char *name, size_t var)
1b635117 1720{
f53b06f9 1721 storeAppendPrintf(entry, "%s %d\n", name, (int) var);
1b635117 1722}
1723
1724static void
a7d59104 1725dump_b_size_t(StoreEntry * entry, const char *name, size_t var)
9906e724 1726{
f53b06f9 1727 storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_BYTES_STR);
9906e724 1728}
1729
1730static void
a7d59104 1731dump_kb_size_t(StoreEntry * entry, const char *name, size_t var)
9906e724 1732{
f53b06f9 1733 storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_KBYTES_STR);
9906e724 1734}
1735
1736static void
a47b9029 1737parse_size_t(size_t * var)
1b635117 1738{
1b635117 1739 int i;
0e4e0e7d 1740 i = GetInteger();
1b635117 1741 *var = (size_t) i;
1742}
1743
1744static void
1745parse_b_size_t(size_t * var)
9906e724 1746{
1747 parseBytesLine(var, B_BYTES_STR);
1748}
1749
1750static void
a47b9029 1751parse_kb_size_t(size_t * var)
9906e724 1752{
1753 parseBytesLine(var, B_KBYTES_STR);
1754}
1755
1756static void
a47b9029 1757free_size_t(size_t * var)
9906e724 1758{
a47b9029 1759 *var = 0;
9906e724 1760}
1761
1b635117 1762#define free_b_size_t free_size_t
9906e724 1763#define free_kb_size_t free_size_t
1764#define free_mb_size_t free_size_t
1765#define free_gb_size_t free_size_t
090089c4 1766
8203a132 1767static void
a7d59104 1768dump_ushort(StoreEntry * entry, const char *name, u_short var)
090089c4 1769{
f53b06f9 1770 storeAppendPrintf(entry, "%s %d\n", name, var);
270b86af 1771}
090089c4 1772
0153d498 1773static void
a47b9029 1774free_ushort(u_short * u)
0153d498 1775{
1776 *u = 0;
1777}
1778
270b86af 1779static void
1780parse_ushort(u_short * var)
1781{
270b86af 1782 int i;
090089c4 1783
0e4e0e7d 1784 i = GetInteger();
270b86af 1785 if (i < 0)
1786 i = 0;
1787 *var = (u_short) i;
090089c4 1788}
1789
270b86af 1790static void
a7d59104 1791dump_wordlist(StoreEntry * entry, const char *name, wordlist * list)
270b86af 1792{
270b86af 1793 while (list != NULL) {
f53b06f9 1794 storeAppendPrintf(entry, "%s %s\n", name, list->key);
270b86af 1795 list = list->next;
429fdbec 1796 }
429fdbec 1797}
1798
94439e4e 1799void
270b86af 1800parse_wordlist(wordlist ** list)
429fdbec 1801{
270b86af 1802 char *token;
270b86af 1803 while ((token = strtok(NULL, w_space)))
1804 wordlistAdd(list, token);
429fdbec 1805}
270b86af 1806
f8d9f54a 1807static int
5da06f20 1808check_null_wordlist(wordlist * w)
f8d9f54a 1809{
1810 return w == NULL;
1811}
1812
63e9d884 1813static int
c6d5b87b 1814check_null_acl_access(acl_access * a)
63e9d884 1815{
1816 return a == NULL;
1817}
1818
0153d498 1819#define free_wordlist wordlistDestroy
270b86af 1820
d548ee64 1821#define free_uri_whitespace free_int
1822
1823static void
1824parse_uri_whitespace(int *var)
1825{
1826 char *token = strtok(NULL, w_space);
1827 if (token == NULL)
1828 self_destruct();
7e3ce7b9 1829 if (!strcasecmp(token, "strip"))
1830 *var = URI_WHITESPACE_STRIP;
1831 else if (!strcasecmp(token, "deny"))
d548ee64 1832 *var = URI_WHITESPACE_DENY;
1833 else if (!strcasecmp(token, "allow"))
1834 *var = URI_WHITESPACE_ALLOW;
1835 else if (!strcasecmp(token, "encode"))
1836 *var = URI_WHITESPACE_ENCODE;
1837 else if (!strcasecmp(token, "chop"))
1838 *var = URI_WHITESPACE_CHOP;
1839 else
1840 self_destruct();
1841}
1842
1843
1844static void
1845dump_uri_whitespace(StoreEntry * entry, const char *name, int var)
1846{
1847 char *s;
1848 if (var == URI_WHITESPACE_ALLOW)
1849 s = "allow";
1850 else if (var == URI_WHITESPACE_ENCODE)
1851 s = "encode";
1852 else if (var == URI_WHITESPACE_CHOP)
1853 s = "chop";
7e3ce7b9 1854 else if (var == URI_WHITESPACE_DENY)
d548ee64 1855 s = "deny";
7e3ce7b9 1856 else
1857 s = "strip";
d548ee64 1858 storeAppendPrintf(entry, "%s %s\n", name, s);
1859}
1860
6a566b9c 1861static void
c1dd71ae 1862free_removalpolicy(RemovalPolicySettings ** settings)
6a566b9c 1863{
1864 if (!*settings)
1865 return;
1866 free_string(&(*settings)->type);
1867 free_wordlist(&(*settings)->args);
1868 xfree(*settings);
1869 *settings = NULL;
1870}
1871
1872static void
c1dd71ae 1873parse_removalpolicy(RemovalPolicySettings ** settings)
6a566b9c 1874{
1875 if (*settings)
1876 free_removalpolicy(settings);
1877 *settings = xcalloc(1, sizeof(**settings));
1878 parse_string(&(*settings)->type);
1879 parse_wordlist(&(*settings)->args);
1880}
1881
1882static void
c1dd71ae 1883dump_removalpolicy(StoreEntry * entry, const char *name, RemovalPolicySettings * settings)
6a566b9c 1884{
1885 wordlist *args;
1886 storeAppendPrintf(entry, "%s %s", name, settings->type);
1887 args = settings->args;
1888 while (args) {
1889 storeAppendPrintf(entry, " %s", args->key);
1890 args = args->next;
1891 }
be58afb5 1892 storeAppendPrintf(entry, "\n");
6a566b9c 1893}
c1dd71ae 1894
6a566b9c 1895
270b86af 1896#include "cf_parser.c"
f1dc9b30 1897
1898peer_t
1899parseNeighborType(const char *s)
1900{
1901 if (!strcasecmp(s, "parent"))
1902 return PEER_PARENT;
1903 if (!strcasecmp(s, "neighbor"))
1904 return PEER_SIBLING;
1905 if (!strcasecmp(s, "neighbour"))
1906 return PEER_SIBLING;
1907 if (!strcasecmp(s, "sibling"))
1908 return PEER_SIBLING;
1909 if (!strcasecmp(s, "multicast"))
1910 return PEER_MULTICAST;
1911 debug(15, 0) ("WARNING: Unknown neighbor type: %s\n", s);
1912 return PEER_SIBLING;
1913}
f150dd4b 1914
7e3ce7b9 1915static void
1916parse_sockaddr_in_list(sockaddr_in_list ** head)
1917{
1918 char *token;
1919 char *t;
efd900cb 1920 char *host;
7e3ce7b9 1921 const struct hostent *hp;
efd900cb 1922 unsigned short port;
7e3ce7b9 1923 sockaddr_in_list *s;
1924 while ((token = strtok(NULL, w_space))) {
efd900cb 1925 host = NULL;
1926 port = 0;
7e3ce7b9 1927 if ((t = strchr(token, ':'))) {
1928 /* host:port */
1929 host = token;
1930 *t = '\0';
efd900cb 1931 port = (unsigned short) atoi(t + 1);
1932 if (0 == port)
7e3ce7b9 1933 self_destruct();
efd900cb 1934 } else if ((port = atoi(token)) > 0) {
7e3ce7b9 1935 /* port */
1936 } else {
1937 self_destruct();
1938 }
1939 s = xcalloc(1, sizeof(*s));
efd900cb 1940 s->s.sin_port = htons(port);
7e3ce7b9 1941 if (NULL == host)
1942 s->s.sin_addr = any_addr;
1943 else if (1 == safe_inet_addr(host, &s->s.sin_addr))
1944 (void) 0;
efd900cb 1945 else if ((hp = gethostbyname(host))) /* dont use ipcache */
7e3ce7b9 1946 s->s.sin_addr = inaddrFromHostent(hp);
1947 else
1948 self_destruct();
1949 while (*head)
1950 head = &(*head)->next;
1951 *head = s;
1952 }
1953}
1954
1955static void
1956dump_sockaddr_in_list(StoreEntry * e, const char *n, const sockaddr_in_list * s)
1957{
1958 while (s) {
1959 storeAppendPrintf(e, "%s %s:%d\n",
1960 n,
1961 inet_ntoa(s->s.sin_addr),
1962 ntohs(s->s.sin_port));
1963 s = s->next;
1964 }
1965}
1966
1967static void
1968free_sockaddr_in_list(sockaddr_in_list ** head)
1969{
1970 sockaddr_in_list *s;
1971 while ((s = *head) != NULL) {
1972 *head = s->next;
1973 xfree(s);
1974 }
1975}
1976
1977static int
1978check_null_sockaddr_in_list(const sockaddr_in_list * s)
1979{
1980 return NULL == s;
1981}
1982
f150dd4b 1983void
1984configFreeMemory(void)
1985{
23ff6968 1986 free_all();
f150dd4b 1987}
f0b19334 1988
94439e4e 1989void
f0b19334 1990requirePathnameExists(const char *name, const char *path)
1991{
1992 struct stat sb;
f0b19334 1993 assert(path != NULL);
137ee196 1994 if (stat(path, &sb) < 0)
1995 fatalf("%s: %s", path, xstrerror());
f0b19334 1996}