4 * DEBUG: section 03 Configuration File Parsing
5 * AUTHOR: Harvest Derived
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
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.
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.
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.
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.
35 #include "squid-old.h"
38 #include "acl/Gadgets.h"
39 #include "acl/MethodData.h"
41 #include "adaptation/Config.h"
44 #include "adaptation/icap/Config.h"
47 #include "adaptation/ecap/Config.h"
49 #include "anyp/PortCfg.h"
51 #include "ssl/support.h"
52 #include "ssl/Config.h"
55 #include "auth/Config.h"
56 #include "auth/Scheme.h"
58 #include "ConfigParser.h"
59 #include "CpuAffinityMap.h"
60 #include "DiskIO/DiskIOModule.h"
61 #include "eui/Config.h"
63 #include "esi/Parser.h"
65 #include "format/Format.h"
66 #include "HttpRequestMethod.h"
67 #include "ident/Config.h"
68 #include "ip/Intercept.h"
69 #include "ip/QosConfig.h"
71 #include "log/Config.h"
73 #include "mgr/Registration.h"
80 #include "StoreFileSystem.h"
94 #include "ssl/gadgets.h"
98 static void parse_adaptation_service_set_type();
99 static void parse_adaptation_service_chain_type();
100 static void parse_adaptation_access_type();
101 static void parse_adaptation_meta_type(Adaptation::Config::MetaHeaders
*);
102 static void dump_adaptation_meta_type(StoreEntry
*, const char *, Adaptation::Config::MetaHeaders
&);
103 static void free_adaptation_meta_type(Adaptation::Config::MetaHeaders
*);
107 static void parse_icap_service_type(Adaptation::Icap::Config
*);
108 static void dump_icap_service_type(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
109 static void free_icap_service_type(Adaptation::Icap::Config
*);
110 static void parse_icap_class_type();
111 static void parse_icap_access_type();
113 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*);
114 static void dump_icap_service_failure_limit(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
115 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*);
119 static void parse_ecap_service_type(Adaptation::Ecap::Config
*);
120 static void dump_ecap_service_type(StoreEntry
*, const char *, const Adaptation::Ecap::Config
&);
121 static void free_ecap_service_type(Adaptation::Ecap::Config
*);
126 static const char *const T_MILLISECOND_STR
= "millisecond";
127 static const char *const T_SECOND_STR
= "second";
128 static const char *const T_MINUTE_STR
= "minute";
129 static const char *const T_HOUR_STR
= "hour";
130 static const char *const T_DAY_STR
= "day";
131 static const char *const T_WEEK_STR
= "week";
132 static const char *const T_FORTNIGHT_STR
= "fortnight";
133 static const char *const T_MONTH_STR
= "month";
134 static const char *const T_YEAR_STR
= "year";
135 static const char *const T_DECADE_STR
= "decade";
137 static const char *const B_BYTES_STR
= "bytes";
138 static const char *const B_KBYTES_STR
= "KB";
139 static const char *const B_MBYTES_STR
= "MB";
140 static const char *const B_GBYTES_STR
= "GB";
142 static const char *const list_sep
= ", \t\n\r";
144 static void parse_access_log(customlog
** customlog_definitions
);
145 static int check_null_access_log(customlog
*customlog_definitions
);
146 static void dump_access_log(StoreEntry
* entry
, const char *name
, customlog
* definitions
);
147 static void free_access_log(customlog
** definitions
);
149 static void update_maxobjsize(void);
150 static void configDoConfigure(void);
151 static void parse_refreshpattern(refresh_t
**);
152 static uint64_t parseTimeUnits(const char *unit
, bool allowMsec
);
153 static void parseTimeLine(time_msec_t
* tptr
, const char *units
, bool allowMsec
);
154 static void parse_u_short(unsigned short * var
);
155 static void parse_string(char **);
156 static void default_all(void);
157 static void defaults_if_none(void);
158 static int parse_line(char *);
159 static void parse_obsolete(const char *);
160 static void parseBytesLine(size_t * bptr
, const char *units
);
162 static void parseBytesOptionValue(size_t * bptr
, const char *units
, char const * value
);
165 static void parseBytesLineSigned(ssize_t
* bptr
, const char *units
);
167 static size_t parseBytesUnits(const char *unit
);
168 static void free_all(void);
169 void requirePathnameExists(const char *name
, const char *path
);
170 static OBJH dump_config
;
171 #if USE_HTTP_VIOLATIONS
172 static void dump_http_header_access(StoreEntry
* entry
, const char *name
, header_mangler header
[]);
173 static void parse_http_header_access(header_mangler header
[]);
174 static void free_http_header_access(header_mangler header
[]);
175 static void dump_http_header_replace(StoreEntry
* entry
, const char *name
, header_mangler header
[]);
176 static void parse_http_header_replace(header_mangler
* header
);
177 static void free_http_header_replace(header_mangler
* header
);
179 static void parse_denyinfo(acl_deny_info_list
** var
);
180 static void dump_denyinfo(StoreEntry
* entry
, const char *name
, acl_deny_info_list
* var
);
181 static void free_denyinfo(acl_deny_info_list
** var
);
184 static void parse_IpAddress_list(Ip::Address_list
**);
185 static void dump_IpAddress_list(StoreEntry
*, const char *, const Ip::Address_list
*);
186 static void free_IpAddress_list(Ip::Address_list
**);
188 static int check_null_IpAddress_list(const Ip::Address_list
*);
189 #endif /* CURRENTLY_UNUSED */
190 #endif /* USE_WCCPv2 */
192 static void parsePortCfg(AnyP::PortCfg
**, const char *protocol
);
193 #define parse_PortCfg(l) parsePortCfg((l), token)
194 static void dump_PortCfg(StoreEntry
*, const char *, const AnyP::PortCfg
*);
195 static void free_PortCfg(AnyP::PortCfg
**);
197 static void parse_b_size_t(size_t * var
);
198 static void parse_b_int64_t(int64_t * var
);
200 static bool parseNamedIntList(const char *data
, const String
&name
, Vector
<int> &list
);
202 static void parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
203 static void dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
);
204 static void free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
206 static int parseOneConfigFile(const char *file_name
, unsigned int depth
);
209 * LegacyParser is a parser for legacy code that uses the global
210 * approach. This is static so that it is only exposed to cache_cf.
211 * Other modules needing access to a ConfigParser should have it
212 * provided to them in their parserFOO methods.
214 static ConfigParser LegacyParser
= ConfigParser();
219 LegacyParser
.destruct();
223 update_maxobjsize(void)
228 for (i
= 0; i
< Config
.cacheSwap
.n_configured
; i
++) {
229 assert (Config
.cacheSwap
.swapDirs
[i
].getRaw());
231 if (dynamic_cast<SwapDir
*>(Config
.cacheSwap
.swapDirs
[i
].getRaw())->
233 ms
= dynamic_cast<SwapDir
*>(Config
.cacheSwap
.swapDirs
[i
].getRaw())->max_objsize
;
235 store_maxobjsize
= ms
;
239 SetConfigFilename(char const *file_name
, bool is_pipe
)
241 cfg_filename
= file_name
;
246 cfg_filename
= file_name
+ 1;
247 else if ((token
= strrchr(cfg_filename
, '/')))
248 cfg_filename
= token
+ 1;
252 skip_ws(const char* s
)
261 parseManyConfigFiles(char* files
, int depth
)
264 char* saveptr
= NULL
;
269 memset(&globbuf
, 0, sizeof(globbuf
));
270 for (path
= strwordtok(files
, &saveptr
); path
; path
= strwordtok(NULL
, &saveptr
)) {
271 if (glob(path
, globbuf
.gl_pathc
? GLOB_APPEND
: 0, NULL
, &globbuf
) != 0) {
272 fatalf("Unable to find configuration file: %s: %s",
276 for (i
= 0; i
< (int)globbuf
.gl_pathc
; i
++) {
277 error_count
+= parseOneConfigFile(globbuf
.gl_pathv
[i
], depth
);
281 char* file
= strwordtok(files
, &saveptr
);
282 while (file
!= NULL
) {
283 error_count
+= parseOneConfigFile(file
, depth
);
284 file
= strwordtok(NULL
, &saveptr
);
286 #endif /* HAVE_GLOB */
291 ReplaceSubstr(char*& str
, int& len
, unsigned substrIdx
, unsigned substrLen
, const char* newSubstr
)
294 assert(newSubstr
!= NULL
);
296 unsigned newSubstrLen
= strlen(newSubstr
);
297 if (newSubstrLen
> substrLen
)
298 str
= (char*)realloc(str
, len
- substrLen
+ newSubstrLen
+ 1);
300 // move tail part including zero
301 memmove(str
+ substrIdx
+ newSubstrLen
, str
+ substrIdx
+ substrLen
, len
- substrIdx
- substrLen
+ 1);
302 // copy new substring in place
303 memcpy(str
+ substrIdx
, newSubstr
, newSubstrLen
);
309 SubstituteMacro(char*& line
, int& len
, const char* macroName
, const char* substStr
)
311 assert(line
!= NULL
);
312 assert(macroName
!= NULL
);
313 assert(substStr
!= NULL
);
314 unsigned macroNameLen
= strlen(macroName
);
315 while (const char* macroPos
= strstr(line
, macroName
)) // we would replace all occurrences
316 ReplaceSubstr(line
, len
, macroPos
- line
, macroNameLen
, substStr
);
320 ProcessMacros(char*& line
, int& len
)
322 SubstituteMacro(line
, len
, "${process_name}", TheKidName
);
323 SubstituteMacro(line
, len
, "${process_number}", xitoa(KidIdentifier
));
327 trim_trailing_ws(char* str
)
330 unsigned i
= strlen(str
);
331 while ((i
> 0) && xisspace(str
[i
- 1]))
337 FindStatement(const char* line
, const char* statement
)
339 assert(line
!= NULL
);
340 assert(statement
!= NULL
);
342 const char* str
= skip_ws(line
);
343 unsigned len
= strlen(statement
);
344 if (strncmp(str
, statement
, len
) == 0) {
348 else if (xisspace(*str
))
356 StrToInt(const char* str
, long& number
)
361 number
= strtol(str
, &end
, 0);
363 return (end
!= str
) && (*end
== '\0'); // returns true if string contains nothing except number
367 EvalBoolExpr(const char* expr
)
369 assert(expr
!= NULL
);
370 if (strcmp(expr
, "true") == 0) {
372 } else if (strcmp(expr
, "false") == 0) {
374 } else if (const char* equation
= strchr(expr
, '=')) {
375 const char* rvalue
= skip_ws(equation
+ 1);
376 char* lvalue
= (char*)xmalloc(equation
- expr
+ 1);
377 xstrncpy(lvalue
, expr
, equation
- expr
+ 1);
378 trim_trailing_ws(lvalue
);
381 if (!StrToInt(lvalue
, number1
))
382 fatalf("String is not a integer number: '%s'\n", lvalue
);
384 if (!StrToInt(rvalue
, number2
))
385 fatalf("String is not a integer number: '%s'\n", rvalue
);
388 return number1
== number2
;
390 fatalf("Unable to evaluate expression '%s'\n", expr
);
391 return false; // this place cannot be reached
395 parseOneConfigFile(const char *file_name
, unsigned int depth
)
398 const char *orig_cfg_filename
= cfg_filename
;
399 const int orig_config_lineno
= config_lineno
;
401 char *tmp_line
= NULL
;
402 int tmp_line_len
= 0;
406 debugs(3, 1, "Processing Configuration File: " << file_name
<< " (depth " << depth
<< ")");
408 fatalf("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name
);
412 if (file_name
[0] == '!' || file_name
[0] == '|') {
413 fp
= popen(file_name
+ 1, "r");
416 fp
= fopen(file_name
, "r");
420 fatalf("Unable to open configuration file: %s: %s", file_name
, xstrerror());
423 setmode(fileno(fp
), O_TEXT
);
426 SetConfigFilename(file_name
, bool(is_pipe
));
428 memset(config_input_line
, '\0', BUFSIZ
);
432 Vector
<bool> if_states
;
433 while (fgets(config_input_line
, BUFSIZ
, fp
)) {
436 if ((token
= strchr(config_input_line
, '\n')))
439 if ((token
= strchr(config_input_line
, '\r')))
442 // strip any prefix whitespace off the line.
443 const char *p
= skip_ws(config_input_line
);
444 if (config_input_line
!= p
)
445 memmove(config_input_line
, p
, strlen(p
)+1);
447 if (strncmp(config_input_line
, "#line ", 6) == 0) {
448 static char new_file_name
[1024];
450 static char new_lineno
;
451 token
= config_input_line
+ 6;
452 new_lineno
= strtol(token
, &file
, 0) - 1;
455 continue; /* Not a valid #line directive, may be a comment */
457 while (*file
&& xisspace((unsigned char) *file
))
462 continue; /* Not a valid #line directive, may be a comment */
464 xstrncpy(new_file_name
, file
+ 1, sizeof(new_file_name
));
466 if ((token
= strchr(new_file_name
, '"')))
469 cfg_filename
= new_file_name
;
472 config_lineno
= new_lineno
;
475 if (config_input_line
[0] == '#')
478 if (config_input_line
[0] == '\0')
481 const char* append
= tmp_line_len
? skip_ws(config_input_line
) : config_input_line
;
483 size_t append_len
= strlen(append
);
485 tmp_line
= (char*)xrealloc(tmp_line
, tmp_line_len
+ append_len
+ 1);
487 strcpy(tmp_line
+ tmp_line_len
, append
);
489 tmp_line_len
+= append_len
;
491 if (tmp_line
[tmp_line_len
-1] == '\\') {
492 debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line
<< "'");
493 tmp_line
[--tmp_line_len
] = '\0';
497 trim_trailing_ws(tmp_line
);
498 ProcessMacros(tmp_line
, tmp_line_len
);
499 debugs(3, (opt_parse_cfg_only
?1:5), "Processing: " << tmp_line
);
501 if (const char* expr
= FindStatement(tmp_line
, "if")) {
502 if_states
.push_back(EvalBoolExpr(expr
)); // store last if-statement meaning
503 } else if (FindStatement(tmp_line
, "endif")) {
504 if (!if_states
.empty())
505 if_states
.pop_back(); // remove last if-statement meaning
507 fatalf("'endif' without 'if'\n");
508 } else if (FindStatement(tmp_line
, "else")) {
509 if (!if_states
.empty())
510 if_states
.back() = !if_states
.back();
512 fatalf("'else' without 'if'\n");
513 } else if (if_states
.empty() || if_states
.back()) { // test last if-statement meaning if present
514 /* Handle includes here */
515 if (tmp_line_len
>= 9 && strncmp(tmp_line
, "include", 7) == 0 && xisspace(tmp_line
[7])) {
516 err_count
+= parseManyConfigFiles(tmp_line
+ 8, depth
+ 1);
517 } else if (!parse_line(tmp_line
)) {
518 debugs(3, 0, HERE
<< cfg_filename
<< ":" << config_lineno
<< " unrecognized: '" << tmp_line
<< "'");
527 if (!if_states
.empty())
528 fatalf("if-statement without 'endif'\n");
531 int ret
= pclose(fp
);
534 fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name
, ret
);
539 cfg_filename
= orig_cfg_filename
;
540 config_lineno
= orig_config_lineno
;
546 parseConfigFile(const char *file_name
)
554 ACLMethodData::ThePurgeCount
= 0;
557 err_count
= parseOneConfigFile(file_name
, 0);
562 * We must call configDoConfigure() before leave_suid() because
563 * configDoConfigure() is where we turn username strings into
568 if (!Config
.chroot_dir
) {
570 setUmask(Config
.umask
);
571 _db_init(Debug::cache_log
, Debug::debugOptions
);
575 if (opt_send_signal
== -1) {
576 Mgr::RegisterAction("config",
577 "Current Squid Configuration",
587 configDoConfigure(void)
589 memset(&Config2
, '\0', sizeof(SquidConfig2
));
590 /* init memory as early as possible */
594 if (Config
.cacheSwap
.swapDirs
== NULL
) {
595 /* Memory-only cache probably in effect. */
596 /* turn off the cache rebuild delays... */
597 StoreController::store_dirs_rebuilding
= 0;
598 } else if (InDaemonMode()) { // no diskers in non-daemon mode
599 for (int i
= 0; i
< Config
.cacheSwap
.n_configured
; ++i
) {
600 const RefCount
<SwapDir
> sd
= Config
.cacheSwap
.swapDirs
[i
];
601 if (sd
->needsDiskStrand())
602 sd
->disker
= Config
.workers
+ (++Config
.cacheSwap
.n_strands
);
606 if (Debug::rotateNumber
< 0) {
607 Debug::rotateNumber
= Config
.Log
.rotateNumber
;
610 #if SIZEOF_OFF_T <= 4
611 if (Config
.Store
.maxObjectSize
> 0x7FFF0000) {
612 debugs(3, 0, "WARNING: This Squid binary can not handle files larger than 2GB. Limiting maximum_object_size to just below 2GB");
613 Config
.Store
.maxObjectSize
= 0x7FFF0000;
616 if (0 == Store::Root().maxSize())
617 /* people might want a zero-sized cache on purpose */
619 else if (Store::Root().maxSize() < Config
.memMaxSize
)
620 /* This is bogus. folk with NULL caches will want this */
621 debugs(3, 0, "WARNING cache_mem is larger than total disk cache space!");
623 if (Config
.Announce
.period
> 0) {
624 Config
.onoff
.announce
= 1;
625 } else if (Config
.Announce
.period
< 1) {
626 Config
.Announce
.period
= 86400 * 365; /* one year */
627 Config
.onoff
.announce
= 0;
630 if (Config
.onoff
.httpd_suppress_version_string
)
631 visible_appname_string
= (char *)appname_string
;
633 visible_appname_string
= (char const *)APP_FULLNAME
;
636 if (Config
.dnsChildren
.n_max
< 1)
637 fatal("No DNS helpers allocated");
640 if (Config
.Program
.redirect
) {
641 if (Config
.redirectChildren
.n_max
< 1) {
642 Config
.redirectChildren
.n_max
= 0;
643 wordlistDestroy(&Config
.Program
.redirect
);
647 if (Config
.appendDomain
)
648 if (*Config
.appendDomain
!= '.')
649 fatal("append_domain must begin with a '.'");
651 if (Config
.errHtmlText
== NULL
)
652 Config
.errHtmlText
= xstrdup(null_string
);
654 #if !HAVE_SETRLIMIT || !defined(RLIMIT_NOFILE)
655 if (Config
.max_filedescriptors
> 0) {
656 debugs(0, DBG_IMPORTANT
, "WARNING: max_filedescriptors disabled. Operating System setrlimit(RLIMIT_NOFILE) is missing.");
658 #elif USE_SELECT || USE_SELECT_WIN32
659 if (Config
.max_filedescriptors
> FD_SETSIZE
) {
660 debugs(0, DBG_IMPORTANT
, "WARNING: max_filedescriptors limited to " << FD_SETSIZE
<< " by select() algorithm.");
666 snprintf(ThisCache
, sizeof(ThisCache
), "%s (%s)",
668 visible_appname_string
);
671 * the extra space is for loop detection in client_side.c -- we search
672 * for substrings in the Via header.
674 snprintf(ThisCache2
, sizeof(ThisCache
), " %s (%s)",
676 visible_appname_string
);
678 /* Use visible_hostname as default surrogate_id */
679 if (!Config
.Accel
.surrogate_id
) {
680 const char *t
= getMyHostname();
681 Config
.Accel
.surrogate_id
= xstrdup( (t
?t
:"unset-id") );
684 if (!Config
.udpMaxHitObjsz
|| Config
.udpMaxHitObjsz
> SQUID_UDP_SO_SNDBUF
)
685 Config
.udpMaxHitObjsz
= SQUID_UDP_SO_SNDBUF
;
687 if (Config
.appendDomain
)
688 Config
.appendDomainLen
= strlen(Config
.appendDomain
);
690 Config
.appendDomainLen
= 0;
692 if (Config
.connect_retries
> 10) {
693 debugs(0,DBG_CRITICAL
, "WARNING: connect_retries cannot be larger than 10. Resetting to 10.");
694 Config
.connect_retries
= 10;
697 requirePathnameExists("MIME Config Table", Config
.mimeTablePathname
);
699 requirePathnameExists("cache_dns_program", Config
.Program
.dnsserver
);
703 requirePathnameExists("unlinkd_program", Config
.Program
.unlinkd
);
705 requirePathnameExists("logfile_daemon", Log::TheConfig
.logfile_daemon
);
706 if (Config
.Program
.redirect
)
707 requirePathnameExists("redirect_program", Config
.Program
.redirect
->key
);
709 requirePathnameExists("Icon Directory", Config
.icons
.directory
);
711 if (Config
.errorDirectory
)
712 requirePathnameExists("Error Directory", Config
.errorDirectory
);
714 #if USE_HTTP_VIOLATIONS
719 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
720 if (!R
->flags
.override_expire
)
723 debugs(22, 1, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP");
728 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
729 if (!R
->flags
.override_lastmod
)
732 debugs(22, 1, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP");
737 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
738 if (!R
->flags
.reload_into_ims
)
741 debugs(22, 1, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP");
746 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
747 if (!R
->flags
.ignore_reload
)
750 debugs(22, 1, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP");
755 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
756 if (!R
->flags
.ignore_no_cache
)
759 debugs(22, 1, "WARNING: use of 'ignore-no-cache' in 'refresh_pattern' violates HTTP");
764 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
765 if (!R
->flags
.ignore_no_store
)
768 debugs(22, 1, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP");
773 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
774 if (!R
->flags
.ignore_must_revalidate
)
776 debugs(22, 1, "WARNING: use of 'ignore-must-revalidate' in 'refresh_pattern' violates HTTP");
780 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
781 if (!R
->flags
.ignore_private
)
784 debugs(22, 1, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP");
789 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
790 if (!R
->flags
.ignore_auth
)
793 debugs(22, 1, "WARNING: use of 'ignore-auth' in 'refresh_pattern' violates HTTP");
800 #if !USE_HTTP_VIOLATIONS
801 Config
.onoff
.via
= 1;
804 if (!Config
.onoff
.via
)
805 debugs(22, 1, "WARNING: HTTP requires the use of Via");
809 // we enable runtime PURGE checks if there is at least one PURGE method ACL
810 // TODO: replace with a dedicated "purge" ACL option?
811 Config2
.onoff
.enable_purge
= (ACLMethodData::ThePurgeCount
> 0);
813 Config2
.onoff
.mangle_request_headers
= httpReqHdrManglersConfigured();
815 if (geteuid() == 0) {
816 if (NULL
!= Config
.effectiveUser
) {
818 struct passwd
*pwd
= getpwnam(Config
.effectiveUser
);
822 * Andres Kroonmaa <andre@online.ee>:
823 * Some getpwnam() implementations (Solaris?) require
824 * an available FD < 256 for opening a FILE* to the
827 * This should be safe at startup, but might still fail
828 * during reconfigure.
830 fatalf("getpwnam failed to find userid for effective user '%s'",
831 Config
.effectiveUser
);
835 Config2
.effectiveUserID
= pwd
->pw_uid
;
837 Config2
.effectiveGroupID
= pwd
->pw_gid
;
841 if (pwd
->pw_dir
&& *pwd
->pw_dir
) {
843 char *env_str
= (char *)xcalloc((len
= strlen(pwd
->pw_dir
) + 6), 1);
844 snprintf(env_str
, len
, "HOME=%s", pwd
->pw_dir
);
852 Config2
.effectiveUserID
= geteuid();
853 Config2
.effectiveGroupID
= getegid();
856 if (NULL
!= Config
.effectiveGroup
) {
858 struct group
*grp
= getgrnam(Config
.effectiveGroup
);
861 fatalf("getgrnam failed to find groupid for effective group '%s'",
862 Config
.effectiveGroup
);
866 Config2
.effectiveGroupID
= grp
->gr_gid
;
869 HttpRequestMethod::Configure(Config
);
872 debugs(3, 1, "Initializing https proxy context");
874 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
);
876 for (peer
*p
= Config
.peers
; p
!= NULL
; p
= p
->next
) {
878 debugs(3, 1, "Initializing cache_peer " << p
->name
<< " SSL context");
879 p
->sslContext
= sslCreateClientContext(p
->sslcert
, p
->sslkey
, p
->sslversion
, p
->sslcipher
, p
->ssloptions
, p
->sslflags
, p
->sslcafile
, p
->sslcapath
, p
->sslcrlfile
);
883 for (AnyP::PortCfg
*s
= Config
.Sockaddr
.http
; s
!= NULL
; s
= s
->next
) {
884 if (!s
->cert
&& !s
->key
)
887 debugs(3, 1, "Initializing http_port " << s
->s
<< " SSL context");
889 s
->staticSslContext
.reset(
890 sslCreateServerContext(s
->cert
, s
->key
,
891 s
->version
, s
->cipher
, s
->options
, s
->sslflags
, s
->clientca
,
892 s
->cafile
, s
->capath
, s
->crlfile
, s
->dhfile
,
893 s
->sslContextSessionId
));
895 Ssl::readCertChainAndPrivateKeyFromFiles(s
->signingCert
, s
->signPkey
, s
->certsToChain
, s
->cert
, s
->key
);
898 for (AnyP::PortCfg
*s
= Config
.Sockaddr
.https
; s
!= NULL
; s
= s
->next
) {
899 debugs(3, 1, "Initializing https_port " << s
->s
<< " SSL context");
901 s
->staticSslContext
.reset(
902 sslCreateServerContext(s
->cert
, s
->key
,
903 s
->version
, s
->cipher
, s
->options
, s
->sslflags
, s
->clientca
,
904 s
->cafile
, s
->capath
, s
->crlfile
, s
->dhfile
,
905 s
->sslContextSessionId
));
910 // prevent infinite fetch loops in the request parser
911 // due to buffer full but not enough data recived to finish parse
912 if (Config
.maxRequestBufferSize
<= Config
.maxRequestHeaderSize
) {
913 fatalf("Client request buffer of %u bytes cannot hold a request with %u bytes of headers." \
914 " Change client_request_buffer_max or request_header_max_size limits.",
915 (uint32_t)Config
.maxRequestBufferSize
, (uint32_t)Config
.maxRequestHeaderSize
);
920 * disable client side request pipelining. There is a race with
921 * Negotiate and NTLM when the client sends a second request on an
922 * connection before the authenticate challenge is sent. With
923 * pipelining OFF, the client may fail to authenticate, but squid's
924 * state will be preserved.
926 if (Config
.onoff
.pipeline_prefetch
) {
927 Auth::Config
*nego
= Auth::Config::Find("Negotiate");
928 Auth::Config
*ntlm
= Auth::Config::Find("NTLM");
929 if ((nego
&& nego
->active()) || (ntlm
&& ntlm
->active())) {
930 debugs(3, DBG_IMPORTANT
, "WARNING: pipeline_prefetch breaks NTLM and Negotiate authentication. Forced OFF.");
931 Config
.onoff
.pipeline_prefetch
= 0;
937 /** Parse a line containing an obsolete directive.
938 * To upgrade it where possible instead of just "Bungled config" for
939 * directives which cannot be marked as simply aliases of the some name.
940 * For example if the parameter order and content has changed.
941 * Or if the directive has been completely removed.
944 parse_obsolete(const char *name
)
946 // Directives which have been radically changed rather than removed
947 if (!strcmp(name
, "url_rewrite_concurrency")) {
950 debugs(3, DBG_CRITICAL
, "WARNING: url_rewrite_concurrency upgrade overriding url_rewrite_children settings.");
951 Config
.redirectChildren
.concurrency
= cval
;
955 /* Parse a time specification from the config file. Store the
956 * result in 'tptr', after converting it to 'units' */
958 parseTimeLine(time_msec_t
* tptr
, const char *units
, bool allowMsec
)
965 if ((u
= parseTimeUnits(units
, allowMsec
)) == 0)
968 if ((token
= strtok(NULL
, w_space
)) == NULL
)
973 m
= u
; /* default to 'units' if none specified */
977 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
978 debugs(3, 0, "WARNING: No units on '" <<
979 config_input_line
<< "', assuming " <<
981 else if ((m
= parseTimeUnits(token
, allowMsec
)) == 0)
984 *tptr
= static_cast<time_msec_t
>(m
* d
);
988 parseTimeUnits(const char *unit
, bool allowMsec
)
990 if (allowMsec
&& !strncasecmp(unit
, T_MILLISECOND_STR
, strlen(T_MILLISECOND_STR
)))
993 if (!strncasecmp(unit
, T_SECOND_STR
, strlen(T_SECOND_STR
)))
996 if (!strncasecmp(unit
, T_MINUTE_STR
, strlen(T_MINUTE_STR
)))
999 if (!strncasecmp(unit
, T_HOUR_STR
, strlen(T_HOUR_STR
)))
1002 if (!strncasecmp(unit
, T_DAY_STR
, strlen(T_DAY_STR
)))
1003 return 86400 * 1000;
1005 if (!strncasecmp(unit
, T_WEEK_STR
, strlen(T_WEEK_STR
)))
1006 return 86400 * 7 * 1000;
1008 if (!strncasecmp(unit
, T_FORTNIGHT_STR
, strlen(T_FORTNIGHT_STR
)))
1009 return 86400 * 14 * 1000;
1011 if (!strncasecmp(unit
, T_MONTH_STR
, strlen(T_MONTH_STR
)))
1012 return static_cast<uint64_t>(86400) * 30 * 1000;
1014 if (!strncasecmp(unit
, T_YEAR_STR
, strlen(T_YEAR_STR
)))
1015 return static_cast<uint64_t>(86400 * 1000 * 365.2522);
1017 if (!strncasecmp(unit
, T_DECADE_STR
, strlen(T_DECADE_STR
)))
1018 return static_cast<uint64_t>(86400 * 1000 * 365.2522 * 10);
1020 debugs(3, 1, "parseTimeUnits: unknown time unit '" << unit
<< "'");
1026 parseBytesLine64(int64_t * bptr
, const char *units
)
1033 if ((u
= parseBytesUnits(units
)) == 0) {
1038 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
1043 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1050 m
= u
; /* default to 'units' if none specified */
1054 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1055 debugs(3, 0, "WARNING: No units on '" <<
1056 config_input_line
<< "', assuming " <<
1057 d
<< " " << units
);
1058 else if ((m
= parseBytesUnits(token
)) == 0) {
1063 *bptr
= static_cast<int64_t>(m
* d
/ u
);
1065 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
1071 parseBytesLine(size_t * bptr
, const char *units
)
1078 if ((u
= parseBytesUnits(units
)) == 0) {
1083 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
1088 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1089 *bptr
= static_cast<size_t>(-1);
1095 m
= u
; /* default to 'units' if none specified */
1099 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1100 debugs(3, 0, "WARNING: No units on '" <<
1101 config_input_line
<< "', assuming " <<
1102 d
<< " " << units
);
1103 else if ((m
= parseBytesUnits(token
)) == 0) {
1108 *bptr
= static_cast<size_t>(m
* d
/ u
);
1110 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
1116 parseBytesLineSigned(ssize_t
* bptr
, const char *units
)
1123 if ((u
= parseBytesUnits(units
)) == 0) {
1128 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
1133 if (strcmp(token
, "none") == 0 || token
[0] == '-' /* -N */) {
1140 m
= u
; /* default to 'units' if none specified */
1144 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1145 debugs(3, 0, "WARNING: No units on '" <<
1146 config_input_line
<< "', assuming " <<
1147 d
<< " " << units
);
1148 else if ((m
= parseBytesUnits(token
)) == 0) {
1153 *bptr
= static_cast<size_t>(m
* d
/ u
);
1155 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
1162 * Parse bytes from a string.
1163 * Similar to the parseBytesLine function but parses the string value instead of
1164 * the current token value.
1166 static void parseBytesOptionValue(size_t * bptr
, const char *units
, char const * value
)
1169 if ((u
= parseBytesUnits(units
)) == 0) {
1174 // Find number from string beginning.
1175 char const * number_begin
= value
;
1176 char const * number_end
= value
;
1178 while ((*number_end
>= '0' && *number_end
<= '9')) {
1183 number
.limitInit(number_begin
, number_end
- number_begin
);
1185 int d
= xatoi(number
.termedBuf());
1187 if ((m
= parseBytesUnits(number_end
)) == 0) {
1192 *bptr
= static_cast<size_t>(m
* d
/ u
);
1193 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
1199 parseBytesUnits(const char *unit
)
1201 if (!strncasecmp(unit
, B_BYTES_STR
, strlen(B_BYTES_STR
)))
1204 if (!strncasecmp(unit
, B_KBYTES_STR
, strlen(B_KBYTES_STR
)))
1207 if (!strncasecmp(unit
, B_MBYTES_STR
, strlen(B_MBYTES_STR
)))
1210 if (!strncasecmp(unit
, B_GBYTES_STR
, strlen(B_GBYTES_STR
)))
1213 debugs(3, DBG_CRITICAL
, "WARNING: Unknown bytes unit '" << unit
<< "'");
1218 /*****************************************************************************
1220 *****************************************************************************/
1223 dump_acl(StoreEntry
* entry
, const char *name
, ACL
* ae
)
1228 while (ae
!= NULL
) {
1229 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
);
1230 storeAppendPrintf(entry
, "%s %s %s ",
1237 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
<< " " << v
->key
);
1238 storeAppendPrintf(entry
, "%s ", v
->key
);
1242 storeAppendPrintf(entry
, "\n");
1243 wordlistDestroy(&w
);
1249 parse_acl(ACL
** ae
)
1251 ACL::ParseAclLine(LegacyParser
, ae
);
1261 dump_acl_list(StoreEntry
* entry
, ACLList
* head
)
1265 for (l
= head
; l
; l
= l
->next
) {
1266 storeAppendPrintf(entry
, " %s%s",
1267 l
->op
? null_string
: "!",
1273 dump_acl_access(StoreEntry
* entry
, const char *name
, acl_access
* head
)
1277 for (l
= head
; l
; l
= l
->next
) {
1278 storeAppendPrintf(entry
, "%s %s",
1280 l
->allow
? "Allow" : "Deny");
1281 dump_acl_list(entry
, l
->aclList
);
1282 storeAppendPrintf(entry
, "\n");
1287 parse_acl_access(acl_access
** head
)
1289 aclParseAccessLine(LegacyParser
, head
);
1293 free_acl_access(acl_access
** head
)
1295 aclDestroyAccessList(head
);
1299 dump_address(StoreEntry
* entry
, const char *name
, Ip::Address
&addr
)
1301 char buf
[MAX_IPSTRLEN
];
1302 storeAppendPrintf(entry
, "%s %s\n", name
, addr
.NtoA(buf
,MAX_IPSTRLEN
) );
1306 parse_address(Ip::Address
*addr
)
1308 char *token
= strtok(NULL
, w_space
);
1315 if (!strcmp(token
,"any_addr"))
1317 else if ( (!strcmp(token
,"no_addr")) || (!strcmp(token
,"full_mask")) )
1319 else if ( (*addr
= token
) ) // try parse numeric/IPA
1322 addr
->GetHostByName(token
); // dont use ipcache
1326 free_address(Ip::Address
*addr
)
1331 CBDATA_TYPE(acl_address
);
1334 dump_acl_address(StoreEntry
* entry
, const char *name
, acl_address
* head
)
1336 char buf
[MAX_IPSTRLEN
];
1339 for (l
= head
; l
; l
= l
->next
) {
1340 if (!l
->addr
.IsAnyAddr())
1341 storeAppendPrintf(entry
, "%s %s", name
, l
->addr
.NtoA(buf
,MAX_IPSTRLEN
));
1343 storeAppendPrintf(entry
, "%s autoselect", name
);
1345 dump_acl_list(entry
, l
->aclList
);
1347 storeAppendPrintf(entry
, "\n");
1352 freed_acl_address(void *data
)
1354 acl_address
*l
= static_cast<acl_address
*>(data
);
1355 aclDestroyAclList(&l
->aclList
);
1359 parse_acl_address(acl_address
** head
)
1362 acl_address
**tail
= head
; /* sane name below */
1363 CBDATA_INIT_TYPE_FREECB(acl_address
, freed_acl_address
);
1364 l
= cbdataAlloc(acl_address
);
1365 parse_address(&l
->addr
);
1366 aclParseAclList(LegacyParser
, &l
->aclList
);
1369 tail
= &(*tail
)->next
;
1375 free_acl_address(acl_address
** head
)
1378 acl_address
*l
= *head
;
1384 CBDATA_TYPE(acl_tos
);
1387 dump_acl_tos(StoreEntry
* entry
, const char *name
, acl_tos
* head
)
1391 for (l
= head
; l
; l
= l
->next
) {
1393 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->tos
);
1395 storeAppendPrintf(entry
, "%s none", name
);
1397 dump_acl_list(entry
, l
->aclList
);
1399 storeAppendPrintf(entry
, "\n");
1404 freed_acl_tos(void *data
)
1406 acl_tos
*l
= static_cast<acl_tos
*>(data
);
1407 aclDestroyAclList(&l
->aclList
);
1411 parse_acl_tos(acl_tos
** head
)
1414 acl_tos
**tail
= head
; /* sane name below */
1415 unsigned int tos
; /* Initially uint for strtoui. Casted to tos_t before return */
1416 char *token
= strtok(NULL
, w_space
);
1423 if (!xstrtoui(token
, NULL
, &tos
, 0, std::numeric_limits
<tos_t
>::max())) {
1428 CBDATA_INIT_TYPE_FREECB(acl_tos
, freed_acl_tos
);
1430 l
= cbdataAlloc(acl_tos
);
1432 l
->tos
= (tos_t
)tos
;
1434 aclParseAclList(LegacyParser
, &l
->aclList
);
1437 tail
= &(*tail
)->next
;
1443 free_acl_tos(acl_tos
** head
)
1453 #if SO_MARK && USE_LIBCAP
1455 CBDATA_TYPE(acl_nfmark
);
1458 dump_acl_nfmark(StoreEntry
* entry
, const char *name
, acl_nfmark
* head
)
1462 for (l
= head
; l
; l
= l
->next
) {
1464 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->nfmark
);
1466 storeAppendPrintf(entry
, "%s none", name
);
1468 dump_acl_list(entry
, l
->aclList
);
1470 storeAppendPrintf(entry
, "\n");
1475 freed_acl_nfmark(void *data
)
1477 acl_nfmark
*l
= static_cast<acl_nfmark
*>(data
);
1478 aclDestroyAclList(&l
->aclList
);
1482 parse_acl_nfmark(acl_nfmark
** head
)
1485 acl_nfmark
**tail
= head
; /* sane name below */
1487 char *token
= strtok(NULL
, w_space
);
1494 if (!xstrtoui(token
, NULL
, &mark
, 0, std::numeric_limits
<nfmark_t
>::max())) {
1499 CBDATA_INIT_TYPE_FREECB(acl_nfmark
, freed_acl_nfmark
);
1501 l
= cbdataAlloc(acl_nfmark
);
1505 aclParseAclList(LegacyParser
, &l
->aclList
);
1508 tail
= &(*tail
)->next
;
1514 free_acl_nfmark(acl_nfmark
** head
)
1517 acl_nfmark
*l
= *head
;
1523 #endif /* SO_MARK */
1525 CBDATA_TYPE(acl_size_t
);
1528 dump_acl_b_size_t(StoreEntry
* entry
, const char *name
, acl_size_t
* head
)
1532 for (l
= head
; l
; l
= l
->next
) {
1534 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) l
->size
, B_BYTES_STR
);
1536 storeAppendPrintf(entry
, "%s none", name
);
1538 dump_acl_list(entry
, l
->aclList
);
1540 storeAppendPrintf(entry
, "\n");
1545 freed_acl_b_size_t(void *data
)
1547 acl_size_t
*l
= static_cast<acl_size_t
*>(data
);
1548 aclDestroyAclList(&l
->aclList
);
1552 parse_acl_b_size_t(acl_size_t
** head
)
1555 acl_size_t
**tail
= head
; /* sane name below */
1557 CBDATA_INIT_TYPE_FREECB(acl_size_t
, freed_acl_b_size_t
);
1559 l
= cbdataAlloc(acl_size_t
);
1561 parse_b_int64_t(&l
->size
);
1563 aclParseAclList(LegacyParser
, &l
->aclList
);
1566 tail
= &(*tail
)->next
;
1572 free_acl_b_size_t(acl_size_t
** head
)
1575 acl_size_t
*l
= *head
;
1584 #include "DelayPools.h"
1585 #include "DelayConfig.h"
1586 /* do nothing - free_delay_pool_count is the magic free function.
1587 * this is why delay_pool_count isn't just marked TYPE: u_short
1589 #define free_delay_pool_class(X)
1590 #define free_delay_pool_access(X)
1591 #define free_delay_pool_rates(X)
1592 #define dump_delay_pool_class(X, Y, Z)
1593 #define dump_delay_pool_access(X, Y, Z)
1594 #define dump_delay_pool_rates(X, Y, Z)
1597 free_delay_pool_count(DelayConfig
* cfg
)
1599 cfg
->freePoolCount();
1603 dump_delay_pool_count(StoreEntry
* entry
, const char *name
, DelayConfig
&cfg
)
1605 cfg
.dumpPoolCount (entry
, name
);
1609 parse_delay_pool_count(DelayConfig
* cfg
)
1611 cfg
->parsePoolCount();
1615 parse_delay_pool_class(DelayConfig
* cfg
)
1617 cfg
->parsePoolClass();
1621 parse_delay_pool_rates(DelayConfig
* cfg
)
1623 cfg
->parsePoolRates();
1627 parse_delay_pool_access(DelayConfig
* cfg
)
1629 cfg
->parsePoolAccess(LegacyParser
);
1635 #include "ClientDelayConfig.h"
1636 /* do nothing - free_client_delay_pool_count is the magic free function.
1637 * this is why client_delay_pool_count isn't just marked TYPE: u_short
1640 #define free_client_delay_pool_access(X)
1641 #define free_client_delay_pool_rates(X)
1642 #define dump_client_delay_pool_access(X, Y, Z)
1643 #define dump_client_delay_pool_rates(X, Y, Z)
1646 free_client_delay_pool_count(ClientDelayConfig
* cfg
)
1648 cfg
->freePoolCount();
1652 dump_client_delay_pool_count(StoreEntry
* entry
, const char *name
, ClientDelayConfig
&cfg
)
1654 cfg
.dumpPoolCount (entry
, name
);
1658 parse_client_delay_pool_count(ClientDelayConfig
* cfg
)
1660 cfg
->parsePoolCount();
1664 parse_client_delay_pool_rates(ClientDelayConfig
* cfg
)
1666 cfg
->parsePoolRates();
1670 parse_client_delay_pool_access(ClientDelayConfig
* cfg
)
1672 cfg
->parsePoolAccess(LegacyParser
);
1676 #if USE_HTTP_VIOLATIONS
1678 dump_http_header_access(StoreEntry
* entry
, const char *name
, header_mangler header
[])
1682 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1683 if (header
[i
].access_list
!= NULL
) {
1684 storeAppendPrintf(entry
, "%s ", name
);
1685 dump_acl_access(entry
, httpHeaderNameById(i
),
1686 header
[i
].access_list
);
1692 parse_http_header_access(header_mangler header
[])
1697 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1698 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1699 debugs(3, 0, "parse_http_header_access: missing header name.");
1703 /* Now lookup index of header. */
1704 id
= httpHeaderIdByNameDef(t
, strlen(t
));
1706 if (strcmp(t
, "All") == 0)
1708 else if (strcmp(t
, "Other") == 0)
1710 else if (id
== -1) {
1711 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1712 debugs(3, 0, "parse_http_header_access: unknown header name '" << t
<< "'");
1716 if (id
!= HDR_ENUM_END
) {
1717 parse_acl_access(&header
[id
].access_list
);
1719 char *next_string
= t
+ strlen(t
) - 1;
1721 *(next_string
+ 1) = ' ';
1723 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1724 char *new_string
= xstrdup(next_string
);
1725 strtok(new_string
, w_space
);
1726 parse_acl_access(&header
[i
].access_list
);
1727 safe_free(new_string
);
1733 free_http_header_access(header_mangler header
[])
1737 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1738 free_acl_access(&header
[i
].access_list
);
1743 dump_http_header_replace(StoreEntry
* entry
, const char *name
, header_mangler
1748 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1749 if (NULL
== header
[i
].replacement
)
1752 storeAppendPrintf(entry
, "%s %s %s\n", name
, httpHeaderNameById(i
),
1753 header
[i
].replacement
);
1758 parse_http_header_replace(header_mangler header
[])
1763 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1764 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1765 debugs(3, 0, "parse_http_header_replace: missing header name.");
1769 /* Now lookup index of header. */
1770 id
= httpHeaderIdByNameDef(t
, strlen(t
));
1772 if (strcmp(t
, "All") == 0)
1774 else if (strcmp(t
, "Other") == 0)
1776 else if (id
== -1) {
1777 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1778 debugs(3, 0, "parse_http_header_replace: unknown header name " << t
<< ".");
1783 if (id
!= HDR_ENUM_END
) {
1784 if (header
[id
].replacement
!= NULL
)
1785 safe_free(header
[id
].replacement
);
1787 header
[id
].replacement
= xstrdup(t
+ strlen(t
) + 1);
1789 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1790 if (header
[i
].replacement
!= NULL
)
1791 safe_free(header
[i
].replacement
);
1793 header
[i
].replacement
= xstrdup(t
+ strlen(t
) + 1);
1799 free_http_header_replace(header_mangler header
[])
1803 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1804 if (header
[i
].replacement
!= NULL
)
1805 safe_free(header
[i
].replacement
);
1812 dump_cachedir(StoreEntry
* entry
, const char *name
, SquidConfig::_cacheSwap swap
)
1818 for (i
= 0; i
< swap
.n_configured
; i
++) {
1819 s
= dynamic_cast<SwapDir
*>(swap
.swapDirs
[i
].getRaw());
1821 storeAppendPrintf(entry
, "%s %s %s", name
, s
->type(), s
->path
);
1823 storeAppendPrintf(entry
, "\n");
1828 check_null_string(char *s
)
1835 parse_authparam(Auth::ConfigVector
* config
)
1840 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1843 if ((param_str
= strtok(NULL
, w_space
)) == NULL
)
1846 /* find a configuration for the scheme in the currently parsed configs... */
1847 Auth::Config
*schemeCfg
= Auth::Config::Find(type_str
);
1849 if (schemeCfg
== NULL
) {
1850 /* Create a configuration based on the scheme info */
1851 Auth::Scheme::Pointer theScheme
= Auth::Scheme::Find(type_str
);
1853 if (theScheme
== NULL
) {
1854 debugs(3, DBG_CRITICAL
, "Parsing Config File: Unknown authentication scheme '" << type_str
<< "'.");
1858 config
->push_back(theScheme
->createConfig());
1859 schemeCfg
= Auth::Config::Find(type_str
);
1860 if (schemeCfg
== NULL
) {
1861 debugs(3, DBG_CRITICAL
, "Parsing Config File: Corruption configuring authentication scheme '" << type_str
<< "'.");
1866 schemeCfg
->parse(schemeCfg
, config
->size(), param_str
);
1870 free_authparam(Auth::ConfigVector
* cfg
)
1872 /* Wipe the Auth globals and Detach/Destruct component config + state. */
1875 /* remove our pointers to the probably-dead sub-configs */
1876 while (cfg
->size()) {
1880 /* on reconfigure initialize new auth schemes for the new config. */
1881 if (reconfiguring
) {
1887 dump_authparam(StoreEntry
* entry
, const char *name
, Auth::ConfigVector cfg
)
1889 for (Auth::ConfigVector::iterator i
= cfg
.begin(); i
!= cfg
.end(); ++i
)
1890 (*i
)->dump(entry
, name
, (*i
));
1892 #endif /* USE_AUTH */
1894 /* TODO: just return the object, the # is irrelevant */
1896 find_fstype(char *type
)
1898 for (size_t i
= 0; i
< StoreFileSystem::FileSystems().size(); ++i
)
1899 if (strcasecmp(type
, StoreFileSystem::FileSystems().items
[i
]->type()) == 0)
1906 parse_cachedir(SquidConfig::_cacheSwap
* swap
)
1910 RefCount
<SwapDir
> sd
;
1914 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1917 if ((path_str
= strtok(NULL
, w_space
)) == NULL
)
1920 fs
= find_fstype(type_str
);
1925 /* reconfigure existing dir */
1927 for (i
= 0; i
< swap
->n_configured
; i
++) {
1928 assert (swap
->swapDirs
[i
].getRaw());
1930 if ((strcasecmp(path_str
, dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw())->path
)) == 0) {
1931 /* this is specific to on-fs Stores. The right
1932 * way to handle this is probably to have a mapping
1933 * from paths to stores, and have on-fs stores
1934 * register with that, and lookip in that in their
1935 * own setup logic. RBC 20041225. TODO.
1938 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw());
1940 if (strcmp(sd
->type(), StoreFileSystem::FileSystems().items
[fs
]->type()) != 0) {
1941 debugs(3, 0, "ERROR: Can't change type of existing cache_dir " <<
1942 sd
->type() << " " << sd
->path
<< " to " << type_str
<< ". Restart required");
1948 update_maxobjsize();
1955 if (swap
->n_configured
> 63) {
1956 /* 7 bits, signed */
1957 debugs(3, DBG_CRITICAL
, "WARNING: There is a fixed maximum of 63 cache_dir entries Squid can handle.");
1958 debugs(3, DBG_CRITICAL
, "WARNING: '" << path_str
<< "' is one to many.");
1963 allocate_new_swapdir(swap
);
1965 swap
->swapDirs
[swap
->n_configured
] = StoreFileSystem::FileSystems().items
[fs
]->createSwapDir();
1967 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[swap
->n_configured
].getRaw());
1969 /* parse the FS parameters and options */
1970 sd
->parse(swap
->n_configured
, path_str
);
1972 ++swap
->n_configured
;
1974 /* Update the max object size */
1975 update_maxobjsize();
1979 peer_type_str(const peer_t type
)
1981 const char * result
;
1993 case PEER_MULTICAST
:
1994 result
= "multicast";
2006 dump_peer(StoreEntry
* entry
, const char *name
, peer
* p
)
2010 LOCAL_ARRAY(char, xname
, 128);
2013 storeAppendPrintf(entry
, "%s %s %s %d %d name=%s",
2020 dump_peer_options(entry
, p
);
2022 for (d
= p
->peer_domain
; d
; d
= d
->next
) {
2023 storeAppendPrintf(entry
, "cache_peer_domain %s %s%s\n",
2025 d
->do_ping
? null_string
: "!",
2030 snprintf(xname
, 128, "cache_peer_access %s", p
->name
);
2031 dump_acl_access(entry
, xname
, p
->access
);
2034 for (t
= p
->typelist
; t
; t
= t
->next
) {
2035 storeAppendPrintf(entry
, "neighbor_type_domain %s %s %s\n",
2037 peer_type_str(t
->type
),
2046 * utility function to prevent getservbyname() being called with a numeric value
2047 * on Windows at least it returns garage results.
2050 isUnsignedNumeric(const char *str
, size_t len
)
2052 if (len
< 1) return false;
2054 for (; len
>0 && *str
; str
++, len
--) {
2055 if (! isdigit(*str
))
2062 \param proto 'tcp' or 'udp' for protocol
2063 \returns Port the named service is supposed to be listening on.
2065 static unsigned short
2066 GetService(const char *proto
)
2068 struct servent
*port
= NULL
;
2069 /** Parses a port number or service name from the squid.conf */
2070 char *token
= strtok(NULL
, w_space
);
2071 if (token
== NULL
) {
2073 return 0; /* NEVER REACHED */
2075 /** Returns either the service port number from /etc/services */
2076 if ( !isUnsignedNumeric(token
, strlen(token
)) )
2077 port
= getservbyname(token
, proto
);
2079 return ntohs((unsigned short)port
->s_port
);
2081 /** Or a numeric translation of the config text. */
2082 return xatos(token
);
2086 \returns Port the named TCP service is supposed to be listening on.
2087 \copydoc GetService(const char *proto)
2089 inline unsigned short
2092 return GetService("tcp");
2096 \returns Port the named UDP service is supposed to be listening on.
2097 \copydoc GetService(const char *proto)
2099 inline unsigned short
2102 return GetService("udp");
2106 parse_peer(peer
** head
)
2110 CBDATA_INIT_TYPE_FREECB(peer
, peerDestroy
);
2111 p
= cbdataAlloc(peer
);
2112 p
->http_port
= CACHE_HTTP_PORT
;
2113 p
->icp
.port
= CACHE_ICP_PORT
;
2116 p
->stats
.logged_state
= PEER_ALIVE
;
2118 if ((token
= strtok(NULL
, w_space
)) == NULL
)
2121 p
->host
= xstrdup(token
);
2123 p
->name
= xstrdup(token
);
2125 if ((token
= strtok(NULL
, w_space
)) == NULL
)
2128 p
->type
= parseNeighborType(token
);
2130 if (p
->type
== PEER_MULTICAST
) {
2131 p
->options
.no_digest
= 1;
2132 p
->options
.no_netdb_exchange
= 1;
2135 p
->http_port
= GetTcpService();
2140 p
->icp
.port
= GetUdpService();
2141 p
->connection_auth
= 2; /* auto */
2143 while ((token
= strtok(NULL
, w_space
))) {
2144 if (!strcasecmp(token
, "proxy-only")) {
2145 p
->options
.proxy_only
= 1;
2146 } else if (!strcasecmp(token
, "no-query")) {
2147 p
->options
.no_query
= 1;
2148 } else if (!strcasecmp(token
, "background-ping")) {
2149 p
->options
.background_ping
= 1;
2150 } else if (!strcasecmp(token
, "no-digest")) {
2151 p
->options
.no_digest
= 1;
2152 } else if (!strcasecmp(token
, "no-tproxy")) {
2153 p
->options
.no_tproxy
= 1;
2154 } else if (!strcasecmp(token
, "multicast-responder")) {
2155 p
->options
.mcast_responder
= 1;
2156 #if PEER_MULTICAST_SIBLINGS
2157 } else if (!strcasecmp(token
, "multicast-siblings")) {
2158 p
->options
.mcast_siblings
= 1;
2160 } else if (!strncasecmp(token
, "weight=", 7)) {
2161 p
->weight
= xatoi(token
+ 7);
2162 } else if (!strncasecmp(token
, "basetime=", 9)) {
2163 p
->basetime
= xatoi(token
+ 9);
2164 } else if (!strcasecmp(token
, "closest-only")) {
2165 p
->options
.closest_only
= 1;
2166 } else if (!strncasecmp(token
, "ttl=", 4)) {
2167 p
->mcast
.ttl
= xatoi(token
+ 4);
2169 if (p
->mcast
.ttl
< 0)
2172 if (p
->mcast
.ttl
> 128)
2174 } else if (!strcasecmp(token
, "default")) {
2175 p
->options
.default_parent
= 1;
2176 } else if (!strcasecmp(token
, "round-robin")) {
2177 p
->options
.roundrobin
= 1;
2178 } else if (!strcasecmp(token
, "weighted-round-robin")) {
2179 p
->options
.weighted_roundrobin
= 1;
2181 } else if (!strcasecmp(token
, "htcp")) {
2182 p
->options
.htcp
= 1;
2183 } else if (!strncasecmp(token
, "htcp=", 5) || !strncasecmp(token
, "htcp-", 5)) {
2184 /* Note: The htcp- form is deprecated, replaced by htcp= */
2185 p
->options
.htcp
= 1;
2186 char *tmp
= xstrdup(token
+5);
2187 char *mode
, *nextmode
;
2188 for (mode
= nextmode
= tmp
; mode
; mode
= nextmode
) {
2189 nextmode
= strchr(mode
, ',');
2192 if (!strcasecmp(mode
, "no-clr")) {
2193 if (p
->options
.htcp_only_clr
)
2194 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
2195 p
->options
.htcp_no_clr
= 1;
2196 } else if (!strcasecmp(mode
, "no-purge-clr")) {
2197 p
->options
.htcp_no_purge_clr
= 1;
2198 } else if (!strcasecmp(mode
, "only-clr")) {
2199 if (p
->options
.htcp_no_clr
)
2200 fatalf("parse_peer: can't set htcp no-clr and only-clr simultaneously");
2201 p
->options
.htcp_only_clr
= 1;
2202 } else if (!strcasecmp(mode
, "forward-clr")) {
2203 p
->options
.htcp_forward_clr
= 1;
2204 } else if (!strcasecmp(mode
, "oldsquid")) {
2205 p
->options
.htcp_oldsquid
= 1;
2207 fatalf("invalid HTCP mode '%s'", mode
);
2212 } else if (!strcasecmp(token
, "no-netdb-exchange")) {
2213 p
->options
.no_netdb_exchange
= 1;
2215 } else if (!strcasecmp(token
, "carp")) {
2216 if (p
->type
!= PEER_PARENT
)
2217 fatalf("parse_peer: non-parent carp peer %s/%d\n", p
->host
, p
->http_port
);
2219 p
->options
.carp
= 1;
2220 } else if (!strncasecmp(token
, "carp-key=", 9)) {
2221 if (p
->options
.carp
!= 1)
2222 fatalf("parse_peer: carp-key specified on non-carp peer %s/%d\n", p
->host
, p
->http_port
);
2223 p
->options
.carp_key
.set
=1;
2224 char *nextkey
=token
+strlen("carp-key="), *key
=nextkey
;
2225 for (; key
; key
= nextkey
) {
2226 nextkey
=strchr(key
,',');
2227 if (nextkey
) ++nextkey
; // skip the comma, any
2228 if (0==strncasecmp(key
,"scheme",6)) {
2229 p
->options
.carp_key
.scheme
=1;
2230 } else if (0==strncasecmp(key
,"host",4)) {
2231 p
->options
.carp_key
.host
=1;
2232 } else if (0==strncasecmp(key
,"port",4)) {
2233 p
->options
.carp_key
.port
=1;
2234 } else if (0==strncasecmp(key
,"path",4)) {
2235 p
->options
.carp_key
.path
=1;
2236 } else if (0==strncasecmp(key
,"params",6)) {
2237 p
->options
.carp_key
.params
=1;
2239 fatalf("invalid carp-key '%s'",key
);
2242 } else if (!strcasecmp(token
, "userhash")) {
2244 if (p
->type
!= PEER_PARENT
)
2245 fatalf("parse_peer: non-parent userhash peer %s/%d\n", p
->host
, p
->http_port
);
2247 p
->options
.userhash
= 1;
2249 fatalf("parse_peer: userhash requires authentication. peer %s/%d\n", p
->host
, p
->http_port
);
2251 } else if (!strcasecmp(token
, "sourcehash")) {
2252 if (p
->type
!= PEER_PARENT
)
2253 fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p
->host
, p
->http_port
);
2255 p
->options
.sourcehash
= 1;
2257 } else if (!strcasecmp(token
, "no-delay")) {
2259 p
->options
.no_delay
= 1;
2261 debugs(0, DBG_CRITICAL
, "WARNING: cache_peer option 'no-delay' requires --enable-delay-pools");
2263 } else if (!strncasecmp(token
, "login=", 6)) {
2264 p
->login
= xstrdup(token
+ 6);
2265 rfc1738_unescape(p
->login
);
2266 } else if (!strncasecmp(token
, "connect-timeout=", 16)) {
2267 p
->connect_timeout
= xatoi(token
+ 16);
2268 } else if (!strncasecmp(token
, "connect-fail-limit=", 19)) {
2269 p
->connect_fail_limit
= xatoi(token
+ 19);
2270 #if USE_CACHE_DIGESTS
2271 } else if (!strncasecmp(token
, "digest-url=", 11)) {
2272 p
->digest_url
= xstrdup(token
+ 11);
2275 } else if (!strcasecmp(token
, "allow-miss")) {
2276 p
->options
.allow_miss
= 1;
2277 } else if (!strncasecmp(token
, "max-conn=", 9)) {
2278 p
->max_conn
= xatoi(token
+ 9);
2279 } else if (!strcasecmp(token
, "originserver")) {
2280 p
->options
.originserver
= 1;
2281 } else if (!strncasecmp(token
, "name=", 5)) {
2285 p
->name
= xstrdup(token
+ 5);
2286 } else if (!strncasecmp(token
, "forceddomain=", 13)) {
2287 safe_free(p
->domain
);
2290 p
->domain
= xstrdup(token
+ 13);
2294 } else if (strcmp(token
, "ssl") == 0) {
2296 } else if (strncmp(token
, "sslcert=", 8) == 0) {
2297 safe_free(p
->sslcert
);
2298 p
->sslcert
= xstrdup(token
+ 8);
2299 } else if (strncmp(token
, "sslkey=", 7) == 0) {
2300 safe_free(p
->sslkey
);
2301 p
->sslkey
= xstrdup(token
+ 7);
2302 } else if (strncmp(token
, "sslversion=", 11) == 0) {
2303 p
->sslversion
= atoi(token
+ 11);
2304 } else if (strncmp(token
, "ssloptions=", 11) == 0) {
2305 safe_free(p
->ssloptions
);
2306 p
->ssloptions
= xstrdup(token
+ 11);
2307 } else if (strncmp(token
, "sslcipher=", 10) == 0) {
2308 safe_free(p
->sslcipher
);
2309 p
->sslcipher
= xstrdup(token
+ 10);
2310 } else if (strncmp(token
, "sslcafile=", 10) == 0) {
2311 safe_free(p
->sslcafile
);
2312 p
->sslcafile
= xstrdup(token
+ 10);
2313 } else if (strncmp(token
, "sslcapath=", 10) == 0) {
2314 safe_free(p
->sslcapath
);
2315 p
->sslcapath
= xstrdup(token
+ 10);
2316 } else if (strncmp(token
, "sslcrlfile=", 11) == 0) {
2317 safe_free(p
->sslcrlfile
);
2318 p
->sslcapath
= xstrdup(token
+ 10);
2319 } else if (strncmp(token
, "sslflags=", 9) == 0) {
2320 safe_free(p
->sslflags
);
2321 p
->sslflags
= xstrdup(token
+ 9);
2322 } else if (strncmp(token
, "ssldomain=", 10) == 0) {
2323 safe_free(p
->ssldomain
);
2324 p
->ssldomain
= xstrdup(token
+ 10);
2327 } else if (strcmp(token
, "front-end-https") == 0) {
2328 p
->front_end_https
= 1;
2329 } else if (strcmp(token
, "front-end-https=on") == 0) {
2330 p
->front_end_https
= 1;
2331 } else if (strcmp(token
, "front-end-https=auto") == 0) {
2332 p
->front_end_https
= 2;
2333 } else if (strcmp(token
, "connection-auth=off") == 0) {
2334 p
->connection_auth
= 0;
2335 } else if (strcmp(token
, "connection-auth") == 0) {
2336 p
->connection_auth
= 1;
2337 } else if (strcmp(token
, "connection-auth=on") == 0) {
2338 p
->connection_auth
= 1;
2339 } else if (strcmp(token
, "connection-auth=auto") == 0) {
2340 p
->connection_auth
= 2;
2342 debugs(3, 0, "parse_peer: token='" << token
<< "'");
2347 if (peerFindByName(p
->name
))
2348 fatalf("ERROR: cache_peer %s specified twice\n", p
->name
);
2353 if (p
->connect_fail_limit
< 1)
2354 p
->connect_fail_limit
= 10;
2356 p
->icp
.version
= ICP_VERSION_CURRENT
;
2358 p
->testing_now
= false;
2360 #if USE_CACHE_DIGESTS
2362 if (!p
->options
.no_digest
) {
2363 /* XXX This looks odd.. who has the original pointer
2366 PeerDigest
*pd
= peerDigestCreate(p
);
2367 p
->digest
= cbdataReference(pd
);
2372 p
->index
= ++Config
.npeers
;
2374 while (*head
!= NULL
)
2375 head
= &(*head
)->next
;
2383 free_peer(peer
** P
)
2387 while ((p
= *P
) != NULL
) {
2389 #if USE_CACHE_DIGESTS
2391 cbdataReferenceDone(p
->digest
);
2401 dump_cachemgrpasswd(StoreEntry
* entry
, const char *name
, cachemgr_passwd
* list
)
2405 while (list
!= NULL
) {
2406 if (strcmp(list
->passwd
, "none") && strcmp(list
->passwd
, "disable"))
2407 storeAppendPrintf(entry
, "%s XXXXXXXXXX", name
);
2409 storeAppendPrintf(entry
, "%s %s", name
, list
->passwd
);
2411 for (w
= list
->actions
; w
!= NULL
; w
= w
->next
) {
2412 storeAppendPrintf(entry
, " %s", w
->key
);
2415 storeAppendPrintf(entry
, "\n");
2421 parse_cachemgrpasswd(cachemgr_passwd
** head
)
2423 char *passwd
= NULL
;
2424 wordlist
*actions
= NULL
;
2426 cachemgr_passwd
**P
;
2427 parse_string(&passwd
);
2428 parse_wordlist(&actions
);
2429 p
= static_cast<cachemgr_passwd
*>(xcalloc(1, sizeof(cachemgr_passwd
)));
2431 p
->actions
= actions
;
2433 for (P
= head
; *P
; P
= &(*P
)->next
) {
2435 * See if any of the actions from this line already have a
2436 * password from previous lines. The password checking
2437 * routines in cache_manager.c take the the password from
2438 * the first cachemgr_passwd struct that contains the
2439 * requested action. Thus, we should warn users who might
2440 * think they can have two passwords for the same action.
2445 for (w
= (*P
)->actions
; w
; w
= w
->next
) {
2446 for (u
= actions
; u
; u
= u
->next
) {
2447 if (strcmp(w
->key
, u
->key
))
2450 debugs(0, 0, "WARNING: action '" << u
->key
<< "' (line " << config_lineno
<< ") already has a password");
2459 free_cachemgrpasswd(cachemgr_passwd
** head
)
2463 while ((p
= *head
) != NULL
) {
2466 wordlistDestroy(&p
->actions
);
2472 dump_denyinfo(StoreEntry
* entry
, const char *name
, acl_deny_info_list
* var
)
2476 while (var
!= NULL
) {
2477 storeAppendPrintf(entry
, "%s %s", name
, var
->err_page_name
);
2479 for (a
= var
->acl_list
; a
!= NULL
; a
= a
->next
)
2480 storeAppendPrintf(entry
, " %s", a
->name
);
2482 storeAppendPrintf(entry
, "\n");
2489 parse_denyinfo(acl_deny_info_list
** var
)
2491 aclParseDenyInfoLine(var
);
2495 free_denyinfo(acl_deny_info_list
** list
)
2497 acl_deny_info_list
*a
= NULL
;
2498 acl_deny_info_list
*a_next
= NULL
;
2499 acl_name_list
*l
= NULL
;
2500 acl_name_list
*l_next
= NULL
;
2502 for (a
= *list
; a
; a
= a_next
) {
2503 for (l
= a
->acl_list
; l
; l
= l_next
) {
2505 memFree(l
, MEM_ACL_NAME_LIST
);
2510 memFree(a
, MEM_ACL_DENY_INFO_LIST
);
2518 parse_peer_access(void)
2523 if (!(host
= strtok(NULL
, w_space
)))
2526 if ((p
= peerFindByName(host
)) == NULL
) {
2527 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2531 aclParseAccessLine(LegacyParser
, &p
->access
);
2535 parse_hostdomain(void)
2538 char *domain
= NULL
;
2540 if (!(host
= strtok(NULL
, w_space
)))
2543 while ((domain
= strtok(NULL
, list_sep
))) {
2544 domain_ping
*l
= NULL
;
2545 domain_ping
**L
= NULL
;
2548 if ((p
= peerFindByName(host
)) == NULL
) {
2549 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2553 l
= static_cast<domain_ping
*>(xcalloc(1, sizeof(domain_ping
)));
2556 if (*domain
== '!') { /* check for !.edu */
2561 l
->domain
= xstrdup(domain
);
2563 for (L
= &(p
->peer_domain
); *L
; L
= &((*L
)->next
));
2569 parse_hostdomaintype(void)
2573 char *domain
= NULL
;
2575 if (!(host
= strtok(NULL
, w_space
)))
2578 if (!(type
= strtok(NULL
, w_space
)))
2581 while ((domain
= strtok(NULL
, list_sep
))) {
2582 domain_type
*l
= NULL
;
2583 domain_type
**L
= NULL
;
2586 if ((p
= peerFindByName(host
)) == NULL
) {
2587 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2591 l
= static_cast<domain_type
*>(xcalloc(1, sizeof(domain_type
)));
2592 l
->type
= parseNeighborType(type
);
2593 l
->domain
= xstrdup(domain
);
2595 for (L
= &(p
->typelist
); *L
; L
= &((*L
)->next
));
2601 dump_int(StoreEntry
* entry
, const char *name
, int var
)
2603 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2621 dump_onoff(StoreEntry
* entry
, const char *name
, int var
)
2623 storeAppendPrintf(entry
, "%s %s\n", name
, var
? "on" : "off");
2627 parse_onoff(int *var
)
2629 char *token
= strtok(NULL
, w_space
);
2634 if (!strcasecmp(token
, "on") || !strcasecmp(token
, "enable"))
2640 #define free_onoff free_int
2643 dump_tristate(StoreEntry
* entry
, const char *name
, int var
)
2654 storeAppendPrintf(entry
, "%s %s\n", name
, state
);
2658 parse_tristate(int *var
)
2660 char *token
= strtok(NULL
, w_space
);
2665 if (!strcasecmp(token
, "on") || !strcasecmp(token
, "enable"))
2667 else if (!strcasecmp(token
, "warn"))
2673 #define free_tristate free_int
2676 dump_refreshpattern(StoreEntry
* entry
, const char *name
, refresh_t
* head
)
2678 while (head
!= NULL
) {
2679 storeAppendPrintf(entry
, "%s%s %s %d %d%% %d",
2681 head
->flags
.icase
? " -i" : null_string
,
2683 (int) head
->min
/ 60,
2684 (int) (100.0 * head
->pct
+ 0.5),
2685 (int) head
->max
/ 60);
2687 if (head
->max_stale
>= 0)
2688 storeAppendPrintf(entry
, " max-stale=%d", head
->max_stale
);
2690 if (head
->flags
.refresh_ims
)
2691 storeAppendPrintf(entry
, " refresh-ims");
2693 if (head
->flags
.store_stale
)
2694 storeAppendPrintf(entry
, " store-stale");
2696 #if USE_HTTP_VIOLATIONS
2698 if (head
->flags
.override_expire
)
2699 storeAppendPrintf(entry
, " override-expire");
2701 if (head
->flags
.override_lastmod
)
2702 storeAppendPrintf(entry
, " override-lastmod");
2704 if (head
->flags
.reload_into_ims
)
2705 storeAppendPrintf(entry
, " reload-into-ims");
2707 if (head
->flags
.ignore_reload
)
2708 storeAppendPrintf(entry
, " ignore-reload");
2710 if (head
->flags
.ignore_no_cache
)
2711 storeAppendPrintf(entry
, " ignore-no-cache");
2713 if (head
->flags
.ignore_no_store
)
2714 storeAppendPrintf(entry
, " ignore-no-store");
2716 if (head
->flags
.ignore_must_revalidate
)
2717 storeAppendPrintf(entry
, " ignore-must-revalidate");
2719 if (head
->flags
.ignore_private
)
2720 storeAppendPrintf(entry
, " ignore-private");
2722 if (head
->flags
.ignore_auth
)
2723 storeAppendPrintf(entry
, " ignore-auth");
2727 storeAppendPrintf(entry
, "\n");
2734 parse_refreshpattern(refresh_t
** head
)
2741 int refresh_ims
= 0;
2742 int store_stale
= 0;
2745 #if USE_HTTP_VIOLATIONS
2747 int override_expire
= 0;
2748 int override_lastmod
= 0;
2749 int reload_into_ims
= 0;
2750 int ignore_reload
= 0;
2751 int ignore_no_cache
= 0;
2752 int ignore_no_store
= 0;
2753 int ignore_must_revalidate
= 0;
2754 int ignore_private
= 0;
2755 int ignore_auth
= 0;
2762 int flags
= REG_EXTENDED
| REG_NOSUB
;
2764 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
2769 if (strcmp(token
, "-i") == 0) {
2771 token
= strtok(NULL
, w_space
);
2772 } else if (strcmp(token
, "+i") == 0) {
2773 flags
&= ~REG_ICASE
;
2774 token
= strtok(NULL
, w_space
);
2777 if (token
== NULL
) {
2782 pattern
= xstrdup(token
);
2784 i
= GetInteger(); /* token: min */
2786 /* catch negative and insanely huge values close to 32-bit wrap */
2788 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age negative. Cropped back to zero.");
2791 if (i
> 60*24*365) {
2792 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age too high. Cropped back to 1 year.");
2796 min
= (time_t) (i
* 60); /* convert minutes to seconds */
2798 i
= GetInteger(); /* token: pct */
2800 pct
= (double) i
/ 100.0;
2802 i
= GetInteger(); /* token: max */
2804 /* catch negative and insanely huge values close to 32-bit wrap */
2806 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age negative. Cropped back to zero.");
2809 if (i
> 60*24*365) {
2810 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age too high. Cropped back to 1 year.");
2814 max
= (time_t) (i
* 60); /* convert minutes to seconds */
2817 while ((token
= strtok(NULL
, w_space
)) != NULL
) {
2818 if (!strcmp(token
, "refresh-ims")) {
2820 } else if (!strcmp(token
, "store-stale")) {
2822 } else if (!strncmp(token
, "max-stale=", 10)) {
2823 max_stale
= atoi(token
+ 10);
2824 #if USE_HTTP_VIOLATIONS
2826 } else if (!strcmp(token
, "override-expire"))
2827 override_expire
= 1;
2828 else if (!strcmp(token
, "override-lastmod"))
2829 override_lastmod
= 1;
2830 else if (!strcmp(token
, "ignore-no-cache"))
2831 ignore_no_cache
= 1;
2832 else if (!strcmp(token
, "ignore-no-store"))
2833 ignore_no_store
= 1;
2834 else if (!strcmp(token
, "ignore-must-revalidate"))
2835 ignore_must_revalidate
= 1;
2836 else if (!strcmp(token
, "ignore-private"))
2838 else if (!strcmp(token
, "ignore-auth"))
2840 else if (!strcmp(token
, "reload-into-ims")) {
2841 reload_into_ims
= 1;
2842 refresh_nocache_hack
= 1;
2843 /* tell client_side.c that this is used */
2844 } else if (!strcmp(token
, "ignore-reload")) {
2846 refresh_nocache_hack
= 1;
2847 /* tell client_side.c that this is used */
2851 debugs(22, 0, "refreshAddToList: Unknown option '" << pattern
<< "': " << token
);
2854 if ((errcode
= regcomp(&comp
, pattern
, flags
)) != 0) {
2856 regerror(errcode
, &comp
, errbuf
, sizeof errbuf
);
2857 debugs(22, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
2858 debugs(22, 0, "refreshAddToList: Invalid regular expression '" << pattern
<< "': " << errbuf
);
2862 pct
= pct
< 0.0 ? 0.0 : pct
;
2863 max
= max
< 0 ? 0 : max
;
2864 t
= static_cast<refresh_t
*>(xcalloc(1, sizeof(refresh_t
)));
2865 t
->pattern
= (char *) xstrdup(pattern
);
2866 t
->compiled_pattern
= comp
;
2871 if (flags
& REG_ICASE
)
2875 t
->flags
.refresh_ims
= 1;
2878 t
->flags
.store_stale
= 1;
2880 t
->max_stale
= max_stale
;
2882 #if USE_HTTP_VIOLATIONS
2884 if (override_expire
)
2885 t
->flags
.override_expire
= 1;
2887 if (override_lastmod
)
2888 t
->flags
.override_lastmod
= 1;
2890 if (reload_into_ims
)
2891 t
->flags
.reload_into_ims
= 1;
2894 t
->flags
.ignore_reload
= 1;
2896 if (ignore_no_cache
)
2897 t
->flags
.ignore_no_cache
= 1;
2899 if (ignore_no_store
)
2900 t
->flags
.ignore_no_store
= 1;
2902 if (ignore_must_revalidate
)
2903 t
->flags
.ignore_must_revalidate
= 1;
2906 t
->flags
.ignore_private
= 1;
2909 t
->flags
.ignore_auth
= 1;
2916 head
= &(*head
)->next
;
2924 free_refreshpattern(refresh_t
** head
)
2928 while ((t
= *head
) != NULL
) {
2930 safe_free(t
->pattern
);
2931 regfree(&t
->compiled_pattern
);
2935 #if USE_HTTP_VIOLATIONS
2936 refresh_nocache_hack
= 0;
2942 dump_string(StoreEntry
* entry
, const char *name
, char *var
)
2945 storeAppendPrintf(entry
, "%s %s\n", name
, var
);
2949 parse_string(char **var
)
2951 char *token
= strtok(NULL
, w_space
);
2957 *var
= xstrdup(token
);
2961 ConfigParser::ParseString(char **var
)
2967 ConfigParser::ParseString(String
*var
)
2969 char *token
= strtok(NULL
, w_space
);
2978 free_string(char **var
)
2984 parse_eol(char *volatile *var
)
2991 unsigned char *token
= (unsigned char *) strtok(NULL
, null_string
);
2999 while (*token
&& xisspace(*token
))
3007 *var
= xstrdup((char *) token
);
3010 #define dump_eol dump_string
3011 #define free_eol free_string
3014 dump_time_t(StoreEntry
* entry
, const char *name
, time_t var
)
3016 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int) var
);
3020 parse_time_t(time_t * var
)
3023 parseTimeLine(&tval
, T_SECOND_STR
, false);
3024 *var
= static_cast<time_t>(tval
/1000);
3028 free_time_t(time_t * var
)
3035 dump_time_msec(StoreEntry
* entry
, const char *name
, time_msec_t var
)
3038 storeAppendPrintf(entry
, "%s %" PRId64
" milliseconds\n", name
, var
);
3040 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int)(var
/1000) );
3044 parse_time_msec(time_msec_t
* var
)
3046 parseTimeLine(var
, T_SECOND_STR
, true);
3050 free_time_msec(time_msec_t
* var
)
3058 dump_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3060 storeAppendPrintf(entry
, "%s %d\n", name
, (int) var
);
3065 dump_b_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3067 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
3072 dump_b_ssize_t(StoreEntry
* entry
, const char *name
, ssize_t var
)
3074 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
3080 dump_kb_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3082 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_KBYTES_STR
);
3087 dump_b_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
3089 storeAppendPrintf(entry
, "%s %" PRId64
" %s\n", name
, var
, B_BYTES_STR
);
3093 dump_kb_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
3095 storeAppendPrintf(entry
, "%s %" PRId64
" %s\n", name
, var
, B_KBYTES_STR
);
3100 parse_size_t(size_t * var
)
3109 parse_b_size_t(size_t * var
)
3111 parseBytesLine(var
, B_BYTES_STR
);
3116 parse_b_ssize_t(ssize_t
* var
)
3118 parseBytesLineSigned(var
, B_BYTES_STR
);
3124 parse_kb_size_t(size_t * var
)
3126 parseBytesLine(var
, B_KBYTES_STR
);
3131 parse_b_int64_t(int64_t * var
)
3133 parseBytesLine64(var
, B_BYTES_STR
);
3137 parse_kb_int64_t(int64_t * var
)
3139 parseBytesLine64(var
, B_KBYTES_STR
);
3143 free_size_t(size_t * var
)
3150 free_ssize_t(ssize_t
* var
)
3157 free_b_int64_t(int64_t * var
)
3162 #define free_b_size_t free_size_t
3163 #define free_b_ssize_t free_ssize_t
3164 #define free_kb_size_t free_size_t
3165 #define free_mb_size_t free_size_t
3166 #define free_gb_size_t free_size_t
3167 #define free_kb_int64_t free_b_int64_t
3170 dump_u_short(StoreEntry
* entry
, const char *name
, unsigned short var
)
3172 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
3176 free_u_short(unsigned short * u
)
3182 parse_u_short(unsigned short * var
)
3184 ConfigParser::ParseUShort(var
);
3188 ConfigParser::ParseUShort(unsigned short *var
)
3194 ConfigParser::ParseBool(bool *var
)
3196 int i
= GetInteger();
3207 dump_wordlist(StoreEntry
* entry
, const char *name
, wordlist
* list
)
3209 while (list
!= NULL
) {
3210 storeAppendPrintf(entry
, "%s %s\n", name
, list
->key
);
3216 ConfigParser::ParseWordList(wordlist
** list
)
3218 parse_wordlist(list
);
3222 parse_wordlist(wordlist
** list
)
3225 char *t
= strtok(NULL
, "");
3227 while ((token
= strwordtok(NULL
, &t
)))
3228 wordlistAdd(list
, token
);
3231 #if 0 /* now unused */
3233 check_null_wordlist(wordlist
* w
)
3240 check_null_acl_access(acl_access
* a
)
3245 #define free_wordlist wordlistDestroy
3247 #define free_uri_whitespace free_int
3250 parse_uri_whitespace(int *var
)
3252 char *token
= strtok(NULL
, w_space
);
3257 if (!strcasecmp(token
, "strip"))
3258 *var
= URI_WHITESPACE_STRIP
;
3259 else if (!strcasecmp(token
, "deny"))
3260 *var
= URI_WHITESPACE_DENY
;
3261 else if (!strcasecmp(token
, "allow"))
3262 *var
= URI_WHITESPACE_ALLOW
;
3263 else if (!strcasecmp(token
, "encode"))
3264 *var
= URI_WHITESPACE_ENCODE
;
3265 else if (!strcasecmp(token
, "chop"))
3266 *var
= URI_WHITESPACE_CHOP
;
3272 dump_uri_whitespace(StoreEntry
* entry
, const char *name
, int var
)
3276 if (var
== URI_WHITESPACE_ALLOW
)
3278 else if (var
== URI_WHITESPACE_ENCODE
)
3280 else if (var
== URI_WHITESPACE_CHOP
)
3282 else if (var
== URI_WHITESPACE_DENY
)
3287 storeAppendPrintf(entry
, "%s %s\n", name
, s
);
3291 free_removalpolicy(RemovalPolicySettings
** settings
)
3296 free_string(&(*settings
)->type
);
3298 free_wordlist(&(*settings
)->args
);
3306 parse_removalpolicy(RemovalPolicySettings
** settings
)
3309 free_removalpolicy(settings
);
3311 *settings
= new RemovalPolicySettings
;
3313 parse_string(&(*settings
)->type
);
3315 parse_wordlist(&(*settings
)->args
);
3319 dump_removalpolicy(StoreEntry
* entry
, const char *name
, RemovalPolicySettings
* settings
)
3322 storeAppendPrintf(entry
, "%s %s", name
, settings
->type
);
3323 args
= settings
->args
;
3326 storeAppendPrintf(entry
, " %s", args
->key
);
3330 storeAppendPrintf(entry
, "\n");
3334 YesNoNone::configure(bool beSet
)
3336 option
= beSet
? +1 : -1;
3339 YesNoNone::operator void*() const
3341 assert(option
!= 0); // must call configure() first
3342 return option
> 0 ? (void*)this : NULL
;
3347 free_YesNoNone(YesNoNone
*)
3349 // do nothing: no explicit cleanup is required
3353 parse_YesNoNone(YesNoNone
*option
)
3356 parse_onoff(&value
);
3357 option
->configure(value
> 0);
3361 dump_YesNoNone(StoreEntry
* entry
, const char *name
, YesNoNone
&option
)
3363 if (option
.configured())
3364 dump_onoff(entry
, name
, option
? 1 : 0);
3368 free_memcachemode(SquidConfig
* config
)
3374 parse_memcachemode(SquidConfig
* config
)
3376 char *token
= strtok(NULL
, w_space
);
3380 if (strcmp(token
, "always") == 0) {
3381 Config
.onoff
.memory_cache_first
= 1;
3382 Config
.onoff
.memory_cache_disk
= 1;
3383 } else if (strcmp(token
, "disk") == 0) {
3384 Config
.onoff
.memory_cache_first
= 0;
3385 Config
.onoff
.memory_cache_disk
= 1;
3386 } else if (strncmp(token
, "net", 3) == 0) {
3387 Config
.onoff
.memory_cache_first
= 1;
3388 Config
.onoff
.memory_cache_disk
= 0;
3389 } else if (strcmp(token
, "never") == 0) {
3390 Config
.onoff
.memory_cache_first
= 0;
3391 Config
.onoff
.memory_cache_disk
= 0;
3397 dump_memcachemode(StoreEntry
* entry
, const char *name
, SquidConfig
&config
)
3399 storeAppendPrintf(entry
, "%s ", name
);
3400 if (Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3401 storeAppendPrintf(entry
, "always");
3402 else if (!Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3403 storeAppendPrintf(entry
, "disk");
3404 else if (Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3405 storeAppendPrintf(entry
, "network");
3406 else if (!Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3407 storeAppendPrintf(entry
, "none");
3408 storeAppendPrintf(entry
, "\n");
3411 #include "cf_parser.cci"
3414 parseNeighborType(const char *s
)
3416 if (!strcasecmp(s
, "parent"))
3419 if (!strcasecmp(s
, "neighbor"))
3420 return PEER_SIBLING
;
3422 if (!strcasecmp(s
, "neighbour"))
3423 return PEER_SIBLING
;
3425 if (!strcasecmp(s
, "sibling"))
3426 return PEER_SIBLING
;
3428 if (!strcasecmp(s
, "multicast"))
3429 return PEER_MULTICAST
;
3431 debugs(15, 0, "WARNING: Unknown neighbor type: " << s
);
3433 return PEER_SIBLING
;
3438 parse_IpAddress_list(Ip::Address_list
** head
)
3441 Ip::Address_list
*s
;
3444 while ((token
= strtok(NULL
, w_space
))) {
3445 if (GetHostWithPort(token
, &ipa
)) {
3448 head
= &(*head
)->next
;
3450 s
= static_cast<Ip::Address_list
*>(xcalloc(1, sizeof(*s
)));
3460 dump_IpAddress_list(StoreEntry
* e
, const char *n
, const Ip::Address_list
* s
)
3462 char ntoabuf
[MAX_IPSTRLEN
];
3465 storeAppendPrintf(e
, "%s %s\n",
3467 s
->s
.NtoA(ntoabuf
,MAX_IPSTRLEN
));
3473 free_IpAddress_list(Ip::Address_list
** head
)
3475 if (*head
) delete *head
;
3479 #if CURRENTLY_UNUSED
3480 /* This code was previously used by http_port. Left as it really should
3481 * be used by icp_port and htcp_port
3484 check_null_IpAddress_list(const Ip::Address_list
* s
)
3489 #endif /* CURRENTLY_UNUSED */
3490 #endif /* USE_WCCPv2 */
3493 parsePortSpecification(AnyP::PortCfg
* s
, char *token
)
3496 unsigned short port
= 0;
3500 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3501 s
->name
= xstrdup(token
);
3502 s
->connection_auth_disabled
= false;
3504 if (*token
== '[') {
3507 t
= strchr(host
, ']');
3509 debugs(3, DBG_CRITICAL
, s
->protocol
<< "_port: missing ']' on IPv6 address: " << token
);
3514 debugs(3, DBG_CRITICAL
, s
->protocol
<< "_port: missing Port in: " << token
);
3517 if (!Ip::EnableIpv6
) {
3518 debugs(3, DBG_CRITICAL
, "FATAL: " << s
->protocol
<< "_port: IPv6 is not available.");
3521 port
= xatos(t
+ 1);
3522 } else if ((t
= strchr(token
, ':'))) {
3527 port
= xatos(t
+ 1);
3529 } else if ((port
= strtol(token
, &junk
, 10)), !*junk
) {
3531 debugs(3, 3, s
->protocol
<< "_port: found Listen on Port: " << port
);
3533 debugs(3, DBG_CRITICAL
, s
->protocol
<< "_port: missing Port: " << token
);
3537 if (port
== 0 && host
!= NULL
) {
3538 debugs(3, DBG_CRITICAL
, s
->protocol
<< "_port: Port cannot be 0: " << token
);
3545 if (!Ip::EnableIpv6
)
3547 debugs(3, 3, s
->protocol
<< "_port: found Listen on wildcard address: *:" << s
->s
.GetPort() );
3548 } else if ( (s
->s
= host
) ) { /* check/parse numeric IPA */
3550 if (!Ip::EnableIpv6
)
3552 debugs(3, 3, s
->protocol
<< "_port: Listen on Host/IP: " << host
<< " --> " << s
->s
);
3553 } else if ( s
->s
.GetHostByName(host
) ) { /* check/parse for FQDN */
3554 /* dont use ipcache */
3555 s
->defaultsite
= xstrdup(host
);
3557 if (!Ip::EnableIpv6
)
3559 debugs(3, 3, s
->protocol
<< "_port: found Listen as Host " << s
->defaultsite
<< " on IP: " << s
->s
);
3561 debugs(3, DBG_CRITICAL
, s
->protocol
<< "_port: failed to resolve Host/IP: " << host
);
3567 parse_port_option(AnyP::PortCfg
* s
, char *token
)
3571 if (strcmp(token
, "accel") == 0) {
3572 if (s
->intercepted
|| s
->spoof_client_ip
) {
3573 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: Accelerator mode requires its own port. It cannot be shared with other modes.");
3576 s
->accel
= s
->vhost
= 1;
3577 } else if (strcmp(token
, "transparent") == 0 || strcmp(token
, "intercept") == 0) {
3578 if (s
->accel
|| s
->spoof_client_ip
) {
3579 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: Intercept mode requires its own interception port. It cannot be shared with other modes.");
3583 Ip::Interceptor
.StartInterception();
3584 /* Log information regarding the port modes under interception. */
3585 debugs(3, DBG_IMPORTANT
, "Starting Authentication on port " << s
->s
);
3586 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (interception enabled)");
3588 /* INET6: until transparent REDIRECT works on IPv6 SOCKET, force wildcard to IPv4 */
3590 debugs(3, DBG_IMPORTANT
, "Disabling IPv6 on port " << s
->s
<< " (interception enabled)");
3591 if ( !s
->s
.SetIPv4() ) {
3592 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 addresses cannot NAT intercept (protocol does not provide NAT)" << s
->s
);
3595 } else if (strcmp(token
, "tproxy") == 0) {
3596 if (s
->intercepted
|| s
->accel
) {
3597 debugs(3,DBG_CRITICAL
, "FATAL: http(s)_port: TPROXY option requires its own interception port. It cannot be shared with other modes.");
3600 s
->spoof_client_ip
= 1;
3601 Ip::Interceptor
.StartTransparency();
3602 /* Log information regarding the port modes under transparency. */
3603 debugs(3, DBG_IMPORTANT
, "Starting IP Spoofing on port " << s
->s
);
3604 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (IP spoofing enabled)");
3606 if (!Ip::Interceptor
.ProbeForTproxy(s
->s
)) {
3607 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: TPROXY support in the system does not work.");
3611 } else if (strncmp(token
, "defaultsite=", 12) == 0) {
3613 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: defaultsite option requires Acceleration mode flag.");
3616 safe_free(s
->defaultsite
);
3617 s
->defaultsite
= xstrdup(token
+ 12);
3618 } else if (strcmp(token
, "vhost") == 0) {
3620 debugs(3, DBG_CRITICAL
, "WARNING: http(s)_port: vhost option is deprecated. Use 'accel' mode flag instead.");
3622 s
->accel
= s
->vhost
= 1;
3623 } else if (strcmp(token
, "no-vhost") == 0) {
3625 debugs(3, DBG_IMPORTANT
, "ERROR: http(s)_port: no-vhost option requires Acceleration mode flag.");
3628 } else if (strcmp(token
, "vport") == 0) {
3630 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3634 } else if (strncmp(token
, "vport=", 6) == 0) {
3636 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3639 s
->vport
= xatos(token
+ 6);
3640 } else if (strncmp(token
, "protocol=", 9) == 0) {
3642 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: protocol option requires Acceleration mode flag.");
3645 s
->protocol
= xstrdup(token
+ 9);
3646 } else if (strcmp(token
, "allow-direct") == 0) {
3648 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: allow-direct option requires Acceleration mode flag.");
3651 s
->allow_direct
= 1;
3652 } else if (strcmp(token
, "act-as-origin") == 0) {
3654 debugs(3, DBG_IMPORTANT
, "ERROR: http(s)_port: act-as-origin option requires Acceleration mode flag.");
3657 } else if (strcmp(token
, "ignore-cc") == 0) {
3658 #if !USE_HTTP_VIOLATIONS
3660 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: ignore-cc option requires Scceleration mode flag.");
3665 } else if (strncmp(token
, "name=", 5) == 0) {
3667 s
->name
= xstrdup(token
+ 5);
3668 } else if (strcmp(token
, "no-connection-auth") == 0) {
3669 s
->connection_auth_disabled
= true;
3670 } else if (strcmp(token
, "connection-auth=off") == 0) {
3671 s
->connection_auth_disabled
= true;
3672 } else if (strcmp(token
, "connection-auth") == 0) {
3673 s
->connection_auth_disabled
= false;
3674 } else if (strcmp(token
, "connection-auth=on") == 0) {
3675 s
->connection_auth_disabled
= false;
3676 } else if (strncmp(token
, "disable-pmtu-discovery=", 23) == 0) {
3677 if (!strcasecmp(token
+ 23, "off"))
3678 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3679 else if (!strcasecmp(token
+ 23, "transparent"))
3680 s
->disable_pmtu_discovery
= DISABLE_PMTU_TRANSPARENT
;
3681 else if (!strcasecmp(token
+ 23, "always"))
3682 s
->disable_pmtu_discovery
= DISABLE_PMTU_ALWAYS
;
3685 } else if (strcmp(token
, "ipv4") == 0) {
3686 if ( !s
->s
.SetIPv4() ) {
3687 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 addresses cannot be used as IPv4-Only. " << s
->s
);
3690 } else if (strcmp(token
, "tcpkeepalive") == 0) {
3691 s
->tcp_keepalive
.enabled
= 1;
3692 } else if (strncmp(token
, "tcpkeepalive=", 13) == 0) {
3693 char *t
= token
+ 13;
3694 s
->tcp_keepalive
.enabled
= 1;
3695 s
->tcp_keepalive
.idle
= atoi(t
);
3699 s
->tcp_keepalive
.interval
= atoi(t
);
3704 s
->tcp_keepalive
.timeout
= atoi(t
);
3708 } else if (strcasecmp(token
, "sslBump") == 0) {
3709 debugs(3, DBG_CRITICAL
, "WARNING: '" << token
<< "' is deprecated " <<
3710 "in http_port. Use 'ssl-bump' instead.");
3711 s
->sslBump
= 1; // accelerated when bumped, otherwise not
3712 } else if (strcmp(token
, "ssl-bump") == 0) {
3713 s
->sslBump
= 1; // accelerated when bumped, otherwise not
3714 } else if (strncmp(token
, "cert=", 5) == 0) {
3716 s
->cert
= xstrdup(token
+ 5);
3717 } else if (strncmp(token
, "key=", 4) == 0) {
3719 s
->key
= xstrdup(token
+ 4);
3720 } else if (strncmp(token
, "version=", 8) == 0) {
3721 s
->version
= xatoi(token
+ 8);
3722 if (s
->version
< 1 || s
->version
> 4)
3724 } else if (strncmp(token
, "options=", 8) == 0) {
3725 safe_free(s
->options
);
3726 s
->options
= xstrdup(token
+ 8);
3727 } else if (strncmp(token
, "cipher=", 7) == 0) {
3728 safe_free(s
->cipher
);
3729 s
->cipher
= xstrdup(token
+ 7);
3730 } else if (strncmp(token
, "clientca=", 9) == 0) {
3731 safe_free(s
->clientca
);
3732 s
->clientca
= xstrdup(token
+ 9);
3733 } else if (strncmp(token
, "cafile=", 7) == 0) {
3734 safe_free(s
->cafile
);
3735 s
->cafile
= xstrdup(token
+ 7);
3736 } else if (strncmp(token
, "capath=", 7) == 0) {
3737 safe_free(s
->capath
);
3738 s
->capath
= xstrdup(token
+ 7);
3739 } else if (strncmp(token
, "crlfile=", 8) == 0) {
3740 safe_free(s
->crlfile
);
3741 s
->crlfile
= xstrdup(token
+ 8);
3742 } else if (strncmp(token
, "dhparams=", 9) == 0) {
3743 safe_free(s
->dhfile
);
3744 s
->dhfile
= xstrdup(token
+ 9);
3745 } else if (strncmp(token
, "sslflags=", 9) == 0) {
3746 safe_free(s
->sslflags
);
3747 s
->sslflags
= xstrdup(token
+ 9);
3748 } else if (strncmp(token
, "sslcontext=", 11) == 0) {
3749 safe_free(s
->sslContextSessionId
);
3750 s
->sslContextSessionId
= xstrdup(token
+ 11);
3751 } else if (strcmp(token
, "generate-host-certificates") == 0) {
3752 s
->generateHostCertificates
= true;
3753 } else if (strcmp(token
, "generate-host-certificates=on") == 0) {
3754 s
->generateHostCertificates
= true;
3755 } else if (strcmp(token
, "generate-host-certificates=off") == 0) {
3756 s
->generateHostCertificates
= false;
3757 } else if (strncmp(token
, "dynamic_cert_mem_cache_size=", 28) == 0) {
3758 parseBytesOptionValue(&s
->dynamicCertMemCacheSize
, B_BYTES_STR
, token
+ 28);
3766 add_http_port(char *portspec
)
3768 AnyP::PortCfg
*s
= new AnyP::PortCfg("http_port");
3769 parsePortSpecification(s
, portspec
);
3770 // we may need to merge better if the above returns a list with clones
3771 assert(s
->next
== NULL
);
3772 s
->next
= cbdataReference(Config
.Sockaddr
.http
);
3773 cbdataReferenceDone(Config
.Sockaddr
.http
);
3774 Config
.Sockaddr
.http
= cbdataReference(s
);
3778 parsePortCfg(AnyP::PortCfg
** head
, const char *optionName
)
3780 const char *protocol
= NULL
;
3781 if (strcmp(optionName
, "http_port") == 0 ||
3782 strcmp(optionName
, "ascii_port") == 0)
3784 else if (strcmp(optionName
, "https_port") == 0)
3791 char *token
= strtok(NULL
, w_space
);
3798 AnyP::PortCfg
*s
= new AnyP::PortCfg(protocol
);
3799 parsePortSpecification(s
, token
);
3801 /* parse options ... */
3802 while ((token
= strtok(NULL
, w_space
))) {
3803 parse_port_option(s
, token
);
3806 if (Ip::EnableIpv6
&IPV6_SPECIAL_SPLITSTACK
&& s
->s
.IsAnyAddr()) {
3807 // clone the port options from *s to *(s->next)
3808 s
->next
= cbdataReference(s
->clone());
3809 s
->next
->s
.SetIPv4();
3810 debugs(3, 3, protocol
<< "_port: clone wildcard address for split-stack: " << s
->s
<< " and " << s
->next
->s
);
3814 head
= &(*head
)->next
;
3816 *head
= cbdataReference(s
);
3820 dump_generic_port(StoreEntry
* e
, const char *n
, const AnyP::PortCfg
* s
)
3822 char buf
[MAX_IPSTRLEN
];
3824 storeAppendPrintf(e
, "%s %s",
3826 s
->s
.ToURL(buf
,MAX_IPSTRLEN
));
3828 // MODES and specific sub-options.
3830 storeAppendPrintf(e
, " intercept");
3832 else if (s
->spoof_client_ip
)
3833 storeAppendPrintf(e
, " tproxy");
3835 else if (s
->accel
) {
3836 storeAppendPrintf(e
, " accel");
3839 storeAppendPrintf(e
, " vhost");
3842 storeAppendPrintf(e
, " vport");
3843 else if (s
->vport
> 0)
3844 storeAppendPrintf(e
, " vport=%d", s
->vport
);
3847 storeAppendPrintf(e
, " defaultsite=%s", s
->defaultsite
);
3849 if (s
->protocol
&& strcmp(s
->protocol
,"http") != 0)
3850 storeAppendPrintf(e
, " protocol=%s", s
->protocol
);
3852 if (s
->allow_direct
)
3853 storeAppendPrintf(e
, " allow-direct");
3856 storeAppendPrintf(e
, " ignore-cc");
3860 // Generic independent options
3863 storeAppendPrintf(e
, " name=%s", s
->name
);
3865 #if USE_HTTP_VIOLATIONS
3866 if (!s
->accel
&& s
->ignore_cc
)
3867 storeAppendPrintf(e
, " ignore-cc");
3870 if (s
->connection_auth_disabled
)
3871 storeAppendPrintf(e
, " connection-auth=off");
3873 storeAppendPrintf(e
, " connection-auth=on");
3875 if (s
->disable_pmtu_discovery
!= DISABLE_PMTU_OFF
) {
3878 if (s
->disable_pmtu_discovery
== DISABLE_PMTU_ALWAYS
)
3881 pmtu
= "transparent";
3883 storeAppendPrintf(e
, " disable-pmtu-discovery=%s", pmtu
);
3886 if (s
->s
.IsAnyAddr() && !s
->s
.IsIPv6())
3887 storeAppendPrintf(e
, " ipv4");
3889 if (s
->tcp_keepalive
.enabled
) {
3890 if (s
->tcp_keepalive
.idle
|| s
->tcp_keepalive
.interval
|| s
->tcp_keepalive
.timeout
) {
3891 storeAppendPrintf(e
, " tcpkeepalive=%d,%d,%d", s
->tcp_keepalive
.idle
, s
->tcp_keepalive
.interval
, s
->tcp_keepalive
.timeout
);
3893 storeAppendPrintf(e
, " tcpkeepalive");
3899 storeAppendPrintf(e
, " ssl-bump");
3902 storeAppendPrintf(e
, " cert=%s", s
->cert
);
3905 storeAppendPrintf(e
, " key=%s", s
->key
);
3908 storeAppendPrintf(e
, " version=%d", s
->version
);
3911 storeAppendPrintf(e
, " options=%s", s
->options
);
3914 storeAppendPrintf(e
, " cipher=%s", s
->cipher
);
3917 storeAppendPrintf(e
, " cafile=%s", s
->cafile
);
3920 storeAppendPrintf(e
, " capath=%s", s
->capath
);
3923 storeAppendPrintf(e
, " crlfile=%s", s
->crlfile
);
3926 storeAppendPrintf(e
, " dhparams=%s", s
->dhfile
);
3929 storeAppendPrintf(e
, " sslflags=%s", s
->sslflags
);
3931 if (s
->sslContextSessionId
)
3932 storeAppendPrintf(e
, " sslcontext=%s", s
->sslContextSessionId
);
3934 if (s
->generateHostCertificates
)
3935 storeAppendPrintf(e
, " generate-host-certificates");
3937 if (s
->dynamicCertMemCacheSize
!= std::numeric_limits
<size_t>::max())
3938 storeAppendPrintf(e
, "dynamic_cert_mem_cache_size=%lu%s\n", (unsigned long)s
->dynamicCertMemCacheSize
, B_BYTES_STR
);
3943 dump_PortCfg(StoreEntry
* e
, const char *n
, const AnyP::PortCfg
* s
)
3946 dump_generic_port(e
, n
, s
);
3947 storeAppendPrintf(e
, "\n");
3953 free_PortCfg(AnyP::PortCfg
** head
)
3957 while ((s
= *head
) != NULL
) {
3959 cbdataReferenceDone(s
);
3964 configFreeMemory(void)
3968 SSL_CTX_free(Config
.ssl_client
.sslContext
);
3973 requirePathnameExists(const char *name
, const char *path
)
3977 char pathbuf
[BUFSIZ
];
3978 assert(path
!= NULL
);
3980 if (Config
.chroot_dir
&& (geteuid() == 0)) {
3981 snprintf(pathbuf
, BUFSIZ
, "%s/%s", Config
.chroot_dir
, path
);
3985 if (stat(path
, &sb
) < 0) {
3986 debugs(0, DBG_CRITICAL
, (opt_parse_cfg_only
?"FATAL ":"") << "ERROR: " << name
<< " " << path
<< ": " << xstrerror());
3987 // keep going to find more issues if we are only checking the config file with "-k parse"
3988 if (opt_parse_cfg_only
)
3990 // this is fatal if it is found during startup or reconfigure
3991 if (opt_send_signal
== -1 || opt_send_signal
== SIGHUP
)
3992 fatalf("%s %s: %s", name
, path
, xstrerror());
3999 return ConfigParser::strtokFile();
4002 #include "AccessLogEntry.h"
4005 parse_access_log(customlog
** logs
)
4007 const char *filename
, *logdef_name
;
4009 customlog
*cl
= (customlog
*)xcalloc(1, sizeof(*cl
));
4011 if ((filename
= strtok(NULL
, w_space
)) == NULL
) {
4016 if (strcmp(filename
, "none") == 0) {
4017 cl
->type
= Log::Format::CLF_NONE
;
4018 aclParseAclList(LegacyParser
, &cl
->aclList
);
4020 logs
= &(*logs
)->next
;
4025 if ((logdef_name
= strtok(NULL
, w_space
)) == NULL
)
4026 logdef_name
= "squid";
4028 debugs(3, 9, "Log definition name '" << logdef_name
<< "' file '" << filename
<< "'");
4030 cl
->filename
= xstrdup(filename
);
4032 /* look for the definition pointer corresponding to this name */
4033 Format::Format
*lf
= Log::TheConfig
.logformats
;
4035 while (lf
!= NULL
) {
4036 debugs(3, 9, "Comparing against '" << lf
->name
<< "'");
4038 if (strcmp(lf
->name
, logdef_name
) == 0)
4045 cl
->type
= Log::Format::CLF_CUSTOM
;
4047 } else if (strcmp(logdef_name
, "auto") == 0) {
4048 debugs(0,0, "WARNING: Log format 'auto' no longer exists. Using 'squid' instead.");
4049 cl
->type
= Log::Format::CLF_SQUID
;
4050 } else if (strcmp(logdef_name
, "squid") == 0) {
4051 cl
->type
= Log::Format::CLF_SQUID
;
4052 } else if (strcmp(logdef_name
, "common") == 0) {
4053 cl
->type
= Log::Format::CLF_COMMON
;
4054 } else if (strcmp(logdef_name
, "combined") == 0) {
4055 cl
->type
= Log::Format::CLF_COMBINED
;
4057 } else if (strcmp(logdef_name
, "icap_squid") == 0) {
4058 cl
->type
= Log::Format::CLF_ICAP_SQUID
;
4060 } else if (strcmp(logdef_name
, "useragent") == 0) {
4061 cl
->type
= Log::Format::CLF_USERAGENT
;
4062 } else if (strcmp(logdef_name
, "referrer") == 0) {
4063 cl
->type
= Log::Format::CLF_REFERER
;
4065 debugs(3, 0, "Log format '" << logdef_name
<< "' is not defined");
4070 aclParseAclList(LegacyParser
, &cl
->aclList
);
4073 logs
= &(*logs
)->next
;
4079 check_null_access_log(customlog
*customlog_definitions
)
4081 return customlog_definitions
== NULL
;
4085 dump_access_log(StoreEntry
* entry
, const char *name
, customlog
* logs
)
4089 for (log
= logs
; log
; log
= log
->next
) {
4090 storeAppendPrintf(entry
, "%s ", name
);
4092 switch (log
->type
) {
4094 case Log::Format::CLF_CUSTOM
:
4095 storeAppendPrintf(entry
, "%s %s", log
->filename
, log
->logFormat
->name
);
4098 case Log::Format::CLF_NONE
:
4099 storeAppendPrintf(entry
, "none");
4102 case Log::Format::CLF_SQUID
:
4103 storeAppendPrintf(entry
, "%s squid", log
->filename
);
4106 case Log::Format::CLF_COMBINED
:
4107 storeAppendPrintf(entry
, "%s combined", log
->filename
);
4110 case Log::Format::CLF_COMMON
:
4111 storeAppendPrintf(entry
, "%s common", log
->filename
);
4115 case Log::Format::CLF_ICAP_SQUID
:
4116 storeAppendPrintf(entry
, "%s icap_squid", log
->filename
);
4119 case Log::Format::CLF_USERAGENT
:
4120 storeAppendPrintf(entry
, "%s useragent", log
->filename
);
4123 case Log::Format::CLF_REFERER
:
4124 storeAppendPrintf(entry
, "%s referrer", log
->filename
);
4127 case Log::Format::CLF_UNKNOWN
:
4132 dump_acl_list(entry
, log
->aclList
);
4134 storeAppendPrintf(entry
, "\n");
4139 free_access_log(customlog
** definitions
)
4141 while (*definitions
) {
4142 customlog
*log
= *definitions
;
4143 *definitions
= log
->next
;
4145 log
->logFormat
= NULL
;
4146 log
->type
= Log::Format::CLF_UNKNOWN
;
4149 aclDestroyAclList(&log
->aclList
);
4151 safe_free(log
->filename
);
4157 /// parses list of integers form name=N1,N2,N3,...
4159 parseNamedIntList(const char *data
, const String
&name
, Vector
<int> &list
)
4161 if (data
&& (strncmp(data
, name
.rawBuf(), name
.size()) == 0)) {
4162 data
+= name
.size();
4167 if (!StringToInt(data
, value
, &data
, 10))
4169 list
.push_back(value
);
4170 if (*data
== '\0' || *data
!= ',')
4175 return data
&& *data
== '\0';
4179 parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4181 #if !HAVE_CPU_AFFINITY
4182 debugs(3, DBG_CRITICAL
, "FATAL: Squid built with no CPU affinity " <<
4183 "support, do not set 'cpu_affinity_map'");
4185 #endif /* HAVE_CPU_AFFINITY */
4187 if (!*cpuAffinityMap
)
4188 *cpuAffinityMap
= new CpuAffinityMap
;
4190 const char *const pToken
= strtok(NULL
, w_space
);
4191 const char *const cToken
= strtok(NULL
, w_space
);
4192 Vector
<int> processes
, cores
;
4193 if (!parseNamedIntList(pToken
, "process_numbers", processes
)) {
4194 debugs(3, DBG_CRITICAL
, "FATAL: bad 'process_numbers' parameter " <<
4195 "in 'cpu_affinity_map'");
4197 } else if (!parseNamedIntList(cToken
, "cores", cores
)) {
4198 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cores' parameter in " <<
4199 "'cpu_affinity_map'");
4201 } else if (!(*cpuAffinityMap
)->add(processes
, cores
)) {
4202 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cpu_affinity_map'; " <<
4203 "process_numbers and cores lists differ in length or " <<
4204 "contain numbers <= 0");
4210 dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
)
4212 if (cpuAffinityMap
) {
4213 storeAppendPrintf(entry
, "%s process_numbers=", name
);
4214 for (size_t i
= 0; i
< cpuAffinityMap
->processes().size(); ++i
) {
4215 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4216 cpuAffinityMap
->processes()[i
]);
4218 storeAppendPrintf(entry
, " cores=");
4219 for (size_t i
= 0; i
< cpuAffinityMap
->processes().size(); ++i
) {
4220 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4221 cpuAffinityMap
->cores()[i
]);
4223 storeAppendPrintf(entry
, "\n");
4228 free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4230 delete *cpuAffinityMap
;
4231 *cpuAffinityMap
= NULL
;
4237 parse_adaptation_service_set_type()
4239 Adaptation::Config::ParseServiceSet();
4243 parse_adaptation_service_chain_type()
4245 Adaptation::Config::ParseServiceChain();
4249 parse_adaptation_access_type()
4251 Adaptation::Config::ParseAccess(LegacyParser
);
4255 parse_adaptation_meta_type(Adaptation::Config::MetaHeaders
*)
4257 Adaptation::Config::ParseMetaHeader(LegacyParser
);
4261 dump_adaptation_meta_type(StoreEntry
*entry
, const char *name
, Adaptation::Config::MetaHeaders
&)
4263 Adaptation::Config::DumpMetaHeader(entry
, name
);
4267 free_adaptation_meta_type(Adaptation::Config::MetaHeaders
*)
4269 // Nothing to do, it is released inside Adaptation::Config::freeService()
4271 #endif /* USE_ADAPTATION */
4277 parse_icap_service_type(Adaptation::Icap::Config
* cfg
)
4279 cfg
->parseService();
4283 free_icap_service_type(Adaptation::Icap::Config
* cfg
)
4289 dump_icap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4291 cfg
.dumpService(entry
, name
);
4295 parse_icap_class_type()
4297 debugs(93, 0, "WARNING: 'icap_class' is depricated. " <<
4298 "Use 'adaptation_service_set' instead");
4299 Adaptation::Config::ParseServiceSet();
4303 parse_icap_access_type()
4305 debugs(93, 0, "WARNING: 'icap_access' is depricated. " <<
4306 "Use 'adaptation_access' instead");
4307 Adaptation::Config::ParseAccess(LegacyParser
);
4316 parse_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4318 cfg
->parseService();
4322 free_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4328 dump_ecap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Ecap::Config
&cfg
)
4330 cfg
.dumpService(entry
, name
);
4333 #endif /* USE_ECAP */
4336 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4341 cfg
->service_failure_limit
= GetInteger();
4343 if ((token
= strtok(NULL
, w_space
)) == NULL
)
4346 if (strcmp(token
,"in") != 0) {
4347 debugs(3, 0, "expecting 'in' on'" << config_input_line
<< "'");
4351 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
4355 d
= static_cast<time_t> (xatoi(token
));
4357 m
= static_cast<time_t> (1);
4361 else if ((token
= strtok(NULL
, w_space
)) == NULL
) {
4362 debugs(3, 0, "No time-units on '" << config_input_line
<< "'");
4364 } else if ((m
= parseTimeUnits(token
, false)) == 0)
4367 cfg
->oldest_service_failure
= (m
* d
);
4370 static void dump_icap_service_failure_limit(StoreEntry
*entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4372 storeAppendPrintf(entry
, "%s %d", name
, cfg
.service_failure_limit
);
4373 if (cfg
.oldest_service_failure
> 0) {
4374 storeAppendPrintf(entry
, " in %d seconds", (int)cfg
.oldest_service_failure
);
4376 storeAppendPrintf(entry
, "\n");
4379 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4381 cfg
->oldest_service_failure
= 0;
4382 cfg
->service_failure_limit
= 0;