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