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