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