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