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