]> git.ipfire.org Git - thirdparty/squid.git/blob - src/cache_cf.cc
Author: wessels & Christos Tsantilas
[thirdparty/squid.git] / src / cache_cf.cc
1
2 /*
3 * $Id: cache_cf.cc,v 1.515 2007/08/13 17:20:51 hno Exp $
4 *
5 * DEBUG: section 3 Configuration File Parsing
6 * AUTHOR: Harvest Derived
7 *
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
10 *
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see the CREDITS file for full details.
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
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
33 *
34 */
35
36 #include "squid.h"
37 #include "authenticate.h"
38 #include "AuthConfig.h"
39 #include "AuthScheme.h"
40 #include "CacheManager.h"
41 #include "Store.h"
42 #include "SwapDir.h"
43 #include "ConfigParser.h"
44 #include "ACL.h"
45 #include "StoreFileSystem.h"
46 #include "Parsing.h"
47 #include "MemBuf.h"
48 #include "wordlist.h"
49
50 #if SQUID_SNMP
51 #include "snmp.h"
52 #endif
53 #if ESI
54 #include "ESIParser.h"
55 #endif
56
57 #if ICAP_CLIENT
58 #include "ICAP/ICAPConfig.h"
59
60 static void parse_icap_service_type(ICAPConfig *);
61 static void dump_icap_service_type(StoreEntry *, const char *, const ICAPConfig &);
62 static void free_icap_service_type(ICAPConfig *);
63 static void parse_icap_class_type(ICAPConfig *);
64 static void dump_icap_class_type(StoreEntry *, const char *, const ICAPConfig &);
65 static void free_icap_class_type(ICAPConfig *);
66 static void parse_icap_access_type(ICAPConfig *);
67 static void dump_icap_access_type(StoreEntry *, const char *, const ICAPConfig &);
68 static void free_icap_access_type(ICAPConfig *);
69
70 #endif
71
72 CBDATA_TYPE(peer);
73
74 static const char *const T_SECOND_STR = "second";
75 static const char *const T_MINUTE_STR = "minute";
76 static const char *const T_HOUR_STR = "hour";
77 static const char *const T_DAY_STR = "day";
78 static const char *const T_WEEK_STR = "week";
79 static const char *const T_FORTNIGHT_STR = "fortnight";
80 static const char *const T_MONTH_STR = "month";
81 static const char *const T_YEAR_STR = "year";
82 static const char *const T_DECADE_STR = "decade";
83
84 static const char *const B_BYTES_STR = "bytes";
85 static const char *const B_KBYTES_STR = "KB";
86 static const char *const B_MBYTES_STR = "MB";
87 static const char *const B_GBYTES_STR = "GB";
88
89 static const char *const list_sep = ", \t\n\r";
90
91 static void parse_logformat(logformat ** logformat_definitions);
92 static void parse_access_log(customlog ** customlog_definitions);
93 static int check_null_access_log(customlog *customlog_definitions);
94
95 static void dump_logformat(StoreEntry * entry, const char *name, logformat * definitions);
96 static void dump_access_log(StoreEntry * entry, const char *name, customlog * definitions);
97 static void free_logformat(logformat ** definitions);
98 static void free_access_log(customlog ** definitions);
99
100 static void update_maxobjsize(void);
101 static void configDoConfigure(void);
102 static void parse_refreshpattern(refresh_t **);
103 static int parseTimeUnits(const char *unit);
104 static void parseTimeLine(time_t * tptr, const char *units);
105 static void parse_ushort(u_short * var);
106 static void parse_string(char **);
107 static void default_all(void);
108 static void defaults_if_none(void);
109 static int parse_line(char *);
110 static void parseBytesLine(size_t * bptr, const char *units);
111 static size_t parseBytesUnits(const char *unit);
112 static void free_all(void);
113 void requirePathnameExists(const char *name, const char *path);
114 static OBJH dump_config;
115 #if HTTP_VIOLATIONS
116 static void dump_http_header_access(StoreEntry * entry, const char *name, header_mangler header[]);
117 static void parse_http_header_access(header_mangler header[]);
118 static void free_http_header_access(header_mangler header[]);
119 static void dump_http_header_replace(StoreEntry * entry, const char *name, header_mangler header[]);
120 static void parse_http_header_replace(header_mangler * header);
121 static void free_http_header_replace(header_mangler * header);
122 #endif
123 static void parse_denyinfo(acl_deny_info_list ** var);
124 static void dump_denyinfo(StoreEntry * entry, const char *name, acl_deny_info_list * var);
125 static void free_denyinfo(acl_deny_info_list ** var);
126 #if USE_WCCPv2
127 static void parse_sockaddr_in_list(sockaddr_in_list **);
128 static void dump_sockaddr_in_list(StoreEntry *, const char *, const sockaddr_in_list *);
129 static void free_sockaddr_in_list(sockaddr_in_list **);
130 #if CURRENTLY_UNUSED
131 static int check_null_sockaddr_in_list(const sockaddr_in_list *);
132 #endif /* CURRENTLY_UNUSED */
133 #endif
134 static void parse_http_port_list(http_port_list **);
135 static void dump_http_port_list(StoreEntry *, const char *, const http_port_list *);
136 static void free_http_port_list(http_port_list **);
137 #if USE_SSL
138 static void parse_https_port_list(https_port_list **);
139 static void dump_https_port_list(StoreEntry *, const char *, const https_port_list *);
140 static void free_https_port_list(https_port_list **);
141 #if 0
142 static int check_null_https_port_list(const https_port_list *);
143 #endif
144 #endif /* USE_SSL */
145 static void parse_b_size_t(size_t * var);
146 static void parse_b_int64_t(int64_t * var);
147
148 /*
149 * LegacyParser is a parser for legacy code that uses the global
150 * approach. This is static so that it is only exposed to cache_cf.
151 * Other modules needing access to a ConfigParser should have it
152 * provided to them in their parserFOO methods.
153 */
154 static ConfigParser LegacyParser = ConfigParser();
155
156 void
157 self_destruct(void)
158 {
159 LegacyParser.destruct();
160 }
161
162 static void
163 update_maxobjsize(void)
164 {
165 int i;
166 int64_t ms = -1;
167
168 for (i = 0; i < Config.cacheSwap.n_configured; i++) {
169 assert (Config.cacheSwap.swapDirs[i].getRaw());
170
171 if (dynamic_cast<SwapDir *>(Config.cacheSwap.swapDirs[i].getRaw())->
172 max_objsize > ms)
173 ms = dynamic_cast<SwapDir *>(Config.cacheSwap.swapDirs[i].getRaw())->max_objsize;
174 }
175 store_maxobjsize = ms;
176 }
177
178 static void
179 SetConfigFilename(char const *file_name, bool is_pipe)
180 {
181 cfg_filename = file_name;
182
183 char const *token;
184
185 if (is_pipe)
186 cfg_filename = file_name + 1;
187 else if ((token = strrchr(cfg_filename, '/')))
188 cfg_filename = token + 1;
189 }
190
191 static const char*
192 skip_ws(const char* s)
193 {
194 while (xisspace(*s))
195 ++s;
196
197 return s;
198 }
199
200 int
201 parseConfigFile(const char *file_name, CacheManager & manager)
202 {
203 FILE *fp = NULL;
204 char *token = NULL;
205 char *tmp_line = NULL;
206 int tmp_line_len = 0;
207 int err_count = 0;
208 int is_pipe = 0;
209 configFreeMemory();
210 default_all();
211
212 if (file_name[0] == '!' || file_name[0] == '|') {
213 fp = popen(file_name + 1, "r");
214 is_pipe = 1;
215 } else {
216 fp = fopen(file_name, "r");
217 }
218
219 if (fp == NULL)
220 fatalf("Unable to open configuration file: %s: %s",
221 file_name, xstrerror());
222
223 #ifdef _SQUID_WIN32_
224
225 setmode(fileno(fp), O_TEXT);
226
227 #endif
228
229 SetConfigFilename(file_name, bool(is_pipe));
230
231 memset(config_input_line, '\0', BUFSIZ);
232
233 config_lineno = 0;
234
235 while (fgets(config_input_line, BUFSIZ, fp)) {
236 config_lineno++;
237
238 if ((token = strchr(config_input_line, '\n')))
239 *token = '\0';
240
241 if ((token = strchr(config_input_line, '\r')))
242 *token = '\0';
243
244 if (strncmp(config_input_line, "#line ", 6) == 0) {
245 static char new_file_name[1024];
246 static char *file;
247 static char new_lineno;
248 token = config_input_line + 6;
249 new_lineno = strtol(token, &file, 0) - 1;
250
251 if (file == token)
252 continue; /* Not a valid #line directive, may be a comment */
253
254 while (*file && xisspace((unsigned char) *file))
255 file++;
256
257 if (*file) {
258 if (*file != '"')
259 continue; /* Not a valid #line directive, may be a comment */
260
261 xstrncpy(new_file_name, file + 1, sizeof(new_file_name));
262
263 if ((token = strchr(new_file_name, '"')))
264 *token = '\0';
265
266 cfg_filename = new_file_name;
267
268 #if PROBABLY_NOT_WANTED_HERE
269
270 SetConfigFilename(cfg_filename, false);
271
272 #endif
273
274 }
275
276 config_lineno = new_lineno;
277 }
278
279 if (config_input_line[0] == '#')
280 continue;
281
282 if (config_input_line[0] == '\0')
283 continue;
284
285 const char* append = tmp_line_len ? skip_ws(config_input_line) : config_input_line;
286
287 size_t append_len = strlen(append);
288
289 tmp_line = (char*)xrealloc(tmp_line, tmp_line_len + append_len + 1);
290
291 strcpy(tmp_line + tmp_line_len, append);
292
293 tmp_line_len += append_len;
294
295 if (tmp_line[tmp_line_len-1] == '\\') {
296 debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line << "'");
297 tmp_line[--tmp_line_len] = '\0';
298 continue;
299 }
300
301 debugs(3, 5, "Processing: '" << tmp_line << "'");
302
303 if (!parse_line(tmp_line)) {
304 debugs(3, 0, "parseConfigFile: '" << cfg_filename << "' line " <<
305 config_lineno << " unrecognized: '" << config_input_line << "'");
306 err_count++;
307 }
308
309 safe_free(tmp_line);
310 tmp_line_len = 0;
311
312 }
313
314 if (is_pipe) {
315 int ret = pclose(fp);
316
317 if (ret != 0)
318 fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name, ret);
319 } else {
320 fclose(fp);
321 }
322
323 defaults_if_none();
324
325 /*
326 * We must call configDoConfigure() before leave_suid() because
327 * configDoConfigure() is where we turn username strings into
328 * uid values.
329 */
330 configDoConfigure();
331
332 if (!Config.chroot_dir) {
333 leave_suid();
334 _db_init(Config.Log.log, Config.debugOptions);
335 enter_suid();
336 }
337
338 if (opt_send_signal == -1) {
339 manager.registerAction("config",
340 "Current Squid Configuration",
341 dump_config,
342 1, 1);
343 }
344
345 return err_count;
346 }
347
348 static void
349 configDoConfigure(void)
350 {
351 memset(&Config2, '\0', sizeof(SquidConfig2));
352 /* init memory as early as possible */
353 memConfigure();
354 /* Sanity checks */
355
356 if (Config.cacheSwap.swapDirs == NULL)
357 fatal("No cache_dir's specified in config file");
358
359 if (0 == Store::Root().maxSize())
360 /* people might want a zero-sized cache on purpose */
361 (void) 0;
362 else if (Store::Root().maxSize() < (Config.memMaxSize >> 10))
363 /* This is bogus. folk with NULL caches will want this */
364 debugs(3, 0, "WARNING cache_mem is larger than total disk cache space!");
365
366 if (Config.Announce.period > 0) {
367 Config.onoff.announce = 1;
368 } else if (Config.Announce.period < 1) {
369 Config.Announce.period = 86400 * 365; /* one year */
370 Config.onoff.announce = 0;
371 }
372
373 if (Config.onoff.httpd_suppress_version_string)
374 visible_appname_string = (char *)appname_string;
375 else
376 visible_appname_string = (char *)full_appname_string;
377
378 #if USE_DNSSERVERS
379
380 if (Config.dnsChildren < 1)
381 fatal("No dnsservers allocated");
382
383 #endif
384
385 if (Config.Program.redirect) {
386 if (Config.redirectChildren < 1) {
387 Config.redirectChildren = 0;
388 wordlistDestroy(&Config.Program.redirect);
389 }
390 }
391
392 if (Config.appendDomain)
393 if (*Config.appendDomain != '.')
394 fatal("append_domain must begin with a '.'");
395
396 if (Config.errHtmlText == NULL)
397 Config.errHtmlText = xstrdup(null_string);
398
399 storeConfigure();
400
401 snprintf(ThisCache, sizeof(ThisCache), "%s (%s)",
402 uniqueHostname(),
403 visible_appname_string);
404
405 /*
406 * the extra space is for loop detection in client_side.c -- we search
407 * for substrings in the Via header.
408 */
409 snprintf(ThisCache2, sizeof(ThisCache), " %s (%s)",
410 uniqueHostname(),
411 visible_appname_string);
412
413 if (!Config.udpMaxHitObjsz || Config.udpMaxHitObjsz > SQUID_UDP_SO_SNDBUF)
414 Config.udpMaxHitObjsz = SQUID_UDP_SO_SNDBUF;
415
416 if (Config.appendDomain)
417 Config.appendDomainLen = strlen(Config.appendDomain);
418 else
419 Config.appendDomainLen = 0;
420
421 safe_free(debug_options)
422 debug_options = xstrdup(Config.debugOptions);
423
424 if (Config.retry.maxtries > 10)
425 fatal("maximum_single_addr_tries cannot be larger than 10");
426
427 if (Config.retry.maxtries < 1) {
428 debugs(3, 0, "WARNING: resetting 'maximum_single_addr_tries to 1");
429 Config.retry.maxtries = 1;
430 }
431
432 requirePathnameExists("MIME Config Table", Config.mimeTablePathname);
433 #if USE_DNSSERVERS
434
435 requirePathnameExists("cache_dns_program", Config.Program.dnsserver);
436 #endif
437 #if USE_UNLINKD
438
439 requirePathnameExists("unlinkd_program", Config.Program.unlinkd);
440 #endif
441
442 if (Config.Program.redirect)
443 requirePathnameExists("redirect_program", Config.Program.redirect->key);
444
445 requirePathnameExists("Icon Directory", Config.icons.directory);
446
447 requirePathnameExists("Error Directory", Config.errorDirectory);
448
449 #if HTTP_VIOLATIONS
450
451 {
452 const refresh_t *R;
453
454 for (R = Config.Refresh; R; R = R->next)
455 {
456 if (!R->flags.override_expire)
457 continue;
458
459 debugs(22, 1, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP");
460
461 break;
462 }
463
464 for (R = Config.Refresh; R; R = R->next)
465 {
466 if (!R->flags.override_lastmod)
467 continue;
468
469 debugs(22, 1, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP");
470
471 break;
472 }
473
474 for (R = Config.Refresh; R; R = R->next)
475 {
476 if (!R->flags.reload_into_ims)
477 continue;
478
479 debugs(22, 1, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP");
480
481 break;
482 }
483
484 for (R = Config.Refresh; R; R = R->next)
485 {
486 if (!R->flags.ignore_reload)
487 continue;
488
489 debugs(22, 1, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP");
490
491 break;
492 }
493
494 for (R = Config.Refresh; R; R = R->next)
495 {
496 if (!R->flags.ignore_no_cache)
497 continue;
498
499 debugs(22, 1, "WARNING: use of 'ignore-no-cache' in 'refresh_pattern' violates HTTP");
500
501 break;
502 }
503
504 for (R = Config.Refresh; R; R = R->next)
505 {
506 if (!R->flags.ignore_no_store)
507 continue;
508
509 debugs(22, 1, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP");
510
511 break;
512 }
513
514 for (R = Config.Refresh; R; R = R->next)
515 {
516 if (!R->flags.ignore_private)
517 continue;
518
519 debugs(22, 1, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP");
520
521 break;
522 }
523
524 for (R = Config.Refresh; R; R = R->next)
525 {
526 if (!R->flags.ignore_auth)
527 continue;
528
529 debugs(22, 1, "WARNING: use of 'ignore-auth' in 'refresh_pattern' violates HTTP");
530
531 break;
532 }
533
534 }
535 #endif
536 #if !HTTP_VIOLATIONS
537 Config.onoff.via = 1;
538 #else
539
540 if (!Config.onoff.via)
541 debugs(22, 1, "WARNING: HTTP requires the use of Via");
542
543 #endif
544
545 if (aclPurgeMethodInUse(Config.accessList.http))
546 Config2.onoff.enable_purge = 1;
547
548 Config2.onoff.mangle_request_headers = httpReqHdrManglersConfigured();
549
550 if (geteuid() == 0) {
551 if (NULL != Config.effectiveUser) {
552
553 struct passwd *pwd = getpwnam(Config.effectiveUser);
554
555 if (NULL == pwd)
556 /*
557 * Andres Kroonmaa <andre@online.ee>:
558 * Some getpwnam() implementations (Solaris?) require
559 * an available FD < 256 for opening a FILE* to the
560 * passwd file.
561 * DW:
562 * This should be safe at startup, but might still fail
563 * during reconfigure.
564 */
565 fatalf("getpwnam failed to find userid for effective user '%s'",
566 Config.effectiveUser);
567
568 Config2.effectiveUserID = pwd->pw_uid;
569
570 Config2.effectiveGroupID = pwd->pw_gid;
571
572 #if HAVE_PUTENV
573
574 if (pwd->pw_dir && *pwd->pw_dir) {
575 int len;
576 char *env_str = (char *)xcalloc((len = strlen(pwd->pw_dir) + 6), 1);
577 snprintf(env_str, len, "HOME=%s", pwd->pw_dir);
578 putenv(env_str);
579 }
580
581 #endif
582
583 }
584 } else {
585 Config2.effectiveUserID = geteuid();
586 Config2.effectiveGroupID = getegid();
587 }
588
589 if (NULL != Config.effectiveGroup) {
590
591 struct group *grp = getgrnam(Config.effectiveGroup);
592
593 if (NULL == grp)
594 fatalf("getgrnam failed to find groupid for effective group '%s'",
595 Config.effectiveGroup);
596
597 Config2.effectiveGroupID = grp->gr_gid;
598 }
599
600 HttpRequestMethod::Configure(Config);
601 #if USE_SSL
602
603 debugs(3, 1, "Initializing https proxy context");
604
605 Config.ssl_client.sslContext = sslCreateClientContext(Config.ssl_client.cert, Config.ssl_client.key, Config.ssl_client.version, Config.ssl_client.cipher, Config.ssl_client.options, Config.ssl_client.flags, Config.ssl_client.cafile, Config.ssl_client.capath, Config.ssl_client.crlfile);
606
607 {
608
609 peer *p;
610
611 for (p = Config.peers; p != NULL; p = p->next) {
612 if (p->use_ssl) {
613 debugs(3, 1, "Initializing cache_peer " << p->name << " SSL context");
614 p->sslContext = sslCreateClientContext(p->sslcert, p->sslkey, p->sslversion, p->sslcipher, p->ssloptions, p->sslflags, p->sslcafile, p->sslcapath, p->sslcrlfile);
615 }
616 }
617 }
618
619 {
620
621 https_port_list *s;
622
623 for (s = Config.Sockaddr.https; s != NULL; s = (https_port_list *) s->http.next) {
624 debugs(3, 1, "Initializing https_port " <<
625 inet_ntoa(s->http.s.sin_addr) << ":" <<
626 ntohs(s->http.s.sin_port) << " SSL context");
627
628 s->sslContext = sslCreateServerContext(s->cert, s->key, s->version, s->cipher, s->options, s->sslflags, s->clientca, s->cafile, s->capath, s->crlfile, s->dhfile, s->sslcontext);
629 }
630 }
631
632 #endif
633 }
634
635 /* Parse a time specification from the config file. Store the
636 * result in 'tptr', after converting it to 'units' */
637 static void
638 parseTimeLine(time_t * tptr, const char *units)
639 {
640 char *token;
641 double d;
642 time_t m;
643 time_t u;
644
645 if ((u = parseTimeUnits(units)) == 0)
646 self_destruct();
647
648 if ((token = strtok(NULL, w_space)) == NULL)
649 self_destruct();
650
651 d = xatof(token);
652
653 m = u; /* default to 'units' if none specified */
654
655 if (0 == d)
656 (void) 0;
657 else if ((token = strtok(NULL, w_space)) == NULL)
658 debugs(3, 0, "WARNING: No units on '" <<
659 config_input_line << "', assuming " <<
660 d << " " << units );
661 else if ((m = parseTimeUnits(token)) == 0)
662 self_destruct();
663
664 *tptr = static_cast<time_t> (m * d / u);
665 }
666
667 static int
668 parseTimeUnits(const char *unit)
669 {
670 if (!strncasecmp(unit, T_SECOND_STR, strlen(T_SECOND_STR)))
671 return 1;
672
673 if (!strncasecmp(unit, T_MINUTE_STR, strlen(T_MINUTE_STR)))
674 return 60;
675
676 if (!strncasecmp(unit, T_HOUR_STR, strlen(T_HOUR_STR)))
677 return 3600;
678
679 if (!strncasecmp(unit, T_DAY_STR, strlen(T_DAY_STR)))
680 return 86400;
681
682 if (!strncasecmp(unit, T_WEEK_STR, strlen(T_WEEK_STR)))
683 return 86400 * 7;
684
685 if (!strncasecmp(unit, T_FORTNIGHT_STR, strlen(T_FORTNIGHT_STR)))
686 return 86400 * 14;
687
688 if (!strncasecmp(unit, T_MONTH_STR, strlen(T_MONTH_STR)))
689 return 86400 * 30;
690
691 if (!strncasecmp(unit, T_YEAR_STR, strlen(T_YEAR_STR)))
692 return static_cast<int>(86400 * 365.2522);
693
694 if (!strncasecmp(unit, T_DECADE_STR, strlen(T_DECADE_STR)))
695 return static_cast<int>(86400 * 365.2522 * 10);
696
697 debugs(3, 1, "parseTimeUnits: unknown time unit '" << unit << "'");
698
699 return 0;
700 }
701
702 static void
703 parseBytesLine64(int64_t * bptr, const char *units)
704 {
705 char *token;
706 double d;
707 int64_t m;
708 int64_t u;
709
710 if ((u = parseBytesUnits(units)) == 0)
711 self_destruct();
712
713 if ((token = strtok(NULL, w_space)) == NULL)
714 self_destruct();
715
716 if (strcmp(token, "none") == 0 || strcmp(token, "-1") == 0) {
717 *bptr = static_cast<size_t>(-1);
718 return;
719 }
720
721 d = xatof(token);
722
723 m = u; /* default to 'units' if none specified */
724
725 if (0.0 == d)
726 (void) 0;
727 else if ((token = strtok(NULL, w_space)) == NULL)
728 debugs(3, 0, "WARNING: No units on '" <<
729 config_input_line << "', assuming " <<
730 d << " " << units );
731 else if ((m = parseBytesUnits(token)) == 0)
732 self_destruct();
733
734 *bptr = static_cast<int64_t>(m * d / u);
735
736 if (static_cast<double>(*bptr) * 2 != m * d / u * 2)
737 self_destruct();
738 }
739
740
741 static void
742 parseBytesLine(size_t * bptr, const char *units)
743 {
744 char *token;
745 double d;
746 int m;
747 int u;
748
749 if ((u = parseBytesUnits(units)) == 0)
750 self_destruct();
751
752 if ((token = strtok(NULL, w_space)) == NULL)
753 self_destruct();
754
755 if (strcmp(token, "none") == 0 || strcmp(token, "-1") == 0) {
756 *bptr = static_cast<size_t>(-1);
757 return;
758 }
759
760 d = xatof(token);
761
762 m = u; /* default to 'units' if none specified */
763
764 if (0.0 == d)
765 (void) 0;
766 else if ((token = strtok(NULL, w_space)) == NULL)
767 debugs(3, 0, "WARNING: No units on '" <<
768 config_input_line << "', assuming " <<
769 d << " " << units );
770 else if ((m = parseBytesUnits(token)) == 0)
771 self_destruct();
772
773 *bptr = static_cast<size_t>(m * d / u);
774
775 if (static_cast<double>(*bptr) * 2 != m * d / u * 2)
776 self_destruct();
777 }
778
779 static size_t
780 parseBytesUnits(const char *unit)
781 {
782 if (!strncasecmp(unit, B_BYTES_STR, strlen(B_BYTES_STR)))
783 return 1;
784
785 if (!strncasecmp(unit, B_KBYTES_STR, strlen(B_KBYTES_STR)))
786 return 1 << 10;
787
788 if (!strncasecmp(unit, B_MBYTES_STR, strlen(B_MBYTES_STR)))
789 return 1 << 20;
790
791 if (!strncasecmp(unit, B_GBYTES_STR, strlen(B_GBYTES_STR)))
792 return 1 << 30;
793
794 debugs(3, 1, "parseBytesUnits: unknown bytes unit '" << unit << "'");
795
796 return 0;
797 }
798
799 /*****************************************************************************
800 * Max
801 *****************************************************************************/
802
803 static void
804 dump_acl(StoreEntry * entry, const char *name, ACL * ae)
805 {
806 wordlist *w;
807 wordlist *v;
808
809 while (ae != NULL) {
810 debugs(3, 3, "dump_acl: " << name << " " << ae->name);
811 storeAppendPrintf(entry, "%s %s %s ",
812 name,
813 ae->name,
814 ae->typeString());
815 v = w = ae->dump();
816
817 while (v != NULL) {
818 debugs(3, 3, "dump_acl: " << name << " " << ae->name << " " << v->key);
819 storeAppendPrintf(entry, "%s ", v->key);
820 v = v->next;
821 }
822
823 storeAppendPrintf(entry, "\n");
824 wordlistDestroy(&w);
825 ae = ae->next;
826 }
827 }
828
829 static void
830 parse_acl(ACL ** ae)
831 {
832 ACL::ParseAclLine(LegacyParser, ae);
833 }
834
835 static void
836 free_acl(ACL ** ae)
837 {
838 aclDestroyAcls(ae);
839 }
840
841 static void
842 dump_acl_list(StoreEntry * entry, acl_list * head)
843 {
844 acl_list *l;
845
846 for (l = head; l; l = l->next) {
847 storeAppendPrintf(entry, " %s%s",
848 l->op ? null_string : "!",
849 l->_acl->name);
850 }
851 }
852
853 void
854 dump_acl_access(StoreEntry * entry, const char *name, acl_access * head)
855 {
856 acl_access *l;
857
858 for (l = head; l; l = l->next) {
859 storeAppendPrintf(entry, "%s %s",
860 name,
861 l->allow ? "Allow" : "Deny");
862 dump_acl_list(entry, l->aclList);
863 storeAppendPrintf(entry, "\n");
864 }
865 }
866
867 static void
868 parse_acl_access(acl_access ** head)
869 {
870 aclParseAccessLine(LegacyParser, head);
871 }
872
873 static void
874 free_acl_access(acl_access ** head)
875 {
876 aclDestroyAccessList(head);
877 }
878
879 static void
880
881 dump_address(StoreEntry * entry, const char *name, struct IN_ADDR addr)
882 {
883 storeAppendPrintf(entry, "%s %s\n", name, inet_ntoa(addr));
884 }
885
886 static void
887
888 parse_address(struct IN_ADDR *addr)
889 {
890
891 const struct hostent *hp;
892 char *token = strtok(NULL, w_space);
893
894 if (token == NULL)
895 self_destruct();
896
897 if (safe_inet_addr(token, addr) == 1)
898 (void) 0;
899 else if ((hp = gethostbyname(token))) /* dont use ipcache */
900 *addr = inaddrFromHostent(hp);
901 else
902 self_destruct();
903 }
904
905 static void
906
907 free_address(struct IN_ADDR *addr)
908 {
909
910 memset(addr, '\0', sizeof(struct IN_ADDR));
911 }
912
913 CBDATA_TYPE(acl_address);
914
915 static void
916 dump_acl_address(StoreEntry * entry, const char *name, acl_address * head)
917 {
918 acl_address *l;
919
920 for (l = head; l; l = l->next) {
921 if (l->addr.s_addr != INADDR_ANY)
922 storeAppendPrintf(entry, "%s %s", name, inet_ntoa(l->addr));
923 else
924 storeAppendPrintf(entry, "%s autoselect", name);
925
926 dump_acl_list(entry, l->aclList);
927
928 storeAppendPrintf(entry, "\n");
929 }
930 }
931
932 static void
933 freed_acl_address(void *data)
934 {
935 acl_address *l = static_cast<acl_address *>(data);
936 aclDestroyAclList(&l->aclList);
937 }
938
939 static void
940 parse_acl_address(acl_address ** head)
941 {
942 acl_address *l;
943 acl_address **tail = head; /* sane name below */
944 CBDATA_INIT_TYPE_FREECB(acl_address, freed_acl_address);
945 l = cbdataAlloc(acl_address);
946 parse_address(&l->addr);
947 aclParseAclList(LegacyParser, &l->aclList);
948
949 while (*tail)
950 tail = &(*tail)->next;
951
952 *tail = l;
953 }
954
955 static void
956 free_acl_address(acl_address ** head)
957 {
958 while (*head) {
959 acl_address *l = *head;
960 *head = l->next;
961 cbdataFree(l);
962 }
963 }
964
965 CBDATA_TYPE(acl_tos);
966
967 static void
968 dump_acl_tos(StoreEntry * entry, const char *name, acl_tos * head)
969 {
970 acl_tos *l;
971
972 for (l = head; l; l = l->next) {
973 if (l->tos > 0)
974 storeAppendPrintf(entry, "%s 0x%02X", name, l->tos);
975 else
976 storeAppendPrintf(entry, "%s none", name);
977
978 dump_acl_list(entry, l->aclList);
979
980 storeAppendPrintf(entry, "\n");
981 }
982 }
983
984 static void
985 freed_acl_tos(void *data)
986 {
987 acl_tos *l = static_cast<acl_tos *>(data);
988 aclDestroyAclList(&l->aclList);
989 }
990
991 static void
992 parse_acl_tos(acl_tos ** head)
993 {
994 acl_tos *l;
995 acl_tos **tail = head; /* sane name below */
996 int tos;
997 char junk;
998 char *token = strtok(NULL, w_space);
999
1000 if (!token)
1001 self_destruct();
1002
1003 if (sscanf(token, "0x%x%c", &tos, &junk) != 1)
1004 self_destruct();
1005
1006 if (tos < 0 || tos > 255)
1007 self_destruct();
1008
1009 CBDATA_INIT_TYPE_FREECB(acl_tos, freed_acl_tos);
1010
1011 l = cbdataAlloc(acl_tos);
1012
1013 l->tos = tos;
1014
1015 aclParseAclList(LegacyParser, &l->aclList);
1016
1017 while (*tail)
1018 tail = &(*tail)->next;
1019
1020 *tail = l;
1021 }
1022
1023 static void
1024 free_acl_tos(acl_tos ** head)
1025 {
1026 while (*head) {
1027 acl_tos *l = *head;
1028 *head = l->next;
1029 l->next = NULL;
1030 cbdataFree(l);
1031 }
1032 }
1033
1034 CBDATA_TYPE(acl_size_t);
1035
1036 static void
1037 dump_acl_b_size_t(StoreEntry * entry, const char *name, acl_size_t * head)
1038 {
1039 acl_size_t *l;
1040
1041 for (l = head; l; l = l->next) {
1042 if (l->size != static_cast<size_t>(-1))
1043 storeAppendPrintf(entry, "%s %d %s\n", name, (int) l->size, B_BYTES_STR);
1044 else
1045 storeAppendPrintf(entry, "%s none", name);
1046
1047 dump_acl_list(entry, l->aclList);
1048
1049 storeAppendPrintf(entry, "\n");
1050 }
1051 }
1052
1053 static void
1054 freed_acl_b_size_t(void *data)
1055 {
1056 acl_size_t *l = static_cast<acl_size_t *>(data);
1057 aclDestroyAclList(&l->aclList);
1058 }
1059
1060 static void
1061 parse_acl_b_size_t(acl_size_t ** head)
1062 {
1063 acl_size_t *l;
1064 acl_size_t **tail = head; /* sane name below */
1065
1066 CBDATA_INIT_TYPE_FREECB(acl_size_t, freed_acl_b_size_t);
1067
1068 l = cbdataAlloc(acl_size_t);
1069
1070 parse_b_int64_t(&l->size);
1071
1072 aclParseAclList(LegacyParser, &l->aclList);
1073
1074 while (*tail)
1075 tail = &(*tail)->next;
1076
1077 *tail = l;
1078 }
1079
1080 static void
1081 free_acl_b_size_t(acl_size_t ** head)
1082 {
1083 while (*head) {
1084 acl_size_t *l = *head;
1085 *head = l->next;
1086 l->next = NULL;
1087 cbdataFree(l);
1088 }
1089 }
1090
1091 #if DELAY_POOLS
1092
1093 #include "DelayPools.h"
1094 #include "DelayConfig.h"
1095 /* do nothing - free_delay_pool_count is the magic free function.
1096 * this is why delay_pool_count isn't just marked TYPE: ushort
1097 */
1098 #define free_delay_pool_class(X)
1099 #define free_delay_pool_access(X)
1100 #define free_delay_pool_rates(X)
1101 #define dump_delay_pool_class(X, Y, Z)
1102 #define dump_delay_pool_access(X, Y, Z)
1103 #define dump_delay_pool_rates(X, Y, Z)
1104
1105 static void
1106 free_delay_pool_count(DelayConfig * cfg)
1107 {
1108 cfg->freePoolCount();
1109 }
1110
1111 static void
1112 dump_delay_pool_count(StoreEntry * entry, const char *name, DelayConfig &cfg)
1113 {
1114 cfg.dumpPoolCount (entry, name);
1115 }
1116
1117 static void
1118 parse_delay_pool_count(DelayConfig * cfg)
1119 {
1120 cfg->parsePoolCount();
1121 }
1122
1123 static void
1124 parse_delay_pool_class(DelayConfig * cfg)
1125 {
1126 cfg->parsePoolClass();
1127 }
1128
1129 static void
1130 parse_delay_pool_rates(DelayConfig * cfg)
1131 {
1132 cfg->parsePoolRates();
1133 }
1134
1135 static void
1136 parse_delay_pool_access(DelayConfig * cfg)
1137 {
1138 cfg->parsePoolAccess(LegacyParser);
1139 }
1140
1141 #endif
1142
1143 #if HTTP_VIOLATIONS
1144 static void
1145 dump_http_header_access(StoreEntry * entry, const char *name, header_mangler header[])
1146 {
1147 int i;
1148
1149 for (i = 0; i < HDR_ENUM_END; i++) {
1150 if (header[i].access_list != NULL) {
1151 storeAppendPrintf(entry, "%s ", name);
1152 dump_acl_access(entry, httpHeaderNameById(i),
1153 header[i].access_list);
1154 }
1155 }
1156 }
1157
1158 static void
1159 parse_http_header_access(header_mangler header[])
1160 {
1161 int id, i;
1162 char *t = NULL;
1163
1164 if ((t = strtok(NULL, w_space)) == NULL) {
1165 debugs(3, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
1166 debugs(3, 0, "parse_http_header_access: missing header name.");
1167 return;
1168 }
1169
1170 /* Now lookup index of header. */
1171 id = httpHeaderIdByNameDef(t, strlen(t));
1172
1173 if (strcmp(t, "All") == 0)
1174 id = HDR_ENUM_END;
1175 else if (strcmp(t, "Other") == 0)
1176 id = HDR_OTHER;
1177 else if (id == -1) {
1178 debugs(3, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
1179 debugs(3, 0, "parse_http_header_access: unknown header name '" << t << "'");
1180 return;
1181 }
1182
1183 if (id != HDR_ENUM_END) {
1184 parse_acl_access(&header[id].access_list);
1185 } else {
1186 char *next_string = t + strlen(t) - 1;
1187 *next_string = 'A';
1188 *(next_string + 1) = ' ';
1189
1190 for (i = 0; i < HDR_ENUM_END; i++) {
1191 char *new_string = xstrdup(next_string);
1192 strtok(new_string, w_space);
1193 parse_acl_access(&header[i].access_list);
1194 safe_free(new_string);
1195 }
1196 }
1197 }
1198
1199 static void
1200 free_http_header_access(header_mangler header[])
1201 {
1202 int i;
1203
1204 for (i = 0; i < HDR_ENUM_END; i++) {
1205 free_acl_access(&header[i].access_list);
1206 }
1207 }
1208
1209 static void
1210 dump_http_header_replace(StoreEntry * entry, const char *name, header_mangler
1211 header[])
1212 {
1213 int i;
1214
1215 for (i = 0; i < HDR_ENUM_END; i++) {
1216 if (NULL == header[i].replacement)
1217 continue;
1218
1219 storeAppendPrintf(entry, "%s %s %s\n", name, httpHeaderNameById(i),
1220 header[i].replacement);
1221 }
1222 }
1223
1224 static void
1225 parse_http_header_replace(header_mangler header[])
1226 {
1227 int id, i;
1228 char *t = NULL;
1229
1230 if ((t = strtok(NULL, w_space)) == NULL) {
1231 debugs(3, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
1232 debugs(3, 0, "parse_http_header_replace: missing header name.");
1233 return;
1234 }
1235
1236 /* Now lookup index of header. */
1237 id = httpHeaderIdByNameDef(t, strlen(t));
1238
1239 if (strcmp(t, "All") == 0)
1240 id = HDR_ENUM_END;
1241 else if (strcmp(t, "Other") == 0)
1242 id = HDR_OTHER;
1243 else if (id == -1) {
1244 debugs(3, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
1245 debugs(3, 0, "parse_http_header_replace: unknown header name " << t << ".");
1246
1247 return;
1248 }
1249
1250 if (id != HDR_ENUM_END) {
1251 if (header[id].replacement != NULL)
1252 safe_free(header[id].replacement);
1253
1254 header[id].replacement = xstrdup(t + strlen(t) + 1);
1255 } else {
1256 for (i = 0; i < HDR_ENUM_END; i++) {
1257 if (header[i].replacement != NULL)
1258 safe_free(header[i].replacement);
1259
1260 header[i].replacement = xstrdup(t + strlen(t) + 1);
1261 }
1262 }
1263 }
1264
1265 static void
1266 free_http_header_replace(header_mangler header[])
1267 {
1268 int i;
1269
1270 for (i = 0; i < HDR_ENUM_END; i++) {
1271 if (header[i].replacement != NULL)
1272 safe_free(header[i].replacement);
1273 }
1274 }
1275
1276 #endif
1277
1278 static void
1279 dump_cachedir(StoreEntry * entry, const char *name, _SquidConfig::_cacheSwap swap)
1280 {
1281 SwapDir *s;
1282 int i;
1283 assert (entry);
1284
1285 for (i = 0; i < swap.n_configured; i++) {
1286 s = dynamic_cast<SwapDir *>(swap.swapDirs[i].getRaw());
1287 if(!s) continue;
1288 storeAppendPrintf(entry, "%s %s %s", name, s->type(), s->path);
1289 s->dump(*entry);
1290 storeAppendPrintf(entry, "\n");
1291 }
1292 }
1293
1294 static int
1295 check_null_cachedir(_SquidConfig::_cacheSwap swap)
1296 {
1297 return swap.swapDirs == NULL;
1298 }
1299
1300 static int
1301 check_null_string(char *s)
1302 {
1303 return s == NULL;
1304 }
1305
1306 static void
1307 parse_authparam(authConfig * config)
1308 {
1309 char *type_str;
1310 char *param_str;
1311
1312 if ((type_str = strtok(NULL, w_space)) == NULL)
1313 self_destruct();
1314
1315 if ((param_str = strtok(NULL, w_space)) == NULL)
1316 self_destruct();
1317
1318 /* find a configuration for the scheme */
1319 AuthConfig *scheme = AuthConfig::Find (type_str);
1320
1321 if (scheme == NULL) {
1322 /* Create a configuration */
1323 AuthScheme *theScheme;
1324
1325 if ((theScheme = AuthScheme::Find(type_str)) == NULL) {
1326 debugs(3, 0, "Parsing Config File: Unknown authentication scheme '" << type_str << "'.");
1327 return;
1328 }
1329
1330 config->push_back(theScheme->createConfig());
1331 scheme = config->back();
1332 assert (scheme);
1333 }
1334
1335 scheme->parse(scheme, config->size(), param_str);
1336 }
1337
1338 static void
1339 free_authparam(authConfig * cfg)
1340 {
1341 AuthConfig *scheme;
1342 /* DON'T FREE THESE FOR RECONFIGURE */
1343
1344 if (reconfiguring)
1345 return;
1346
1347 while (cfg->size()) {
1348 scheme = cfg->pop_back();
1349 scheme->done();
1350 }
1351 }
1352
1353 static void
1354 dump_authparam(StoreEntry * entry, const char *name, authConfig cfg)
1355 {
1356 for (authConfig::iterator i = cfg.begin(); i != cfg.end(); ++i)
1357 (*i)->dump(entry, name, (*i));
1358 }
1359
1360 /* TODO: just return the object, the # is irrelevant */
1361 static int
1362 find_fstype(char *type)
1363 {
1364 for (size_t i = 0; i < StoreFileSystem::FileSystems().size(); ++i)
1365 if (strcasecmp(type, StoreFileSystem::FileSystems().items[i]->type()) == 0)
1366 return (int)i;
1367
1368 return (-1);
1369 }
1370
1371 static void
1372 parse_cachedir(_SquidConfig::_cacheSwap * swap)
1373 {
1374 char *type_str;
1375 char *path_str;
1376 RefCount<SwapDir> sd;
1377 int i;
1378 int fs;
1379
1380 if ((type_str = strtok(NULL, w_space)) == NULL)
1381 self_destruct();
1382
1383 if ((path_str = strtok(NULL, w_space)) == NULL)
1384 self_destruct();
1385
1386 fs = find_fstype(type_str);
1387
1388 if (fs < 0)
1389 self_destruct();
1390
1391 /* reconfigure existing dir */
1392
1393 for (i = 0; i < swap->n_configured; i++) {
1394 assert (swap->swapDirs[i].getRaw());
1395
1396 if ((strcasecmp(path_str, dynamic_cast<SwapDir *>(swap->swapDirs[i].getRaw())->path)
1397 ) == 0) {
1398 /* this is specific to on-fs Stores. The right
1399 * way to handle this is probably to have a mapping
1400 * from paths to stores, and have on-fs stores
1401 * register with that, and lookip in that in their
1402 * own setup logic. RBC 20041225. TODO.
1403 */
1404
1405 sd = dynamic_cast<SwapDir *>(swap->swapDirs[i].getRaw());
1406
1407 if (sd->type() != StoreFileSystem::FileSystems().items[fs]->type()) {
1408 debugs(3, 0, "ERROR: Can't change type of existing cache_dir " <<
1409 sd->type() << " " << sd->path << " to " << type_str << ". Restart required");
1410 return;
1411 }
1412
1413 sd->reconfigure (i, path_str);
1414
1415 update_maxobjsize();
1416
1417 return;
1418 }
1419 }
1420
1421 /* new cache_dir */
1422 assert(swap->n_configured < 63); /* 7 bits, signed */
1423
1424 allocate_new_swapdir(swap);
1425
1426 swap->swapDirs[swap->n_configured] = StoreFileSystem::FileSystems().items[fs]->createSwapDir();
1427
1428 sd = dynamic_cast<SwapDir *>(swap->swapDirs[swap->n_configured].getRaw());
1429
1430 /* parse the FS parameters and options */
1431 sd->parse(swap->n_configured, path_str);
1432
1433 ++swap->n_configured;
1434
1435 /* Update the max object size */
1436 update_maxobjsize();
1437 }
1438
1439 static const char *
1440 peer_type_str(const peer_t type)
1441 {
1442 const char * result;
1443
1444 switch (type) {
1445
1446 case PEER_PARENT:
1447 result = "parent";
1448 break;
1449
1450 case PEER_SIBLING:
1451 result = "sibling";
1452 break;
1453
1454 case PEER_MULTICAST:
1455 result = "multicast";
1456 break;
1457
1458 default:
1459 result = "unknown";
1460 break;
1461 }
1462
1463 return result;
1464 }
1465
1466 static void
1467 dump_peer(StoreEntry * entry, const char *name, peer * p)
1468 {
1469 domain_ping *d;
1470 domain_type *t;
1471 LOCAL_ARRAY(char, xname, 128);
1472
1473 while (p != NULL) {
1474 storeAppendPrintf(entry, "%s %s %s %d %d",
1475 name,
1476 p->host,
1477 neighborTypeStr(p),
1478 p->http_port,
1479 p->icp.port);
1480 dump_peer_options(entry, p);
1481
1482 for (d = p->peer_domain; d; d = d->next) {
1483 storeAppendPrintf(entry, "cache_peer_domain %s %s%s\n",
1484 p->host,
1485 d->do_ping ? null_string : "!",
1486 d->domain);
1487 }
1488
1489 if (p->access) {
1490 snprintf(xname, 128, "cache_peer_access %s", p->name);
1491 dump_acl_access(entry, xname, p->access);
1492 }
1493
1494 for (t = p->typelist; t; t = t->next) {
1495 storeAppendPrintf(entry, "neighbor_type_domain %s %s %s\n",
1496 p->host,
1497 peer_type_str(t->type),
1498 t->domain);
1499 }
1500
1501 p = p->next;
1502 }
1503 }
1504
1505 static void
1506 parse_peer(peer ** head)
1507 {
1508 char *token = NULL;
1509 peer *p;
1510 CBDATA_INIT_TYPE_FREECB(peer, peerDestroy);
1511 p = cbdataAlloc(peer);
1512 p->http_port = CACHE_HTTP_PORT;
1513 p->icp.port = CACHE_ICP_PORT;
1514 p->weight = 1;
1515 p->basetime = 0;
1516 p->stats.logged_state = PEER_ALIVE;
1517
1518 if ((token = strtok(NULL, w_space)) == NULL)
1519 self_destruct();
1520
1521 p->host = xstrdup(token);
1522
1523 p->name = xstrdup(token);
1524
1525 if ((token = strtok(NULL, w_space)) == NULL)
1526 self_destruct();
1527
1528 p->type = parseNeighborType(token);
1529
1530 if (p->type == PEER_MULTICAST) {
1531 p->options.no_digest = 1;
1532 p->options.no_netdb_exchange = 1;
1533 }
1534
1535 p->http_port = GetShort();
1536
1537 if (!p->http_port)
1538 self_destruct();
1539
1540 p->icp.port = GetShort();
1541
1542 while ((token = strtok(NULL, w_space))) {
1543 if (!strcasecmp(token, "proxy-only")) {
1544 p->options.proxy_only = 1;
1545 } else if (!strcasecmp(token, "no-query")) {
1546 p->options.no_query = 1;
1547 } else if (!strcasecmp(token, "background-ping")) {
1548 p->options.background_ping = 1;
1549 } else if (!strcasecmp(token, "no-digest")) {
1550 p->options.no_digest = 1;
1551 } else if (!strcasecmp(token, "multicast-responder")) {
1552 p->options.mcast_responder = 1;
1553 } else if (!strncasecmp(token, "weight=", 7)) {
1554 p->weight = xatoi(token + 7);
1555 } else if (!strncasecmp(token, "basetime=", 9)) {
1556 p->basetime = xatoi(token + 9);
1557 } else if (!strcasecmp(token, "closest-only")) {
1558 p->options.closest_only = 1;
1559 } else if (!strncasecmp(token, "ttl=", 4)) {
1560 p->mcast.ttl = xatoi(token + 4);
1561
1562 if (p->mcast.ttl < 0)
1563 p->mcast.ttl = 0;
1564
1565 if (p->mcast.ttl > 128)
1566 p->mcast.ttl = 128;
1567 } else if (!strcasecmp(token, "default")) {
1568 p->options.default_parent = 1;
1569 } else if (!strcasecmp(token, "round-robin")) {
1570 p->options.roundrobin = 1;
1571 } else if (!strcasecmp(token, "weighted-round-robin")) {
1572 p->options.weighted_roundrobin = 1;
1573 #if USE_HTCP
1574
1575 } else if (!strcasecmp(token, "htcp")) {
1576 p->options.htcp = 1;
1577 } else if (!strcasecmp(token, "htcp-oldsquid")) {
1578 p->options.htcp = 1;
1579 p->options.htcp_oldsquid = 1;
1580 #endif
1581
1582 } else if (!strcasecmp(token, "no-netdb-exchange")) {
1583 p->options.no_netdb_exchange = 1;
1584 #if USE_CARP
1585
1586 } else if (!strcasecmp(token, "carp")) {
1587 if (p->type != PEER_PARENT)
1588 fatalf("parse_peer: non-parent carp peer %s/%d\n", p->host, p->http_port);
1589
1590 p->options.carp = 1;
1591
1592 #endif
1593 #if DELAY_POOLS
1594
1595 } else if (!strcasecmp(token, "no-delay")) {
1596 p->options.no_delay = 1;
1597 #endif
1598
1599 } else if (!strncasecmp(token, "login=", 6)) {
1600 p->login = xstrdup(token + 6);
1601 rfc1738_unescape(p->login);
1602 } else if (!strncasecmp(token, "connect-timeout=", 16)) {
1603 p->connect_timeout = xatoi(token + 16);
1604 #if USE_CACHE_DIGESTS
1605
1606 } else if (!strncasecmp(token, "digest-url=", 11)) {
1607 p->digest_url = xstrdup(token + 11);
1608 #endif
1609
1610 } else if (!strcasecmp(token, "allow-miss")) {
1611 p->options.allow_miss = 1;
1612 } else if (!strncasecmp(token, "max-conn=", 9)) {
1613 p->max_conn = xatoi(token + 9);
1614 } else if (!strcasecmp(token, "originserver")) {
1615 p->options.originserver = 1;
1616 } else if (!strncasecmp(token, "name=", 5)) {
1617 safe_free(p->name);
1618
1619 if (token[5])
1620 p->name = xstrdup(token + 5);
1621 } else if (!strncasecmp(token, "forceddomain=", 13)) {
1622 safe_free(p->domain);
1623
1624 if (token[13])
1625 p->domain = xstrdup(token + 13);
1626
1627 #if USE_SSL
1628
1629 } else if (strcmp(token, "ssl") == 0) {
1630 p->use_ssl = 1;
1631 } else if (strncmp(token, "sslcert=", 8) == 0) {
1632 safe_free(p->sslcert);
1633 p->sslcert = xstrdup(token + 8);
1634 } else if (strncmp(token, "sslkey=", 7) == 0) {
1635 safe_free(p->sslkey);
1636 p->sslkey = xstrdup(token + 7);
1637 } else if (strncmp(token, "sslversion=", 11) == 0) {
1638 p->sslversion = atoi(token + 11);
1639 } else if (strncmp(token, "ssloptions=", 11) == 0) {
1640 safe_free(p->ssloptions);
1641 p->ssloptions = xstrdup(token + 11);
1642 } else if (strncmp(token, "sslcipher=", 10) == 0) {
1643 safe_free(p->sslcipher);
1644 p->sslcipher = xstrdup(token + 10);
1645 } else if (strncmp(token, "sslcafile=", 10) == 0) {
1646 safe_free(p->sslcafile);
1647 p->sslcafile = xstrdup(token + 10);
1648 } else if (strncmp(token, "sslcapath=", 10) == 0) {
1649 safe_free(p->sslcapath);
1650 p->sslcapath = xstrdup(token + 10);
1651 } else if (strncmp(token, "sslcrlfile=", 11) == 0) {
1652 safe_free(p->sslcrlfile);
1653 p->sslcapath = xstrdup(token + 10);
1654 } else if (strncmp(token, "sslflags=", 9) == 0) {
1655 safe_free(p->sslflags);
1656 p->sslflags = xstrdup(token + 9);
1657 } else if (strncmp(token, "ssldomain=", 10) == 0) {
1658 safe_free(p->ssldomain);
1659 p->ssldomain = xstrdup(token + 10);
1660 #endif
1661
1662 } else if (strcmp(token, "front-end-https") == 0) {
1663 p->front_end_https = 1;
1664 } else if (strcmp(token, "front-end-https=on") == 0) {
1665 p->front_end_https = 1;
1666 } else if (strcmp(token, "front-end-https=auto") == 0) {
1667 p->front_end_https = 2;
1668 } else {
1669 debugs(3, 0, "parse_peer: token='" << token << "'");
1670 self_destruct();
1671 }
1672 }
1673
1674 if (peerFindByName(p->name))
1675 fatalf("ERROR: cache_peer %s specified twice\n", p->name);
1676
1677 if (p->weight < 1)
1678 p->weight = 1;
1679
1680 p->icp.version = ICP_VERSION_CURRENT;
1681
1682 p->test_fd = -1;
1683
1684 #if USE_CACHE_DIGESTS
1685
1686 if (!p->options.no_digest) {
1687 /* XXX This looks odd.. who has the original pointer
1688 * then?
1689 */
1690 PeerDigest *pd = peerDigestCreate(p);
1691 p->digest = cbdataReference(pd);
1692 }
1693
1694 #endif
1695 while (*head != NULL)
1696 head = &(*head)->next;
1697
1698 *head = p;
1699
1700 Config.npeers++;
1701
1702 peerClearRR(p);
1703 }
1704
1705 static void
1706 free_peer(peer ** P)
1707 {
1708 peer *p;
1709
1710 while ((p = *P) != NULL) {
1711 *P = p->next;
1712 #if USE_CACHE_DIGESTS
1713
1714 cbdataReferenceDone(p->digest);
1715 #endif
1716
1717 cbdataFree(p);
1718 }
1719
1720 Config.npeers = 0;
1721 }
1722
1723 static void
1724 dump_cachemgrpasswd(StoreEntry * entry, const char *name, cachemgr_passwd * list)
1725 {
1726 wordlist *w;
1727
1728 while (list != NULL) {
1729 if (strcmp(list->passwd, "none") && strcmp(list->passwd, "disable"))
1730 storeAppendPrintf(entry, "%s XXXXXXXXXX", name);
1731 else
1732 storeAppendPrintf(entry, "%s %s", name, list->passwd);
1733
1734 for (w = list->actions; w != NULL; w = w->next) {
1735 storeAppendPrintf(entry, " %s", w->key);
1736 }
1737
1738 storeAppendPrintf(entry, "\n");
1739 list = list->next;
1740 }
1741 }
1742
1743 static void
1744 parse_cachemgrpasswd(cachemgr_passwd ** head)
1745 {
1746 char *passwd = NULL;
1747 wordlist *actions = NULL;
1748 cachemgr_passwd *p;
1749 cachemgr_passwd **P;
1750 parse_string(&passwd);
1751 parse_wordlist(&actions);
1752 p = static_cast<cachemgr_passwd *>(xcalloc(1, sizeof(cachemgr_passwd)));
1753 p->passwd = passwd;
1754 p->actions = actions;
1755
1756 for (P = head; *P; P = &(*P)->next) {
1757 /*
1758 * See if any of the actions from this line already have a
1759 * password from previous lines. The password checking
1760 * routines in cache_manager.c take the the password from
1761 * the first cachemgr_passwd struct that contains the
1762 * requested action. Thus, we should warn users who might
1763 * think they can have two passwords for the same action.
1764 */
1765 wordlist *w;
1766 wordlist *u;
1767
1768 for (w = (*P)->actions; w; w = w->next) {
1769 for (u = actions; u; u = u->next) {
1770 if (strcmp(w->key, u->key))
1771 continue;
1772
1773 debugs(0, 0, "WARNING: action '" << u->key << "' (line " << config_lineno << ") already has a password");
1774 }
1775 }
1776 }
1777
1778 *P = p;
1779 }
1780
1781 static void
1782 free_cachemgrpasswd(cachemgr_passwd ** head)
1783 {
1784 cachemgr_passwd *p;
1785
1786 while ((p = *head) != NULL) {
1787 *head = p->next;
1788 xfree(p->passwd);
1789 wordlistDestroy(&p->actions);
1790 xfree(p);
1791 }
1792 }
1793
1794 static void
1795 dump_denyinfo(StoreEntry * entry, const char *name, acl_deny_info_list * var)
1796 {
1797 acl_name_list *a;
1798
1799 while (var != NULL) {
1800 storeAppendPrintf(entry, "%s %s", name, var->err_page_name);
1801
1802 for (a = var->acl_list; a != NULL; a = a->next)
1803 storeAppendPrintf(entry, " %s", a->name);
1804
1805 storeAppendPrintf(entry, "\n");
1806
1807 var = var->next;
1808 }
1809 }
1810
1811 static void
1812 parse_denyinfo(acl_deny_info_list ** var)
1813 {
1814 aclParseDenyInfoLine(var);
1815 }
1816
1817 void
1818 free_denyinfo(acl_deny_info_list ** list)
1819 {
1820 acl_deny_info_list *a = NULL;
1821 acl_deny_info_list *a_next = NULL;
1822 acl_name_list *l = NULL;
1823 acl_name_list *l_next = NULL;
1824
1825 for (a = *list; a; a = a_next) {
1826 for (l = a->acl_list; l; l = l_next) {
1827 l_next = l->next;
1828 memFree(l, MEM_ACL_NAME_LIST);
1829 l = NULL;
1830 }
1831
1832 a_next = a->next;
1833 memFree(a, MEM_ACL_DENY_INFO_LIST);
1834 a = NULL;
1835 }
1836
1837 *list = NULL;
1838 }
1839
1840 static void
1841 parse_peer_access(void)
1842 {
1843 char *host = NULL;
1844 peer *p;
1845
1846 if (!(host = strtok(NULL, w_space)))
1847 self_destruct();
1848
1849 if ((p = peerFindByName(host)) == NULL) {
1850 debugs(15, 0, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'");
1851 return;
1852 }
1853
1854 aclParseAccessLine(LegacyParser, &p->access);
1855 }
1856
1857 static void
1858 parse_hostdomain(void)
1859 {
1860 char *host = NULL;
1861 char *domain = NULL;
1862
1863 if (!(host = strtok(NULL, w_space)))
1864 self_destruct();
1865
1866 while ((domain = strtok(NULL, list_sep))) {
1867 domain_ping *l = NULL;
1868 domain_ping **L = NULL;
1869 peer *p;
1870
1871 if ((p = peerFindByName(host)) == NULL) {
1872 debugs(15, 0, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'");
1873 continue;
1874 }
1875
1876 l = static_cast<domain_ping *>(xcalloc(1, sizeof(domain_ping)));
1877 l->do_ping = 1;
1878
1879 if (*domain == '!') { /* check for !.edu */
1880 l->do_ping = 0;
1881 domain++;
1882 }
1883
1884 l->domain = xstrdup(domain);
1885
1886 for (L = &(p->peer_domain); *L; L = &((*L)->next))
1887
1888 ;
1889 *L = l;
1890 }
1891 }
1892
1893 static void
1894 parse_hostdomaintype(void)
1895 {
1896 char *host = NULL;
1897 char *type = NULL;
1898 char *domain = NULL;
1899
1900 if (!(host = strtok(NULL, w_space)))
1901 self_destruct();
1902
1903 if (!(type = strtok(NULL, w_space)))
1904 self_destruct();
1905
1906 while ((domain = strtok(NULL, list_sep))) {
1907 domain_type *l = NULL;
1908 domain_type **L = NULL;
1909 peer *p;
1910
1911 if ((p = peerFindByName(host)) == NULL) {
1912 debugs(15, 0, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'");
1913 return;
1914 }
1915
1916 l = static_cast<domain_type *>(xcalloc(1, sizeof(domain_type)));
1917 l->type = parseNeighborType(type);
1918 l->domain = xstrdup(domain);
1919
1920 for (L = &(p->typelist); *L; L = &((*L)->next))
1921
1922 ;
1923 *L = l;
1924 }
1925 }
1926
1927 static void
1928 dump_int(StoreEntry * entry, const char *name, int var)
1929 {
1930 storeAppendPrintf(entry, "%s %d\n", name, var);
1931 }
1932
1933 void
1934 parse_int(int *var)
1935 {
1936 int i;
1937 i = GetInteger();
1938 *var = i;
1939 }
1940
1941 static void
1942 free_int(int *var)
1943 {
1944 *var = 0;
1945 }
1946
1947 static void
1948 dump_onoff(StoreEntry * entry, const char *name, int var)
1949 {
1950 storeAppendPrintf(entry, "%s %s\n", name, var ? "on" : "off");
1951 }
1952
1953 void
1954 parse_onoff(int *var)
1955 {
1956 char *token = strtok(NULL, w_space);
1957
1958 if (token == NULL)
1959 self_destruct();
1960
1961 if (!strcasecmp(token, "on") || !strcasecmp(token, "enable"))
1962 *var = 1;
1963 else
1964 *var = 0;
1965 }
1966
1967 #define free_onoff free_int
1968
1969 static void
1970 dump_tristate(StoreEntry * entry, const char *name, int var)
1971 {
1972 const char *state;
1973
1974 if (var > 0)
1975 state = "on";
1976 else if (var < 0)
1977 state = "warn";
1978 else
1979 state = "off";
1980
1981 storeAppendPrintf(entry, "%s %s\n", name, state);
1982 }
1983
1984 static void
1985 parse_tristate(int *var)
1986 {
1987 char *token = strtok(NULL, w_space);
1988
1989 if (token == NULL)
1990 self_destruct();
1991
1992 if (!strcasecmp(token, "on") || !strcasecmp(token, "enable"))
1993 *var = 1;
1994 else if (!strcasecmp(token, "warn"))
1995 *var = -1;
1996 else
1997 *var = 0;
1998 }
1999
2000 #define free_tristate free_int
2001
2002 static void
2003 dump_refreshpattern(StoreEntry * entry, const char *name, refresh_t * head)
2004 {
2005 while (head != NULL) {
2006 storeAppendPrintf(entry, "%s%s %s %d %d%% %d\n",
2007 name,
2008 head->flags.icase ? " -i" : null_string,
2009 head->pattern,
2010 (int) head->min / 60,
2011 (int) (100.0 * head->pct + 0.5),
2012 (int) head->max / 60);
2013
2014 if (head->flags.refresh_ims)
2015 storeAppendPrintf(entry, " refresh-ims");
2016
2017 #if HTTP_VIOLATIONS
2018
2019 if (head->flags.override_expire)
2020 storeAppendPrintf(entry, " override-expire");
2021
2022 if (head->flags.override_lastmod)
2023 storeAppendPrintf(entry, " override-lastmod");
2024
2025 if (head->flags.reload_into_ims)
2026 storeAppendPrintf(entry, " reload-into-ims");
2027
2028 if (head->flags.ignore_reload)
2029 storeAppendPrintf(entry, " ignore-reload");
2030
2031 if (head->flags.ignore_no_cache)
2032 storeAppendPrintf(entry, " ignore-no-cache");
2033
2034 if (head->flags.ignore_no_store)
2035 storeAppendPrintf(entry, " ignore-no-store");
2036
2037 if (head->flags.ignore_private)
2038 storeAppendPrintf(entry, " ignore-private");
2039
2040 if (head->flags.ignore_auth)
2041 storeAppendPrintf(entry, " ignore-auth");
2042
2043 #endif
2044
2045 storeAppendPrintf(entry, "\n");
2046
2047 head = head->next;
2048 }
2049 }
2050
2051 static void
2052 parse_refreshpattern(refresh_t ** head)
2053 {
2054 char *token;
2055 char *pattern;
2056 time_t min = 0;
2057 double pct = 0.0;
2058 time_t max = 0;
2059 int refresh_ims = 0;
2060 #if HTTP_VIOLATIONS
2061
2062 int override_expire = 0;
2063 int override_lastmod = 0;
2064 int reload_into_ims = 0;
2065 int ignore_reload = 0;
2066 int ignore_no_cache = 0;
2067 int ignore_no_store = 0;
2068 int ignore_private = 0;
2069 int ignore_auth = 0;
2070 #endif
2071
2072 int i;
2073 refresh_t *t;
2074 regex_t comp;
2075 int errcode;
2076 int flags = REG_EXTENDED | REG_NOSUB;
2077
2078 if ((token = strtok(NULL, w_space)) == NULL)
2079 self_destruct();
2080
2081 if (strcmp(token, "-i") == 0) {
2082 flags |= REG_ICASE;
2083 token = strtok(NULL, w_space);
2084 } else if (strcmp(token, "+i") == 0) {
2085 flags &= ~REG_ICASE;
2086 token = strtok(NULL, w_space);
2087 }
2088
2089 if (token == NULL)
2090 self_destruct();
2091
2092 pattern = xstrdup(token);
2093
2094 i = GetInteger(); /* token: min */
2095
2096 min = (time_t) (i * 60); /* convert minutes to seconds */
2097
2098 i = GetInteger(); /* token: pct */
2099
2100 pct = (double) i / 100.0;
2101
2102 i = GetInteger(); /* token: max */
2103
2104 max = (time_t) (i * 60); /* convert minutes to seconds */
2105
2106 /* Options */
2107 while ((token = strtok(NULL, w_space)) != NULL) {
2108 if (!strcmp(token, "refresh-ims")) {
2109 refresh_ims = 1;
2110 #if HTTP_VIOLATIONS
2111
2112 } else if (!strcmp(token, "override-expire"))
2113 override_expire = 1;
2114 else if (!strcmp(token, "override-lastmod"))
2115 override_lastmod = 1;
2116 else if (!strcmp(token, "ignore-no-cache"))
2117 ignore_no_cache = 1;
2118 else if (!strcmp(token, "ignore-no-store"))
2119 ignore_no_store = 1;
2120 else if (!strcmp(token, "ignore-private"))
2121 ignore_private = 1;
2122 else if (!strcmp(token, "ignore-auth"))
2123 ignore_auth = 1;
2124 else if (!strcmp(token, "reload-into-ims")) {
2125 reload_into_ims = 1;
2126 refresh_nocache_hack = 1;
2127 /* tell client_side.c that this is used */
2128 } else if (!strcmp(token, "ignore-reload")) {
2129 ignore_reload = 1;
2130 refresh_nocache_hack = 1;
2131 /* tell client_side.c that this is used */
2132 #endif
2133
2134 } else
2135 debugs(22, 0, "redreshAddToList: Unknown option '" << pattern << "': " << token);
2136 }
2137
2138 if ((errcode = regcomp(&comp, pattern, flags)) != 0) {
2139 char errbuf[256];
2140 regerror(errcode, &comp, errbuf, sizeof errbuf);
2141 debugs(22, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
2142 debugs(22, 0, "refreshAddToList: Invalid regular expression '" << pattern << "': " << errbuf);
2143 return;
2144 }
2145
2146 pct = pct < 0.0 ? 0.0 : pct;
2147 max = max < 0 ? 0 : max;
2148 t = static_cast<refresh_t *>(xcalloc(1, sizeof(refresh_t)));
2149 t->pattern = (char *) xstrdup(pattern);
2150 t->compiled_pattern = comp;
2151 t->min = min;
2152 t->pct = pct;
2153 t->max = max;
2154
2155 if (flags & REG_ICASE)
2156 t->flags.icase = 1;
2157
2158 if (refresh_ims)
2159 t->flags.refresh_ims = 1;
2160
2161 #if HTTP_VIOLATIONS
2162
2163 if (override_expire)
2164 t->flags.override_expire = 1;
2165
2166 if (override_lastmod)
2167 t->flags.override_lastmod = 1;
2168
2169 if (reload_into_ims)
2170 t->flags.reload_into_ims = 1;
2171
2172 if (ignore_reload)
2173 t->flags.ignore_reload = 1;
2174
2175 if (ignore_no_cache)
2176 t->flags.ignore_no_cache = 1;
2177
2178 if (ignore_no_store)
2179 t->flags.ignore_no_store = 1;
2180
2181 if (ignore_private)
2182 t->flags.ignore_private = 1;
2183
2184 if (ignore_auth)
2185 t->flags.ignore_auth = 1;
2186
2187 #endif
2188
2189 t->next = NULL;
2190
2191 while (*head)
2192 head = &(*head)->next;
2193
2194 *head = t;
2195
2196 safe_free(pattern);
2197 }
2198
2199 static void
2200 free_refreshpattern(refresh_t ** head)
2201 {
2202 refresh_t *t;
2203
2204 while ((t = *head) != NULL) {
2205 *head = t->next;
2206 safe_free(t->pattern);
2207 regfree(&t->compiled_pattern);
2208 safe_free(t);
2209 }
2210
2211 #if HTTP_VIOLATIONS
2212 refresh_nocache_hack = 0;
2213
2214 #endif
2215 }
2216
2217 static void
2218 dump_string(StoreEntry * entry, const char *name, char *var)
2219 {
2220 if (var != NULL)
2221 storeAppendPrintf(entry, "%s %s\n", name, var);
2222 }
2223
2224 static void
2225 parse_string(char **var)
2226 {
2227 char *token = strtok(NULL, w_space);
2228 safe_free(*var);
2229
2230 if (token == NULL)
2231 self_destruct();
2232
2233 *var = xstrdup(token);
2234 }
2235
2236 void
2237 ConfigParser::ParseString(char **var)
2238 {
2239 parse_string(var);
2240 }
2241
2242 void
2243 ConfigParser::ParseString(String *var)
2244 {
2245 char *token = strtok(NULL, w_space);
2246
2247 if (token == NULL)
2248 self_destruct();
2249
2250 var->reset(token);
2251 }
2252
2253 static void
2254 free_string(char **var)
2255 {
2256 safe_free(*var);
2257 }
2258
2259 void
2260 parse_eol(char *volatile *var)
2261 {
2262 unsigned char *token = (unsigned char *) strtok(NULL, null_string);
2263 safe_free(*var);
2264
2265 if (token == NULL)
2266 self_destruct();
2267
2268 while (*token && xisspace(*token))
2269 token++;
2270
2271 if (!*token)
2272 self_destruct();
2273
2274 *var = xstrdup((char *) token);
2275 }
2276
2277 #define dump_eol dump_string
2278 #define free_eol free_string
2279
2280 void
2281 parse_debug(char *volatile *var)
2282 {
2283 parse_eol(var);
2284 safe_free(debug_options)
2285 debug_options = xstrdup(Config.debugOptions);
2286 Debug::parseOptions(Config.debugOptions);
2287 }
2288
2289 #define dump_debug dump_string
2290 #define free_debug free_string
2291
2292 static void
2293 dump_time_t(StoreEntry * entry, const char *name, time_t var)
2294 {
2295 storeAppendPrintf(entry, "%s %d seconds\n", name, (int) var);
2296 }
2297
2298 void
2299 parse_time_t(time_t * var)
2300 {
2301 parseTimeLine(var, T_SECOND_STR);
2302 }
2303
2304 static void
2305 free_time_t(time_t * var)
2306 {
2307 *var = 0;
2308 }
2309
2310 static void
2311 dump_size_t(StoreEntry * entry, const char *name, size_t var)
2312 {
2313 storeAppendPrintf(entry, "%s %d\n", name, (int) var);
2314 }
2315
2316 static void
2317 dump_b_size_t(StoreEntry * entry, const char *name, size_t var)
2318 {
2319 storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_BYTES_STR);
2320 }
2321
2322 static void
2323 dump_kb_size_t(StoreEntry * entry, const char *name, size_t var)
2324 {
2325 storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_KBYTES_STR);
2326 }
2327
2328 static void
2329 dump_b_int64_t(StoreEntry * entry, const char *name, int64_t var)
2330 {
2331 storeAppendPrintf(entry, "%s %"PRId64" %s\n", name, var, B_BYTES_STR);
2332 }
2333
2334 static void
2335 dump_kb_int64_t(StoreEntry * entry, const char *name, int64_t var)
2336 {
2337 storeAppendPrintf(entry, "%s %"PRId64" %s\n", name, var, B_KBYTES_STR);
2338 }
2339
2340 static void
2341 parse_size_t(size_t * var)
2342 {
2343 int i;
2344 i = GetInteger();
2345 *var = (size_t) i;
2346 }
2347
2348 static void
2349 parse_b_size_t(size_t * var)
2350 {
2351 parseBytesLine(var, B_BYTES_STR);
2352 }
2353
2354 static void
2355 parse_kb_size_t(size_t * var)
2356 {
2357 parseBytesLine(var, B_KBYTES_STR);
2358 }
2359
2360 static void
2361 parse_b_int64_t(int64_t * var)
2362 {
2363 parseBytesLine64(var, B_BYTES_STR);
2364 }
2365
2366 static void
2367 parse_kb_int64_t(int64_t * var)
2368 {
2369 parseBytesLine64(var, B_KBYTES_STR);
2370 }
2371
2372 static void
2373 free_size_t(size_t * var)
2374 {
2375 *var = 0;
2376 }
2377
2378 static void
2379 free_b_int64_t(int64_t * var)
2380 {
2381 *var = 0;
2382 }
2383
2384 #define free_b_size_t free_size_t
2385 #define free_kb_size_t free_size_t
2386 #define free_mb_size_t free_size_t
2387 #define free_gb_size_t free_size_t
2388 #define free_kb_int64_t free_b_int64_t
2389
2390 static void
2391 dump_ushort(StoreEntry * entry, const char *name, u_short var)
2392 {
2393 storeAppendPrintf(entry, "%s %d\n", name, var);
2394 }
2395
2396 static void
2397 free_ushort(u_short * u)
2398 {
2399 *u = 0;
2400 }
2401
2402 static void
2403 parse_ushort(u_short * var)
2404 {
2405 ConfigParser::ParseUShort(var);
2406 }
2407
2408 void
2409 ConfigParser::ParseUShort(u_short *var)
2410 {
2411 *var = GetShort();
2412 }
2413
2414 void
2415 ConfigParser::ParseBool(bool *var)
2416 {
2417 int i = GetInteger();
2418
2419 if (0 == i)
2420 *var = false;
2421 else if (1 == i)
2422 *var = true;
2423 else
2424 self_destruct();
2425 }
2426
2427 static void
2428 dump_wordlist(StoreEntry * entry, const char *name, wordlist * list)
2429 {
2430 while (list != NULL) {
2431 storeAppendPrintf(entry, "%s %s\n", name, list->key);
2432 list = list->next;
2433 }
2434 }
2435
2436 void
2437 ConfigParser::ParseWordList(wordlist ** list)
2438 {
2439 parse_wordlist(list);
2440 }
2441
2442 void
2443 parse_wordlist(wordlist ** list)
2444 {
2445 char *token;
2446 char *t = strtok(NULL, "");
2447
2448 while ((token = strwordtok(NULL, &t)))
2449 wordlistAdd(list, token);
2450 }
2451
2452 static int
2453 check_null_wordlist(wordlist * w)
2454 {
2455 return w == NULL;
2456 }
2457
2458 static int
2459 check_null_acl_access(acl_access * a)
2460 {
2461 return a == NULL;
2462 }
2463
2464 #define free_wordlist wordlistDestroy
2465
2466 #define free_uri_whitespace free_int
2467
2468 static void
2469 parse_uri_whitespace(int *var)
2470 {
2471 char *token = strtok(NULL, w_space);
2472
2473 if (token == NULL)
2474 self_destruct();
2475
2476 if (!strcasecmp(token, "strip"))
2477 *var = URI_WHITESPACE_STRIP;
2478 else if (!strcasecmp(token, "deny"))
2479 *var = URI_WHITESPACE_DENY;
2480 else if (!strcasecmp(token, "allow"))
2481 *var = URI_WHITESPACE_ALLOW;
2482 else if (!strcasecmp(token, "encode"))
2483 *var = URI_WHITESPACE_ENCODE;
2484 else if (!strcasecmp(token, "chop"))
2485 *var = URI_WHITESPACE_CHOP;
2486 else
2487 self_destruct();
2488 }
2489
2490 static void
2491 dump_uri_whitespace(StoreEntry * entry, const char *name, int var)
2492 {
2493 const char *s;
2494
2495 if (var == URI_WHITESPACE_ALLOW)
2496 s = "allow";
2497 else if (var == URI_WHITESPACE_ENCODE)
2498 s = "encode";
2499 else if (var == URI_WHITESPACE_CHOP)
2500 s = "chop";
2501 else if (var == URI_WHITESPACE_DENY)
2502 s = "deny";
2503 else
2504 s = "strip";
2505
2506 storeAppendPrintf(entry, "%s %s\n", name, s);
2507 }
2508
2509 static void
2510 free_removalpolicy(RemovalPolicySettings ** settings)
2511 {
2512 if (!*settings)
2513 return;
2514
2515 free_string(&(*settings)->type);
2516
2517 free_wordlist(&(*settings)->args);
2518
2519 delete *settings;
2520
2521 *settings = NULL;
2522 }
2523
2524 static void
2525 parse_removalpolicy(RemovalPolicySettings ** settings)
2526 {
2527 if (*settings)
2528 free_removalpolicy(settings);
2529
2530 *settings = new RemovalPolicySettings;
2531
2532 parse_string(&(*settings)->type);
2533
2534 parse_wordlist(&(*settings)->args);
2535 }
2536
2537 static void
2538 dump_removalpolicy(StoreEntry * entry, const char *name, RemovalPolicySettings * settings)
2539 {
2540 wordlist *args;
2541 storeAppendPrintf(entry, "%s %s", name, settings->type);
2542 args = settings->args;
2543
2544 while (args) {
2545 storeAppendPrintf(entry, " %s", args->key);
2546 args = args->next;
2547 }
2548
2549 storeAppendPrintf(entry, "\n");
2550 }
2551
2552 #include "cf_parser.h"
2553
2554 peer_t
2555 parseNeighborType(const char *s)
2556 {
2557 if (!strcasecmp(s, "parent"))
2558 return PEER_PARENT;
2559
2560 if (!strcasecmp(s, "neighbor"))
2561 return PEER_SIBLING;
2562
2563 if (!strcasecmp(s, "neighbour"))
2564 return PEER_SIBLING;
2565
2566 if (!strcasecmp(s, "sibling"))
2567 return PEER_SIBLING;
2568
2569 if (!strcasecmp(s, "multicast"))
2570 return PEER_MULTICAST;
2571
2572 debugs(15, 0, "WARNING: Unknown neighbor type: " << s);
2573
2574 return PEER_SIBLING;
2575 }
2576
2577 #if USE_WCCPv2
2578 void
2579 parse_sockaddr_in_list_token(sockaddr_in_list ** head, char *token)
2580 {
2581 char *t;
2582 char *host;
2583 char *tmp;
2584
2585 const struct hostent *hp;
2586 unsigned short port;
2587 sockaddr_in_list *s;
2588
2589 host = NULL;
2590 port = 0;
2591
2592 if ((t = strchr(token, ':'))) {
2593 /* host:port */
2594 host = token;
2595 *t = '\0';
2596 port = xatos(t + 1);
2597
2598 if (0 == port)
2599 self_destruct();
2600 } else if ((port = strtol(token, &tmp, 10)), !*tmp) {
2601 /* port */
2602 } else {
2603 host = token;
2604 port = 0;
2605 }
2606
2607 s = static_cast<sockaddr_in_list *>(xcalloc(1, sizeof(*s)));
2608 s->s.sin_port = htons(port);
2609
2610 if (NULL == host)
2611 s->s.sin_addr = any_addr;
2612 else if (1 == safe_inet_addr(host, &s->s.sin_addr))
2613 (void) 0;
2614 else if ((hp = gethostbyname(host))) /* dont use ipcache */
2615 s->s.sin_addr = inaddrFromHostent(hp);
2616 else
2617 self_destruct();
2618
2619 while (*head)
2620 head = &(*head)->next;
2621
2622 *head = s;
2623 }
2624
2625 static void
2626 parse_sockaddr_in_list(sockaddr_in_list ** head)
2627 {
2628 char *token;
2629
2630 while ((token = strtok(NULL, w_space))) {
2631 parse_sockaddr_in_list_token(head, token);
2632 }
2633 }
2634
2635 static void
2636 dump_sockaddr_in_list(StoreEntry * e, const char *n, const sockaddr_in_list * s)
2637 {
2638 while (s) {
2639 storeAppendPrintf(e, "%s %s:%d\n",
2640 n,
2641 inet_ntoa(s->s.sin_addr),
2642 ntohs(s->s.sin_port));
2643 s = s->next;
2644 }
2645 }
2646
2647 static void
2648 free_sockaddr_in_list(sockaddr_in_list ** head)
2649 {
2650 sockaddr_in_list *s;
2651
2652 while ((s = *head) != NULL) {
2653 *head = s->next;
2654 xfree(s);
2655 }
2656 }
2657
2658 #if CURRENTLY_UNUSED
2659 /* This code was previously used by http_port. Left as it really should
2660 * be used by icp_port and htcp_port
2661 */
2662 static int
2663 check_null_sockaddr_in_list(const sockaddr_in_list * s)
2664 {
2665 return NULL == s;
2666 }
2667
2668 #endif /* CURRENTLY_UNUSED */
2669 #endif /* USE_WCCPv2 */
2670
2671 static void
2672 parse_http_port_specification(http_port_list * s, char *token)
2673 {
2674 char *host = NULL;
2675
2676 const struct hostent *hp;
2677 unsigned short port = 0;
2678 char *t;
2679
2680 s->disable_pmtu_discovery = DISABLE_PMTU_OFF;
2681
2682 if ((t = strchr(token, ':'))) {
2683 /* host:port */
2684 host = token;
2685 *t = '\0';
2686 port = xatos(t + 1);
2687 } else {
2688 /* port */
2689 port = xatos(token);
2690 }
2691
2692 if (port == 0)
2693 self_destruct();
2694
2695 s->s.sin_port = htons(port);
2696
2697 if (NULL == host)
2698 s->s.sin_addr = any_addr;
2699 else if (1 == safe_inet_addr(host, &s->s.sin_addr))
2700 (void) 0;
2701 else if ((hp = gethostbyname(host))) {
2702 /* dont use ipcache */
2703 s->s.sin_addr = inaddrFromHostent(hp);
2704 s->defaultsite = xstrdup(host);
2705 } else
2706 self_destruct();
2707 }
2708
2709 static void
2710 parse_http_port_option(http_port_list * s, char *token)
2711 {
2712 if (strncmp(token, "defaultsite=", 12) == 0) {
2713 safe_free(s->defaultsite);
2714 s->defaultsite = xstrdup(token + 12);
2715 s->accel = 1;
2716 } else if (strncmp(token, "name=", 5) == 0) {
2717 safe_free(s->name);
2718 s->name = xstrdup(token + 5);
2719 } else if (strcmp(token, "transparent") == 0) {
2720 s->transparent = 1;
2721 } else if (strcmp(token, "vhost") == 0) {
2722 s->vhost = 1;
2723 s->accel = 1;
2724 } else if (strcmp(token, "vport") == 0) {
2725 s->vport = -1;
2726 s->accel = 1;
2727 } else if (strncmp(token, "vport=", 6) == 0) {
2728 s->vport = xatos(token + 6);
2729 s->accel = 1;
2730 } else if (strncmp(token, "protocol=", 9) == 0) {
2731 s->protocol = xstrdup(token + 9);
2732 s->accel = 1;
2733 } else if (strcmp(token, "accel") == 0) {
2734 s->accel = 1;
2735 } else if (strncmp(token, "disable-pmtu-discovery=", 23) == 0) {
2736 if (!strcasecmp(token + 23, "off"))
2737 s->disable_pmtu_discovery = DISABLE_PMTU_OFF;
2738 else if (!strcasecmp(token + 23, "transparent"))
2739 s->disable_pmtu_discovery = DISABLE_PMTU_TRANSPARENT;
2740 else if (!strcasecmp(token + 23, "always"))
2741 s->disable_pmtu_discovery = DISABLE_PMTU_ALWAYS;
2742 else
2743 self_destruct();
2744
2745 #if LINUX_TPROXY
2746
2747 } else if (strcmp(token, "tproxy") == 0) {
2748 s->tproxy = 1;
2749 need_linux_tproxy = 1;
2750 #endif
2751
2752 } else {
2753 self_destruct();
2754 }
2755 }
2756
2757 static void
2758 free_generic_http_port_data(http_port_list * s)
2759 {
2760 safe_free(s->name);
2761 safe_free(s->defaultsite);
2762 safe_free(s->protocol);
2763 }
2764
2765 static void
2766 cbdataFree_http_port(void *data)
2767 {
2768 free_generic_http_port_data((http_port_list *)data);
2769 }
2770
2771 static http_port_list *
2772 create_http_port(char *portspec)
2773 {
2774 CBDATA_TYPE(http_port_list);
2775 CBDATA_INIT_TYPE_FREECB(http_port_list, cbdataFree_http_port);
2776
2777 http_port_list *s = cbdataAlloc(http_port_list);
2778 s->protocol = xstrdup("http");
2779 parse_http_port_specification(s, portspec);
2780 return s;
2781 }
2782
2783 void
2784 add_http_port(char *portspec)
2785 {
2786 http_port_list *s = create_http_port(portspec);
2787 s->next = Config.Sockaddr.http;
2788 Config.Sockaddr.http = s;
2789 }
2790
2791 static void
2792 parse_http_port_list(http_port_list ** head)
2793 {
2794 char *token = strtok(NULL, w_space);
2795
2796 if (!token)
2797 self_destruct();
2798
2799 http_port_list *s = create_http_port(token);
2800
2801 /* parse options ... */
2802 while ((token = strtok(NULL, w_space))) {
2803 parse_http_port_option(s, token);
2804 }
2805
2806 while (*head)
2807 head = &(*head)->next;
2808
2809 *head = s;
2810 }
2811
2812 static void
2813 dump_generic_http_port(StoreEntry * e, const char *n, const http_port_list * s)
2814 {
2815 storeAppendPrintf(e, "%s %s:%d",
2816 n,
2817 inet_ntoa(s->s.sin_addr),
2818 ntohs(s->s.sin_port));
2819
2820 if (s->defaultsite)
2821 storeAppendPrintf(e, " defaultsite=%s", s->defaultsite);
2822
2823 if (s->transparent)
2824 storeAppendPrintf(e, " transparent");
2825
2826 if (s->vhost)
2827 storeAppendPrintf(e, " vhost");
2828
2829 if (s->vport)
2830 storeAppendPrintf(e, " vport");
2831
2832 if (s->disable_pmtu_discovery != DISABLE_PMTU_OFF) {
2833 const char *pmtu;
2834
2835 if (s->disable_pmtu_discovery == DISABLE_PMTU_ALWAYS)
2836 pmtu = "always";
2837 else
2838 pmtu = "transparent";
2839
2840 storeAppendPrintf(e, " disable-pmtu-discovery=%s", pmtu);
2841 }
2842 }
2843
2844 static void
2845 dump_http_port_list(StoreEntry * e, const char *n, const http_port_list * s)
2846 {
2847 while (s) {
2848 dump_generic_http_port(e, n, s);
2849 storeAppendPrintf(e, "\n");
2850 s = s->next;
2851 }
2852 }
2853
2854 static void
2855 free_http_port_list(http_port_list ** head)
2856 {
2857 http_port_list *s;
2858
2859 while ((s = *head) != NULL) {
2860 *head = s->next;
2861 cbdataFree(s);
2862 }
2863 }
2864
2865 #if USE_SSL
2866 static void
2867 cbdataFree_https_port(void *data)
2868 {
2869 https_port_list *s = (https_port_list *)data;
2870 free_generic_http_port_data(&s->http);
2871 safe_free(s->cert);
2872 safe_free(s->key);
2873 safe_free(s->options);
2874 safe_free(s->cipher);
2875 safe_free(s->cafile);
2876 safe_free(s->capath);
2877 safe_free(s->dhfile);
2878 safe_free(s->sslflags);
2879 }
2880
2881 static void
2882 parse_https_port_list(https_port_list ** head)
2883 {
2884 CBDATA_TYPE(https_port_list);
2885 char *token;
2886 https_port_list *s;
2887 CBDATA_INIT_TYPE_FREECB(https_port_list, cbdataFree_https_port);
2888 token = strtok(NULL, w_space);
2889
2890 if (!token)
2891 self_destruct();
2892
2893 s = cbdataAlloc(https_port_list);
2894
2895 s->http.protocol = xstrdup("https");
2896
2897 parse_http_port_specification(&s->http, token);
2898
2899 /* parse options ... */
2900 while ((token = strtok(NULL, w_space))) {
2901 if (strncmp(token, "cert=", 5) == 0) {
2902 safe_free(s->cert);
2903 s->cert = xstrdup(token + 5);
2904 } else if (strncmp(token, "key=", 4) == 0) {
2905 safe_free(s->key);
2906 s->key = xstrdup(token + 4);
2907 } else if (strncmp(token, "version=", 8) == 0) {
2908 s->version = xatoi(token + 8);
2909
2910 if (s->version < 1 || s->version > 4)
2911 self_destruct();
2912 } else if (strncmp(token, "options=", 8) == 0) {
2913 safe_free(s->options);
2914 s->options = xstrdup(token + 8);
2915 } else if (strncmp(token, "cipher=", 7) == 0) {
2916 safe_free(s->cipher);
2917 s->cipher = xstrdup(token + 7);
2918 } else if (strncmp(token, "clientca=", 9) == 0) {
2919 safe_free(s->clientca);
2920 s->clientca = xstrdup(token + 9);
2921 } else if (strncmp(token, "cafile=", 7) == 0) {
2922 safe_free(s->cafile);
2923 s->cafile = xstrdup(token + 7);
2924 } else if (strncmp(token, "capath=", 7) == 0) {
2925 safe_free(s->capath);
2926 s->capath = xstrdup(token + 7);
2927 } else if (strncmp(token, "crlfile=", 8) == 0) {
2928 safe_free(s->crlfile);
2929 s->crlfile = xstrdup(token + 8);
2930 } else if (strncmp(token, "dhparams=", 9) == 0) {
2931 safe_free(s->dhfile);
2932 s->dhfile = xstrdup(token + 9);
2933 } else if (strncmp(token, "sslflags=", 9) == 0) {
2934 safe_free(s->sslflags);
2935 s->sslflags = xstrdup(token + 9);
2936 } else if (strncmp(token, "sslcontext=", 11) == 0) {
2937 safe_free(s->sslcontext);
2938 s->sslcontext = xstrdup(token + 11);
2939 } else {
2940 parse_http_port_option(&s->http, token);
2941 }
2942 }
2943
2944 while (*head) {
2945 http_port_list ** headTmp = &(*head)->http.next;
2946 head = (https_port_list **)headTmp;
2947 }
2948
2949 *head = s;
2950 }
2951
2952 static void
2953 dump_https_port_list(StoreEntry * e, const char *n, const https_port_list * s)
2954 {
2955 while (s) {
2956 dump_generic_http_port(e, n, &s->http);
2957
2958 if (s->cert)
2959 storeAppendPrintf(e, " cert=%s", s->cert);
2960
2961 if (s->key)
2962 storeAppendPrintf(e, " key=%s", s->key);
2963
2964 if (s->version)
2965 storeAppendPrintf(e, " version=%d", s->version);
2966
2967 if (s->options)
2968 storeAppendPrintf(e, " options=%s", s->options);
2969
2970 if (s->cipher)
2971 storeAppendPrintf(e, " cipher=%s", s->cipher);
2972
2973 if (s->cafile)
2974 storeAppendPrintf(e, " cafile=%s", s->cafile);
2975
2976 if (s->capath)
2977 storeAppendPrintf(e, " capath=%s", s->capath);
2978
2979 if (s->crlfile)
2980 storeAppendPrintf(e, " crlfile=%s", s->crlfile);
2981
2982 if (s->dhfile)
2983 storeAppendPrintf(e, " dhparams=%s", s->dhfile);
2984
2985 if (s->sslflags)
2986 storeAppendPrintf(e, " sslflags=%s", s->sslflags);
2987
2988 if (s->sslcontext)
2989 storeAppendPrintf(e, " sslcontext=%s", s->sslcontext);
2990
2991 storeAppendPrintf(e, "\n");
2992
2993 s = (https_port_list *) s->http.next;
2994 }
2995 }
2996
2997 static void
2998 free_https_port_list(https_port_list ** head)
2999 {
3000 https_port_list *s;
3001
3002 while ((s = *head) != NULL) {
3003 *head = (https_port_list *) s->http.next;
3004 cbdataFree(s);
3005 }
3006 }
3007
3008 #if 0
3009 static int
3010 check_null_https_port_list(const https_port_list * s)
3011 {
3012 return NULL == s;
3013 }
3014
3015 #endif
3016
3017 #endif /* USE_SSL */
3018
3019 void
3020 configFreeMemory(void)
3021 {
3022 free_all();
3023 }
3024
3025 void
3026 requirePathnameExists(const char *name, const char *path)
3027 {
3028
3029 struct stat sb;
3030 char pathbuf[BUFSIZ];
3031 assert(path != NULL);
3032
3033 if (Config.chroot_dir && (geteuid() == 0)) {
3034 snprintf(pathbuf, BUFSIZ, "%s/%s", Config.chroot_dir, path);
3035 path = pathbuf;
3036 }
3037
3038 if (stat(path, &sb) < 0) {
3039 if (opt_send_signal == -1 || opt_send_signal == SIGHUP)
3040 fatalf("%s %s: %s", name, path, xstrerror());
3041 else
3042 fprintf(stderr, "WARNING: %s %s: %s\n", name, path, xstrerror());
3043 }
3044 }
3045
3046 char *
3047 strtokFile(void)
3048 {
3049 return ConfigParser::strtokFile();
3050 }
3051
3052 #include "AccessLogEntry.h"
3053 /* TODO: split out parsing somehow ...*/
3054 static void
3055 parse_logformat(logformat ** logformat_definitions)
3056 {
3057 logformat *nlf;
3058 char *name, *def;
3059
3060 if ((name = strtok(NULL, w_space)) == NULL)
3061 self_destruct();
3062
3063 if ((def = strtok(NULL, "\r\n")) == NULL)
3064 self_destruct();
3065
3066 debugs(3, 2, "Logformat for '" << name << "' is '" << def << "'");
3067
3068 nlf = (logformat *)xcalloc(1, sizeof(logformat));
3069
3070 nlf->name = xstrdup(name);
3071
3072 if (!accessLogParseLogFormat(&nlf->format, def))
3073 self_destruct();
3074
3075 nlf->next = *logformat_definitions;
3076
3077 *logformat_definitions = nlf;
3078 }
3079
3080 static void
3081 parse_access_log(customlog ** logs)
3082 {
3083 const char *filename, *logdef_name;
3084 customlog *cl;
3085 logformat *lf;
3086
3087 cl = (customlog *)xcalloc(1, sizeof(*cl));
3088
3089 if ((filename = strtok(NULL, w_space)) == NULL)
3090 self_destruct();
3091
3092 if (strcmp(filename, "none") == 0) {
3093 cl->type = CLF_NONE;
3094 goto done;
3095 }
3096
3097 if ((logdef_name = strtok(NULL, w_space)) == NULL)
3098 logdef_name = "auto";
3099
3100 debugs(3, 9, "Log definition name '" << logdef_name << "' file '" << filename << "'");
3101
3102 cl->filename = xstrdup(filename);
3103
3104 /* look for the definition pointer corresponding to this name */
3105 lf = Config.Log.logformats;
3106
3107 while (lf != NULL) {
3108 debugs(3, 9, "Comparing against '" << lf->name << "'");
3109
3110 if (strcmp(lf->name, logdef_name) == 0)
3111 break;
3112
3113 lf = lf->next;
3114 }
3115
3116 if (lf != NULL) {
3117 cl->type = CLF_CUSTOM;
3118 cl->logFormat = lf;
3119 } else if (strcmp(logdef_name, "auto") == 0) {
3120 cl->type = CLF_AUTO;
3121 } else if (strcmp(logdef_name, "squid") == 0) {
3122 cl->type = CLF_SQUID;
3123 } else if (strcmp(logdef_name, "common") == 0) {
3124 cl->type = CLF_COMMON;
3125 } else {
3126 debugs(3, 0, "Log format '" << logdef_name << "' is not defined");
3127 self_destruct();
3128 }
3129
3130 done:
3131 aclParseAclList(LegacyParser, &cl->aclList);
3132
3133 while (*logs)
3134 logs = &(*logs)->next;
3135
3136 *logs = cl;
3137 }
3138
3139 static int
3140 check_null_access_log(customlog *customlog_definitions)
3141 {
3142 return customlog_definitions == NULL;
3143 }
3144
3145 static void
3146 dump_logformat(StoreEntry * entry, const char *name, logformat * definitions)
3147 {
3148 accessLogDumpLogFormat(entry, name, definitions);
3149 }
3150
3151 static void
3152 dump_access_log(StoreEntry * entry, const char *name, customlog * logs)
3153 {
3154 customlog *log;
3155
3156 for (log = logs; log; log = log->next) {
3157 storeAppendPrintf(entry, "%s ", name);
3158
3159 switch (log->type) {
3160
3161 case CLF_CUSTOM:
3162 storeAppendPrintf(entry, "%s %s", log->filename, log->logFormat->name);
3163 break;
3164
3165 case CLF_NONE:
3166 storeAppendPrintf(entry, "none");
3167 break;
3168
3169 case CLF_SQUID:
3170 storeAppendPrintf(entry, "%s squid", log->filename);
3171 break;
3172
3173 case CLF_COMMON:
3174 storeAppendPrintf(entry, "%s squid", log->filename);
3175 break;
3176
3177 case CLF_AUTO:
3178
3179 if (log->aclList)
3180 storeAppendPrintf(entry, "%s auto", log->filename);
3181 else
3182 storeAppendPrintf(entry, "%s", log->filename);
3183
3184 break;
3185
3186 case CLF_UNKNOWN:
3187 break;
3188 }
3189
3190 if (log->aclList)
3191 dump_acl_list(entry, log->aclList);
3192
3193 storeAppendPrintf(entry, "\n");
3194 }
3195 }
3196
3197 static void
3198 free_logformat(logformat ** definitions)
3199 {
3200 while (*definitions) {
3201 logformat *format = *definitions;
3202 *definitions = format->next;
3203 accessLogFreeLogFormat(&format->format);
3204 xfree(format);
3205 }
3206 }
3207
3208 static void
3209 free_access_log(customlog ** definitions)
3210 {
3211 while (*definitions) {
3212 customlog *log = *definitions;
3213 *definitions = log->next;
3214
3215 log->logFormat = NULL;
3216 log->type = CLF_UNKNOWN;
3217
3218 if (log->aclList)
3219 aclDestroyAclList(&log->aclList);
3220
3221 safe_free(log->filename);
3222
3223 xfree(log);
3224 }
3225 }
3226
3227 #if ICAP_CLIENT
3228
3229 static void
3230 parse_icap_service_type(ICAPConfig * cfg)
3231 {
3232 cfg->parseICAPService();
3233 }
3234
3235 static void
3236 free_icap_service_type(ICAPConfig * cfg)
3237 {
3238 cfg->freeICAPService();
3239 }
3240
3241 static void
3242 dump_icap_service_type(StoreEntry * entry, const char *name, const ICAPConfig &cfg)
3243 {
3244 cfg.dumpICAPService(entry, name);
3245 }
3246
3247 static void
3248 parse_icap_class_type(ICAPConfig * cfg)
3249 {
3250 cfg->parseICAPClass();
3251 }
3252
3253 static void
3254 free_icap_class_type(ICAPConfig * cfg)
3255 {
3256 cfg->freeICAPClass();
3257 }
3258
3259 static void
3260 dump_icap_class_type(StoreEntry * entry, const char *name, const ICAPConfig &cfg)
3261 {
3262 cfg.dumpICAPClass(entry, name);
3263 }
3264
3265 static void
3266 parse_icap_access_type(ICAPConfig * cfg)
3267 {
3268 cfg->parseICAPAccess(LegacyParser);
3269 }
3270
3271 static void
3272 free_icap_access_type(ICAPConfig * cfg)
3273 {
3274 cfg->freeICAPAccess();
3275 }
3276
3277 static void
3278 dump_icap_access_type(StoreEntry * entry, const char *name, const ICAPConfig &cfg)
3279 {
3280 cfg.dumpICAPAccess(entry, name);
3281 }
3282
3283 #endif