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