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