]> git.ipfire.org Git - thirdparty/squid.git/blob - src/cache_cf.cc
Merged from trunk
[thirdparty/squid.git] / src / cache_cf.cc
1 /*
2 * $Id$
3 *
4 * DEBUG: section 03 Configuration File Parsing
5 * AUTHOR: Harvest Derived
6 *
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
9 *
10 * Squid is the result of efforts by numerous individuals from
11 * the Internet community; see the CONTRIBUTORS file for full
12 * details. Many organizations have provided support for Squid's
13 * development; see the SPONSORS file for full details. Squid is
14 * Copyrighted (C) 2001 by the Regents of the University of
15 * California; see the COPYRIGHT file for full details. Squid
16 * incorporates software developed and/or copyrighted by other
17 * sources; see the CREDITS file for full details.
18 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
32 *
33 */
34
35 #include "squid-old.h"
36
37 #include "acl/Acl.h"
38 #include "acl/Gadgets.h"
39 #include "acl/MethodData.h"
40 #if USE_ADAPTATION
41 #include "adaptation/Config.h"
42 #endif
43 #if ICAP_CLIENT
44 #include "adaptation/icap/Config.h"
45 #endif
46 #if USE_ECAP
47 #include "adaptation/ecap/Config.h"
48 #endif
49 #include "anyp/PortCfg.h"
50 #if USE_SSL
51 #include "ssl/support.h"
52 #include "ssl/Config.h"
53 #endif
54 #if USE_AUTH
55 #include "auth/Config.h"
56 #include "auth/Scheme.h"
57 #endif
58 #include "ConfigParser.h"
59 #include "CpuAffinityMap.h"
60 #include "DiskIO/DiskIOModule.h"
61 #include "eui/Config.h"
62 #if USE_SQUID_ESI
63 #include "esi/Parser.h"
64 #endif
65 #include "format/Format.h"
66 #include "HttpRequestMethod.h"
67 #include "ident/Config.h"
68 #include "ip/Intercept.h"
69 #include "ip/QosConfig.h"
70 #include "ip/tools.h"
71 #include "log/Config.h"
72 #include "MemBuf.h"
73 #include "mgr/Registration.h"
74 #include "Parsing.h"
75 #include "rfc1738.h"
76 #if SQUID_SNMP
77 #include "snmp.h"
78 #endif
79 #include "Store.h"
80 #include "StoreFileSystem.h"
81 #include "SwapDir.h"
82 #include "wordlist.h"
83 #include "ipc/Kids.h"
84
85 #if HAVE_GLOB_H
86 #include <glob.h>
87 #endif
88
89 #if HAVE_LIMITS_H
90 #include <limits>
91 #endif
92
93 #if USE_SSL
94 #include "ssl/gadgets.h"
95 #endif
96
97 #if USE_ADAPTATION
98 static void parse_adaptation_service_set_type();
99 static void parse_adaptation_service_chain_type();
100 static void parse_adaptation_access_type();
101 static void parse_adaptation_meta_type(Adaptation::Config::MetaHeaders *);
102 static void dump_adaptation_meta_type(StoreEntry *, const char *, Adaptation::Config::MetaHeaders &);
103 static void free_adaptation_meta_type(Adaptation::Config::MetaHeaders *);
104 #endif
105
106 #if ICAP_CLIENT
107 static void parse_icap_service_type(Adaptation::Icap::Config *);
108 static void dump_icap_service_type(StoreEntry *, const char *, const Adaptation::Icap::Config &);
109 static void free_icap_service_type(Adaptation::Icap::Config *);
110 static void parse_icap_class_type();
111 static void parse_icap_access_type();
112
113 static void parse_icap_service_failure_limit(Adaptation::Icap::Config *);
114 static void dump_icap_service_failure_limit(StoreEntry *, const char *, const Adaptation::Icap::Config &);
115 static void free_icap_service_failure_limit(Adaptation::Icap::Config *);
116 #endif
117
118 #if USE_ECAP
119 static void parse_ecap_service_type(Adaptation::Ecap::Config *);
120 static void dump_ecap_service_type(StoreEntry *, const char *, const Adaptation::Ecap::Config &);
121 static void free_ecap_service_type(Adaptation::Ecap::Config *);
122 #endif
123
124 CBDATA_TYPE(peer);
125
126 static const char *const T_MILLISECOND_STR = "millisecond";
127 static const char *const T_SECOND_STR = "second";
128 static const char *const T_MINUTE_STR = "minute";
129 static const char *const T_HOUR_STR = "hour";
130 static const char *const T_DAY_STR = "day";
131 static const char *const T_WEEK_STR = "week";
132 static const char *const T_FORTNIGHT_STR = "fortnight";
133 static const char *const T_MONTH_STR = "month";
134 static const char *const T_YEAR_STR = "year";
135 static const char *const T_DECADE_STR = "decade";
136
137 static const char *const B_BYTES_STR = "bytes";
138 static const char *const B_KBYTES_STR = "KB";
139 static const char *const B_MBYTES_STR = "MB";
140 static const char *const B_GBYTES_STR = "GB";
141
142 static const char *const list_sep = ", \t\n\r";
143
144 static void parse_access_log(customlog ** customlog_definitions);
145 static int check_null_access_log(customlog *customlog_definitions);
146 static void dump_access_log(StoreEntry * entry, const char *name, customlog * definitions);
147 static void free_access_log(customlog ** definitions);
148
149 static void update_maxobjsize(void);
150 static void configDoConfigure(void);
151 static void parse_refreshpattern(refresh_t **);
152 static uint64_t parseTimeUnits(const char *unit, bool allowMsec);
153 static void parseTimeLine(time_msec_t * tptr, const char *units, bool allowMsec);
154 static void parse_u_short(unsigned short * var);
155 static void parse_string(char **);
156 static void default_all(void);
157 static void defaults_if_none(void);
158 static int parse_line(char *);
159 static void parse_obsolete(const char *);
160 static void parseBytesLine(size_t * bptr, const char *units);
161 #if USE_SSL
162 static void parseBytesOptionValue(size_t * bptr, const char *units, char const * value);
163 #endif
164 #if !USE_DNSHELPER
165 static void parseBytesLineSigned(ssize_t * bptr, const char *units);
166 #endif
167 static size_t parseBytesUnits(const char *unit);
168 static void free_all(void);
169 void requirePathnameExists(const char *name, const char *path);
170 static OBJH dump_config;
171 #if USE_HTTP_VIOLATIONS
172 static void free_HeaderManglers(HeaderManglers **pm);
173 static void dump_http_header_access(StoreEntry * entry, const char *name, const HeaderManglers *manglers);
174 static void parse_http_header_access(HeaderManglers **manglers);
175 #define free_http_header_access free_HeaderManglers
176 static void dump_http_header_replace(StoreEntry * entry, const char *name, const HeaderManglers *manglers);
177 static void parse_http_header_replace(HeaderManglers **manglers);
178 #define free_http_header_replace free_HeaderManglers
179 #endif
180 static void parse_denyinfo(acl_deny_info_list ** var);
181 static void dump_denyinfo(StoreEntry * entry, const char *name, acl_deny_info_list * var);
182 static void free_denyinfo(acl_deny_info_list ** var);
183
184 #if USE_WCCPv2
185 static void parse_IpAddress_list(Ip::Address_list **);
186 static void dump_IpAddress_list(StoreEntry *, const char *, const Ip::Address_list *);
187 static void free_IpAddress_list(Ip::Address_list **);
188 #if CURRENTLY_UNUSED
189 static int check_null_IpAddress_list(const Ip::Address_list *);
190 #endif /* CURRENTLY_UNUSED */
191 #endif /* USE_WCCPv2 */
192
193 static void parsePortCfg(AnyP::PortCfg **, const char *protocol);
194 #define parse_PortCfg(l) parsePortCfg((l), token)
195 static void dump_PortCfg(StoreEntry *, const char *, const AnyP::PortCfg *);
196 static void free_PortCfg(AnyP::PortCfg **);
197
198 static void parse_b_size_t(size_t * var);
199 static void parse_b_int64_t(int64_t * var);
200
201 static bool parseNamedIntList(const char *data, const String &name, Vector<int> &list);
202
203 static void parse_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap);
204 static void dump_CpuAffinityMap(StoreEntry *const entry, const char *const name, const CpuAffinityMap *const cpuAffinityMap);
205 static void free_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap);
206
207 static int parseOneConfigFile(const char *file_name, unsigned int depth);
208
209 /*
210 * LegacyParser is a parser for legacy code that uses the global
211 * approach. This is static so that it is only exposed to cache_cf.
212 * Other modules needing access to a ConfigParser should have it
213 * provided to them in their parserFOO methods.
214 */
215 static ConfigParser LegacyParser = ConfigParser();
216
217 void
218 self_destruct(void)
219 {
220 LegacyParser.destruct();
221 }
222
223 static void
224 update_maxobjsize(void)
225 {
226 int i;
227 int64_t ms = -1;
228
229 for (i = 0; i < Config.cacheSwap.n_configured; i++) {
230 assert (Config.cacheSwap.swapDirs[i].getRaw());
231
232 if (dynamic_cast<SwapDir *>(Config.cacheSwap.swapDirs[i].getRaw())->
233 max_objsize > ms)
234 ms = dynamic_cast<SwapDir *>(Config.cacheSwap.swapDirs[i].getRaw())->max_objsize;
235 }
236 store_maxobjsize = ms;
237 }
238
239 static void
240 SetConfigFilename(char const *file_name, bool is_pipe)
241 {
242 cfg_filename = file_name;
243
244 char const *token;
245
246 if (is_pipe)
247 cfg_filename = file_name + 1;
248 else if ((token = strrchr(cfg_filename, '/')))
249 cfg_filename = token + 1;
250 }
251
252 static const char*
253 skip_ws(const char* s)
254 {
255 while (xisspace(*s))
256 ++s;
257
258 return s;
259 }
260
261 static int
262 parseManyConfigFiles(char* files, int depth)
263 {
264 int error_count = 0;
265 char* saveptr = NULL;
266 #if HAVE_GLOB
267 char *path;
268 glob_t globbuf;
269 int i;
270 memset(&globbuf, 0, sizeof(globbuf));
271 for (path = strwordtok(files, &saveptr); path; path = strwordtok(NULL, &saveptr)) {
272 if (glob(path, globbuf.gl_pathc ? GLOB_APPEND : 0, NULL, &globbuf) != 0) {
273 fatalf("Unable to find configuration file: %s: %s",
274 path, xstrerror());
275 }
276 }
277 for (i = 0; i < (int)globbuf.gl_pathc; i++) {
278 error_count += parseOneConfigFile(globbuf.gl_pathv[i], depth);
279 }
280 globfree(&globbuf);
281 #else
282 char* file = strwordtok(files, &saveptr);
283 while (file != NULL) {
284 error_count += parseOneConfigFile(file, depth);
285 file = strwordtok(NULL, &saveptr);
286 }
287 #endif /* HAVE_GLOB */
288 return error_count;
289 }
290
291 static void
292 ReplaceSubstr(char*& str, int& len, unsigned substrIdx, unsigned substrLen, const char* newSubstr)
293 {
294 assert(str != NULL);
295 assert(newSubstr != NULL);
296
297 unsigned newSubstrLen = strlen(newSubstr);
298 if (newSubstrLen > substrLen)
299 str = (char*)realloc(str, len - substrLen + newSubstrLen + 1);
300
301 // move tail part including zero
302 memmove(str + substrIdx + newSubstrLen, str + substrIdx + substrLen, len - substrIdx - substrLen + 1);
303 // copy new substring in place
304 memcpy(str + substrIdx, newSubstr, newSubstrLen);
305
306 len = strlen(str);
307 }
308
309 static void
310 SubstituteMacro(char*& line, int& len, const char* macroName, const char* substStr)
311 {
312 assert(line != NULL);
313 assert(macroName != NULL);
314 assert(substStr != NULL);
315 unsigned macroNameLen = strlen(macroName);
316 while (const char* macroPos = strstr(line, macroName)) // we would replace all occurrences
317 ReplaceSubstr(line, len, macroPos - line, macroNameLen, substStr);
318 }
319
320 static void
321 ProcessMacros(char*& line, int& len)
322 {
323 SubstituteMacro(line, len, "${process_name}", TheKidName);
324 SubstituteMacro(line, len, "${process_number}", xitoa(KidIdentifier));
325 }
326
327 static void
328 trim_trailing_ws(char* str)
329 {
330 assert(str != NULL);
331 unsigned i = strlen(str);
332 while ((i > 0) && xisspace(str[i - 1]))
333 --i;
334 str[i] = '\0';
335 }
336
337 static const char*
338 FindStatement(const char* line, const char* statement)
339 {
340 assert(line != NULL);
341 assert(statement != NULL);
342
343 const char* str = skip_ws(line);
344 unsigned len = strlen(statement);
345 if (strncmp(str, statement, len) == 0) {
346 str += len;
347 if (*str == '\0')
348 return str;
349 else if (xisspace(*str))
350 return skip_ws(str);
351 }
352
353 return NULL;
354 }
355
356 static bool
357 StrToInt(const char* str, long& number)
358 {
359 assert(str != NULL);
360
361 char* end;
362 number = strtol(str, &end, 0);
363
364 return (end != str) && (*end == '\0'); // returns true if string contains nothing except number
365 }
366
367 static bool
368 EvalBoolExpr(const char* expr)
369 {
370 assert(expr != NULL);
371 if (strcmp(expr, "true") == 0) {
372 return true;
373 } else if (strcmp(expr, "false") == 0) {
374 return false;
375 } else if (const char* equation = strchr(expr, '=')) {
376 const char* rvalue = skip_ws(equation + 1);
377 char* lvalue = (char*)xmalloc(equation - expr + 1);
378 xstrncpy(lvalue, expr, equation - expr + 1);
379 trim_trailing_ws(lvalue);
380
381 long number1;
382 if (!StrToInt(lvalue, number1))
383 fatalf("String is not a integer number: '%s'\n", lvalue);
384 long number2;
385 if (!StrToInt(rvalue, number2))
386 fatalf("String is not a integer number: '%s'\n", rvalue);
387
388 xfree(lvalue);
389 return number1 == number2;
390 }
391 fatalf("Unable to evaluate expression '%s'\n", expr);
392 return false; // this place cannot be reached
393 }
394
395 static int
396 parseOneConfigFile(const char *file_name, unsigned int depth)
397 {
398 FILE *fp = NULL;
399 const char *orig_cfg_filename = cfg_filename;
400 const int orig_config_lineno = config_lineno;
401 char *token = NULL;
402 char *tmp_line = NULL;
403 int tmp_line_len = 0;
404 int err_count = 0;
405 int is_pipe = 0;
406
407 debugs(3, 1, "Processing Configuration File: " << file_name << " (depth " << depth << ")");
408 if (depth > 16) {
409 fatalf("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name);
410 return 1;
411 }
412
413 if (file_name[0] == '!' || file_name[0] == '|') {
414 fp = popen(file_name + 1, "r");
415 is_pipe = 1;
416 } else {
417 fp = fopen(file_name, "r");
418 }
419
420 if (fp == NULL)
421 fatalf("Unable to open configuration file: %s: %s", file_name, xstrerror());
422
423 #if _SQUID_WINDOWS_
424 setmode(fileno(fp), O_TEXT);
425 #endif
426
427 SetConfigFilename(file_name, bool(is_pipe));
428
429 memset(config_input_line, '\0', BUFSIZ);
430
431 config_lineno = 0;
432
433 Vector<bool> if_states;
434 while (fgets(config_input_line, BUFSIZ, fp)) {
435 config_lineno++;
436
437 if ((token = strchr(config_input_line, '\n')))
438 *token = '\0';
439
440 if ((token = strchr(config_input_line, '\r')))
441 *token = '\0';
442
443 // strip any prefix whitespace off the line.
444 const char *p = skip_ws(config_input_line);
445 if (config_input_line != p)
446 memmove(config_input_line, p, strlen(p)+1);
447
448 if (strncmp(config_input_line, "#line ", 6) == 0) {
449 static char new_file_name[1024];
450 static char *file;
451 static char new_lineno;
452 token = config_input_line + 6;
453 new_lineno = strtol(token, &file, 0) - 1;
454
455 if (file == token)
456 continue; /* Not a valid #line directive, may be a comment */
457
458 while (*file && xisspace((unsigned char) *file))
459 file++;
460
461 if (*file) {
462 if (*file != '"')
463 continue; /* Not a valid #line directive, may be a comment */
464
465 xstrncpy(new_file_name, file + 1, sizeof(new_file_name));
466
467 if ((token = strchr(new_file_name, '"')))
468 *token = '\0';
469
470 cfg_filename = new_file_name;
471 }
472
473 config_lineno = new_lineno;
474 }
475
476 if (config_input_line[0] == '#')
477 continue;
478
479 if (config_input_line[0] == '\0')
480 continue;
481
482 const char* append = tmp_line_len ? skip_ws(config_input_line) : config_input_line;
483
484 size_t append_len = strlen(append);
485
486 tmp_line = (char*)xrealloc(tmp_line, tmp_line_len + append_len + 1);
487
488 strcpy(tmp_line + tmp_line_len, append);
489
490 tmp_line_len += append_len;
491
492 if (tmp_line[tmp_line_len-1] == '\\') {
493 debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line << "'");
494 tmp_line[--tmp_line_len] = '\0';
495 continue;
496 }
497
498 trim_trailing_ws(tmp_line);
499 ProcessMacros(tmp_line, tmp_line_len);
500 debugs(3, (opt_parse_cfg_only?1:5), "Processing: " << tmp_line);
501
502 if (const char* expr = FindStatement(tmp_line, "if")) {
503 if_states.push_back(EvalBoolExpr(expr)); // store last if-statement meaning
504 } else if (FindStatement(tmp_line, "endif")) {
505 if (!if_states.empty())
506 if_states.pop_back(); // remove last if-statement meaning
507 else
508 fatalf("'endif' without 'if'\n");
509 } else if (FindStatement(tmp_line, "else")) {
510 if (!if_states.empty())
511 if_states.back() = !if_states.back();
512 else
513 fatalf("'else' without 'if'\n");
514 } else if (if_states.empty() || if_states.back()) { // test last if-statement meaning if present
515 /* Handle includes here */
516 if (tmp_line_len >= 9 && strncmp(tmp_line, "include", 7) == 0 && xisspace(tmp_line[7])) {
517 err_count += parseManyConfigFiles(tmp_line + 8, depth + 1);
518 } else if (!parse_line(tmp_line)) {
519 debugs(3, 0, HERE << cfg_filename << ":" << config_lineno << " unrecognized: '" << tmp_line << "'");
520 err_count++;
521 }
522 }
523
524 safe_free(tmp_line);
525 tmp_line_len = 0;
526
527 }
528 if (!if_states.empty())
529 fatalf("if-statement without 'endif'\n");
530
531 if (is_pipe) {
532 int ret = pclose(fp);
533
534 if (ret != 0)
535 fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name, ret);
536 } else {
537 fclose(fp);
538 }
539
540 cfg_filename = orig_cfg_filename;
541 config_lineno = orig_config_lineno;
542
543 return err_count;
544 }
545
546 int
547 parseConfigFile(const char *file_name)
548 {
549 int err_count = 0;
550
551 debugs(5, 4, HERE);
552
553 configFreeMemory();
554
555 ACLMethodData::ThePurgeCount = 0;
556 default_all();
557
558 err_count = parseOneConfigFile(file_name, 0);
559
560 defaults_if_none();
561
562 /*
563 * We must call configDoConfigure() before leave_suid() because
564 * configDoConfigure() is where we turn username strings into
565 * uid values.
566 */
567 configDoConfigure();
568
569 if (!Config.chroot_dir) {
570 leave_suid();
571 setUmask(Config.umask);
572 _db_init(Debug::cache_log, Debug::debugOptions);
573 enter_suid();
574 }
575
576 if (opt_send_signal == -1) {
577 Mgr::RegisterAction("config",
578 "Current Squid Configuration",
579 dump_config,
580 1, 1);
581 }
582
583 return err_count;
584 }
585
586
587 static void
588 configDoConfigure(void)
589 {
590 memset(&Config2, '\0', sizeof(SquidConfig2));
591 /* init memory as early as possible */
592 memConfigure();
593 /* Sanity checks */
594
595 if (Config.cacheSwap.swapDirs == NULL) {
596 /* Memory-only cache probably in effect. */
597 /* turn off the cache rebuild delays... */
598 StoreController::store_dirs_rebuilding = 0;
599 } else if (InDaemonMode()) { // no diskers in non-daemon mode
600 for (int i = 0; i < Config.cacheSwap.n_configured; ++i) {
601 const RefCount<SwapDir> sd = Config.cacheSwap.swapDirs[i];
602 if (sd->needsDiskStrand())
603 sd->disker = Config.workers + (++Config.cacheSwap.n_strands);
604 }
605 }
606
607 if (Debug::rotateNumber < 0) {
608 Debug::rotateNumber = Config.Log.rotateNumber;
609 }
610
611 #if SIZEOF_OFF_T <= 4
612 if (Config.Store.maxObjectSize > 0x7FFF0000) {
613 debugs(3, 0, "WARNING: This Squid binary can not handle files larger than 2GB. Limiting maximum_object_size to just below 2GB");
614 Config.Store.maxObjectSize = 0x7FFF0000;
615 }
616 #endif
617 if (0 == Store::Root().maxSize())
618 /* people might want a zero-sized cache on purpose */
619 (void) 0;
620 else if (Store::Root().maxSize() < Config.memMaxSize)
621 /* This is bogus. folk with NULL caches will want this */
622 debugs(3, 0, "WARNING cache_mem is larger than total disk cache space!");
623
624 if (Config.Announce.period > 0) {
625 Config.onoff.announce = 1;
626 } else if (Config.Announce.period < 1) {
627 Config.Announce.period = 86400 * 365; /* one year */
628 Config.onoff.announce = 0;
629 }
630
631 if (Config.onoff.httpd_suppress_version_string)
632 visible_appname_string = (char *)appname_string;
633 else
634 visible_appname_string = (char const *)APP_FULLNAME;
635
636 #if USE_DNSHELPER
637 if (Config.dnsChildren.n_max < 1)
638 fatal("No DNS helpers allocated");
639 #endif
640
641 if (Config.Program.redirect) {
642 if (Config.redirectChildren.n_max < 1) {
643 Config.redirectChildren.n_max = 0;
644 wordlistDestroy(&Config.Program.redirect);
645 }
646 }
647
648 if (Config.appendDomain)
649 if (*Config.appendDomain != '.')
650 fatal("append_domain must begin with a '.'");
651
652 if (Config.errHtmlText == NULL)
653 Config.errHtmlText = xstrdup(null_string);
654
655 #if !HAVE_SETRLIMIT || !defined(RLIMIT_NOFILE)
656 if (Config.max_filedescriptors > 0) {
657 debugs(0, DBG_IMPORTANT, "WARNING: max_filedescriptors disabled. Operating System setrlimit(RLIMIT_NOFILE) is missing.");
658 }
659 #elif USE_SELECT || USE_SELECT_WIN32
660 if (Config.max_filedescriptors > FD_SETSIZE) {
661 debugs(0, DBG_IMPORTANT, "WARNING: max_filedescriptors limited to " << FD_SETSIZE << " by select() algorithm.");
662 }
663 #endif
664
665 storeConfigure();
666
667 snprintf(ThisCache, sizeof(ThisCache), "%s (%s)",
668 uniqueHostname(),
669 visible_appname_string);
670
671 /*
672 * the extra space is for loop detection in client_side.c -- we search
673 * for substrings in the Via header.
674 */
675 snprintf(ThisCache2, sizeof(ThisCache), " %s (%s)",
676 uniqueHostname(),
677 visible_appname_string);
678
679 /* Use visible_hostname as default surrogate_id */
680 if (!Config.Accel.surrogate_id) {
681 const char *t = getMyHostname();
682 Config.Accel.surrogate_id = xstrdup( (t?t:"unset-id") );
683 }
684
685 if (!Config.udpMaxHitObjsz || Config.udpMaxHitObjsz > SQUID_UDP_SO_SNDBUF)
686 Config.udpMaxHitObjsz = SQUID_UDP_SO_SNDBUF;
687
688 if (Config.appendDomain)
689 Config.appendDomainLen = strlen(Config.appendDomain);
690 else
691 Config.appendDomainLen = 0;
692
693 if (Config.connect_retries > 10) {
694 debugs(0,DBG_CRITICAL, "WARNING: connect_retries cannot be larger than 10. Resetting to 10.");
695 Config.connect_retries = 10;
696 }
697
698 requirePathnameExists("MIME Config Table", Config.mimeTablePathname);
699 #if USE_DNSHELPER
700 requirePathnameExists("cache_dns_program", Config.Program.dnsserver);
701 #endif
702 #if USE_UNLINKD
703
704 requirePathnameExists("unlinkd_program", Config.Program.unlinkd);
705 #endif
706 requirePathnameExists("logfile_daemon", Log::TheConfig.logfile_daemon);
707 if (Config.Program.redirect)
708 requirePathnameExists("redirect_program", Config.Program.redirect->key);
709
710 requirePathnameExists("Icon Directory", Config.icons.directory);
711
712 if (Config.errorDirectory)
713 requirePathnameExists("Error Directory", Config.errorDirectory);
714
715 #if USE_HTTP_VIOLATIONS
716
717 {
718 const refresh_t *R;
719
720 for (R = Config.Refresh; R; R = R->next) {
721 if (!R->flags.override_expire)
722 continue;
723
724 debugs(22, 1, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP");
725
726 break;
727 }
728
729 for (R = Config.Refresh; R; R = R->next) {
730 if (!R->flags.override_lastmod)
731 continue;
732
733 debugs(22, 1, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP");
734
735 break;
736 }
737
738 for (R = Config.Refresh; R; R = R->next) {
739 if (!R->flags.reload_into_ims)
740 continue;
741
742 debugs(22, 1, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP");
743
744 break;
745 }
746
747 for (R = Config.Refresh; R; R = R->next) {
748 if (!R->flags.ignore_reload)
749 continue;
750
751 debugs(22, 1, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP");
752
753 break;
754 }
755
756 for (R = Config.Refresh; R; R = R->next) {
757 if (!R->flags.ignore_no_cache)
758 continue;
759
760 debugs(22, 1, "WARNING: use of 'ignore-no-cache' in 'refresh_pattern' violates HTTP");
761
762 break;
763 }
764
765 for (R = Config.Refresh; R; R = R->next) {
766 if (!R->flags.ignore_no_store)
767 continue;
768
769 debugs(22, 1, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP");
770
771 break;
772 }
773
774 for (R = Config.Refresh; R; R = R->next) {
775 if (!R->flags.ignore_must_revalidate)
776 continue;
777 debugs(22, 1, "WARNING: use of 'ignore-must-revalidate' in 'refresh_pattern' violates HTTP");
778 break;
779 }
780
781 for (R = Config.Refresh; R; R = R->next) {
782 if (!R->flags.ignore_private)
783 continue;
784
785 debugs(22, 1, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP");
786
787 break;
788 }
789
790 for (R = Config.Refresh; R; R = R->next) {
791 if (!R->flags.ignore_auth)
792 continue;
793
794 debugs(22, 1, "WARNING: use of 'ignore-auth' in 'refresh_pattern' violates HTTP");
795
796 break;
797 }
798
799 }
800 #endif
801 #if !USE_HTTP_VIOLATIONS
802 Config.onoff.via = 1;
803 #else
804
805 if (!Config.onoff.via)
806 debugs(22, 1, "WARNING: HTTP requires the use of Via");
807
808 #endif
809
810 // we enable runtime PURGE checks if there is at least one PURGE method ACL
811 // TODO: replace with a dedicated "purge" ACL option?
812 Config2.onoff.enable_purge = (ACLMethodData::ThePurgeCount > 0);
813
814 Config2.onoff.mangle_request_headers = (Config.request_header_access != NULL);
815
816 if (geteuid() == 0) {
817 if (NULL != Config.effectiveUser) {
818
819 struct passwd *pwd = getpwnam(Config.effectiveUser);
820
821 if (NULL == pwd) {
822 /*
823 * Andres Kroonmaa <andre@online.ee>:
824 * Some getpwnam() implementations (Solaris?) require
825 * an available FD < 256 for opening a FILE* to the
826 * passwd file.
827 * DW:
828 * This should be safe at startup, but might still fail
829 * during reconfigure.
830 */
831 fatalf("getpwnam failed to find userid for effective user '%s'",
832 Config.effectiveUser);
833 return;
834 }
835
836 Config2.effectiveUserID = pwd->pw_uid;
837
838 Config2.effectiveGroupID = pwd->pw_gid;
839
840 #if HAVE_PUTENV
841
842 if (pwd->pw_dir && *pwd->pw_dir) {
843 int len;
844 char *env_str = (char *)xcalloc((len = strlen(pwd->pw_dir) + 6), 1);
845 snprintf(env_str, len, "HOME=%s", pwd->pw_dir);
846 putenv(env_str);
847 }
848
849 #endif
850
851 }
852 } else {
853 Config2.effectiveUserID = geteuid();
854 Config2.effectiveGroupID = getegid();
855 }
856
857 if (NULL != Config.effectiveGroup) {
858
859 struct group *grp = getgrnam(Config.effectiveGroup);
860
861 if (NULL == grp) {
862 fatalf("getgrnam failed to find groupid for effective group '%s'",
863 Config.effectiveGroup);
864 return;
865 }
866
867 Config2.effectiveGroupID = grp->gr_gid;
868 }
869
870 HttpRequestMethod::Configure(Config);
871 #if USE_SSL
872
873 debugs(3, 1, "Initializing https proxy context");
874
875 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);
876
877 for (peer *p = Config.peers; p != NULL; p = p->next) {
878 if (p->use_ssl) {
879 debugs(3, 1, "Initializing cache_peer " << p->name << " SSL context");
880 p->sslContext = sslCreateClientContext(p->sslcert, p->sslkey, p->sslversion, p->sslcipher, p->ssloptions, p->sslflags, p->sslcafile, p->sslcapath, p->sslcrlfile);
881 }
882 }
883
884 for (AnyP::PortCfg *s = Config.Sockaddr.http; s != NULL; s = s->next) {
885 if (!s->cert && !s->key)
886 continue;
887
888 debugs(3, 1, "Initializing http_port " << s->s << " SSL context");
889
890 s->staticSslContext.reset(
891 sslCreateServerContext(s->cert, s->key,
892 s->version, s->cipher, s->options, s->sslflags, s->clientca,
893 s->cafile, s->capath, s->crlfile, s->dhfile,
894 s->sslContextSessionId));
895
896 Ssl::readCertChainAndPrivateKeyFromFiles(s->signingCert, s->signPkey, s->certsToChain, s->cert, s->key);
897 }
898
899 for (AnyP::PortCfg *s = Config.Sockaddr.https; s != NULL; s = s->next) {
900 debugs(3, 1, "Initializing https_port " << s->s << " SSL context");
901
902 s->staticSslContext.reset(
903 sslCreateServerContext(s->cert, s->key,
904 s->version, s->cipher, s->options, s->sslflags, s->clientca,
905 s->cafile, s->capath, s->crlfile, s->dhfile,
906 s->sslContextSessionId));
907 }
908
909 #endif
910
911 // prevent infinite fetch loops in the request parser
912 // due to buffer full but not enough data recived to finish parse
913 if (Config.maxRequestBufferSize <= Config.maxRequestHeaderSize) {
914 fatalf("Client request buffer of %u bytes cannot hold a request with %u bytes of headers." \
915 " Change client_request_buffer_max or request_header_max_size limits.",
916 (uint32_t)Config.maxRequestBufferSize, (uint32_t)Config.maxRequestHeaderSize);
917 }
918
919 #if USE_AUTH
920 /*
921 * disable client side request pipelining. There is a race with
922 * Negotiate and NTLM when the client sends a second request on an
923 * connection before the authenticate challenge is sent. With
924 * pipelining OFF, the client may fail to authenticate, but squid's
925 * state will be preserved.
926 */
927 if (Config.onoff.pipeline_prefetch) {
928 Auth::Config *nego = Auth::Config::Find("Negotiate");
929 Auth::Config *ntlm = Auth::Config::Find("NTLM");
930 if ((nego && nego->active()) || (ntlm && ntlm->active())) {
931 debugs(3, DBG_IMPORTANT, "WARNING: pipeline_prefetch breaks NTLM and Negotiate authentication. Forced OFF.");
932 Config.onoff.pipeline_prefetch = 0;
933 }
934 }
935 #endif
936 }
937
938 /** Parse a line containing an obsolete directive.
939 * To upgrade it where possible instead of just "Bungled config" for
940 * directives which cannot be marked as simply aliases of the some name.
941 * For example if the parameter order and content has changed.
942 * Or if the directive has been completely removed.
943 */
944 void
945 parse_obsolete(const char *name)
946 {
947 // Directives which have been radically changed rather than removed
948 if (!strcmp(name, "url_rewrite_concurrency")) {
949 int cval;
950 parse_int(&cval);
951 debugs(3, DBG_CRITICAL, "WARNING: url_rewrite_concurrency upgrade overriding url_rewrite_children settings.");
952 Config.redirectChildren.concurrency = cval;
953 }
954 }
955
956 /* Parse a time specification from the config file. Store the
957 * result in 'tptr', after converting it to 'units' */
958 static void
959 parseTimeLine(time_msec_t * tptr, const char *units, bool allowMsec)
960 {
961 char *token;
962 double d;
963 time_msec_t m;
964 time_msec_t u;
965
966 if ((u = parseTimeUnits(units, allowMsec)) == 0)
967 self_destruct();
968
969 if ((token = strtok(NULL, w_space)) == NULL)
970 self_destruct();
971
972 d = xatof(token);
973
974 m = u; /* default to 'units' if none specified */
975
976 if (0 == d)
977 (void) 0;
978 else if ((token = strtok(NULL, w_space)) == NULL)
979 debugs(3, 0, "WARNING: No units on '" <<
980 config_input_line << "', assuming " <<
981 d << " " << units );
982 else if ((m = parseTimeUnits(token, allowMsec)) == 0)
983 self_destruct();
984
985 *tptr = static_cast<time_msec_t>(m * d);
986 }
987
988 static uint64_t
989 parseTimeUnits(const char *unit, bool allowMsec)
990 {
991 if (allowMsec && !strncasecmp(unit, T_MILLISECOND_STR, strlen(T_MILLISECOND_STR)))
992 return 1;
993
994 if (!strncasecmp(unit, T_SECOND_STR, strlen(T_SECOND_STR)))
995 return 1000;
996
997 if (!strncasecmp(unit, T_MINUTE_STR, strlen(T_MINUTE_STR)))
998 return 60 * 1000;
999
1000 if (!strncasecmp(unit, T_HOUR_STR, strlen(T_HOUR_STR)))
1001 return 3600 * 1000;
1002
1003 if (!strncasecmp(unit, T_DAY_STR, strlen(T_DAY_STR)))
1004 return 86400 * 1000;
1005
1006 if (!strncasecmp(unit, T_WEEK_STR, strlen(T_WEEK_STR)))
1007 return 86400 * 7 * 1000;
1008
1009 if (!strncasecmp(unit, T_FORTNIGHT_STR, strlen(T_FORTNIGHT_STR)))
1010 return 86400 * 14 * 1000;
1011
1012 if (!strncasecmp(unit, T_MONTH_STR, strlen(T_MONTH_STR)))
1013 return static_cast<uint64_t>(86400) * 30 * 1000;
1014
1015 if (!strncasecmp(unit, T_YEAR_STR, strlen(T_YEAR_STR)))
1016 return static_cast<uint64_t>(86400 * 1000 * 365.2522);
1017
1018 if (!strncasecmp(unit, T_DECADE_STR, strlen(T_DECADE_STR)))
1019 return static_cast<uint64_t>(86400 * 1000 * 365.2522 * 10);
1020
1021 debugs(3, 1, "parseTimeUnits: unknown time unit '" << unit << "'");
1022
1023 return 0;
1024 }
1025
1026 static void
1027 parseBytesLine64(int64_t * bptr, const char *units)
1028 {
1029 char *token;
1030 double d;
1031 int64_t m;
1032 int64_t u;
1033
1034 if ((u = parseBytesUnits(units)) == 0) {
1035 self_destruct();
1036 return;
1037 }
1038
1039 if ((token = strtok(NULL, w_space)) == NULL) {
1040 self_destruct();
1041 return;
1042 }
1043
1044 if (strcmp(token, "none") == 0 || strcmp(token, "-1") == 0) {
1045 *bptr = -1;
1046 return;
1047 }
1048
1049 d = xatof(token);
1050
1051 m = u; /* default to 'units' if none specified */
1052
1053 if (0.0 == d)
1054 (void) 0;
1055 else if ((token = strtok(NULL, w_space)) == NULL)
1056 debugs(3, 0, "WARNING: No units on '" <<
1057 config_input_line << "', assuming " <<
1058 d << " " << units );
1059 else if ((m = parseBytesUnits(token)) == 0) {
1060 self_destruct();
1061 return;
1062 }
1063
1064 *bptr = static_cast<int64_t>(m * d / u);
1065
1066 if (static_cast<double>(*bptr) * 2 != m * d / u * 2)
1067 self_destruct();
1068 }
1069
1070
1071 static void
1072 parseBytesLine(size_t * bptr, const char *units)
1073 {
1074 char *token;
1075 double d;
1076 int m;
1077 int u;
1078
1079 if ((u = parseBytesUnits(units)) == 0) {
1080 self_destruct();
1081 return;
1082 }
1083
1084 if ((token = strtok(NULL, w_space)) == NULL) {
1085 self_destruct();
1086 return;
1087 }
1088
1089 if (strcmp(token, "none") == 0 || strcmp(token, "-1") == 0) {
1090 *bptr = static_cast<size_t>(-1);
1091 return;
1092 }
1093
1094 d = xatof(token);
1095
1096 m = u; /* default to 'units' if none specified */
1097
1098 if (0.0 == d)
1099 (void) 0;
1100 else if ((token = strtok(NULL, w_space)) == NULL)
1101 debugs(3, 0, "WARNING: No units on '" <<
1102 config_input_line << "', assuming " <<
1103 d << " " << units );
1104 else if ((m = parseBytesUnits(token)) == 0) {
1105 self_destruct();
1106 return;
1107 }
1108
1109 *bptr = static_cast<size_t>(m * d / u);
1110
1111 if (static_cast<double>(*bptr) * 2 != m * d / u * 2)
1112 self_destruct();
1113 }
1114
1115 #if !USE_DNSHELPER
1116 static void
1117 parseBytesLineSigned(ssize_t * bptr, const char *units)
1118 {
1119 char *token;
1120 double d;
1121 int m;
1122 int u;
1123
1124 if ((u = parseBytesUnits(units)) == 0) {
1125 self_destruct();
1126 return;
1127 }
1128
1129 if ((token = strtok(NULL, w_space)) == NULL) {
1130 self_destruct();
1131 return;
1132 }
1133
1134 if (strcmp(token, "none") == 0 || token[0] == '-' /* -N */) {
1135 *bptr = -1;
1136 return;
1137 }
1138
1139 d = xatof(token);
1140
1141 m = u; /* default to 'units' if none specified */
1142
1143 if (0.0 == d)
1144 (void) 0;
1145 else if ((token = strtok(NULL, w_space)) == NULL)
1146 debugs(3, 0, "WARNING: No units on '" <<
1147 config_input_line << "', assuming " <<
1148 d << " " << units );
1149 else if ((m = parseBytesUnits(token)) == 0) {
1150 self_destruct();
1151 return;
1152 }
1153
1154 *bptr = static_cast<size_t>(m * d / u);
1155
1156 if (static_cast<double>(*bptr) * 2 != m * d / u * 2)
1157 self_destruct();
1158 }
1159 #endif
1160
1161 #if USE_SSL
1162 /**
1163 * Parse bytes from a string.
1164 * Similar to the parseBytesLine function but parses the string value instead of
1165 * the current token value.
1166 */
1167 static void parseBytesOptionValue(size_t * bptr, const char *units, char const * value)
1168 {
1169 int u;
1170 if ((u = parseBytesUnits(units)) == 0) {
1171 self_destruct();
1172 return;
1173 }
1174
1175 // Find number from string beginning.
1176 char const * number_begin = value;
1177 char const * number_end = value;
1178
1179 while ((*number_end >= '0' && *number_end <= '9')) {
1180 number_end++;
1181 }
1182
1183 String number;
1184 number.limitInit(number_begin, number_end - number_begin);
1185
1186 int d = xatoi(number.termedBuf());
1187 int m;
1188 if ((m = parseBytesUnits(number_end)) == 0) {
1189 self_destruct();
1190 return;
1191 }
1192
1193 *bptr = static_cast<size_t>(m * d / u);
1194 if (static_cast<double>(*bptr) * 2 != m * d / u * 2)
1195 self_destruct();
1196 }
1197 #endif
1198
1199 static size_t
1200 parseBytesUnits(const char *unit)
1201 {
1202 if (!strncasecmp(unit, B_BYTES_STR, strlen(B_BYTES_STR)))
1203 return 1;
1204
1205 if (!strncasecmp(unit, B_KBYTES_STR, strlen(B_KBYTES_STR)))
1206 return 1 << 10;
1207
1208 if (!strncasecmp(unit, B_MBYTES_STR, strlen(B_MBYTES_STR)))
1209 return 1 << 20;
1210
1211 if (!strncasecmp(unit, B_GBYTES_STR, strlen(B_GBYTES_STR)))
1212 return 1 << 30;
1213
1214 debugs(3, DBG_CRITICAL, "WARNING: Unknown bytes unit '" << unit << "'");
1215
1216 return 0;
1217 }
1218
1219 /*****************************************************************************
1220 * Max
1221 *****************************************************************************/
1222
1223 static void
1224 dump_acl(StoreEntry * entry, const char *name, ACL * ae)
1225 {
1226 wordlist *w;
1227 wordlist *v;
1228
1229 while (ae != NULL) {
1230 debugs(3, 3, "dump_acl: " << name << " " << ae->name);
1231 storeAppendPrintf(entry, "%s %s %s ",
1232 name,
1233 ae->name,
1234 ae->typeString());
1235 v = w = ae->dump();
1236
1237 while (v != NULL) {
1238 debugs(3, 3, "dump_acl: " << name << " " << ae->name << " " << v->key);
1239 storeAppendPrintf(entry, "%s ", v->key);
1240 v = v->next;
1241 }
1242
1243 storeAppendPrintf(entry, "\n");
1244 wordlistDestroy(&w);
1245 ae = ae->next;
1246 }
1247 }
1248
1249 static void
1250 parse_acl(ACL ** ae)
1251 {
1252 ACL::ParseAclLine(LegacyParser, ae);
1253 }
1254
1255 static void
1256 free_acl(ACL ** ae)
1257 {
1258 aclDestroyAcls(ae);
1259 }
1260
1261 void
1262 dump_acl_list(StoreEntry * entry, ACLList * head)
1263 {
1264 ACLList *l;
1265
1266 for (l = head; l; l = l->next) {
1267 storeAppendPrintf(entry, " %s%s",
1268 l->op ? null_string : "!",
1269 l->_acl->name);
1270 }
1271 }
1272
1273 void
1274 dump_acl_access(StoreEntry * entry, const char *name, acl_access * head)
1275 {
1276 acl_access *l;
1277
1278 for (l = head; l; l = l->next) {
1279 storeAppendPrintf(entry, "%s %s",
1280 name,
1281 l->allow ? "Allow" : "Deny");
1282 dump_acl_list(entry, l->aclList);
1283 storeAppendPrintf(entry, "\n");
1284 }
1285 }
1286
1287 static void
1288 parse_acl_access(acl_access ** head)
1289 {
1290 aclParseAccessLine(LegacyParser, head);
1291 }
1292
1293 static void
1294 free_acl_access(acl_access ** head)
1295 {
1296 aclDestroyAccessList(head);
1297 }
1298
1299 static void
1300 dump_address(StoreEntry * entry, const char *name, Ip::Address &addr)
1301 {
1302 char buf[MAX_IPSTRLEN];
1303 storeAppendPrintf(entry, "%s %s\n", name, addr.NtoA(buf,MAX_IPSTRLEN) );
1304 }
1305
1306 static void
1307 parse_address(Ip::Address *addr)
1308 {
1309 char *token = strtok(NULL, w_space);
1310
1311 if (!token) {
1312 self_destruct();
1313 return;
1314 }
1315
1316 if (!strcmp(token,"any_addr"))
1317 addr->SetAnyAddr();
1318 else if ( (!strcmp(token,"no_addr")) || (!strcmp(token,"full_mask")) )
1319 addr->SetNoAddr();
1320 else if ( (*addr = token) ) // try parse numeric/IPA
1321 (void) 0;
1322 else
1323 addr->GetHostByName(token); // dont use ipcache
1324 }
1325
1326 static void
1327 free_address(Ip::Address *addr)
1328 {
1329 addr->SetEmpty();
1330 }
1331
1332 CBDATA_TYPE(acl_address);
1333
1334 static void
1335 dump_acl_address(StoreEntry * entry, const char *name, acl_address * head)
1336 {
1337 char buf[MAX_IPSTRLEN];
1338 acl_address *l;
1339
1340 for (l = head; l; l = l->next) {
1341 if (!l->addr.IsAnyAddr())
1342 storeAppendPrintf(entry, "%s %s", name, l->addr.NtoA(buf,MAX_IPSTRLEN));
1343 else
1344 storeAppendPrintf(entry, "%s autoselect", name);
1345
1346 dump_acl_list(entry, l->aclList);
1347
1348 storeAppendPrintf(entry, "\n");
1349 }
1350 }
1351
1352 static void
1353 freed_acl_address(void *data)
1354 {
1355 acl_address *l = static_cast<acl_address *>(data);
1356 aclDestroyAclList(&l->aclList);
1357 }
1358
1359 static void
1360 parse_acl_address(acl_address ** head)
1361 {
1362 acl_address *l;
1363 acl_address **tail = head; /* sane name below */
1364 CBDATA_INIT_TYPE_FREECB(acl_address, freed_acl_address);
1365 l = cbdataAlloc(acl_address);
1366 parse_address(&l->addr);
1367 aclParseAclList(LegacyParser, &l->aclList);
1368
1369 while (*tail)
1370 tail = &(*tail)->next;
1371
1372 *tail = l;
1373 }
1374
1375 static void
1376 free_acl_address(acl_address ** head)
1377 {
1378 while (*head) {
1379 acl_address *l = *head;
1380 *head = l->next;
1381 cbdataFree(l);
1382 }
1383 }
1384
1385 CBDATA_TYPE(acl_tos);
1386
1387 static void
1388 dump_acl_tos(StoreEntry * entry, const char *name, acl_tos * head)
1389 {
1390 acl_tos *l;
1391
1392 for (l = head; l; l = l->next) {
1393 if (l->tos > 0)
1394 storeAppendPrintf(entry, "%s 0x%02X", name, l->tos);
1395 else
1396 storeAppendPrintf(entry, "%s none", name);
1397
1398 dump_acl_list(entry, l->aclList);
1399
1400 storeAppendPrintf(entry, "\n");
1401 }
1402 }
1403
1404 static void
1405 freed_acl_tos(void *data)
1406 {
1407 acl_tos *l = static_cast<acl_tos *>(data);
1408 aclDestroyAclList(&l->aclList);
1409 }
1410
1411 static void
1412 parse_acl_tos(acl_tos ** head)
1413 {
1414 acl_tos *l;
1415 acl_tos **tail = head; /* sane name below */
1416 unsigned int tos; /* Initially uint for strtoui. Casted to tos_t before return */
1417 char *token = strtok(NULL, w_space);
1418
1419 if (!token) {
1420 self_destruct();
1421 return;
1422 }
1423
1424 if (!xstrtoui(token, NULL, &tos, 0, std::numeric_limits<tos_t>::max())) {
1425 self_destruct();
1426 return;
1427 }
1428
1429 CBDATA_INIT_TYPE_FREECB(acl_tos, freed_acl_tos);
1430
1431 l = cbdataAlloc(acl_tos);
1432
1433 l->tos = (tos_t)tos;
1434
1435 aclParseAclList(LegacyParser, &l->aclList);
1436
1437 while (*tail)
1438 tail = &(*tail)->next;
1439
1440 *tail = l;
1441 }
1442
1443 static void
1444 free_acl_tos(acl_tos ** head)
1445 {
1446 while (*head) {
1447 acl_tos *l = *head;
1448 *head = l->next;
1449 l->next = NULL;
1450 cbdataFree(l);
1451 }
1452 }
1453
1454 #if SO_MARK && USE_LIBCAP
1455
1456 CBDATA_TYPE(acl_nfmark);
1457
1458 static void
1459 dump_acl_nfmark(StoreEntry * entry, const char *name, acl_nfmark * head)
1460 {
1461 acl_nfmark *l;
1462
1463 for (l = head; l; l = l->next) {
1464 if (l->nfmark > 0)
1465 storeAppendPrintf(entry, "%s 0x%02X", name, l->nfmark);
1466 else
1467 storeAppendPrintf(entry, "%s none", name);
1468
1469 dump_acl_list(entry, l->aclList);
1470
1471 storeAppendPrintf(entry, "\n");
1472 }
1473 }
1474
1475 static void
1476 freed_acl_nfmark(void *data)
1477 {
1478 acl_nfmark *l = static_cast<acl_nfmark *>(data);
1479 aclDestroyAclList(&l->aclList);
1480 }
1481
1482 static void
1483 parse_acl_nfmark(acl_nfmark ** head)
1484 {
1485 acl_nfmark *l;
1486 acl_nfmark **tail = head; /* sane name below */
1487 nfmark_t mark;
1488 char *token = strtok(NULL, w_space);
1489
1490 if (!token) {
1491 self_destruct();
1492 return;
1493 }
1494
1495 if (!xstrtoui(token, NULL, &mark, 0, std::numeric_limits<nfmark_t>::max())) {
1496 self_destruct();
1497 return;
1498 }
1499
1500 CBDATA_INIT_TYPE_FREECB(acl_nfmark, freed_acl_nfmark);
1501
1502 l = cbdataAlloc(acl_nfmark);
1503
1504 l->nfmark = mark;
1505
1506 aclParseAclList(LegacyParser, &l->aclList);
1507
1508 while (*tail)
1509 tail = &(*tail)->next;
1510
1511 *tail = l;
1512 }
1513
1514 static void
1515 free_acl_nfmark(acl_nfmark ** head)
1516 {
1517 while (*head) {
1518 acl_nfmark *l = *head;
1519 *head = l->next;
1520 l->next = NULL;
1521 cbdataFree(l);
1522 }
1523 }
1524 #endif /* SO_MARK */
1525
1526 CBDATA_TYPE(acl_size_t);
1527
1528 static void
1529 dump_acl_b_size_t(StoreEntry * entry, const char *name, acl_size_t * head)
1530 {
1531 acl_size_t *l;
1532
1533 for (l = head; l; l = l->next) {
1534 if (l->size != -1)
1535 storeAppendPrintf(entry, "%s %d %s\n", name, (int) l->size, B_BYTES_STR);
1536 else
1537 storeAppendPrintf(entry, "%s none", name);
1538
1539 dump_acl_list(entry, l->aclList);
1540
1541 storeAppendPrintf(entry, "\n");
1542 }
1543 }
1544
1545 static void
1546 freed_acl_b_size_t(void *data)
1547 {
1548 acl_size_t *l = static_cast<acl_size_t *>(data);
1549 aclDestroyAclList(&l->aclList);
1550 }
1551
1552 static void
1553 parse_acl_b_size_t(acl_size_t ** head)
1554 {
1555 acl_size_t *l;
1556 acl_size_t **tail = head; /* sane name below */
1557
1558 CBDATA_INIT_TYPE_FREECB(acl_size_t, freed_acl_b_size_t);
1559
1560 l = cbdataAlloc(acl_size_t);
1561
1562 parse_b_int64_t(&l->size);
1563
1564 aclParseAclList(LegacyParser, &l->aclList);
1565
1566 while (*tail)
1567 tail = &(*tail)->next;
1568
1569 *tail = l;
1570 }
1571
1572 static void
1573 free_acl_b_size_t(acl_size_t ** head)
1574 {
1575 while (*head) {
1576 acl_size_t *l = *head;
1577 *head = l->next;
1578 l->next = NULL;
1579 cbdataFree(l);
1580 }
1581 }
1582
1583 #if USE_DELAY_POOLS
1584
1585 #include "DelayPools.h"
1586 #include "DelayConfig.h"
1587 /* do nothing - free_delay_pool_count is the magic free function.
1588 * this is why delay_pool_count isn't just marked TYPE: u_short
1589 */
1590 #define free_delay_pool_class(X)
1591 #define free_delay_pool_access(X)
1592 #define free_delay_pool_rates(X)
1593 #define dump_delay_pool_class(X, Y, Z)
1594 #define dump_delay_pool_access(X, Y, Z)
1595 #define dump_delay_pool_rates(X, Y, Z)
1596
1597 static void
1598 free_delay_pool_count(DelayConfig * cfg)
1599 {
1600 cfg->freePoolCount();
1601 }
1602
1603 static void
1604 dump_delay_pool_count(StoreEntry * entry, const char *name, DelayConfig &cfg)
1605 {
1606 cfg.dumpPoolCount (entry, name);
1607 }
1608
1609 static void
1610 parse_delay_pool_count(DelayConfig * cfg)
1611 {
1612 cfg->parsePoolCount();
1613 }
1614
1615 static void
1616 parse_delay_pool_class(DelayConfig * cfg)
1617 {
1618 cfg->parsePoolClass();
1619 }
1620
1621 static void
1622 parse_delay_pool_rates(DelayConfig * cfg)
1623 {
1624 cfg->parsePoolRates();
1625 }
1626
1627 static void
1628 parse_delay_pool_access(DelayConfig * cfg)
1629 {
1630 cfg->parsePoolAccess(LegacyParser);
1631 }
1632
1633 #endif
1634
1635 #if USE_DELAY_POOLS
1636 #include "ClientDelayConfig.h"
1637 /* do nothing - free_client_delay_pool_count is the magic free function.
1638 * this is why client_delay_pool_count isn't just marked TYPE: u_short
1639 */
1640
1641 #define free_client_delay_pool_access(X)
1642 #define free_client_delay_pool_rates(X)
1643 #define dump_client_delay_pool_access(X, Y, Z)
1644 #define dump_client_delay_pool_rates(X, Y, Z)
1645
1646 static void
1647 free_client_delay_pool_count(ClientDelayConfig * cfg)
1648 {
1649 cfg->freePoolCount();
1650 }
1651
1652 static void
1653 dump_client_delay_pool_count(StoreEntry * entry, const char *name, ClientDelayConfig &cfg)
1654 {
1655 cfg.dumpPoolCount (entry, name);
1656 }
1657
1658 static void
1659 parse_client_delay_pool_count(ClientDelayConfig * cfg)
1660 {
1661 cfg->parsePoolCount();
1662 }
1663
1664 static void
1665 parse_client_delay_pool_rates(ClientDelayConfig * cfg)
1666 {
1667 cfg->parsePoolRates();
1668 }
1669
1670 static void
1671 parse_client_delay_pool_access(ClientDelayConfig * cfg)
1672 {
1673 cfg->parsePoolAccess(LegacyParser);
1674 }
1675 #endif
1676
1677 #if USE_HTTP_VIOLATIONS
1678 static void
1679 dump_http_header_access(StoreEntry * entry, const char *name, const HeaderManglers *manglers)
1680 {
1681 if (manglers)
1682 manglers->dumpAccess(entry, name);
1683 }
1684
1685 static void
1686 parse_http_header_access(HeaderManglers **pm)
1687 {
1688 char *t = NULL;
1689
1690 if ((t = strtok(NULL, w_space)) == NULL) {
1691 debugs(3, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
1692 debugs(3, 0, "parse_http_header_access: missing header name.");
1693 return;
1694 }
1695
1696 if (!*pm)
1697 *pm = new HeaderManglers;
1698 HeaderManglers *manglers = *pm;
1699 header_mangler *mangler = manglers->track(t);
1700 assert(mangler);
1701 parse_acl_access(&mangler->access_list);
1702 }
1703
1704 static void
1705 free_HeaderManglers(HeaderManglers **pm)
1706 {
1707 // we delete the entire http_header_* mangler configuration at once
1708 if (const HeaderManglers *manglers = *pm) {
1709 delete manglers;
1710 *pm = NULL;
1711 }
1712 }
1713
1714 static void
1715 dump_http_header_replace(StoreEntry * entry, const char *name, const HeaderManglers *manglers)
1716 {
1717 if (manglers)
1718 manglers->dumpReplacement(entry, name);
1719 }
1720
1721 static void
1722 parse_http_header_replace(HeaderManglers **pm)
1723 {
1724 char *t = NULL;
1725
1726 if ((t = strtok(NULL, w_space)) == NULL) {
1727 debugs(3, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
1728 debugs(3, 0, "parse_http_header_replace: missing header name.");
1729 return;
1730 }
1731
1732 const char *value = t + strlen(t) + 1;
1733
1734 if (!*pm)
1735 *pm = new HeaderManglers;
1736 HeaderManglers *manglers = *pm;
1737 manglers->setReplacement(t, value);
1738 }
1739
1740 #endif
1741
1742 static void
1743 dump_cachedir(StoreEntry * entry, const char *name, SquidConfig::_cacheSwap swap)
1744 {
1745 SwapDir *s;
1746 int i;
1747 assert (entry);
1748
1749 for (i = 0; i < swap.n_configured; i++) {
1750 s = dynamic_cast<SwapDir *>(swap.swapDirs[i].getRaw());
1751 if (!s) continue;
1752 storeAppendPrintf(entry, "%s %s %s", name, s->type(), s->path);
1753 s->dump(*entry);
1754 storeAppendPrintf(entry, "\n");
1755 }
1756 }
1757
1758 static int
1759 check_null_string(char *s)
1760 {
1761 return s == NULL;
1762 }
1763
1764 #if USE_AUTH
1765 static void
1766 parse_authparam(Auth::ConfigVector * config)
1767 {
1768 char *type_str;
1769 char *param_str;
1770
1771 if ((type_str = strtok(NULL, w_space)) == NULL)
1772 self_destruct();
1773
1774 if ((param_str = strtok(NULL, w_space)) == NULL)
1775 self_destruct();
1776
1777 /* find a configuration for the scheme in the currently parsed configs... */
1778 Auth::Config *schemeCfg = Auth::Config::Find(type_str);
1779
1780 if (schemeCfg == NULL) {
1781 /* Create a configuration based on the scheme info */
1782 Auth::Scheme::Pointer theScheme = Auth::Scheme::Find(type_str);
1783
1784 if (theScheme == NULL) {
1785 debugs(3, DBG_CRITICAL, "Parsing Config File: Unknown authentication scheme '" << type_str << "'.");
1786 self_destruct();
1787 }
1788
1789 config->push_back(theScheme->createConfig());
1790 schemeCfg = Auth::Config::Find(type_str);
1791 if (schemeCfg == NULL) {
1792 debugs(3, DBG_CRITICAL, "Parsing Config File: Corruption configuring authentication scheme '" << type_str << "'.");
1793 self_destruct();
1794 }
1795 }
1796
1797 schemeCfg->parse(schemeCfg, config->size(), param_str);
1798 }
1799
1800 static void
1801 free_authparam(Auth::ConfigVector * cfg)
1802 {
1803 /* Wipe the Auth globals and Detach/Destruct component config + state. */
1804 cfg->clean();
1805
1806 /* remove our pointers to the probably-dead sub-configs */
1807 while (cfg->size()) {
1808 cfg->pop_back();
1809 }
1810
1811 /* on reconfigure initialize new auth schemes for the new config. */
1812 if (reconfiguring) {
1813 Auth::Init();
1814 }
1815 }
1816
1817 static void
1818 dump_authparam(StoreEntry * entry, const char *name, Auth::ConfigVector cfg)
1819 {
1820 for (Auth::ConfigVector::iterator i = cfg.begin(); i != cfg.end(); ++i)
1821 (*i)->dump(entry, name, (*i));
1822 }
1823 #endif /* USE_AUTH */
1824
1825 /* TODO: just return the object, the # is irrelevant */
1826 static int
1827 find_fstype(char *type)
1828 {
1829 for (size_t i = 0; i < StoreFileSystem::FileSystems().size(); ++i)
1830 if (strcasecmp(type, StoreFileSystem::FileSystems().items[i]->type()) == 0)
1831 return (int)i;
1832
1833 return (-1);
1834 }
1835
1836 static void
1837 parse_cachedir(SquidConfig::_cacheSwap * swap)
1838 {
1839 char *type_str;
1840 char *path_str;
1841 RefCount<SwapDir> sd;
1842 int i;
1843 int fs;
1844
1845 if ((type_str = strtok(NULL, w_space)) == NULL)
1846 self_destruct();
1847
1848 if ((path_str = strtok(NULL, w_space)) == NULL)
1849 self_destruct();
1850
1851 fs = find_fstype(type_str);
1852
1853 if (fs < 0)
1854 self_destruct();
1855
1856 /* reconfigure existing dir */
1857
1858 for (i = 0; i < swap->n_configured; i++) {
1859 assert (swap->swapDirs[i].getRaw());
1860
1861 if ((strcasecmp(path_str, dynamic_cast<SwapDir *>(swap->swapDirs[i].getRaw())->path)) == 0) {
1862 /* this is specific to on-fs Stores. The right
1863 * way to handle this is probably to have a mapping
1864 * from paths to stores, and have on-fs stores
1865 * register with that, and lookip in that in their
1866 * own setup logic. RBC 20041225. TODO.
1867 */
1868
1869 sd = dynamic_cast<SwapDir *>(swap->swapDirs[i].getRaw());
1870
1871 if (strcmp(sd->type(), StoreFileSystem::FileSystems().items[fs]->type()) != 0) {
1872 debugs(3, 0, "ERROR: Can't change type of existing cache_dir " <<
1873 sd->type() << " " << sd->path << " to " << type_str << ". Restart required");
1874 return;
1875 }
1876
1877 sd->reconfigure();
1878
1879 update_maxobjsize();
1880
1881 return;
1882 }
1883 }
1884
1885 /* new cache_dir */
1886 if (swap->n_configured > 63) {
1887 /* 7 bits, signed */
1888 debugs(3, DBG_CRITICAL, "WARNING: There is a fixed maximum of 63 cache_dir entries Squid can handle.");
1889 debugs(3, DBG_CRITICAL, "WARNING: '" << path_str << "' is one to many.");
1890 self_destruct();
1891 return;
1892 }
1893
1894 allocate_new_swapdir(swap);
1895
1896 swap->swapDirs[swap->n_configured] = StoreFileSystem::FileSystems().items[fs]->createSwapDir();
1897
1898 sd = dynamic_cast<SwapDir *>(swap->swapDirs[swap->n_configured].getRaw());
1899
1900 /* parse the FS parameters and options */
1901 sd->parse(swap->n_configured, path_str);
1902
1903 ++swap->n_configured;
1904
1905 /* Update the max object size */
1906 update_maxobjsize();
1907 }
1908
1909 static const char *
1910 peer_type_str(const peer_t type)
1911 {
1912 const char * result;
1913
1914 switch (type) {
1915
1916 case PEER_PARENT:
1917 result = "parent";
1918 break;
1919
1920 case PEER_SIBLING:
1921 result = "sibling";
1922 break;
1923
1924 case PEER_MULTICAST:
1925 result = "multicast";
1926 break;
1927
1928 default:
1929 result = "unknown";
1930 break;
1931 }
1932
1933 return result;
1934 }
1935
1936 static void
1937 dump_peer(StoreEntry * entry, const char *name, peer * p)
1938 {
1939 domain_ping *d;
1940 domain_type *t;
1941 LOCAL_ARRAY(char, xname, 128);
1942
1943 while (p != NULL) {
1944 storeAppendPrintf(entry, "%s %s %s %d %d name=%s",
1945 name,
1946 p->host,
1947 neighborTypeStr(p),
1948 p->http_port,
1949 p->icp.port,
1950 p->name);
1951 dump_peer_options(entry, p);
1952
1953 for (d = p->peer_domain; d; d = d->next) {
1954 storeAppendPrintf(entry, "cache_peer_domain %s %s%s\n",
1955 p->host,
1956 d->do_ping ? null_string : "!",
1957 d->domain);
1958 }
1959
1960 if (p->access) {
1961 snprintf(xname, 128, "cache_peer_access %s", p->name);
1962 dump_acl_access(entry, xname, p->access);
1963 }
1964
1965 for (t = p->typelist; t; t = t->next) {
1966 storeAppendPrintf(entry, "neighbor_type_domain %s %s %s\n",
1967 p->host,
1968 peer_type_str(t->type),
1969 t->domain);
1970 }
1971
1972 p = p->next;
1973 }
1974 }
1975
1976 /**
1977 * utility function to prevent getservbyname() being called with a numeric value
1978 * on Windows at least it returns garage results.
1979 */
1980 static bool
1981 isUnsignedNumeric(const char *str, size_t len)
1982 {
1983 if (len < 1) return false;
1984
1985 for (; len >0 && *str; str++, len--) {
1986 if (! isdigit(*str))
1987 return false;
1988 }
1989 return true;
1990 }
1991
1992 /**
1993 \param proto 'tcp' or 'udp' for protocol
1994 \returns Port the named service is supposed to be listening on.
1995 */
1996 static unsigned short
1997 GetService(const char *proto)
1998 {
1999 struct servent *port = NULL;
2000 /** Parses a port number or service name from the squid.conf */
2001 char *token = strtok(NULL, w_space);
2002 if (token == NULL) {
2003 self_destruct();
2004 return 0; /* NEVER REACHED */
2005 }
2006 /** Returns either the service port number from /etc/services */
2007 if ( !isUnsignedNumeric(token, strlen(token)) )
2008 port = getservbyname(token, proto);
2009 if (port != NULL) {
2010 return ntohs((unsigned short)port->s_port);
2011 }
2012 /** Or a numeric translation of the config text. */
2013 return xatos(token);
2014 }
2015
2016 /**
2017 \returns Port the named TCP service is supposed to be listening on.
2018 \copydoc GetService(const char *proto)
2019 */
2020 inline unsigned short
2021 GetTcpService(void)
2022 {
2023 return GetService("tcp");
2024 }
2025
2026 /**
2027 \returns Port the named UDP service is supposed to be listening on.
2028 \copydoc GetService(const char *proto)
2029 */
2030 inline unsigned short
2031 GetUdpService(void)
2032 {
2033 return GetService("udp");
2034 }
2035
2036 static void
2037 parse_peer(peer ** head)
2038 {
2039 char *token = NULL;
2040 peer *p;
2041 CBDATA_INIT_TYPE_FREECB(peer, peerDestroy);
2042 p = cbdataAlloc(peer);
2043 p->http_port = CACHE_HTTP_PORT;
2044 p->icp.port = CACHE_ICP_PORT;
2045 p->weight = 1;
2046 p->basetime = 0;
2047 p->stats.logged_state = PEER_ALIVE;
2048
2049 if ((token = strtok(NULL, w_space)) == NULL)
2050 self_destruct();
2051
2052 p->host = xstrdup(token);
2053
2054 p->name = xstrdup(token);
2055
2056 if ((token = strtok(NULL, w_space)) == NULL)
2057 self_destruct();
2058
2059 p->type = parseNeighborType(token);
2060
2061 if (p->type == PEER_MULTICAST) {
2062 p->options.no_digest = 1;
2063 p->options.no_netdb_exchange = 1;
2064 }
2065
2066 p->http_port = GetTcpService();
2067
2068 if (!p->http_port)
2069 self_destruct();
2070
2071 p->icp.port = GetUdpService();
2072 p->connection_auth = 2; /* auto */
2073
2074 while ((token = strtok(NULL, w_space))) {
2075 if (!strcasecmp(token, "proxy-only")) {
2076 p->options.proxy_only = 1;
2077 } else if (!strcasecmp(token, "no-query")) {
2078 p->options.no_query = 1;
2079 } else if (!strcasecmp(token, "background-ping")) {
2080 p->options.background_ping = 1;
2081 } else if (!strcasecmp(token, "no-digest")) {
2082 p->options.no_digest = 1;
2083 } else if (!strcasecmp(token, "no-tproxy")) {
2084 p->options.no_tproxy = 1;
2085 } else if (!strcasecmp(token, "multicast-responder")) {
2086 p->options.mcast_responder = 1;
2087 #if PEER_MULTICAST_SIBLINGS
2088 } else if (!strcasecmp(token, "multicast-siblings")) {
2089 p->options.mcast_siblings = 1;
2090 #endif
2091 } else if (!strncasecmp(token, "weight=", 7)) {
2092 p->weight = xatoi(token + 7);
2093 } else if (!strncasecmp(token, "basetime=", 9)) {
2094 p->basetime = xatoi(token + 9);
2095 } else if (!strcasecmp(token, "closest-only")) {
2096 p->options.closest_only = 1;
2097 } else if (!strncasecmp(token, "ttl=", 4)) {
2098 p->mcast.ttl = xatoi(token + 4);
2099
2100 if (p->mcast.ttl < 0)
2101 p->mcast.ttl = 0;
2102
2103 if (p->mcast.ttl > 128)
2104 p->mcast.ttl = 128;
2105 } else if (!strcasecmp(token, "default")) {
2106 p->options.default_parent = 1;
2107 } else if (!strcasecmp(token, "round-robin")) {
2108 p->options.roundrobin = 1;
2109 } else if (!strcasecmp(token, "weighted-round-robin")) {
2110 p->options.weighted_roundrobin = 1;
2111 #if USE_HTCP
2112 } else if (!strcasecmp(token, "htcp")) {
2113 p->options.htcp = 1;
2114 } else if (!strncasecmp(token, "htcp=", 5) || !strncasecmp(token, "htcp-", 5)) {
2115 /* Note: The htcp- form is deprecated, replaced by htcp= */
2116 p->options.htcp = 1;
2117 char *tmp = xstrdup(token+5);
2118 char *mode, *nextmode;
2119 for (mode = nextmode = tmp; mode; mode = nextmode) {
2120 nextmode = strchr(mode, ',');
2121 if (nextmode)
2122 *nextmode++ = '\0';
2123 if (!strcasecmp(mode, "no-clr")) {
2124 if (p->options.htcp_only_clr)
2125 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
2126 p->options.htcp_no_clr = 1;
2127 } else if (!strcasecmp(mode, "no-purge-clr")) {
2128 p->options.htcp_no_purge_clr = 1;
2129 } else if (!strcasecmp(mode, "only-clr")) {
2130 if (p->options.htcp_no_clr)
2131 fatalf("parse_peer: can't set htcp no-clr and only-clr simultaneously");
2132 p->options.htcp_only_clr = 1;
2133 } else if (!strcasecmp(mode, "forward-clr")) {
2134 p->options.htcp_forward_clr = 1;
2135 } else if (!strcasecmp(mode, "oldsquid")) {
2136 p->options.htcp_oldsquid = 1;
2137 } else {
2138 fatalf("invalid HTCP mode '%s'", mode);
2139 }
2140 }
2141 safe_free(tmp);
2142 #endif
2143 } else if (!strcasecmp(token, "no-netdb-exchange")) {
2144 p->options.no_netdb_exchange = 1;
2145
2146 } else if (!strcasecmp(token, "carp")) {
2147 if (p->type != PEER_PARENT)
2148 fatalf("parse_peer: non-parent carp peer %s/%d\n", p->host, p->http_port);
2149
2150 p->options.carp = 1;
2151 } else if (!strncasecmp(token, "carp-key=", 9)) {
2152 if (p->options.carp != 1)
2153 fatalf("parse_peer: carp-key specified on non-carp peer %s/%d\n", p->host, p->http_port);
2154 p->options.carp_key.set=1;
2155 char *nextkey=token+strlen("carp-key="), *key=nextkey;
2156 for (; key; key = nextkey) {
2157 nextkey=strchr(key,',');
2158 if (nextkey) ++nextkey; // skip the comma, any
2159 if (0==strncasecmp(key,"scheme",6)) {
2160 p->options.carp_key.scheme=1;
2161 } else if (0==strncasecmp(key,"host",4)) {
2162 p->options.carp_key.host=1;
2163 } else if (0==strncasecmp(key,"port",4)) {
2164 p->options.carp_key.port=1;
2165 } else if (0==strncasecmp(key,"path",4)) {
2166 p->options.carp_key.path=1;
2167 } else if (0==strncasecmp(key,"params",6)) {
2168 p->options.carp_key.params=1;
2169 } else {
2170 fatalf("invalid carp-key '%s'",key);
2171 }
2172 }
2173 } else if (!strcasecmp(token, "userhash")) {
2174 #if USE_AUTH
2175 if (p->type != PEER_PARENT)
2176 fatalf("parse_peer: non-parent userhash peer %s/%d\n", p->host, p->http_port);
2177
2178 p->options.userhash = 1;
2179 #else
2180 fatalf("parse_peer: userhash requires authentication. peer %s/%d\n", p->host, p->http_port);
2181 #endif
2182 } else if (!strcasecmp(token, "sourcehash")) {
2183 if (p->type != PEER_PARENT)
2184 fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p->host, p->http_port);
2185
2186 p->options.sourcehash = 1;
2187
2188 } else if (!strcasecmp(token, "no-delay")) {
2189 #if USE_DELAY_POOLS
2190 p->options.no_delay = 1;
2191 #else
2192 debugs(0, DBG_CRITICAL, "WARNING: cache_peer option 'no-delay' requires --enable-delay-pools");
2193 #endif
2194 } else if (!strncasecmp(token, "login=", 6)) {
2195 p->login = xstrdup(token + 6);
2196 rfc1738_unescape(p->login);
2197 } else if (!strncasecmp(token, "connect-timeout=", 16)) {
2198 p->connect_timeout = xatoi(token + 16);
2199 } else if (!strncasecmp(token, "connect-fail-limit=", 19)) {
2200 p->connect_fail_limit = xatoi(token + 19);
2201 #if USE_CACHE_DIGESTS
2202 } else if (!strncasecmp(token, "digest-url=", 11)) {
2203 p->digest_url = xstrdup(token + 11);
2204 #endif
2205
2206 } else if (!strcasecmp(token, "allow-miss")) {
2207 p->options.allow_miss = 1;
2208 } else if (!strncasecmp(token, "max-conn=", 9)) {
2209 p->max_conn = xatoi(token + 9);
2210 } else if (!strcasecmp(token, "originserver")) {
2211 p->options.originserver = 1;
2212 } else if (!strncasecmp(token, "name=", 5)) {
2213 safe_free(p->name);
2214
2215 if (token[5])
2216 p->name = xstrdup(token + 5);
2217 } else if (!strncasecmp(token, "forceddomain=", 13)) {
2218 safe_free(p->domain);
2219
2220 if (token[13])
2221 p->domain = xstrdup(token + 13);
2222
2223 #if USE_SSL
2224
2225 } else if (strcmp(token, "ssl") == 0) {
2226 p->use_ssl = 1;
2227 } else if (strncmp(token, "sslcert=", 8) == 0) {
2228 safe_free(p->sslcert);
2229 p->sslcert = xstrdup(token + 8);
2230 } else if (strncmp(token, "sslkey=", 7) == 0) {
2231 safe_free(p->sslkey);
2232 p->sslkey = xstrdup(token + 7);
2233 } else if (strncmp(token, "sslversion=", 11) == 0) {
2234 p->sslversion = atoi(token + 11);
2235 } else if (strncmp(token, "ssloptions=", 11) == 0) {
2236 safe_free(p->ssloptions);
2237 p->ssloptions = xstrdup(token + 11);
2238 } else if (strncmp(token, "sslcipher=", 10) == 0) {
2239 safe_free(p->sslcipher);
2240 p->sslcipher = xstrdup(token + 10);
2241 } else if (strncmp(token, "sslcafile=", 10) == 0) {
2242 safe_free(p->sslcafile);
2243 p->sslcafile = xstrdup(token + 10);
2244 } else if (strncmp(token, "sslcapath=", 10) == 0) {
2245 safe_free(p->sslcapath);
2246 p->sslcapath = xstrdup(token + 10);
2247 } else if (strncmp(token, "sslcrlfile=", 11) == 0) {
2248 safe_free(p->sslcrlfile);
2249 p->sslcapath = xstrdup(token + 10);
2250 } else if (strncmp(token, "sslflags=", 9) == 0) {
2251 safe_free(p->sslflags);
2252 p->sslflags = xstrdup(token + 9);
2253 } else if (strncmp(token, "ssldomain=", 10) == 0) {
2254 safe_free(p->ssldomain);
2255 p->ssldomain = xstrdup(token + 10);
2256 #endif
2257
2258 } else if (strcmp(token, "front-end-https") == 0) {
2259 p->front_end_https = 1;
2260 } else if (strcmp(token, "front-end-https=on") == 0) {
2261 p->front_end_https = 1;
2262 } else if (strcmp(token, "front-end-https=auto") == 0) {
2263 p->front_end_https = 2;
2264 } else if (strcmp(token, "connection-auth=off") == 0) {
2265 p->connection_auth = 0;
2266 } else if (strcmp(token, "connection-auth") == 0) {
2267 p->connection_auth = 1;
2268 } else if (strcmp(token, "connection-auth=on") == 0) {
2269 p->connection_auth = 1;
2270 } else if (strcmp(token, "connection-auth=auto") == 0) {
2271 p->connection_auth = 2;
2272 } else {
2273 debugs(3, 0, "parse_peer: token='" << token << "'");
2274 self_destruct();
2275 }
2276 }
2277
2278 if (peerFindByName(p->name))
2279 fatalf("ERROR: cache_peer %s specified twice\n", p->name);
2280
2281 if (p->weight < 1)
2282 p->weight = 1;
2283
2284 if (p->connect_fail_limit < 1)
2285 p->connect_fail_limit = 10;
2286
2287 p->icp.version = ICP_VERSION_CURRENT;
2288
2289 p->testing_now = false;
2290
2291 #if USE_CACHE_DIGESTS
2292
2293 if (!p->options.no_digest) {
2294 /* XXX This looks odd.. who has the original pointer
2295 * then?
2296 */
2297 PeerDigest *pd = peerDigestCreate(p);
2298 p->digest = cbdataReference(pd);
2299 }
2300
2301 #endif
2302
2303 p->index = ++Config.npeers;
2304
2305 while (*head != NULL)
2306 head = &(*head)->next;
2307
2308 *head = p;
2309
2310 peerClearRRStart();
2311 }
2312
2313 static void
2314 free_peer(peer ** P)
2315 {
2316 peer *p;
2317
2318 while ((p = *P) != NULL) {
2319 *P = p->next;
2320 #if USE_CACHE_DIGESTS
2321
2322 cbdataReferenceDone(p->digest);
2323 #endif
2324
2325 cbdataFree(p);
2326 }
2327
2328 Config.npeers = 0;
2329 }
2330
2331 static void
2332 dump_cachemgrpasswd(StoreEntry * entry, const char *name, cachemgr_passwd * list)
2333 {
2334 wordlist *w;
2335
2336 while (list != NULL) {
2337 if (strcmp(list->passwd, "none") && strcmp(list->passwd, "disable"))
2338 storeAppendPrintf(entry, "%s XXXXXXXXXX", name);
2339 else
2340 storeAppendPrintf(entry, "%s %s", name, list->passwd);
2341
2342 for (w = list->actions; w != NULL; w = w->next) {
2343 storeAppendPrintf(entry, " %s", w->key);
2344 }
2345
2346 storeAppendPrintf(entry, "\n");
2347 list = list->next;
2348 }
2349 }
2350
2351 static void
2352 parse_cachemgrpasswd(cachemgr_passwd ** head)
2353 {
2354 char *passwd = NULL;
2355 wordlist *actions = NULL;
2356 cachemgr_passwd *p;
2357 cachemgr_passwd **P;
2358 parse_string(&passwd);
2359 parse_wordlist(&actions);
2360 p = static_cast<cachemgr_passwd *>(xcalloc(1, sizeof(cachemgr_passwd)));
2361 p->passwd = passwd;
2362 p->actions = actions;
2363
2364 for (P = head; *P; P = &(*P)->next) {
2365 /*
2366 * See if any of the actions from this line already have a
2367 * password from previous lines. The password checking
2368 * routines in cache_manager.c take the the password from
2369 * the first cachemgr_passwd struct that contains the
2370 * requested action. Thus, we should warn users who might
2371 * think they can have two passwords for the same action.
2372 */
2373 wordlist *w;
2374 wordlist *u;
2375
2376 for (w = (*P)->actions; w; w = w->next) {
2377 for (u = actions; u; u = u->next) {
2378 if (strcmp(w->key, u->key))
2379 continue;
2380
2381 debugs(0, 0, "WARNING: action '" << u->key << "' (line " << config_lineno << ") already has a password");
2382 }
2383 }
2384 }
2385
2386 *P = p;
2387 }
2388
2389 static void
2390 free_cachemgrpasswd(cachemgr_passwd ** head)
2391 {
2392 cachemgr_passwd *p;
2393
2394 while ((p = *head) != NULL) {
2395 *head = p->next;
2396 xfree(p->passwd);
2397 wordlistDestroy(&p->actions);
2398 xfree(p);
2399 }
2400 }
2401
2402 static void
2403 dump_denyinfo(StoreEntry * entry, const char *name, acl_deny_info_list * var)
2404 {
2405 acl_name_list *a;
2406
2407 while (var != NULL) {
2408 storeAppendPrintf(entry, "%s %s", name, var->err_page_name);
2409
2410 for (a = var->acl_list; a != NULL; a = a->next)
2411 storeAppendPrintf(entry, " %s", a->name);
2412
2413 storeAppendPrintf(entry, "\n");
2414
2415 var = var->next;
2416 }
2417 }
2418
2419 static void
2420 parse_denyinfo(acl_deny_info_list ** var)
2421 {
2422 aclParseDenyInfoLine(var);
2423 }
2424
2425 void
2426 free_denyinfo(acl_deny_info_list ** list)
2427 {
2428 acl_deny_info_list *a = NULL;
2429 acl_deny_info_list *a_next = NULL;
2430 acl_name_list *l = NULL;
2431 acl_name_list *l_next = NULL;
2432
2433 for (a = *list; a; a = a_next) {
2434 for (l = a->acl_list; l; l = l_next) {
2435 l_next = l->next;
2436 memFree(l, MEM_ACL_NAME_LIST);
2437 l = NULL;
2438 }
2439
2440 a_next = a->next;
2441 memFree(a, MEM_ACL_DENY_INFO_LIST);
2442 a = NULL;
2443 }
2444
2445 *list = NULL;
2446 }
2447
2448 static void
2449 parse_peer_access(void)
2450 {
2451 char *host = NULL;
2452 peer *p;
2453
2454 if (!(host = strtok(NULL, w_space)))
2455 self_destruct();
2456
2457 if ((p = peerFindByName(host)) == NULL) {
2458 debugs(15, 0, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'");
2459 return;
2460 }
2461
2462 aclParseAccessLine(LegacyParser, &p->access);
2463 }
2464
2465 static void
2466 parse_hostdomain(void)
2467 {
2468 char *host = NULL;
2469 char *domain = NULL;
2470
2471 if (!(host = strtok(NULL, w_space)))
2472 self_destruct();
2473
2474 while ((domain = strtok(NULL, list_sep))) {
2475 domain_ping *l = NULL;
2476 domain_ping **L = NULL;
2477 peer *p;
2478
2479 if ((p = peerFindByName(host)) == NULL) {
2480 debugs(15, 0, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'");
2481 continue;
2482 }
2483
2484 l = static_cast<domain_ping *>(xcalloc(1, sizeof(domain_ping)));
2485 l->do_ping = 1;
2486
2487 if (*domain == '!') { /* check for !.edu */
2488 l->do_ping = 0;
2489 domain++;
2490 }
2491
2492 l->domain = xstrdup(domain);
2493
2494 for (L = &(p->peer_domain); *L; L = &((*L)->next));
2495 *L = l;
2496 }
2497 }
2498
2499 static void
2500 parse_hostdomaintype(void)
2501 {
2502 char *host = NULL;
2503 char *type = NULL;
2504 char *domain = NULL;
2505
2506 if (!(host = strtok(NULL, w_space)))
2507 self_destruct();
2508
2509 if (!(type = strtok(NULL, w_space)))
2510 self_destruct();
2511
2512 while ((domain = strtok(NULL, list_sep))) {
2513 domain_type *l = NULL;
2514 domain_type **L = NULL;
2515 peer *p;
2516
2517 if ((p = peerFindByName(host)) == NULL) {
2518 debugs(15, 0, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'");
2519 return;
2520 }
2521
2522 l = static_cast<domain_type *>(xcalloc(1, sizeof(domain_type)));
2523 l->type = parseNeighborType(type);
2524 l->domain = xstrdup(domain);
2525
2526 for (L = &(p->typelist); *L; L = &((*L)->next));
2527 *L = l;
2528 }
2529 }
2530
2531 static void
2532 dump_int(StoreEntry * entry, const char *name, int var)
2533 {
2534 storeAppendPrintf(entry, "%s %d\n", name, var);
2535 }
2536
2537 void
2538 parse_int(int *var)
2539 {
2540 int i;
2541 i = GetInteger();
2542 *var = i;
2543 }
2544
2545 static void
2546 free_int(int *var)
2547 {
2548 *var = 0;
2549 }
2550
2551 static void
2552 dump_onoff(StoreEntry * entry, const char *name, int var)
2553 {
2554 storeAppendPrintf(entry, "%s %s\n", name, var ? "on" : "off");
2555 }
2556
2557 void
2558 parse_onoff(int *var)
2559 {
2560 char *token = strtok(NULL, w_space);
2561
2562 if (token == NULL)
2563 self_destruct();
2564
2565 if (!strcasecmp(token, "on") || !strcasecmp(token, "enable"))
2566 *var = 1;
2567 else
2568 *var = 0;
2569 }
2570
2571 #define free_onoff free_int
2572
2573 static void
2574 dump_tristate(StoreEntry * entry, const char *name, int var)
2575 {
2576 const char *state;
2577
2578 if (var > 0)
2579 state = "on";
2580 else if (var < 0)
2581 state = "warn";
2582 else
2583 state = "off";
2584
2585 storeAppendPrintf(entry, "%s %s\n", name, state);
2586 }
2587
2588 static void
2589 parse_tristate(int *var)
2590 {
2591 char *token = strtok(NULL, w_space);
2592
2593 if (token == NULL)
2594 self_destruct();
2595
2596 if (!strcasecmp(token, "on") || !strcasecmp(token, "enable"))
2597 *var = 1;
2598 else if (!strcasecmp(token, "warn"))
2599 *var = -1;
2600 else
2601 *var = 0;
2602 }
2603
2604 #define free_tristate free_int
2605
2606 static void
2607 dump_refreshpattern(StoreEntry * entry, const char *name, refresh_t * head)
2608 {
2609 while (head != NULL) {
2610 storeAppendPrintf(entry, "%s%s %s %d %d%% %d",
2611 name,
2612 head->flags.icase ? " -i" : null_string,
2613 head->pattern,
2614 (int) head->min / 60,
2615 (int) (100.0 * head->pct + 0.5),
2616 (int) head->max / 60);
2617
2618 if (head->max_stale >= 0)
2619 storeAppendPrintf(entry, " max-stale=%d", head->max_stale);
2620
2621 if (head->flags.refresh_ims)
2622 storeAppendPrintf(entry, " refresh-ims");
2623
2624 if (head->flags.store_stale)
2625 storeAppendPrintf(entry, " store-stale");
2626
2627 #if USE_HTTP_VIOLATIONS
2628
2629 if (head->flags.override_expire)
2630 storeAppendPrintf(entry, " override-expire");
2631
2632 if (head->flags.override_lastmod)
2633 storeAppendPrintf(entry, " override-lastmod");
2634
2635 if (head->flags.reload_into_ims)
2636 storeAppendPrintf(entry, " reload-into-ims");
2637
2638 if (head->flags.ignore_reload)
2639 storeAppendPrintf(entry, " ignore-reload");
2640
2641 if (head->flags.ignore_no_cache)
2642 storeAppendPrintf(entry, " ignore-no-cache");
2643
2644 if (head->flags.ignore_no_store)
2645 storeAppendPrintf(entry, " ignore-no-store");
2646
2647 if (head->flags.ignore_must_revalidate)
2648 storeAppendPrintf(entry, " ignore-must-revalidate");
2649
2650 if (head->flags.ignore_private)
2651 storeAppendPrintf(entry, " ignore-private");
2652
2653 if (head->flags.ignore_auth)
2654 storeAppendPrintf(entry, " ignore-auth");
2655
2656 #endif
2657
2658 storeAppendPrintf(entry, "\n");
2659
2660 head = head->next;
2661 }
2662 }
2663
2664 static void
2665 parse_refreshpattern(refresh_t ** head)
2666 {
2667 char *token;
2668 char *pattern;
2669 time_t min = 0;
2670 double pct = 0.0;
2671 time_t max = 0;
2672 int refresh_ims = 0;
2673 int store_stale = 0;
2674 int max_stale = -1;
2675
2676 #if USE_HTTP_VIOLATIONS
2677
2678 int override_expire = 0;
2679 int override_lastmod = 0;
2680 int reload_into_ims = 0;
2681 int ignore_reload = 0;
2682 int ignore_no_cache = 0;
2683 int ignore_no_store = 0;
2684 int ignore_must_revalidate = 0;
2685 int ignore_private = 0;
2686 int ignore_auth = 0;
2687 #endif
2688
2689 int i;
2690 refresh_t *t;
2691 regex_t comp;
2692 int errcode;
2693 int flags = REG_EXTENDED | REG_NOSUB;
2694
2695 if ((token = strtok(NULL, w_space)) == NULL) {
2696 self_destruct();
2697 return;
2698 }
2699
2700 if (strcmp(token, "-i") == 0) {
2701 flags |= REG_ICASE;
2702 token = strtok(NULL, w_space);
2703 } else if (strcmp(token, "+i") == 0) {
2704 flags &= ~REG_ICASE;
2705 token = strtok(NULL, w_space);
2706 }
2707
2708 if (token == NULL) {
2709 self_destruct();
2710 return;
2711 }
2712
2713 pattern = xstrdup(token);
2714
2715 i = GetInteger(); /* token: min */
2716
2717 /* catch negative and insanely huge values close to 32-bit wrap */
2718 if (i < 0) {
2719 debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern minimum age negative. Cropped back to zero.");
2720 i = 0;
2721 }
2722 if (i > 60*24*365) {
2723 debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern minimum age too high. Cropped back to 1 year.");
2724 i = 60*24*365;
2725 }
2726
2727 min = (time_t) (i * 60); /* convert minutes to seconds */
2728
2729 i = GetInteger(); /* token: pct */
2730
2731 pct = (double) i / 100.0;
2732
2733 i = GetInteger(); /* token: max */
2734
2735 /* catch negative and insanely huge values close to 32-bit wrap */
2736 if (i < 0) {
2737 debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern maximum age negative. Cropped back to zero.");
2738 i = 0;
2739 }
2740 if (i > 60*24*365) {
2741 debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern maximum age too high. Cropped back to 1 year.");
2742 i = 60*24*365;
2743 }
2744
2745 max = (time_t) (i * 60); /* convert minutes to seconds */
2746
2747 /* Options */
2748 while ((token = strtok(NULL, w_space)) != NULL) {
2749 if (!strcmp(token, "refresh-ims")) {
2750 refresh_ims = 1;
2751 } else if (!strcmp(token, "store-stale")) {
2752 store_stale = 1;
2753 } else if (!strncmp(token, "max-stale=", 10)) {
2754 max_stale = atoi(token + 10);
2755 #if USE_HTTP_VIOLATIONS
2756
2757 } else if (!strcmp(token, "override-expire"))
2758 override_expire = 1;
2759 else if (!strcmp(token, "override-lastmod"))
2760 override_lastmod = 1;
2761 else if (!strcmp(token, "ignore-no-cache"))
2762 ignore_no_cache = 1;
2763 else if (!strcmp(token, "ignore-no-store"))
2764 ignore_no_store = 1;
2765 else if (!strcmp(token, "ignore-must-revalidate"))
2766 ignore_must_revalidate = 1;
2767 else if (!strcmp(token, "ignore-private"))
2768 ignore_private = 1;
2769 else if (!strcmp(token, "ignore-auth"))
2770 ignore_auth = 1;
2771 else if (!strcmp(token, "reload-into-ims")) {
2772 reload_into_ims = 1;
2773 refresh_nocache_hack = 1;
2774 /* tell client_side.c that this is used */
2775 } else if (!strcmp(token, "ignore-reload")) {
2776 ignore_reload = 1;
2777 refresh_nocache_hack = 1;
2778 /* tell client_side.c that this is used */
2779 #endif
2780
2781 } else
2782 debugs(22, 0, "refreshAddToList: Unknown option '" << pattern << "': " << token);
2783 }
2784
2785 if ((errcode = regcomp(&comp, pattern, flags)) != 0) {
2786 char errbuf[256];
2787 regerror(errcode, &comp, errbuf, sizeof errbuf);
2788 debugs(22, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line);
2789 debugs(22, 0, "refreshAddToList: Invalid regular expression '" << pattern << "': " << errbuf);
2790 return;
2791 }
2792
2793 pct = pct < 0.0 ? 0.0 : pct;
2794 max = max < 0 ? 0 : max;
2795 t = static_cast<refresh_t *>(xcalloc(1, sizeof(refresh_t)));
2796 t->pattern = (char *) xstrdup(pattern);
2797 t->compiled_pattern = comp;
2798 t->min = min;
2799 t->pct = pct;
2800 t->max = max;
2801
2802 if (flags & REG_ICASE)
2803 t->flags.icase = 1;
2804
2805 if (refresh_ims)
2806 t->flags.refresh_ims = 1;
2807
2808 if (store_stale)
2809 t->flags.store_stale = 1;
2810
2811 t->max_stale = max_stale;
2812
2813 #if USE_HTTP_VIOLATIONS
2814
2815 if (override_expire)
2816 t->flags.override_expire = 1;
2817
2818 if (override_lastmod)
2819 t->flags.override_lastmod = 1;
2820
2821 if (reload_into_ims)
2822 t->flags.reload_into_ims = 1;
2823
2824 if (ignore_reload)
2825 t->flags.ignore_reload = 1;
2826
2827 if (ignore_no_cache)
2828 t->flags.ignore_no_cache = 1;
2829
2830 if (ignore_no_store)
2831 t->flags.ignore_no_store = 1;
2832
2833 if (ignore_must_revalidate)
2834 t->flags.ignore_must_revalidate = 1;
2835
2836 if (ignore_private)
2837 t->flags.ignore_private = 1;
2838
2839 if (ignore_auth)
2840 t->flags.ignore_auth = 1;
2841
2842 #endif
2843
2844 t->next = NULL;
2845
2846 while (*head)
2847 head = &(*head)->next;
2848
2849 *head = t;
2850
2851 safe_free(pattern);
2852 }
2853
2854 static void
2855 free_refreshpattern(refresh_t ** head)
2856 {
2857 refresh_t *t;
2858
2859 while ((t = *head) != NULL) {
2860 *head = t->next;
2861 safe_free(t->pattern);
2862 regfree(&t->compiled_pattern);
2863 safe_free(t);
2864 }
2865
2866 #if USE_HTTP_VIOLATIONS
2867 refresh_nocache_hack = 0;
2868
2869 #endif
2870 }
2871
2872 static void
2873 dump_string(StoreEntry * entry, const char *name, char *var)
2874 {
2875 if (var != NULL)
2876 storeAppendPrintf(entry, "%s %s\n", name, var);
2877 }
2878
2879 static void
2880 parse_string(char **var)
2881 {
2882 char *token = strtok(NULL, w_space);
2883 safe_free(*var);
2884
2885 if (token == NULL)
2886 self_destruct();
2887
2888 *var = xstrdup(token);
2889 }
2890
2891 void
2892 ConfigParser::ParseString(char **var)
2893 {
2894 parse_string(var);
2895 }
2896
2897 void
2898 ConfigParser::ParseString(String *var)
2899 {
2900 char *token = strtok(NULL, w_space);
2901
2902 if (token == NULL)
2903 self_destruct();
2904
2905 var->reset(token);
2906 }
2907
2908 static void
2909 free_string(char **var)
2910 {
2911 safe_free(*var);
2912 }
2913
2914 void
2915 parse_eol(char *volatile *var)
2916 {
2917 if (!var) {
2918 self_destruct();
2919 return;
2920 }
2921
2922 unsigned char *token = (unsigned char *) strtok(NULL, null_string);
2923 safe_free(*var);
2924
2925 if (!token) {
2926 self_destruct();
2927 return;
2928 }
2929
2930 while (*token && xisspace(*token))
2931 token++;
2932
2933 if (!*token) {
2934 self_destruct();
2935 return;
2936 }
2937
2938 *var = xstrdup((char *) token);
2939 }
2940
2941 #define dump_eol dump_string
2942 #define free_eol free_string
2943
2944 static void
2945 dump_time_t(StoreEntry * entry, const char *name, time_t var)
2946 {
2947 storeAppendPrintf(entry, "%s %d seconds\n", name, (int) var);
2948 }
2949
2950 void
2951 parse_time_t(time_t * var)
2952 {
2953 time_msec_t tval;
2954 parseTimeLine(&tval, T_SECOND_STR, false);
2955 *var = static_cast<time_t>(tval/1000);
2956 }
2957
2958 static void
2959 free_time_t(time_t * var)
2960 {
2961 *var = 0;
2962 }
2963
2964 #if !USE_DNSHELPER
2965 static void
2966 dump_time_msec(StoreEntry * entry, const char *name, time_msec_t var)
2967 {
2968 if (var % 1000)
2969 storeAppendPrintf(entry, "%s %" PRId64 " milliseconds\n", name, var);
2970 else
2971 storeAppendPrintf(entry, "%s %d seconds\n", name, (int)(var/1000) );
2972 }
2973
2974 void
2975 parse_time_msec(time_msec_t * var)
2976 {
2977 parseTimeLine(var, T_SECOND_STR, true);
2978 }
2979
2980 static void
2981 free_time_msec(time_msec_t * var)
2982 {
2983 *var = 0;
2984 }
2985 #endif
2986
2987 #if UNUSED_CODE
2988 static void
2989 dump_size_t(StoreEntry * entry, const char *name, size_t var)
2990 {
2991 storeAppendPrintf(entry, "%s %d\n", name, (int) var);
2992 }
2993 #endif
2994
2995 static void
2996 dump_b_size_t(StoreEntry * entry, const char *name, size_t var)
2997 {
2998 storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_BYTES_STR);
2999 }
3000
3001 #if !USE_DNSHELPER
3002 static void
3003 dump_b_ssize_t(StoreEntry * entry, const char *name, ssize_t var)
3004 {
3005 storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_BYTES_STR);
3006 }
3007 #endif
3008
3009 #if UNUSED_CODE
3010 static void
3011 dump_kb_size_t(StoreEntry * entry, const char *name, size_t var)
3012 {
3013 storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_KBYTES_STR);
3014 }
3015 #endif
3016
3017 static void
3018 dump_b_int64_t(StoreEntry * entry, const char *name, int64_t var)
3019 {
3020 storeAppendPrintf(entry, "%s %" PRId64 " %s\n", name, var, B_BYTES_STR);
3021 }
3022
3023 static void
3024 dump_kb_int64_t(StoreEntry * entry, const char *name, int64_t var)
3025 {
3026 storeAppendPrintf(entry, "%s %" PRId64 " %s\n", name, var, B_KBYTES_STR);
3027 }
3028
3029 #if UNUSED_CODE
3030 static void
3031 parse_size_t(size_t * var)
3032 {
3033 int i;
3034 i = GetInteger();
3035 *var = (size_t) i;
3036 }
3037 #endif
3038
3039 static void
3040 parse_b_size_t(size_t * var)
3041 {
3042 parseBytesLine(var, B_BYTES_STR);
3043 }
3044
3045 #if !USE_DNSHELPER
3046 static void
3047 parse_b_ssize_t(ssize_t * var)
3048 {
3049 parseBytesLineSigned(var, B_BYTES_STR);
3050 }
3051 #endif
3052
3053 #if UNUSED_CODE
3054 static void
3055 parse_kb_size_t(size_t * var)
3056 {
3057 parseBytesLine(var, B_KBYTES_STR);
3058 }
3059 #endif
3060
3061 static void
3062 parse_b_int64_t(int64_t * var)
3063 {
3064 parseBytesLine64(var, B_BYTES_STR);
3065 }
3066
3067 static void
3068 parse_kb_int64_t(int64_t * var)
3069 {
3070 parseBytesLine64(var, B_KBYTES_STR);
3071 }
3072
3073 static void
3074 free_size_t(size_t * var)
3075 {
3076 *var = 0;
3077 }
3078
3079 #if !USE_DNSHELPER
3080 static void
3081 free_ssize_t(ssize_t * var)
3082 {
3083 *var = 0;
3084 }
3085 #endif
3086
3087 static void
3088 free_b_int64_t(int64_t * var)
3089 {
3090 *var = 0;
3091 }
3092
3093 #define free_b_size_t free_size_t
3094 #define free_b_ssize_t free_ssize_t
3095 #define free_kb_size_t free_size_t
3096 #define free_mb_size_t free_size_t
3097 #define free_gb_size_t free_size_t
3098 #define free_kb_int64_t free_b_int64_t
3099
3100 static void
3101 dump_u_short(StoreEntry * entry, const char *name, unsigned short var)
3102 {
3103 storeAppendPrintf(entry, "%s %d\n", name, var);
3104 }
3105
3106 static void
3107 free_u_short(unsigned short * u)
3108 {
3109 *u = 0;
3110 }
3111
3112 static void
3113 parse_u_short(unsigned short * var)
3114 {
3115 ConfigParser::ParseUShort(var);
3116 }
3117
3118 void
3119 ConfigParser::ParseUShort(unsigned short *var)
3120 {
3121 *var = GetShort();
3122 }
3123
3124 void
3125 ConfigParser::ParseBool(bool *var)
3126 {
3127 int i = GetInteger();
3128
3129 if (0 == i)
3130 *var = false;
3131 else if (1 == i)
3132 *var = true;
3133 else
3134 self_destruct();
3135 }
3136
3137 static void
3138 dump_wordlist(StoreEntry * entry, const char *name, wordlist * list)
3139 {
3140 while (list != NULL) {
3141 storeAppendPrintf(entry, "%s %s\n", name, list->key);
3142 list = list->next;
3143 }
3144 }
3145
3146 void
3147 ConfigParser::ParseWordList(wordlist ** list)
3148 {
3149 parse_wordlist(list);
3150 }
3151
3152 void
3153 parse_wordlist(wordlist ** list)
3154 {
3155 char *token;
3156 char *t = strtok(NULL, "");
3157
3158 while ((token = strwordtok(NULL, &t)))
3159 wordlistAdd(list, token);
3160 }
3161
3162 #if 0 /* now unused */
3163 static int
3164 check_null_wordlist(wordlist * w)
3165 {
3166 return w == NULL;
3167 }
3168 #endif
3169
3170 static int
3171 check_null_acl_access(acl_access * a)
3172 {
3173 return a == NULL;
3174 }
3175
3176 #define free_wordlist wordlistDestroy
3177
3178 #define free_uri_whitespace free_int
3179
3180 static void
3181 parse_uri_whitespace(int *var)
3182 {
3183 char *token = strtok(NULL, w_space);
3184
3185 if (token == NULL)
3186 self_destruct();
3187
3188 if (!strcasecmp(token, "strip"))
3189 *var = URI_WHITESPACE_STRIP;
3190 else if (!strcasecmp(token, "deny"))
3191 *var = URI_WHITESPACE_DENY;
3192 else if (!strcasecmp(token, "allow"))
3193 *var = URI_WHITESPACE_ALLOW;
3194 else if (!strcasecmp(token, "encode"))
3195 *var = URI_WHITESPACE_ENCODE;
3196 else if (!strcasecmp(token, "chop"))
3197 *var = URI_WHITESPACE_CHOP;
3198 else
3199 self_destruct();
3200 }
3201
3202 static void
3203 dump_uri_whitespace(StoreEntry * entry, const char *name, int var)
3204 {
3205 const char *s;
3206
3207 if (var == URI_WHITESPACE_ALLOW)
3208 s = "allow";
3209 else if (var == URI_WHITESPACE_ENCODE)
3210 s = "encode";
3211 else if (var == URI_WHITESPACE_CHOP)
3212 s = "chop";
3213 else if (var == URI_WHITESPACE_DENY)
3214 s = "deny";
3215 else
3216 s = "strip";
3217
3218 storeAppendPrintf(entry, "%s %s\n", name, s);
3219 }
3220
3221 static void
3222 free_removalpolicy(RemovalPolicySettings ** settings)
3223 {
3224 if (!*settings)
3225 return;
3226
3227 free_string(&(*settings)->type);
3228
3229 free_wordlist(&(*settings)->args);
3230
3231 delete *settings;
3232
3233 *settings = NULL;
3234 }
3235
3236 static void
3237 parse_removalpolicy(RemovalPolicySettings ** settings)
3238 {
3239 if (*settings)
3240 free_removalpolicy(settings);
3241
3242 *settings = new RemovalPolicySettings;
3243
3244 parse_string(&(*settings)->type);
3245
3246 parse_wordlist(&(*settings)->args);
3247 }
3248
3249 static void
3250 dump_removalpolicy(StoreEntry * entry, const char *name, RemovalPolicySettings * settings)
3251 {
3252 wordlist *args;
3253 storeAppendPrintf(entry, "%s %s", name, settings->type);
3254 args = settings->args;
3255
3256 while (args) {
3257 storeAppendPrintf(entry, " %s", args->key);
3258 args = args->next;
3259 }
3260
3261 storeAppendPrintf(entry, "\n");
3262 }
3263
3264 void
3265 YesNoNone::configure(bool beSet)
3266 {
3267 option = beSet ? +1 : -1;
3268 }
3269
3270 YesNoNone::operator void*() const
3271 {
3272 assert(option != 0); // must call configure() first
3273 return option > 0 ? (void*)this : NULL;
3274 }
3275
3276
3277 inline void
3278 free_YesNoNone(YesNoNone *)
3279 {
3280 // do nothing: no explicit cleanup is required
3281 }
3282
3283 static void
3284 parse_YesNoNone(YesNoNone *option)
3285 {
3286 int value = 0;
3287 parse_onoff(&value);
3288 option->configure(value > 0);
3289 }
3290
3291 static void
3292 dump_YesNoNone(StoreEntry * entry, const char *name, YesNoNone &option)
3293 {
3294 if (option.configured())
3295 dump_onoff(entry, name, option ? 1 : 0);
3296 }
3297
3298 static void
3299 free_memcachemode(SquidConfig * config)
3300 {
3301 return;
3302 }
3303
3304 static void
3305 parse_memcachemode(SquidConfig * config)
3306 {
3307 char *token = strtok(NULL, w_space);
3308 if (!token)
3309 self_destruct();
3310
3311 if (strcmp(token, "always") == 0) {
3312 Config.onoff.memory_cache_first = 1;
3313 Config.onoff.memory_cache_disk = 1;
3314 } else if (strcmp(token, "disk") == 0) {
3315 Config.onoff.memory_cache_first = 0;
3316 Config.onoff.memory_cache_disk = 1;
3317 } else if (strncmp(token, "net", 3) == 0) {
3318 Config.onoff.memory_cache_first = 1;
3319 Config.onoff.memory_cache_disk = 0;
3320 } else if (strcmp(token, "never") == 0) {
3321 Config.onoff.memory_cache_first = 0;
3322 Config.onoff.memory_cache_disk = 0;
3323 } else
3324 self_destruct();
3325 }
3326
3327 static void
3328 dump_memcachemode(StoreEntry * entry, const char *name, SquidConfig &config)
3329 {
3330 storeAppendPrintf(entry, "%s ", name);
3331 if (Config.onoff.memory_cache_first && Config.onoff.memory_cache_disk)
3332 storeAppendPrintf(entry, "always");
3333 else if (!Config.onoff.memory_cache_first && Config.onoff.memory_cache_disk)
3334 storeAppendPrintf(entry, "disk");
3335 else if (Config.onoff.memory_cache_first && !Config.onoff.memory_cache_disk)
3336 storeAppendPrintf(entry, "network");
3337 else if (!Config.onoff.memory_cache_first && !Config.onoff.memory_cache_disk)
3338 storeAppendPrintf(entry, "none");
3339 storeAppendPrintf(entry, "\n");
3340 }
3341
3342 #include "cf_parser.cci"
3343
3344 peer_t
3345 parseNeighborType(const char *s)
3346 {
3347 if (!strcasecmp(s, "parent"))
3348 return PEER_PARENT;
3349
3350 if (!strcasecmp(s, "neighbor"))
3351 return PEER_SIBLING;
3352
3353 if (!strcasecmp(s, "neighbour"))
3354 return PEER_SIBLING;
3355
3356 if (!strcasecmp(s, "sibling"))
3357 return PEER_SIBLING;
3358
3359 if (!strcasecmp(s, "multicast"))
3360 return PEER_MULTICAST;
3361
3362 debugs(15, 0, "WARNING: Unknown neighbor type: " << s);
3363
3364 return PEER_SIBLING;
3365 }
3366
3367 #if USE_WCCPv2
3368 static void
3369 parse_IpAddress_list(Ip::Address_list ** head)
3370 {
3371 char *token;
3372 Ip::Address_list *s;
3373 Ip::Address ipa;
3374
3375 while ((token = strtok(NULL, w_space))) {
3376 if (GetHostWithPort(token, &ipa)) {
3377
3378 while (*head)
3379 head = &(*head)->next;
3380
3381 s = static_cast<Ip::Address_list *>(xcalloc(1, sizeof(*s)));
3382 s->s = ipa;
3383
3384 *head = s;
3385 } else
3386 self_destruct();
3387 }
3388 }
3389
3390 static void
3391 dump_IpAddress_list(StoreEntry * e, const char *n, const Ip::Address_list * s)
3392 {
3393 char ntoabuf[MAX_IPSTRLEN];
3394
3395 while (s) {
3396 storeAppendPrintf(e, "%s %s\n",
3397 n,
3398 s->s.NtoA(ntoabuf,MAX_IPSTRLEN));
3399 s = s->next;
3400 }
3401 }
3402
3403 static void
3404 free_IpAddress_list(Ip::Address_list ** head)
3405 {
3406 if (*head) delete *head;
3407 *head = NULL;
3408 }
3409
3410 #if CURRENTLY_UNUSED
3411 /* This code was previously used by http_port. Left as it really should
3412 * be used by icp_port and htcp_port
3413 */
3414 static int
3415 check_null_IpAddress_list(const Ip::Address_list * s)
3416 {
3417 return NULL == s;
3418 }
3419
3420 #endif /* CURRENTLY_UNUSED */
3421 #endif /* USE_WCCPv2 */
3422
3423 static void
3424 parsePortSpecification(AnyP::PortCfg * s, char *token)
3425 {
3426 char *host = NULL;
3427 unsigned short port = 0;
3428 char *t = NULL;
3429 char *junk = NULL;
3430
3431 s->disable_pmtu_discovery = DISABLE_PMTU_OFF;
3432 s->name = xstrdup(token);
3433 s->connection_auth_disabled = false;
3434
3435 if (*token == '[') {
3436 /* [ipv6]:port */
3437 host = token + 1;
3438 t = strchr(host, ']');
3439 if (!t) {
3440 debugs(3, DBG_CRITICAL, s->protocol << "_port: missing ']' on IPv6 address: " << token);
3441 self_destruct();
3442 }
3443 *t++ = '\0';
3444 if (*t != ':') {
3445 debugs(3, DBG_CRITICAL, s->protocol << "_port: missing Port in: " << token);
3446 self_destruct();
3447 }
3448 if (!Ip::EnableIpv6) {
3449 debugs(3, DBG_CRITICAL, "FATAL: " << s->protocol << "_port: IPv6 is not available.");
3450 self_destruct();
3451 }
3452 port = xatos(t + 1);
3453 } else if ((t = strchr(token, ':'))) {
3454 /* host:port */
3455 /* ipv4:port */
3456 host = token;
3457 *t = '\0';
3458 port = xatos(t + 1);
3459
3460 } else if ((port = strtol(token, &junk, 10)), !*junk) {
3461 /* port */
3462 debugs(3, 3, s->protocol << "_port: found Listen on Port: " << port);
3463 } else {
3464 debugs(3, DBG_CRITICAL, s->protocol << "_port: missing Port: " << token);
3465 self_destruct();
3466 }
3467
3468 if (port == 0 && host != NULL) {
3469 debugs(3, DBG_CRITICAL, s->protocol << "_port: Port cannot be 0: " << token);
3470 self_destruct();
3471 }
3472
3473 if (NULL == host) {
3474 s->s.SetAnyAddr();
3475 s->s.SetPort(port);
3476 if (!Ip::EnableIpv6)
3477 s->s.SetIPv4();
3478 debugs(3, 3, s->protocol << "_port: found Listen on wildcard address: *:" << s->s.GetPort() );
3479 } else if ( (s->s = host) ) { /* check/parse numeric IPA */
3480 s->s.SetPort(port);
3481 if (!Ip::EnableIpv6)
3482 s->s.SetIPv4();
3483 debugs(3, 3, s->protocol << "_port: Listen on Host/IP: " << host << " --> " << s->s);
3484 } else if ( s->s.GetHostByName(host) ) { /* check/parse for FQDN */
3485 /* dont use ipcache */
3486 s->defaultsite = xstrdup(host);
3487 s->s.SetPort(port);
3488 if (!Ip::EnableIpv6)
3489 s->s.SetIPv4();
3490 debugs(3, 3, s->protocol << "_port: found Listen as Host " << s->defaultsite << " on IP: " << s->s);
3491 } else {
3492 debugs(3, DBG_CRITICAL, s->protocol << "_port: failed to resolve Host/IP: " << host);
3493 self_destruct();
3494 }
3495 }
3496
3497 static void
3498 parse_port_option(AnyP::PortCfg * s, char *token)
3499 {
3500 /* modes first */
3501
3502 if (strcmp(token, "accel") == 0) {
3503 if (s->intercepted || s->spoof_client_ip) {
3504 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: Accelerator mode requires its own port. It cannot be shared with other modes.");
3505 self_destruct();
3506 }
3507 s->accel = s->vhost = 1;
3508 } else if (strcmp(token, "transparent") == 0 || strcmp(token, "intercept") == 0) {
3509 if (s->accel || s->spoof_client_ip) {
3510 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: Intercept mode requires its own interception port. It cannot be shared with other modes.");
3511 self_destruct();
3512 }
3513 s->intercepted = 1;
3514 Ip::Interceptor.StartInterception();
3515 /* Log information regarding the port modes under interception. */
3516 debugs(3, DBG_IMPORTANT, "Starting Authentication on port " << s->s);
3517 debugs(3, DBG_IMPORTANT, "Disabling Authentication on port " << s->s << " (interception enabled)");
3518
3519 /* INET6: until transparent REDIRECT works on IPv6 SOCKET, force wildcard to IPv4 */
3520 if (Ip::EnableIpv6)
3521 debugs(3, DBG_IMPORTANT, "Disabling IPv6 on port " << s->s << " (interception enabled)");
3522 if ( !s->s.SetIPv4() ) {
3523 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: IPv6 addresses cannot NAT intercept (protocol does not provide NAT)" << s->s );
3524 self_destruct();
3525 }
3526 } else if (strcmp(token, "tproxy") == 0) {
3527 if (s->intercepted || s->accel) {
3528 debugs(3,DBG_CRITICAL, "FATAL: http(s)_port: TPROXY option requires its own interception port. It cannot be shared with other modes.");
3529 self_destruct();
3530 }
3531 s->spoof_client_ip = 1;
3532 Ip::Interceptor.StartTransparency();
3533 /* Log information regarding the port modes under transparency. */
3534 debugs(3, DBG_IMPORTANT, "Starting IP Spoofing on port " << s->s);
3535 debugs(3, DBG_IMPORTANT, "Disabling Authentication on port " << s->s << " (IP spoofing enabled)");
3536
3537 if (!Ip::Interceptor.ProbeForTproxy(s->s)) {
3538 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: TPROXY support in the system does not work.");
3539 self_destruct();
3540 }
3541
3542 } else if (strncmp(token, "defaultsite=", 12) == 0) {
3543 if (!s->accel) {
3544 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: defaultsite option requires Acceleration mode flag.");
3545 self_destruct();
3546 }
3547 safe_free(s->defaultsite);
3548 s->defaultsite = xstrdup(token + 12);
3549 } else if (strcmp(token, "vhost") == 0) {
3550 if (!s->accel) {
3551 debugs(3, DBG_CRITICAL, "WARNING: http(s)_port: vhost option is deprecated. Use 'accel' mode flag instead.");
3552 }
3553 s->accel = s->vhost = 1;
3554 } else if (strcmp(token, "no-vhost") == 0) {
3555 if (!s->accel) {
3556 debugs(3, DBG_IMPORTANT, "ERROR: http(s)_port: no-vhost option requires Acceleration mode flag.");
3557 }
3558 s->vhost = 0;
3559 } else if (strcmp(token, "vport") == 0) {
3560 if (!s->accel) {
3561 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3562 self_destruct();
3563 }
3564 s->vport = -1;
3565 } else if (strncmp(token, "vport=", 6) == 0) {
3566 if (!s->accel) {
3567 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3568 self_destruct();
3569 }
3570 s->vport = xatos(token + 6);
3571 } else if (strncmp(token, "protocol=", 9) == 0) {
3572 if (!s->accel) {
3573 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: protocol option requires Acceleration mode flag.");
3574 self_destruct();
3575 }
3576 s->protocol = xstrdup(token + 9);
3577 } else if (strcmp(token, "allow-direct") == 0) {
3578 if (!s->accel) {
3579 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: allow-direct option requires Acceleration mode flag.");
3580 self_destruct();
3581 }
3582 s->allow_direct = 1;
3583 } else if (strcmp(token, "act-as-origin") == 0) {
3584 if (!s->accel) {
3585 debugs(3, DBG_IMPORTANT, "ERROR: http(s)_port: act-as-origin option requires Acceleration mode flag.");
3586 } else
3587 s->actAsOrigin = 1;
3588 } else if (strcmp(token, "ignore-cc") == 0) {
3589 #if !USE_HTTP_VIOLATIONS
3590 if (!s->accel) {
3591 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: ignore-cc option requires Scceleration mode flag.");
3592 self_destruct();
3593 }
3594 #endif
3595 s->ignore_cc = 1;
3596 } else if (strncmp(token, "name=", 5) == 0) {
3597 safe_free(s->name);
3598 s->name = xstrdup(token + 5);
3599 } else if (strcmp(token, "no-connection-auth") == 0) {
3600 s->connection_auth_disabled = true;
3601 } else if (strcmp(token, "connection-auth=off") == 0) {
3602 s->connection_auth_disabled = true;
3603 } else if (strcmp(token, "connection-auth") == 0) {
3604 s->connection_auth_disabled = false;
3605 } else if (strcmp(token, "connection-auth=on") == 0) {
3606 s->connection_auth_disabled = false;
3607 } else if (strncmp(token, "disable-pmtu-discovery=", 23) == 0) {
3608 if (!strcasecmp(token + 23, "off"))
3609 s->disable_pmtu_discovery = DISABLE_PMTU_OFF;
3610 else if (!strcasecmp(token + 23, "transparent"))
3611 s->disable_pmtu_discovery = DISABLE_PMTU_TRANSPARENT;
3612 else if (!strcasecmp(token + 23, "always"))
3613 s->disable_pmtu_discovery = DISABLE_PMTU_ALWAYS;
3614 else
3615 self_destruct();
3616 } else if (strcmp(token, "ipv4") == 0) {
3617 if ( !s->s.SetIPv4() ) {
3618 debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: IPv6 addresses cannot be used as IPv4-Only. " << s->s );
3619 self_destruct();
3620 }
3621 } else if (strcmp(token, "tcpkeepalive") == 0) {
3622 s->tcp_keepalive.enabled = 1;
3623 } else if (strncmp(token, "tcpkeepalive=", 13) == 0) {
3624 char *t = token + 13;
3625 s->tcp_keepalive.enabled = 1;
3626 s->tcp_keepalive.idle = atoi(t);
3627 t = strchr(t, ',');
3628 if (t) {
3629 t++;
3630 s->tcp_keepalive.interval = atoi(t);
3631 t = strchr(t, ',');
3632 }
3633 if (t) {
3634 t++;
3635 s->tcp_keepalive.timeout = atoi(t);
3636 t = strchr(t, ',');
3637 }
3638 #if USE_SSL
3639 } else if (strcasecmp(token, "sslBump") == 0) {
3640 debugs(3, DBG_CRITICAL, "WARNING: '" << token << "' is deprecated " <<
3641 "in http_port. Use 'ssl-bump' instead.");
3642 s->sslBump = 1; // accelerated when bumped, otherwise not
3643 } else if (strcmp(token, "ssl-bump") == 0) {
3644 s->sslBump = 1; // accelerated when bumped, otherwise not
3645 } else if (strncmp(token, "cert=", 5) == 0) {
3646 safe_free(s->cert);
3647 s->cert = xstrdup(token + 5);
3648 } else if (strncmp(token, "key=", 4) == 0) {
3649 safe_free(s->key);
3650 s->key = xstrdup(token + 4);
3651 } else if (strncmp(token, "version=", 8) == 0) {
3652 s->version = xatoi(token + 8);
3653 if (s->version < 1 || s->version > 4)
3654 self_destruct();
3655 } else if (strncmp(token, "options=", 8) == 0) {
3656 safe_free(s->options);
3657 s->options = xstrdup(token + 8);
3658 } else if (strncmp(token, "cipher=", 7) == 0) {
3659 safe_free(s->cipher);
3660 s->cipher = xstrdup(token + 7);
3661 } else if (strncmp(token, "clientca=", 9) == 0) {
3662 safe_free(s->clientca);
3663 s->clientca = xstrdup(token + 9);
3664 } else if (strncmp(token, "cafile=", 7) == 0) {
3665 safe_free(s->cafile);
3666 s->cafile = xstrdup(token + 7);
3667 } else if (strncmp(token, "capath=", 7) == 0) {
3668 safe_free(s->capath);
3669 s->capath = xstrdup(token + 7);
3670 } else if (strncmp(token, "crlfile=", 8) == 0) {
3671 safe_free(s->crlfile);
3672 s->crlfile = xstrdup(token + 8);
3673 } else if (strncmp(token, "dhparams=", 9) == 0) {
3674 safe_free(s->dhfile);
3675 s->dhfile = xstrdup(token + 9);
3676 } else if (strncmp(token, "sslflags=", 9) == 0) {
3677 safe_free(s->sslflags);
3678 s->sslflags = xstrdup(token + 9);
3679 } else if (strncmp(token, "sslcontext=", 11) == 0) {
3680 safe_free(s->sslContextSessionId);
3681 s->sslContextSessionId = xstrdup(token + 11);
3682 } else if (strcmp(token, "generate-host-certificates") == 0) {
3683 s->generateHostCertificates = true;
3684 } else if (strcmp(token, "generate-host-certificates=on") == 0) {
3685 s->generateHostCertificates = true;
3686 } else if (strcmp(token, "generate-host-certificates=off") == 0) {
3687 s->generateHostCertificates = false;
3688 } else if (strncmp(token, "dynamic_cert_mem_cache_size=", 28) == 0) {
3689 parseBytesOptionValue(&s->dynamicCertMemCacheSize, B_BYTES_STR, token + 28);
3690 #endif
3691 } else {
3692 self_destruct();
3693 }
3694 }
3695
3696 void
3697 add_http_port(char *portspec)
3698 {
3699 AnyP::PortCfg *s = new AnyP::PortCfg("http_port");
3700 parsePortSpecification(s, portspec);
3701 // we may need to merge better if the above returns a list with clones
3702 assert(s->next == NULL);
3703 s->next = cbdataReference(Config.Sockaddr.http);
3704 cbdataReferenceDone(Config.Sockaddr.http);
3705 Config.Sockaddr.http = cbdataReference(s);
3706 }
3707
3708 static void
3709 parsePortCfg(AnyP::PortCfg ** head, const char *optionName)
3710 {
3711 const char *protocol = NULL;
3712 if (strcmp(optionName, "http_port") == 0 ||
3713 strcmp(optionName, "ascii_port") == 0)
3714 protocol = "http";
3715 else if (strcmp(optionName, "https_port") == 0)
3716 protocol = "https";
3717 if (!protocol) {
3718 self_destruct();
3719 return;
3720 }
3721
3722 char *token = strtok(NULL, w_space);
3723
3724 if (!token) {
3725 self_destruct();
3726 return;
3727 }
3728
3729 AnyP::PortCfg *s = new AnyP::PortCfg(protocol);
3730 parsePortSpecification(s, token);
3731
3732 /* parse options ... */
3733 while ((token = strtok(NULL, w_space))) {
3734 parse_port_option(s, token);
3735 }
3736
3737 if (Ip::EnableIpv6&IPV6_SPECIAL_SPLITSTACK && s->s.IsAnyAddr()) {
3738 // clone the port options from *s to *(s->next)
3739 s->next = cbdataReference(s->clone());
3740 s->next->s.SetIPv4();
3741 debugs(3, 3, protocol << "_port: clone wildcard address for split-stack: " << s->s << " and " << s->next->s);
3742 }
3743
3744 while (*head)
3745 head = &(*head)->next;
3746
3747 *head = cbdataReference(s);
3748 }
3749
3750 static void
3751 dump_generic_port(StoreEntry * e, const char *n, const AnyP::PortCfg * s)
3752 {
3753 char buf[MAX_IPSTRLEN];
3754
3755 storeAppendPrintf(e, "%s %s",
3756 n,
3757 s->s.ToURL(buf,MAX_IPSTRLEN));
3758
3759 // MODES and specific sub-options.
3760 if (s->intercepted)
3761 storeAppendPrintf(e, " intercept");
3762
3763 else if (s->spoof_client_ip)
3764 storeAppendPrintf(e, " tproxy");
3765
3766 else if (s->accel) {
3767 storeAppendPrintf(e, " accel");
3768
3769 if (s->vhost)
3770 storeAppendPrintf(e, " vhost");
3771
3772 if (s->vport < 0)
3773 storeAppendPrintf(e, " vport");
3774 else if (s->vport > 0)
3775 storeAppendPrintf(e, " vport=%d", s->vport);
3776
3777 if (s->defaultsite)
3778 storeAppendPrintf(e, " defaultsite=%s", s->defaultsite);
3779
3780 if (s->protocol && strcmp(s->protocol,"http") != 0)
3781 storeAppendPrintf(e, " protocol=%s", s->protocol);
3782
3783 if (s->allow_direct)
3784 storeAppendPrintf(e, " allow-direct");
3785
3786 if (s->ignore_cc)
3787 storeAppendPrintf(e, " ignore-cc");
3788
3789 }
3790
3791 // Generic independent options
3792
3793 if (s->name)
3794 storeAppendPrintf(e, " name=%s", s->name);
3795
3796 #if USE_HTTP_VIOLATIONS
3797 if (!s->accel && s->ignore_cc)
3798 storeAppendPrintf(e, " ignore-cc");
3799 #endif
3800
3801 if (s->connection_auth_disabled)
3802 storeAppendPrintf(e, " connection-auth=off");
3803 else
3804 storeAppendPrintf(e, " connection-auth=on");
3805
3806 if (s->disable_pmtu_discovery != DISABLE_PMTU_OFF) {
3807 const char *pmtu;
3808
3809 if (s->disable_pmtu_discovery == DISABLE_PMTU_ALWAYS)
3810 pmtu = "always";
3811 else
3812 pmtu = "transparent";
3813
3814 storeAppendPrintf(e, " disable-pmtu-discovery=%s", pmtu);
3815 }
3816
3817 if (s->s.IsAnyAddr() && !s->s.IsIPv6())
3818 storeAppendPrintf(e, " ipv4");
3819
3820 if (s->tcp_keepalive.enabled) {
3821 if (s->tcp_keepalive.idle || s->tcp_keepalive.interval || s->tcp_keepalive.timeout) {
3822 storeAppendPrintf(e, " tcpkeepalive=%d,%d,%d", s->tcp_keepalive.idle, s->tcp_keepalive.interval, s->tcp_keepalive.timeout);
3823 } else {
3824 storeAppendPrintf(e, " tcpkeepalive");
3825 }
3826 }
3827
3828 #if USE_SSL
3829 if (s->sslBump)
3830 storeAppendPrintf(e, " ssl-bump");
3831
3832 if (s->cert)
3833 storeAppendPrintf(e, " cert=%s", s->cert);
3834
3835 if (s->key)
3836 storeAppendPrintf(e, " key=%s", s->key);
3837
3838 if (s->version)
3839 storeAppendPrintf(e, " version=%d", s->version);
3840
3841 if (s->options)
3842 storeAppendPrintf(e, " options=%s", s->options);
3843
3844 if (s->cipher)
3845 storeAppendPrintf(e, " cipher=%s", s->cipher);
3846
3847 if (s->cafile)
3848 storeAppendPrintf(e, " cafile=%s", s->cafile);
3849
3850 if (s->capath)
3851 storeAppendPrintf(e, " capath=%s", s->capath);
3852
3853 if (s->crlfile)
3854 storeAppendPrintf(e, " crlfile=%s", s->crlfile);
3855
3856 if (s->dhfile)
3857 storeAppendPrintf(e, " dhparams=%s", s->dhfile);
3858
3859 if (s->sslflags)
3860 storeAppendPrintf(e, " sslflags=%s", s->sslflags);
3861
3862 if (s->sslContextSessionId)
3863 storeAppendPrintf(e, " sslcontext=%s", s->sslContextSessionId);
3864
3865 if (s->generateHostCertificates)
3866 storeAppendPrintf(e, " generate-host-certificates");
3867
3868 if (s->dynamicCertMemCacheSize != std::numeric_limits<size_t>::max())
3869 storeAppendPrintf(e, "dynamic_cert_mem_cache_size=%lu%s\n", (unsigned long)s->dynamicCertMemCacheSize, B_BYTES_STR);
3870 #endif
3871 }
3872
3873 static void
3874 dump_PortCfg(StoreEntry * e, const char *n, const AnyP::PortCfg * s)
3875 {
3876 while (s) {
3877 dump_generic_port(e, n, s);
3878 storeAppendPrintf(e, "\n");
3879 s = s->next;
3880 }
3881 }
3882
3883 static void
3884 free_PortCfg(AnyP::PortCfg ** head)
3885 {
3886 AnyP::PortCfg *s;
3887
3888 while ((s = *head) != NULL) {
3889 *head = s->next;
3890 cbdataReferenceDone(s);
3891 }
3892 }
3893
3894 void
3895 configFreeMemory(void)
3896 {
3897 free_all();
3898 #if USE_SSL
3899 SSL_CTX_free(Config.ssl_client.sslContext);
3900 #endif
3901 }
3902
3903 void
3904 requirePathnameExists(const char *name, const char *path)
3905 {
3906
3907 struct stat sb;
3908 char pathbuf[BUFSIZ];
3909 assert(path != NULL);
3910
3911 if (Config.chroot_dir && (geteuid() == 0)) {
3912 snprintf(pathbuf, BUFSIZ, "%s/%s", Config.chroot_dir, path);
3913 path = pathbuf;
3914 }
3915
3916 if (stat(path, &sb) < 0) {
3917 debugs(0, DBG_CRITICAL, (opt_parse_cfg_only?"FATAL ":"") << "ERROR: " << name << " " << path << ": " << xstrerror());
3918 // keep going to find more issues if we are only checking the config file with "-k parse"
3919 if (opt_parse_cfg_only)
3920 return;
3921 // this is fatal if it is found during startup or reconfigure
3922 if (opt_send_signal == -1 || opt_send_signal == SIGHUP)
3923 fatalf("%s %s: %s", name, path, xstrerror());
3924 }
3925 }
3926
3927 char *
3928 strtokFile(void)
3929 {
3930 return ConfigParser::strtokFile();
3931 }
3932
3933 #include "AccessLogEntry.h"
3934
3935 static void
3936 parse_access_log(customlog ** logs)
3937 {
3938 const char *filename, *logdef_name;
3939
3940 customlog *cl = (customlog *)xcalloc(1, sizeof(*cl));
3941
3942 if ((filename = strtok(NULL, w_space)) == NULL) {
3943 self_destruct();
3944 return;
3945 }
3946
3947 if (strcmp(filename, "none") == 0) {
3948 cl->type = Log::Format::CLF_NONE;
3949 aclParseAclList(LegacyParser, &cl->aclList);
3950 while (*logs)
3951 logs = &(*logs)->next;
3952 *logs = cl;
3953 return;
3954 }
3955
3956 if ((logdef_name = strtok(NULL, w_space)) == NULL)
3957 logdef_name = "squid";
3958
3959 debugs(3, 9, "Log definition name '" << logdef_name << "' file '" << filename << "'");
3960
3961 cl->filename = xstrdup(filename);
3962
3963 /* look for the definition pointer corresponding to this name */
3964 Format::Format *lf = Log::TheConfig.logformats;
3965
3966 while (lf != NULL) {
3967 debugs(3, 9, "Comparing against '" << lf->name << "'");
3968
3969 if (strcmp(lf->name, logdef_name) == 0)
3970 break;
3971
3972 lf = lf->next;
3973 }
3974
3975 if (lf != NULL) {
3976 cl->type = Log::Format::CLF_CUSTOM;
3977 cl->logFormat = lf;
3978 } else if (strcmp(logdef_name, "auto") == 0) {
3979 debugs(0,0, "WARNING: Log format 'auto' no longer exists. Using 'squid' instead.");
3980 cl->type = Log::Format::CLF_SQUID;
3981 } else if (strcmp(logdef_name, "squid") == 0) {
3982 cl->type = Log::Format::CLF_SQUID;
3983 } else if (strcmp(logdef_name, "common") == 0) {
3984 cl->type = Log::Format::CLF_COMMON;
3985 } else if (strcmp(logdef_name, "combined") == 0) {
3986 cl->type = Log::Format::CLF_COMBINED;
3987 #if ICAP_CLIENT
3988 } else if (strcmp(logdef_name, "icap_squid") == 0) {
3989 cl->type = Log::Format::CLF_ICAP_SQUID;
3990 #endif
3991 } else if (strcmp(logdef_name, "useragent") == 0) {
3992 cl->type = Log::Format::CLF_USERAGENT;
3993 } else if (strcmp(logdef_name, "referrer") == 0) {
3994 cl->type = Log::Format::CLF_REFERER;
3995 } else {
3996 debugs(3, 0, "Log format '" << logdef_name << "' is not defined");
3997 self_destruct();
3998 return;
3999 }
4000
4001 aclParseAclList(LegacyParser, &cl->aclList);
4002
4003 while (*logs)
4004 logs = &(*logs)->next;
4005
4006 *logs = cl;
4007 }
4008
4009 static int
4010 check_null_access_log(customlog *customlog_definitions)
4011 {
4012 return customlog_definitions == NULL;
4013 }
4014
4015 static void
4016 dump_access_log(StoreEntry * entry, const char *name, customlog * logs)
4017 {
4018 customlog *log;
4019
4020 for (log = logs; log; log = log->next) {
4021 storeAppendPrintf(entry, "%s ", name);
4022
4023 switch (log->type) {
4024
4025 case Log::Format::CLF_CUSTOM:
4026 storeAppendPrintf(entry, "%s %s", log->filename, log->logFormat->name);
4027 break;
4028
4029 case Log::Format::CLF_NONE:
4030 storeAppendPrintf(entry, "none");
4031 break;
4032
4033 case Log::Format::CLF_SQUID:
4034 storeAppendPrintf(entry, "%s squid", log->filename);
4035 break;
4036
4037 case Log::Format::CLF_COMBINED:
4038 storeAppendPrintf(entry, "%s combined", log->filename);
4039 break;
4040
4041 case Log::Format::CLF_COMMON:
4042 storeAppendPrintf(entry, "%s common", log->filename);
4043 break;
4044
4045 #if ICAP_CLIENT
4046 case Log::Format::CLF_ICAP_SQUID:
4047 storeAppendPrintf(entry, "%s icap_squid", log->filename);
4048 break;
4049 #endif
4050 case Log::Format::CLF_USERAGENT:
4051 storeAppendPrintf(entry, "%s useragent", log->filename);
4052 break;
4053
4054 case Log::Format::CLF_REFERER:
4055 storeAppendPrintf(entry, "%s referrer", log->filename);
4056 break;
4057
4058 case Log::Format::CLF_UNKNOWN:
4059 break;
4060 }
4061
4062 if (log->aclList)
4063 dump_acl_list(entry, log->aclList);
4064
4065 storeAppendPrintf(entry, "\n");
4066 }
4067 }
4068
4069 static void
4070 free_access_log(customlog ** definitions)
4071 {
4072 while (*definitions) {
4073 customlog *log = *definitions;
4074 *definitions = log->next;
4075
4076 log->logFormat = NULL;
4077 log->type = Log::Format::CLF_UNKNOWN;
4078
4079 if (log->aclList)
4080 aclDestroyAclList(&log->aclList);
4081
4082 safe_free(log->filename);
4083
4084 xfree(log);
4085 }
4086 }
4087
4088 /// parses list of integers form name=N1,N2,N3,...
4089 static bool
4090 parseNamedIntList(const char *data, const String &name, Vector<int> &list)
4091 {
4092 if (data && (strncmp(data, name.rawBuf(), name.size()) == 0)) {
4093 data += name.size();
4094 if (*data == '=') {
4095 while (true) {
4096 ++data;
4097 int value = 0;
4098 if (!StringToInt(data, value, &data, 10))
4099 break;
4100 list.push_back(value);
4101 if (*data == '\0' || *data != ',')
4102 break;
4103 }
4104 }
4105 }
4106 return data && *data == '\0';
4107 }
4108
4109 static void
4110 parse_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap)
4111 {
4112 #if !HAVE_CPU_AFFINITY
4113 debugs(3, DBG_CRITICAL, "FATAL: Squid built with no CPU affinity " <<
4114 "support, do not set 'cpu_affinity_map'");
4115 self_destruct();
4116 #endif /* HAVE_CPU_AFFINITY */
4117
4118 if (!*cpuAffinityMap)
4119 *cpuAffinityMap = new CpuAffinityMap;
4120
4121 const char *const pToken = strtok(NULL, w_space);
4122 const char *const cToken = strtok(NULL, w_space);
4123 Vector<int> processes, cores;
4124 if (!parseNamedIntList(pToken, "process_numbers", processes)) {
4125 debugs(3, DBG_CRITICAL, "FATAL: bad 'process_numbers' parameter " <<
4126 "in 'cpu_affinity_map'");
4127 self_destruct();
4128 } else if (!parseNamedIntList(cToken, "cores", cores)) {
4129 debugs(3, DBG_CRITICAL, "FATAL: bad 'cores' parameter in " <<
4130 "'cpu_affinity_map'");
4131 self_destruct();
4132 } else if (!(*cpuAffinityMap)->add(processes, cores)) {
4133 debugs(3, DBG_CRITICAL, "FATAL: bad 'cpu_affinity_map'; " <<
4134 "process_numbers and cores lists differ in length or " <<
4135 "contain numbers <= 0");
4136 self_destruct();
4137 }
4138 }
4139
4140 static void
4141 dump_CpuAffinityMap(StoreEntry *const entry, const char *const name, const CpuAffinityMap *const cpuAffinityMap)
4142 {
4143 if (cpuAffinityMap) {
4144 storeAppendPrintf(entry, "%s process_numbers=", name);
4145 for (size_t i = 0; i < cpuAffinityMap->processes().size(); ++i) {
4146 storeAppendPrintf(entry, "%s%i", (i ? "," : ""),
4147 cpuAffinityMap->processes()[i]);
4148 }
4149 storeAppendPrintf(entry, " cores=");
4150 for (size_t i = 0; i < cpuAffinityMap->processes().size(); ++i) {
4151 storeAppendPrintf(entry, "%s%i", (i ? "," : ""),
4152 cpuAffinityMap->cores()[i]);
4153 }
4154 storeAppendPrintf(entry, "\n");
4155 }
4156 }
4157
4158 static void
4159 free_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap)
4160 {
4161 delete *cpuAffinityMap;
4162 *cpuAffinityMap = NULL;
4163 }
4164
4165 #if USE_ADAPTATION
4166
4167 static void
4168 parse_adaptation_service_set_type()
4169 {
4170 Adaptation::Config::ParseServiceSet();
4171 }
4172
4173 static void
4174 parse_adaptation_service_chain_type()
4175 {
4176 Adaptation::Config::ParseServiceChain();
4177 }
4178
4179 static void
4180 parse_adaptation_access_type()
4181 {
4182 Adaptation::Config::ParseAccess(LegacyParser);
4183 }
4184
4185 static void
4186 parse_adaptation_meta_type(Adaptation::Config::MetaHeaders *)
4187 {
4188 Adaptation::Config::ParseMetaHeader(LegacyParser);
4189 }
4190
4191 static void
4192 dump_adaptation_meta_type(StoreEntry *entry, const char *name, Adaptation::Config::MetaHeaders &)
4193 {
4194 Adaptation::Config::DumpMetaHeader(entry, name);
4195 }
4196
4197 static void
4198 free_adaptation_meta_type(Adaptation::Config::MetaHeaders *)
4199 {
4200 // Nothing to do, it is released inside Adaptation::Config::freeService()
4201 }
4202 #endif /* USE_ADAPTATION */
4203
4204
4205 #if ICAP_CLIENT
4206
4207 static void
4208 parse_icap_service_type(Adaptation::Icap::Config * cfg)
4209 {
4210 cfg->parseService();
4211 }
4212
4213 static void
4214 free_icap_service_type(Adaptation::Icap::Config * cfg)
4215 {
4216 cfg->freeService();
4217 }
4218
4219 static void
4220 dump_icap_service_type(StoreEntry * entry, const char *name, const Adaptation::Icap::Config &cfg)
4221 {
4222 cfg.dumpService(entry, name);
4223 }
4224
4225 static void
4226 parse_icap_class_type()
4227 {
4228 debugs(93, 0, "WARNING: 'icap_class' is depricated. " <<
4229 "Use 'adaptation_service_set' instead");
4230 Adaptation::Config::ParseServiceSet();
4231 }
4232
4233 static void
4234 parse_icap_access_type()
4235 {
4236 debugs(93, 0, "WARNING: 'icap_access' is depricated. " <<
4237 "Use 'adaptation_access' instead");
4238 Adaptation::Config::ParseAccess(LegacyParser);
4239 }
4240
4241 #endif
4242
4243
4244 #if USE_ECAP
4245
4246 static void
4247 parse_ecap_service_type(Adaptation::Ecap::Config * cfg)
4248 {
4249 cfg->parseService();
4250 }
4251
4252 static void
4253 free_ecap_service_type(Adaptation::Ecap::Config * cfg)
4254 {
4255 cfg->freeService();
4256 }
4257
4258 static void
4259 dump_ecap_service_type(StoreEntry * entry, const char *name, const Adaptation::Ecap::Config &cfg)
4260 {
4261 cfg.dumpService(entry, name);
4262 }
4263
4264 #endif /* USE_ECAP */
4265
4266 #if ICAP_CLIENT
4267 static void parse_icap_service_failure_limit(Adaptation::Icap::Config *cfg)
4268 {
4269 char *token;
4270 time_t d;
4271 time_t m;
4272 cfg->service_failure_limit = GetInteger();
4273
4274 if ((token = strtok(NULL, w_space)) == NULL)
4275 return;
4276
4277 if (strcmp(token,"in") != 0) {
4278 debugs(3, 0, "expecting 'in' on'" << config_input_line << "'");
4279 self_destruct();
4280 }
4281
4282 if ((token = strtok(NULL, w_space)) == NULL) {
4283 self_destruct();
4284 }
4285
4286 d = static_cast<time_t> (xatoi(token));
4287
4288 m = static_cast<time_t> (1);
4289
4290 if (0 == d)
4291 (void) 0;
4292 else if ((token = strtok(NULL, w_space)) == NULL) {
4293 debugs(3, 0, "No time-units on '" << config_input_line << "'");
4294 self_destruct();
4295 } else if ((m = parseTimeUnits(token, false)) == 0)
4296 self_destruct();
4297
4298 cfg->oldest_service_failure = (m * d);
4299 }
4300
4301 static void dump_icap_service_failure_limit(StoreEntry *entry, const char *name, const Adaptation::Icap::Config &cfg)
4302 {
4303 storeAppendPrintf(entry, "%s %d", name, cfg.service_failure_limit);
4304 if (cfg.oldest_service_failure > 0) {
4305 storeAppendPrintf(entry, " in %d seconds", (int)cfg.oldest_service_failure);
4306 }
4307 storeAppendPrintf(entry, "\n");
4308 }
4309
4310 static void free_icap_service_failure_limit(Adaptation::Icap::Config *cfg)
4311 {
4312 cfg->oldest_service_failure = 0;
4313 cfg->service_failure_limit = 0;
4314 }
4315
4316 #endif