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