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