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