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