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