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