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