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