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