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.
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"
50 #include "ssl/support.h"
51 #include "ssl/Config.h"
54 #include "auth/Config.h"
55 #include "auth/Scheme.h"
57 #include "ConfigParser.h"
58 #include "CpuAffinityMap.h"
59 #include "eui/Config.h"
61 #include "esi/Parser.h"
63 #include "format/Format.h"
64 #include "HttpRequestMethod.h"
65 #include "ident/Config.h"
66 #include "ip/Intercept.h"
67 #include "ip/QosConfig.h"
69 #include "log/Config.h"
71 #include "mgr/Registration.h"
73 #include "ProtoPort.h"
79 #include "StoreFileSystem.h"
93 #include "ssl/gadgets.h"
97 static void parse_adaptation_service_set_type();
98 static void parse_adaptation_service_chain_type();
99 static void parse_adaptation_access_type();
103 static void parse_icap_service_type(Adaptation::Icap::Config
*);
104 static void dump_icap_service_type(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
105 static void free_icap_service_type(Adaptation::Icap::Config
*);
106 static void parse_icap_class_type();
107 static void parse_icap_access_type();
109 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*);
110 static void dump_icap_service_failure_limit(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
111 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*);
115 static void parse_ecap_service_type(Adaptation::Ecap::Config
*);
116 static void dump_ecap_service_type(StoreEntry
*, const char *, const Adaptation::Ecap::Config
&);
117 static void free_ecap_service_type(Adaptation::Ecap::Config
*);
122 static const char *const T_MILLISECOND_STR
= "millisecond";
123 static const char *const T_SECOND_STR
= "second";
124 static const char *const T_MINUTE_STR
= "minute";
125 static const char *const T_HOUR_STR
= "hour";
126 static const char *const T_DAY_STR
= "day";
127 static const char *const T_WEEK_STR
= "week";
128 static const char *const T_FORTNIGHT_STR
= "fortnight";
129 static const char *const T_MONTH_STR
= "month";
130 static const char *const T_YEAR_STR
= "year";
131 static const char *const T_DECADE_STR
= "decade";
133 static const char *const B_BYTES_STR
= "bytes";
134 static const char *const B_KBYTES_STR
= "KB";
135 static const char *const B_MBYTES_STR
= "MB";
136 static const char *const B_GBYTES_STR
= "GB";
138 static const char *const list_sep
= ", \t\n\r";
140 static void parse_access_log(customlog
** customlog_definitions
);
141 static int check_null_access_log(customlog
*customlog_definitions
);
142 static void dump_access_log(StoreEntry
* entry
, const char *name
, customlog
* definitions
);
143 static void free_access_log(customlog
** definitions
);
145 static void update_maxobjsize(void);
146 static void configDoConfigure(void);
147 static void parse_refreshpattern(refresh_t
**);
148 static uint64_t parseTimeUnits(const char *unit
, bool allowMsec
);
149 static void parseTimeLine(time_msec_t
* tptr
, const char *units
, bool allowMsec
);
150 static void parse_u_short(unsigned short * var
);
151 static void parse_string(char **);
152 static void default_all(void);
153 static void defaults_if_none(void);
154 static int parse_line(char *);
155 static void parse_obsolete(const char *);
156 static void parseBytesLine(size_t * bptr
, const char *units
);
158 static void parseBytesOptionValue(size_t * bptr
, const char *units
, char const * value
);
161 static void parseBytesLineSigned(ssize_t
* bptr
, const char *units
);
163 static size_t parseBytesUnits(const char *unit
);
164 static void free_all(void);
165 void requirePathnameExists(const char *name
, const char *path
);
166 static OBJH dump_config
;
167 #if USE_HTTP_VIOLATIONS
168 static void dump_http_header_access(StoreEntry
* entry
, const char *name
, header_mangler header
[]);
169 static void parse_http_header_access(header_mangler header
[]);
170 static void free_http_header_access(header_mangler header
[]);
171 static void dump_http_header_replace(StoreEntry
* entry
, const char *name
, header_mangler header
[]);
172 static void parse_http_header_replace(header_mangler
* header
);
173 static void free_http_header_replace(header_mangler
* header
);
175 static void parse_denyinfo(acl_deny_info_list
** var
);
176 static void dump_denyinfo(StoreEntry
* entry
, const char *name
, acl_deny_info_list
* var
);
177 static void free_denyinfo(acl_deny_info_list
** var
);
180 static void parse_IpAddress_list(Ip::Address_list
**);
181 static void dump_IpAddress_list(StoreEntry
*, const char *, const Ip::Address_list
*);
182 static void free_IpAddress_list(Ip::Address_list
**);
184 static int check_null_IpAddress_list(const Ip::Address_list
*);
185 #endif /* CURRENTLY_UNUSED */
186 #endif /* USE_WCCPv2 */
188 static void parse_http_port_list(http_port_list
**);
189 static void dump_http_port_list(StoreEntry
*, const char *, const http_port_list
*);
190 static void free_http_port_list(http_port_list
**);
193 static void parse_https_port_list(https_port_list
**);
194 static void dump_https_port_list(StoreEntry
*, const char *, const https_port_list
*);
195 static void free_https_port_list(https_port_list
**);
197 static int check_null_https_port_list(const https_port_list
*);
201 static void parse_b_size_t(size_t * var
);
202 static void parse_b_int64_t(int64_t * var
);
204 static bool parseNamedIntList(const char *data
, const String
&name
, Vector
<int> &list
);
206 static void parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
207 static void dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
);
208 static void free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
210 static int parseOneConfigFile(const char *file_name
, unsigned int depth
);
213 * LegacyParser is a parser for legacy code that uses the global
214 * approach. This is static so that it is only exposed to cache_cf.
215 * Other modules needing access to a ConfigParser should have it
216 * provided to them in their parserFOO methods.
218 static ConfigParser LegacyParser
= ConfigParser();
223 LegacyParser
.destruct();
227 update_maxobjsize(void)
232 for (i
= 0; i
< Config
.cacheSwap
.n_configured
; i
++) {
233 assert (Config
.cacheSwap
.swapDirs
[i
].getRaw());
235 if (dynamic_cast<SwapDir
*>(Config
.cacheSwap
.swapDirs
[i
].getRaw())->
237 ms
= dynamic_cast<SwapDir
*>(Config
.cacheSwap
.swapDirs
[i
].getRaw())->max_objsize
;
239 store_maxobjsize
= ms
;
243 SetConfigFilename(char const *file_name
, bool is_pipe
)
245 cfg_filename
= file_name
;
250 cfg_filename
= file_name
+ 1;
251 else if ((token
= strrchr(cfg_filename
, '/')))
252 cfg_filename
= token
+ 1;
256 skip_ws(const char* s
)
265 parseManyConfigFiles(char* files
, int depth
)
268 char* saveptr
= NULL
;
273 memset(&globbuf
, 0, sizeof(globbuf
));
274 for (path
= strwordtok(files
, &saveptr
); path
; path
= strwordtok(NULL
, &saveptr
)) {
275 if (glob(path
, globbuf
.gl_pathc
? GLOB_APPEND
: 0, NULL
, &globbuf
) != 0) {
276 fatalf("Unable to find configuration file: %s: %s",
280 for (i
= 0; i
< (int)globbuf
.gl_pathc
; i
++) {
281 error_count
+= parseOneConfigFile(globbuf
.gl_pathv
[i
], depth
);
285 char* file
= strwordtok(files
, &saveptr
);
286 while (file
!= NULL
) {
287 error_count
+= parseOneConfigFile(file
, depth
);
288 file
= strwordtok(NULL
, &saveptr
);
290 #endif /* HAVE_GLOB */
295 ReplaceSubstr(char*& str
, int& len
, unsigned substrIdx
, unsigned substrLen
, const char* newSubstr
)
298 assert(newSubstr
!= NULL
);
300 unsigned newSubstrLen
= strlen(newSubstr
);
301 if (newSubstrLen
> substrLen
)
302 str
= (char*)realloc(str
, len
- substrLen
+ newSubstrLen
+ 1);
304 // move tail part including zero
305 memmove(str
+ substrIdx
+ newSubstrLen
, str
+ substrIdx
+ substrLen
, len
- substrIdx
- substrLen
+ 1);
306 // copy new substring in place
307 memcpy(str
+ substrIdx
, newSubstr
, newSubstrLen
);
313 SubstituteMacro(char*& line
, int& len
, const char* macroName
, const char* substStr
)
315 assert(line
!= NULL
);
316 assert(macroName
!= NULL
);
317 assert(substStr
!= NULL
);
318 unsigned macroNameLen
= strlen(macroName
);
319 while (const char* macroPos
= strstr(line
, macroName
)) // we would replace all occurrences
320 ReplaceSubstr(line
, len
, macroPos
- line
, macroNameLen
, substStr
);
324 ProcessMacros(char*& line
, int& len
)
326 SubstituteMacro(line
, len
, "${process_name}", TheKidName
);
327 SubstituteMacro(line
, len
, "${process_number}", xitoa(KidIdentifier
));
331 trim_trailing_ws(char* str
)
334 unsigned i
= strlen(str
);
335 while ((i
> 0) && xisspace(str
[i
- 1]))
341 FindStatement(const char* line
, const char* statement
)
343 assert(line
!= NULL
);
344 assert(statement
!= NULL
);
346 const char* str
= skip_ws(line
);
347 unsigned len
= strlen(statement
);
348 if (strncmp(str
, statement
, len
) == 0) {
352 else if (xisspace(*str
))
360 StrToInt(const char* str
, long& number
)
365 number
= strtol(str
, &end
, 0);
367 return (end
!= str
) && (*end
== '\0'); // returns true if string contains nothing except number
371 EvalBoolExpr(const char* expr
)
373 assert(expr
!= NULL
);
374 if (strcmp(expr
, "true") == 0) {
376 } else if (strcmp(expr
, "false") == 0) {
378 } else if (const char* equation
= strchr(expr
, '=')) {
379 const char* rvalue
= skip_ws(equation
+ 1);
380 char* lvalue
= (char*)xmalloc(equation
- expr
+ 1);
381 xstrncpy(lvalue
, expr
, equation
- expr
+ 1);
382 trim_trailing_ws(lvalue
);
385 if (!StrToInt(lvalue
, number1
))
386 fatalf("String is not a integer number: '%s'\n", lvalue
);
388 if (!StrToInt(rvalue
, number2
))
389 fatalf("String is not a integer number: '%s'\n", rvalue
);
392 return number1
== number2
;
394 fatalf("Unable to evaluate expression '%s'\n", expr
);
395 return false; // this place cannot be reached
399 parseOneConfigFile(const char *file_name
, unsigned int depth
)
402 const char *orig_cfg_filename
= cfg_filename
;
403 const int orig_config_lineno
= config_lineno
;
405 char *tmp_line
= NULL
;
406 int tmp_line_len
= 0;
410 debugs(3, 1, "Processing Configuration File: " << file_name
<< " (depth " << depth
<< ")");
412 fatalf("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name
);
416 if (file_name
[0] == '!' || file_name
[0] == '|') {
417 fp
= popen(file_name
+ 1, "r");
420 fp
= fopen(file_name
, "r");
424 fatalf("Unable to open configuration file: %s: %s", file_name
, xstrerror());
427 setmode(fileno(fp
), O_TEXT
);
430 SetConfigFilename(file_name
, bool(is_pipe
));
432 memset(config_input_line
, '\0', BUFSIZ
);
436 Vector
<bool> if_states
;
437 while (fgets(config_input_line
, BUFSIZ
, fp
)) {
440 if ((token
= strchr(config_input_line
, '\n')))
443 if ((token
= strchr(config_input_line
, '\r')))
446 // strip any prefix whitespace off the line.
447 const char *p
= skip_ws(config_input_line
);
448 if (config_input_line
!= p
)
449 memmove(config_input_line
, p
, strlen(p
)+1);
451 if (strncmp(config_input_line
, "#line ", 6) == 0) {
452 static char new_file_name
[1024];
454 static char new_lineno
;
455 token
= config_input_line
+ 6;
456 new_lineno
= strtol(token
, &file
, 0) - 1;
459 continue; /* Not a valid #line directive, may be a comment */
461 while (*file
&& xisspace((unsigned char) *file
))
466 continue; /* Not a valid #line directive, may be a comment */
468 xstrncpy(new_file_name
, file
+ 1, sizeof(new_file_name
));
470 if ((token
= strchr(new_file_name
, '"')))
473 cfg_filename
= new_file_name
;
476 config_lineno
= new_lineno
;
479 if (config_input_line
[0] == '#')
482 if (config_input_line
[0] == '\0')
485 const char* append
= tmp_line_len
? skip_ws(config_input_line
) : config_input_line
;
487 size_t append_len
= strlen(append
);
489 tmp_line
= (char*)xrealloc(tmp_line
, tmp_line_len
+ append_len
+ 1);
491 strcpy(tmp_line
+ tmp_line_len
, append
);
493 tmp_line_len
+= append_len
;
495 if (tmp_line
[tmp_line_len
-1] == '\\') {
496 debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line
<< "'");
497 tmp_line
[--tmp_line_len
] = '\0';
501 trim_trailing_ws(tmp_line
);
502 ProcessMacros(tmp_line
, tmp_line_len
);
503 debugs(3, (opt_parse_cfg_only
?1:5), "Processing: " << tmp_line
);
505 if (const char* expr
= FindStatement(tmp_line
, "if")) {
506 if_states
.push_back(EvalBoolExpr(expr
)); // store last if-statement meaning
507 } else if (FindStatement(tmp_line
, "endif")) {
508 if (!if_states
.empty())
509 if_states
.pop_back(); // remove last if-statement meaning
511 fatalf("'endif' without 'if'\n");
512 } else if (FindStatement(tmp_line
, "else")) {
513 if (!if_states
.empty())
514 if_states
.back() = !if_states
.back();
516 fatalf("'else' without 'if'\n");
517 } else if (if_states
.empty() || if_states
.back()) { // test last if-statement meaning if present
518 /* Handle includes here */
519 if (tmp_line_len
>= 9 && strncmp(tmp_line
, "include", 7) == 0 && xisspace(tmp_line
[7])) {
520 err_count
+= parseManyConfigFiles(tmp_line
+ 8, depth
+ 1);
521 } else if (!parse_line(tmp_line
)) {
522 debugs(3, 0, HERE
<< cfg_filename
<< ":" << config_lineno
<< " unrecognized: '" << tmp_line
<< "'");
531 if (!if_states
.empty())
532 fatalf("if-statement without 'endif'\n");
535 int ret
= pclose(fp
);
538 fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name
, ret
);
543 cfg_filename
= orig_cfg_filename
;
544 config_lineno
= orig_config_lineno
;
550 parseConfigFile(const char *file_name
)
558 ACLMethodData::ThePurgeCount
= 0;
561 err_count
= parseOneConfigFile(file_name
, 0);
566 * We must call configDoConfigure() before leave_suid() because
567 * configDoConfigure() is where we turn username strings into
572 if (!Config
.chroot_dir
) {
574 setUmask(Config
.umask
);
575 _db_init(Debug::cache_log
, Debug::debugOptions
);
579 if (opt_send_signal
== -1) {
580 Mgr::RegisterAction("config",
581 "Current Squid Configuration",
591 configDoConfigure(void)
593 memset(&Config2
, '\0', sizeof(SquidConfig2
));
594 /* init memory as early as possible */
598 if (Config
.cacheSwap
.swapDirs
== NULL
) {
599 /* Memory-only cache probably in effect. */
600 /* turn off the cache rebuild delays... */
601 StoreController::store_dirs_rebuilding
= 0;
604 if (Debug::rotateNumber
< 0) {
605 Debug::rotateNumber
= Config
.Log
.rotateNumber
;
608 #if SIZEOF_OFF_T <= 4
609 if (Config
.Store
.maxObjectSize
> 0x7FFF0000) {
610 debugs(3, 0, "WARNING: This Squid binary can not handle files larger than 2GB. Limiting maximum_object_size to just below 2GB");
611 Config
.Store
.maxObjectSize
= 0x7FFF0000;
614 if (0 == Store::Root().maxSize())
615 /* people might want a zero-sized cache on purpose */
617 else if (Store::Root().maxSize() < Config
.memMaxSize
)
618 /* This is bogus. folk with NULL caches will want this */
619 debugs(3, 0, "WARNING cache_mem is larger than total disk cache space!");
621 if (Config
.Announce
.period
> 0) {
622 Config
.onoff
.announce
= 1;
623 } else if (Config
.Announce
.period
< 1) {
624 Config
.Announce
.period
= 86400 * 365; /* one year */
625 Config
.onoff
.announce
= 0;
628 if (Config
.onoff
.httpd_suppress_version_string
)
629 visible_appname_string
= (char *)appname_string
;
631 visible_appname_string
= (char const *)APP_FULLNAME
;
635 if (Config
.dnsChildren
.n_max
< 1)
636 fatal("No dnsservers 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
);
700 requirePathnameExists("cache_dns_program", Config
.Program
.dnsserver
);
704 requirePathnameExists("unlinkd_program", Config
.Program
.unlinkd
);
706 requirePathnameExists("logfile_daemon", Log::TheConfig
.logfile_daemon
);
707 if (Config
.Program
.redirect
)
708 requirePathnameExists("redirect_program", Config
.Program
.redirect
->key
);
710 requirePathnameExists("Icon Directory", Config
.icons
.directory
);
712 if (Config
.errorDirectory
)
713 requirePathnameExists("Error Directory", Config
.errorDirectory
);
715 #if USE_HTTP_VIOLATIONS
720 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
721 if (!R
->flags
.override_expire
)
724 debugs(22, 1, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP");
729 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
730 if (!R
->flags
.override_lastmod
)
733 debugs(22, 1, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP");
738 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
739 if (!R
->flags
.reload_into_ims
)
742 debugs(22, 1, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP");
747 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
748 if (!R
->flags
.ignore_reload
)
751 debugs(22, 1, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP");
756 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
757 if (!R
->flags
.ignore_no_cache
)
760 debugs(22, 1, "WARNING: use of 'ignore-no-cache' in 'refresh_pattern' violates HTTP");
765 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
766 if (!R
->flags
.ignore_no_store
)
769 debugs(22, 1, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP");
774 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
775 if (!R
->flags
.ignore_must_revalidate
)
777 debugs(22, 1, "WARNING: use of 'ignore-must-revalidate' in 'refresh_pattern' violates HTTP");
781 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
782 if (!R
->flags
.ignore_private
)
785 debugs(22, 1, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP");
790 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
791 if (!R
->flags
.ignore_auth
)
794 debugs(22, 1, "WARNING: use of 'ignore-auth' in 'refresh_pattern' violates HTTP");
801 #if !USE_HTTP_VIOLATIONS
802 Config
.onoff
.via
= 1;
805 if (!Config
.onoff
.via
)
806 debugs(22, 1, "WARNING: HTTP requires the use of Via");
810 // we enable runtime PURGE checks if there is at least one PURGE method ACL
811 // TODO: replace with a dedicated "purge" ACL option?
812 Config2
.onoff
.enable_purge
= (ACLMethodData::ThePurgeCount
> 0);
814 Config2
.onoff
.mangle_request_headers
= httpReqHdrManglersConfigured();
816 if (geteuid() == 0) {
817 if (NULL
!= Config
.effectiveUser
) {
819 struct passwd
*pwd
= getpwnam(Config
.effectiveUser
);
823 * Andres Kroonmaa <andre@online.ee>:
824 * Some getpwnam() implementations (Solaris?) require
825 * an available FD < 256 for opening a FILE* to the
828 * This should be safe at startup, but might still fail
829 * during reconfigure.
831 fatalf("getpwnam failed to find userid for effective user '%s'",
832 Config
.effectiveUser
);
836 Config2
.effectiveUserID
= pwd
->pw_uid
;
838 Config2
.effectiveGroupID
= pwd
->pw_gid
;
842 if (pwd
->pw_dir
&& *pwd
->pw_dir
) {
844 char *env_str
= (char *)xcalloc((len
= strlen(pwd
->pw_dir
) + 6), 1);
845 snprintf(env_str
, len
, "HOME=%s", pwd
->pw_dir
);
853 Config2
.effectiveUserID
= geteuid();
854 Config2
.effectiveGroupID
= getegid();
857 if (NULL
!= Config
.effectiveGroup
) {
859 struct group
*grp
= getgrnam(Config
.effectiveGroup
);
862 fatalf("getgrnam failed to find groupid for effective group '%s'",
863 Config
.effectiveGroup
);
867 Config2
.effectiveGroupID
= grp
->gr_gid
;
870 HttpRequestMethod::Configure(Config
);
873 debugs(3, 1, "Initializing https proxy context");
875 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
);
881 for (p
= Config
.peers
; p
!= NULL
; p
= p
->next
) {
883 debugs(3, 1, "Initializing cache_peer " << p
->name
<< " SSL context");
884 p
->sslContext
= sslCreateClientContext(p
->sslcert
, p
->sslkey
, p
->sslversion
, p
->sslcipher
, p
->ssloptions
, p
->sslflags
, p
->sslcafile
, p
->sslcapath
, p
->sslcrlfile
);
893 for (s
= Config
.Sockaddr
.http
; s
!= NULL
; s
= (http_port_list
*) s
->next
) {
894 if (!s
->cert
&& !s
->key
)
897 debugs(3, 1, "Initializing http_port " << s
->http
.s
<< " SSL context");
899 s
->staticSslContext
.reset(
900 sslCreateServerContext(s
->cert
, s
->key
,
901 s
->version
, s
->cipher
, s
->options
, s
->sslflags
, s
->clientca
,
902 s
->cafile
, s
->capath
, s
->crlfile
, s
->dhfile
,
903 s
->sslContextSessionId
));
905 Ssl::readCertAndPrivateKeyFromFiles(s
->signingCert
, s
->signPkey
, s
->cert
, s
->key
);
913 for (s
= Config
.Sockaddr
.https
; s
!= NULL
; s
= (https_port_list
*) s
->http
.next
) {
914 debugs(3, 1, "Initializing https_port " << s
->http
.s
<< " SSL context");
916 s
->staticSslContext
.reset(
917 sslCreateServerContext(s
->cert
, s
->key
,
918 s
->version
, s
->cipher
, s
->options
, s
->sslflags
, s
->clientca
,
919 s
->cafile
, s
->capath
, s
->crlfile
, s
->dhfile
,
920 s
->sslContextSessionId
));
926 // prevent infinite fetch loops in the request parser
927 // due to buffer full but not enough data recived to finish parse
928 if (Config
.maxRequestBufferSize
<= Config
.maxRequestHeaderSize
) {
929 fatalf("Client request buffer of %u bytes cannot hold a request with %u bytes of headers." \
930 " Change client_request_buffer_max or request_header_max_size limits.",
931 (uint32_t)Config
.maxRequestBufferSize
, (uint32_t)Config
.maxRequestHeaderSize
);
936 * disable client side request pipelining. There is a race with
937 * Negotiate and NTLM when the client sends a second request on an
938 * connection before the authenticate challenge is sent. With
939 * pipelining OFF, the client may fail to authenticate, but squid's
940 * state will be preserved.
942 if (Config
.onoff
.pipeline_prefetch
) {
943 Auth::Config
*nego
= Auth::Config::Find("Negotiate");
944 Auth::Config
*ntlm
= Auth::Config::Find("NTLM");
945 if ((nego
&& nego
->active()) || (ntlm
&& ntlm
->active())) {
946 debugs(3, DBG_IMPORTANT
, "WARNING: pipeline_prefetch breaks NTLM and Negotiate authentication. Forced OFF.");
947 Config
.onoff
.pipeline_prefetch
= 0;
953 /** Parse a line containing an obsolete directive.
954 * To upgrade it where possible instead of just "Bungled config" for
955 * directives which cannot be marked as simply aliases of the some name.
956 * For example if the parameter order and content has changed.
957 * Or if the directive has been completely removed.
960 parse_obsolete(const char *name
)
962 // Directives which have been radically changed rather than removed
963 if (!strcmp(name
, "url_rewrite_concurrency")) {
966 debugs(3, DBG_CRITICAL
, "WARNING: url_rewrite_concurrency upgrade overriding url_rewrite_children settings.");
967 Config
.redirectChildren
.concurrency
= cval
;
971 /* Parse a time specification from the config file. Store the
972 * result in 'tptr', after converting it to 'units' */
974 parseTimeLine(time_msec_t
* tptr
, const char *units
, bool allowMsec
)
981 if ((u
= parseTimeUnits(units
, allowMsec
)) == 0)
984 if ((token
= strtok(NULL
, w_space
)) == NULL
)
989 m
= u
; /* default to 'units' if none specified */
993 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
994 debugs(3, 0, "WARNING: No units on '" <<
995 config_input_line
<< "', assuming " <<
997 else if ((m
= parseTimeUnits(token
, allowMsec
)) == 0)
1000 *tptr
= static_cast<time_msec_t
>(m
* d
);
1004 parseTimeUnits(const char *unit
, bool allowMsec
)
1006 if (allowMsec
&& !strncasecmp(unit
, T_MILLISECOND_STR
, strlen(T_MILLISECOND_STR
)))
1009 if (!strncasecmp(unit
, T_SECOND_STR
, strlen(T_SECOND_STR
)))
1012 if (!strncasecmp(unit
, T_MINUTE_STR
, strlen(T_MINUTE_STR
)))
1015 if (!strncasecmp(unit
, T_HOUR_STR
, strlen(T_HOUR_STR
)))
1018 if (!strncasecmp(unit
, T_DAY_STR
, strlen(T_DAY_STR
)))
1019 return 86400 * 1000;
1021 if (!strncasecmp(unit
, T_WEEK_STR
, strlen(T_WEEK_STR
)))
1022 return 86400 * 7 * 1000;
1024 if (!strncasecmp(unit
, T_FORTNIGHT_STR
, strlen(T_FORTNIGHT_STR
)))
1025 return 86400 * 14 * 1000;
1027 if (!strncasecmp(unit
, T_MONTH_STR
, strlen(T_MONTH_STR
)))
1028 return static_cast<uint64_t>(86400) * 30 * 1000;
1030 if (!strncasecmp(unit
, T_YEAR_STR
, strlen(T_YEAR_STR
)))
1031 return static_cast<uint64_t>(86400 * 1000 * 365.2522);
1033 if (!strncasecmp(unit
, T_DECADE_STR
, strlen(T_DECADE_STR
)))
1034 return static_cast<uint64_t>(86400 * 1000 * 365.2522 * 10);
1036 debugs(3, 1, "parseTimeUnits: unknown time unit '" << unit
<< "'");
1042 parseBytesLine64(int64_t * bptr
, const char *units
)
1049 if ((u
= parseBytesUnits(units
)) == 0) {
1054 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
1059 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1066 m
= u
; /* default to 'units' if none specified */
1070 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1071 debugs(3, 0, "WARNING: No units on '" <<
1072 config_input_line
<< "', assuming " <<
1073 d
<< " " << units
);
1074 else if ((m
= parseBytesUnits(token
)) == 0) {
1079 *bptr
= static_cast<int64_t>(m
* d
/ u
);
1081 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
1087 parseBytesLine(size_t * bptr
, const char *units
)
1094 if ((u
= parseBytesUnits(units
)) == 0) {
1099 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
1104 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1105 *bptr
= static_cast<size_t>(-1);
1111 m
= u
; /* default to 'units' if none specified */
1115 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1116 debugs(3, 0, "WARNING: No units on '" <<
1117 config_input_line
<< "', assuming " <<
1118 d
<< " " << units
);
1119 else if ((m
= parseBytesUnits(token
)) == 0) {
1124 *bptr
= static_cast<size_t>(m
* d
/ u
);
1126 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
1132 parseBytesLineSigned(ssize_t
* bptr
, const char *units
)
1139 if ((u
= parseBytesUnits(units
)) == 0) {
1144 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
1149 if (strcmp(token
, "none") == 0 || token
[0] == '-' /* -N */) {
1156 m
= u
; /* default to 'units' if none specified */
1160 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1161 debugs(3, 0, "WARNING: No units on '" <<
1162 config_input_line
<< "', assuming " <<
1163 d
<< " " << units
);
1164 else if ((m
= parseBytesUnits(token
)) == 0) {
1169 *bptr
= static_cast<size_t>(m
* d
/ u
);
1171 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
1178 * Parse bytes from a string.
1179 * Similar to the parseBytesLine function but parses the string value instead of
1180 * the current token value.
1182 static void parseBytesOptionValue(size_t * bptr
, const char *units
, char const * value
)
1185 if ((u
= parseBytesUnits(units
)) == 0) {
1190 // Find number from string beginning.
1191 char const * number_begin
= value
;
1192 char const * number_end
= value
;
1194 while ((*number_end
>= '0' && *number_end
<= '9')) {
1199 number
.limitInit(number_begin
, number_end
- number_begin
);
1201 int d
= xatoi(number
.termedBuf());
1203 if ((m
= parseBytesUnits(number_end
)) == 0) {
1208 *bptr
= static_cast<size_t>(m
* d
/ u
);
1209 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
1215 parseBytesUnits(const char *unit
)
1217 if (!strncasecmp(unit
, B_BYTES_STR
, strlen(B_BYTES_STR
)))
1220 if (!strncasecmp(unit
, B_KBYTES_STR
, strlen(B_KBYTES_STR
)))
1223 if (!strncasecmp(unit
, B_MBYTES_STR
, strlen(B_MBYTES_STR
)))
1226 if (!strncasecmp(unit
, B_GBYTES_STR
, strlen(B_GBYTES_STR
)))
1229 debugs(3, DBG_CRITICAL
, "WARNING: Unknown bytes unit '" << unit
<< "'");
1234 /*****************************************************************************
1236 *****************************************************************************/
1239 dump_acl(StoreEntry
* entry
, const char *name
, ACL
* ae
)
1244 while (ae
!= NULL
) {
1245 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
);
1246 storeAppendPrintf(entry
, "%s %s %s ",
1253 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
<< " " << v
->key
);
1254 storeAppendPrintf(entry
, "%s ", v
->key
);
1258 storeAppendPrintf(entry
, "\n");
1259 wordlistDestroy(&w
);
1265 parse_acl(ACL
** ae
)
1267 ACL::ParseAclLine(LegacyParser
, ae
);
1277 dump_acl_list(StoreEntry
* entry
, ACLList
* head
)
1281 for (l
= head
; l
; l
= l
->next
) {
1282 storeAppendPrintf(entry
, " %s%s",
1283 l
->op
? null_string
: "!",
1289 dump_acl_access(StoreEntry
* entry
, const char *name
, acl_access
* head
)
1293 for (l
= head
; l
; l
= l
->next
) {
1294 storeAppendPrintf(entry
, "%s %s",
1296 l
->allow
? "Allow" : "Deny");
1297 dump_acl_list(entry
, l
->aclList
);
1298 storeAppendPrintf(entry
, "\n");
1303 parse_acl_access(acl_access
** head
)
1305 aclParseAccessLine(LegacyParser
, head
);
1309 free_acl_access(acl_access
** head
)
1311 aclDestroyAccessList(head
);
1315 dump_address(StoreEntry
* entry
, const char *name
, Ip::Address
&addr
)
1317 char buf
[MAX_IPSTRLEN
];
1318 storeAppendPrintf(entry
, "%s %s\n", name
, addr
.NtoA(buf
,MAX_IPSTRLEN
) );
1322 parse_address(Ip::Address
*addr
)
1324 char *token
= strtok(NULL
, w_space
);
1331 if (!strcmp(token
,"any_addr")) {
1334 } else if ( (!strcmp(token
,"no_addr")) || (!strcmp(token
,"full_mask")) ) {
1342 free_address(Ip::Address
*addr
)
1347 CBDATA_TYPE(acl_address
);
1350 dump_acl_address(StoreEntry
* entry
, const char *name
, acl_address
* head
)
1352 char buf
[MAX_IPSTRLEN
];
1355 for (l
= head
; l
; l
= l
->next
) {
1356 if (!l
->addr
.IsAnyAddr())
1357 storeAppendPrintf(entry
, "%s %s", name
, l
->addr
.NtoA(buf
,MAX_IPSTRLEN
));
1359 storeAppendPrintf(entry
, "%s autoselect", name
);
1361 dump_acl_list(entry
, l
->aclList
);
1363 storeAppendPrintf(entry
, "\n");
1368 freed_acl_address(void *data
)
1370 acl_address
*l
= static_cast<acl_address
*>(data
);
1371 aclDestroyAclList(&l
->aclList
);
1375 parse_acl_address(acl_address
** head
)
1378 acl_address
**tail
= head
; /* sane name below */
1379 CBDATA_INIT_TYPE_FREECB(acl_address
, freed_acl_address
);
1380 l
= cbdataAlloc(acl_address
);
1381 parse_address(&l
->addr
);
1382 aclParseAclList(LegacyParser
, &l
->aclList
);
1385 tail
= &(*tail
)->next
;
1391 free_acl_address(acl_address
** head
)
1394 acl_address
*l
= *head
;
1400 CBDATA_TYPE(acl_tos
);
1403 dump_acl_tos(StoreEntry
* entry
, const char *name
, acl_tos
* head
)
1407 for (l
= head
; l
; l
= l
->next
) {
1409 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->tos
);
1411 storeAppendPrintf(entry
, "%s none", name
);
1413 dump_acl_list(entry
, l
->aclList
);
1415 storeAppendPrintf(entry
, "\n");
1420 freed_acl_tos(void *data
)
1422 acl_tos
*l
= static_cast<acl_tos
*>(data
);
1423 aclDestroyAclList(&l
->aclList
);
1427 parse_acl_tos(acl_tos
** head
)
1430 acl_tos
**tail
= head
; /* sane name below */
1431 unsigned int tos
; /* Initially uint for strtoui. Casted to tos_t before return */
1432 char *token
= strtok(NULL
, w_space
);
1439 if (!xstrtoui(token
, NULL
, &tos
, 0, std::numeric_limits
<tos_t
>::max())) {
1444 CBDATA_INIT_TYPE_FREECB(acl_tos
, freed_acl_tos
);
1446 l
= cbdataAlloc(acl_tos
);
1448 l
->tos
= (tos_t
)tos
;
1450 aclParseAclList(LegacyParser
, &l
->aclList
);
1453 tail
= &(*tail
)->next
;
1459 free_acl_tos(acl_tos
** head
)
1469 #if SO_MARK && USE_LIBCAP
1471 CBDATA_TYPE(acl_nfmark
);
1474 dump_acl_nfmark(StoreEntry
* entry
, const char *name
, acl_nfmark
* head
)
1478 for (l
= head
; l
; l
= l
->next
) {
1480 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->nfmark
);
1482 storeAppendPrintf(entry
, "%s none", name
);
1484 dump_acl_list(entry
, l
->aclList
);
1486 storeAppendPrintf(entry
, "\n");
1491 freed_acl_nfmark(void *data
)
1493 acl_nfmark
*l
= static_cast<acl_nfmark
*>(data
);
1494 aclDestroyAclList(&l
->aclList
);
1498 parse_acl_nfmark(acl_nfmark
** head
)
1501 acl_nfmark
**tail
= head
; /* sane name below */
1503 char *token
= strtok(NULL
, w_space
);
1510 if (!xstrtoui(token
, NULL
, &mark
, 0, std::numeric_limits
<nfmark_t
>::max())) {
1515 CBDATA_INIT_TYPE_FREECB(acl_nfmark
, freed_acl_nfmark
);
1517 l
= cbdataAlloc(acl_nfmark
);
1521 aclParseAclList(LegacyParser
, &l
->aclList
);
1524 tail
= &(*tail
)->next
;
1530 free_acl_nfmark(acl_nfmark
** head
)
1533 acl_nfmark
*l
= *head
;
1539 #endif /* SO_MARK */
1541 CBDATA_TYPE(acl_size_t
);
1544 dump_acl_b_size_t(StoreEntry
* entry
, const char *name
, acl_size_t
* head
)
1548 for (l
= head
; l
; l
= l
->next
) {
1550 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) l
->size
, B_BYTES_STR
);
1552 storeAppendPrintf(entry
, "%s none", name
);
1554 dump_acl_list(entry
, l
->aclList
);
1556 storeAppendPrintf(entry
, "\n");
1561 freed_acl_b_size_t(void *data
)
1563 acl_size_t
*l
= static_cast<acl_size_t
*>(data
);
1564 aclDestroyAclList(&l
->aclList
);
1568 parse_acl_b_size_t(acl_size_t
** head
)
1571 acl_size_t
**tail
= head
; /* sane name below */
1573 CBDATA_INIT_TYPE_FREECB(acl_size_t
, freed_acl_b_size_t
);
1575 l
= cbdataAlloc(acl_size_t
);
1577 parse_b_int64_t(&l
->size
);
1579 aclParseAclList(LegacyParser
, &l
->aclList
);
1582 tail
= &(*tail
)->next
;
1588 free_acl_b_size_t(acl_size_t
** head
)
1591 acl_size_t
*l
= *head
;
1600 #include "DelayPools.h"
1601 #include "DelayConfig.h"
1602 /* do nothing - free_delay_pool_count is the magic free function.
1603 * this is why delay_pool_count isn't just marked TYPE: u_short
1605 #define free_delay_pool_class(X)
1606 #define free_delay_pool_access(X)
1607 #define free_delay_pool_rates(X)
1608 #define dump_delay_pool_class(X, Y, Z)
1609 #define dump_delay_pool_access(X, Y, Z)
1610 #define dump_delay_pool_rates(X, Y, Z)
1613 free_delay_pool_count(DelayConfig
* cfg
)
1615 cfg
->freePoolCount();
1619 dump_delay_pool_count(StoreEntry
* entry
, const char *name
, DelayConfig
&cfg
)
1621 cfg
.dumpPoolCount (entry
, name
);
1625 parse_delay_pool_count(DelayConfig
* cfg
)
1627 cfg
->parsePoolCount();
1631 parse_delay_pool_class(DelayConfig
* cfg
)
1633 cfg
->parsePoolClass();
1637 parse_delay_pool_rates(DelayConfig
* cfg
)
1639 cfg
->parsePoolRates();
1643 parse_delay_pool_access(DelayConfig
* cfg
)
1645 cfg
->parsePoolAccess(LegacyParser
);
1651 #include "ClientDelayConfig.h"
1652 /* do nothing - free_client_delay_pool_count is the magic free function.
1653 * this is why client_delay_pool_count isn't just marked TYPE: u_short
1656 #define free_client_delay_pool_access(X)
1657 #define free_client_delay_pool_rates(X)
1658 #define dump_client_delay_pool_access(X, Y, Z)
1659 #define dump_client_delay_pool_rates(X, Y, Z)
1662 free_client_delay_pool_count(ClientDelayConfig
* cfg
)
1664 cfg
->freePoolCount();
1668 dump_client_delay_pool_count(StoreEntry
* entry
, const char *name
, ClientDelayConfig
&cfg
)
1670 cfg
.dumpPoolCount (entry
, name
);
1674 parse_client_delay_pool_count(ClientDelayConfig
* cfg
)
1676 cfg
->parsePoolCount();
1680 parse_client_delay_pool_rates(ClientDelayConfig
* cfg
)
1682 cfg
->parsePoolRates();
1686 parse_client_delay_pool_access(ClientDelayConfig
* cfg
)
1688 cfg
->parsePoolAccess(LegacyParser
);
1692 #if USE_HTTP_VIOLATIONS
1694 dump_http_header_access(StoreEntry
* entry
, const char *name
, header_mangler header
[])
1698 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1699 if (header
[i
].access_list
!= NULL
) {
1700 storeAppendPrintf(entry
, "%s ", name
);
1701 dump_acl_access(entry
, httpHeaderNameById(i
),
1702 header
[i
].access_list
);
1708 parse_http_header_access(header_mangler header
[])
1713 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1714 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1715 debugs(3, 0, "parse_http_header_access: missing header name.");
1719 /* Now lookup index of header. */
1720 id
= httpHeaderIdByNameDef(t
, strlen(t
));
1722 if (strcmp(t
, "All") == 0)
1724 else if (strcmp(t
, "Other") == 0)
1726 else if (id
== -1) {
1727 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1728 debugs(3, 0, "parse_http_header_access: unknown header name '" << t
<< "'");
1732 if (id
!= HDR_ENUM_END
) {
1733 parse_acl_access(&header
[id
].access_list
);
1735 char *next_string
= t
+ strlen(t
) - 1;
1737 *(next_string
+ 1) = ' ';
1739 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1740 char *new_string
= xstrdup(next_string
);
1741 strtok(new_string
, w_space
);
1742 parse_acl_access(&header
[i
].access_list
);
1743 safe_free(new_string
);
1749 free_http_header_access(header_mangler header
[])
1753 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1754 free_acl_access(&header
[i
].access_list
);
1759 dump_http_header_replace(StoreEntry
* entry
, const char *name
, header_mangler
1764 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1765 if (NULL
== header
[i
].replacement
)
1768 storeAppendPrintf(entry
, "%s %s %s\n", name
, httpHeaderNameById(i
),
1769 header
[i
].replacement
);
1774 parse_http_header_replace(header_mangler header
[])
1779 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1780 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1781 debugs(3, 0, "parse_http_header_replace: missing header name.");
1785 /* Now lookup index of header. */
1786 id
= httpHeaderIdByNameDef(t
, strlen(t
));
1788 if (strcmp(t
, "All") == 0)
1790 else if (strcmp(t
, "Other") == 0)
1792 else if (id
== -1) {
1793 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1794 debugs(3, 0, "parse_http_header_replace: unknown header name " << t
<< ".");
1799 if (id
!= HDR_ENUM_END
) {
1800 if (header
[id
].replacement
!= NULL
)
1801 safe_free(header
[id
].replacement
);
1803 header
[id
].replacement
= xstrdup(t
+ strlen(t
) + 1);
1805 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1806 if (header
[i
].replacement
!= NULL
)
1807 safe_free(header
[i
].replacement
);
1809 header
[i
].replacement
= xstrdup(t
+ strlen(t
) + 1);
1815 free_http_header_replace(header_mangler header
[])
1819 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1820 if (header
[i
].replacement
!= NULL
)
1821 safe_free(header
[i
].replacement
);
1828 dump_cachedir(StoreEntry
* entry
, const char *name
, SquidConfig::_cacheSwap swap
)
1834 for (i
= 0; i
< swap
.n_configured
; i
++) {
1835 s
= dynamic_cast<SwapDir
*>(swap
.swapDirs
[i
].getRaw());
1837 storeAppendPrintf(entry
, "%s %s %s", name
, s
->type(), s
->path
);
1839 storeAppendPrintf(entry
, "\n");
1844 check_null_string(char *s
)
1851 parse_authparam(Auth::ConfigVector
* config
)
1856 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1859 if ((param_str
= strtok(NULL
, w_space
)) == NULL
)
1862 /* find a configuration for the scheme in the currently parsed configs... */
1863 Auth::Config
*schemeCfg
= Auth::Config::Find(type_str
);
1865 if (schemeCfg
== NULL
) {
1866 /* Create a configuration based on the scheme info */
1867 Auth::Scheme::Pointer theScheme
= Auth::Scheme::Find(type_str
);
1869 if (theScheme
== NULL
) {
1870 debugs(3, DBG_CRITICAL
, "Parsing Config File: Unknown authentication scheme '" << type_str
<< "'.");
1874 config
->push_back(theScheme
->createConfig());
1875 schemeCfg
= Auth::Config::Find(type_str
);
1876 if (schemeCfg
== NULL
) {
1877 debugs(3, DBG_CRITICAL
, "Parsing Config File: Corruption configuring authentication scheme '" << type_str
<< "'.");
1882 schemeCfg
->parse(schemeCfg
, config
->size(), param_str
);
1886 free_authparam(Auth::ConfigVector
* cfg
)
1888 /* Wipe the Auth globals and Detach/Destruct component config + state. */
1891 /* remove our pointers to the probably-dead sub-configs */
1892 while (cfg
->size()) {
1896 /* on reconfigure initialize new auth schemes for the new config. */
1897 if (reconfiguring
) {
1903 dump_authparam(StoreEntry
* entry
, const char *name
, Auth::ConfigVector cfg
)
1905 for (Auth::ConfigVector::iterator i
= cfg
.begin(); i
!= cfg
.end(); ++i
)
1906 (*i
)->dump(entry
, name
, (*i
));
1908 #endif /* USE_AUTH */
1910 /* TODO: just return the object, the # is irrelevant */
1912 find_fstype(char *type
)
1914 for (size_t i
= 0; i
< StoreFileSystem::FileSystems().size(); ++i
)
1915 if (strcasecmp(type
, StoreFileSystem::FileSystems().items
[i
]->type()) == 0)
1922 parse_cachedir(SquidConfig::_cacheSwap
* swap
)
1926 RefCount
<SwapDir
> sd
;
1930 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1933 if ((path_str
= strtok(NULL
, w_space
)) == NULL
)
1936 fs
= find_fstype(type_str
);
1941 /* reconfigure existing dir */
1943 for (i
= 0; i
< swap
->n_configured
; i
++) {
1944 assert (swap
->swapDirs
[i
].getRaw());
1946 if ((strcasecmp(path_str
, dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw())->path
)) == 0) {
1947 /* this is specific to on-fs Stores. The right
1948 * way to handle this is probably to have a mapping
1949 * from paths to stores, and have on-fs stores
1950 * register with that, and lookip in that in their
1951 * own setup logic. RBC 20041225. TODO.
1954 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw());
1956 if (sd
->type() != StoreFileSystem::FileSystems().items
[fs
]->type()) {
1957 debugs(3, 0, "ERROR: Can't change type of existing cache_dir " <<
1958 sd
->type() << " " << sd
->path
<< " to " << type_str
<< ". Restart required");
1962 sd
->reconfigure (i
, path_str
);
1964 update_maxobjsize();
1971 if (swap
->n_configured
> 63) {
1972 /* 7 bits, signed */
1973 debugs(3, DBG_CRITICAL
, "WARNING: There is a fixed maximum of 63 cache_dir entries Squid can handle.");
1974 debugs(3, DBG_CRITICAL
, "WARNING: '" << path_str
<< "' is one to many.");
1979 allocate_new_swapdir(swap
);
1981 swap
->swapDirs
[swap
->n_configured
] = StoreFileSystem::FileSystems().items
[fs
]->createSwapDir();
1983 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[swap
->n_configured
].getRaw());
1985 /* parse the FS parameters and options */
1986 sd
->parse(swap
->n_configured
, path_str
);
1988 ++swap
->n_configured
;
1990 if (sd
->needsDiskStrand())
1993 /* Update the max object size */
1994 update_maxobjsize();
1998 peer_type_str(const peer_t type
)
2000 const char * result
;
2012 case PEER_MULTICAST
:
2013 result
= "multicast";
2025 dump_peer(StoreEntry
* entry
, const char *name
, peer
* p
)
2029 LOCAL_ARRAY(char, xname
, 128);
2032 storeAppendPrintf(entry
, "%s %s %s %d %d name=%s",
2039 dump_peer_options(entry
, p
);
2041 for (d
= p
->peer_domain
; d
; d
= d
->next
) {
2042 storeAppendPrintf(entry
, "cache_peer_domain %s %s%s\n",
2044 d
->do_ping
? null_string
: "!",
2049 snprintf(xname
, 128, "cache_peer_access %s", p
->name
);
2050 dump_acl_access(entry
, xname
, p
->access
);
2053 for (t
= p
->typelist
; t
; t
= t
->next
) {
2054 storeAppendPrintf(entry
, "neighbor_type_domain %s %s %s\n",
2056 peer_type_str(t
->type
),
2065 * utility function to prevent getservbyname() being called with a numeric value
2066 * on Windows at least it returns garage results.
2069 isUnsignedNumeric(const char *str
, size_t len
)
2071 if (len
< 1) return false;
2073 for (; len
>0 && *str
; str
++, len
--) {
2074 if (! isdigit(*str
))
2081 \param proto 'tcp' or 'udp' for protocol
2082 \returns Port the named service is supposed to be listening on.
2084 static unsigned short
2085 GetService(const char *proto
)
2087 struct servent
*port
= NULL
;
2088 /** Parses a port number or service name from the squid.conf */
2089 char *token
= strtok(NULL
, w_space
);
2090 if (token
== NULL
) {
2092 return 0; /* NEVER REACHED */
2094 /** Returns either the service port number from /etc/services */
2095 if ( !isUnsignedNumeric(token
, strlen(token
)) )
2096 port
= getservbyname(token
, proto
);
2098 return ntohs((unsigned short)port
->s_port
);
2100 /** Or a numeric translation of the config text. */
2101 return xatos(token
);
2105 \returns Port the named TCP service is supposed to be listening on.
2106 \copydoc GetService(const char *proto)
2108 inline unsigned short
2111 return GetService("tcp");
2115 \returns Port the named UDP service is supposed to be listening on.
2116 \copydoc GetService(const char *proto)
2118 inline unsigned short
2121 return GetService("udp");
2125 parse_peer(peer
** head
)
2129 CBDATA_INIT_TYPE_FREECB(peer
, peerDestroy
);
2130 p
= cbdataAlloc(peer
);
2131 p
->http_port
= CACHE_HTTP_PORT
;
2132 p
->icp
.port
= CACHE_ICP_PORT
;
2135 p
->stats
.logged_state
= PEER_ALIVE
;
2137 if ((token
= strtok(NULL
, w_space
)) == NULL
)
2140 p
->host
= xstrdup(token
);
2142 p
->name
= xstrdup(token
);
2144 if ((token
= strtok(NULL
, w_space
)) == NULL
)
2147 p
->type
= parseNeighborType(token
);
2149 if (p
->type
== PEER_MULTICAST
) {
2150 p
->options
.no_digest
= 1;
2151 p
->options
.no_netdb_exchange
= 1;
2154 p
->http_port
= GetTcpService();
2159 p
->icp
.port
= GetUdpService();
2160 p
->connection_auth
= 2; /* auto */
2162 while ((token
= strtok(NULL
, w_space
))) {
2163 if (!strcasecmp(token
, "proxy-only")) {
2164 p
->options
.proxy_only
= 1;
2165 } else if (!strcasecmp(token
, "no-query")) {
2166 p
->options
.no_query
= 1;
2167 } else if (!strcasecmp(token
, "background-ping")) {
2168 p
->options
.background_ping
= 1;
2169 } else if (!strcasecmp(token
, "no-digest")) {
2170 p
->options
.no_digest
= 1;
2171 } else if (!strcasecmp(token
, "no-tproxy")) {
2172 p
->options
.no_tproxy
= 1;
2173 } else if (!strcasecmp(token
, "multicast-responder")) {
2174 p
->options
.mcast_responder
= 1;
2175 #if PEER_MULTICAST_SIBLINGS
2176 } else if (!strcasecmp(token
, "multicast-siblings")) {
2177 p
->options
.mcast_siblings
= 1;
2179 } else if (!strncasecmp(token
, "weight=", 7)) {
2180 p
->weight
= xatoi(token
+ 7);
2181 } else if (!strncasecmp(token
, "basetime=", 9)) {
2182 p
->basetime
= xatoi(token
+ 9);
2183 } else if (!strcasecmp(token
, "closest-only")) {
2184 p
->options
.closest_only
= 1;
2185 } else if (!strncasecmp(token
, "ttl=", 4)) {
2186 p
->mcast
.ttl
= xatoi(token
+ 4);
2188 if (p
->mcast
.ttl
< 0)
2191 if (p
->mcast
.ttl
> 128)
2193 } else if (!strcasecmp(token
, "default")) {
2194 p
->options
.default_parent
= 1;
2195 } else if (!strcasecmp(token
, "round-robin")) {
2196 p
->options
.roundrobin
= 1;
2197 } else if (!strcasecmp(token
, "weighted-round-robin")) {
2198 p
->options
.weighted_roundrobin
= 1;
2200 } else if (!strcasecmp(token
, "htcp")) {
2201 p
->options
.htcp
= 1;
2202 } else if (!strncasecmp(token
, "htcp=", 5) || !strncasecmp(token
, "htcp-", 5)) {
2203 /* Note: The htcp- form is deprecated, replaced by htcp= */
2204 p
->options
.htcp
= 1;
2205 char *tmp
= xstrdup(token
+5);
2206 char *mode
, *nextmode
;
2207 for (mode
= nextmode
= tmp
; mode
; mode
= nextmode
) {
2208 nextmode
= strchr(mode
, ',');
2211 if (!strcasecmp(mode
, "no-clr")) {
2212 if (p
->options
.htcp_only_clr
)
2213 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
2214 p
->options
.htcp_no_clr
= 1;
2215 } else if (!strcasecmp(mode
, "no-purge-clr")) {
2216 p
->options
.htcp_no_purge_clr
= 1;
2217 } else if (!strcasecmp(mode
, "only-clr")) {
2218 if (p
->options
.htcp_no_clr
)
2219 fatalf("parse_peer: can't set htcp no-clr and only-clr simultaneously");
2220 p
->options
.htcp_only_clr
= 1;
2221 } else if (!strcasecmp(mode
, "forward-clr")) {
2222 p
->options
.htcp_forward_clr
= 1;
2223 } else if (!strcasecmp(mode
, "oldsquid")) {
2224 p
->options
.htcp_oldsquid
= 1;
2226 fatalf("invalid HTCP mode '%s'", mode
);
2231 } else if (!strcasecmp(token
, "no-netdb-exchange")) {
2232 p
->options
.no_netdb_exchange
= 1;
2234 } else if (!strcasecmp(token
, "carp")) {
2235 if (p
->type
!= PEER_PARENT
)
2236 fatalf("parse_peer: non-parent carp peer %s/%d\n", p
->host
, p
->http_port
);
2238 p
->options
.carp
= 1;
2239 } else if (!strncasecmp(token
, "carp-key=", 9)) {
2240 if (p
->options
.carp
!= 1)
2241 fatalf("parse_peer: carp-key specified on non-carp peer %s/%d\n", p
->host
, p
->http_port
);
2242 p
->options
.carp_key
.set
=1;
2243 char *nextkey
=token
+strlen("carp-key="), *key
=nextkey
;
2244 for (; key
; key
= nextkey
) {
2245 nextkey
=strchr(key
,',');
2246 if (nextkey
) ++nextkey
; // skip the comma, any
2247 if (0==strncasecmp(key
,"scheme",6)) {
2248 p
->options
.carp_key
.scheme
=1;
2249 } else if (0==strncasecmp(key
,"host",4)) {
2250 p
->options
.carp_key
.host
=1;
2251 } else if (0==strncasecmp(key
,"port",4)) {
2252 p
->options
.carp_key
.port
=1;
2253 } else if (0==strncasecmp(key
,"path",4)) {
2254 p
->options
.carp_key
.path
=1;
2255 } else if (0==strncasecmp(key
,"params",6)) {
2256 p
->options
.carp_key
.params
=1;
2258 fatalf("invalid carp-key '%s'",key
);
2261 } else if (!strcasecmp(token
, "userhash")) {
2263 if (p
->type
!= PEER_PARENT
)
2264 fatalf("parse_peer: non-parent userhash peer %s/%d\n", p
->host
, p
->http_port
);
2266 p
->options
.userhash
= 1;
2268 fatalf("parse_peer: userhash requires authentication. peer %s/%d\n", p
->host
, p
->http_port
);
2270 } else if (!strcasecmp(token
, "sourcehash")) {
2271 if (p
->type
!= PEER_PARENT
)
2272 fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p
->host
, p
->http_port
);
2274 p
->options
.sourcehash
= 1;
2276 } else if (!strcasecmp(token
, "no-delay")) {
2278 p
->options
.no_delay
= 1;
2280 debugs(0, DBG_CRITICAL
, "WARNING: cache_peer option 'no-delay' requires --enable-delay-pools");
2282 } else if (!strncasecmp(token
, "login=", 6)) {
2283 p
->login
= xstrdup(token
+ 6);
2284 rfc1738_unescape(p
->login
);
2285 } else if (!strncasecmp(token
, "connect-timeout=", 16)) {
2286 p
->connect_timeout
= xatoi(token
+ 16);
2287 } else if (!strncasecmp(token
, "connect-fail-limit=", 19)) {
2288 p
->connect_fail_limit
= xatoi(token
+ 19);
2289 #if USE_CACHE_DIGESTS
2290 } else if (!strncasecmp(token
, "digest-url=", 11)) {
2291 p
->digest_url
= xstrdup(token
+ 11);
2294 } else if (!strcasecmp(token
, "allow-miss")) {
2295 p
->options
.allow_miss
= 1;
2296 } else if (!strncasecmp(token
, "max-conn=", 9)) {
2297 p
->max_conn
= xatoi(token
+ 9);
2298 } else if (!strcasecmp(token
, "originserver")) {
2299 p
->options
.originserver
= 1;
2300 } else if (!strncasecmp(token
, "name=", 5)) {
2304 p
->name
= xstrdup(token
+ 5);
2305 } else if (!strncasecmp(token
, "forceddomain=", 13)) {
2306 safe_free(p
->domain
);
2309 p
->domain
= xstrdup(token
+ 13);
2313 } else if (strcmp(token
, "ssl") == 0) {
2315 } else if (strncmp(token
, "sslcert=", 8) == 0) {
2316 safe_free(p
->sslcert
);
2317 p
->sslcert
= xstrdup(token
+ 8);
2318 } else if (strncmp(token
, "sslkey=", 7) == 0) {
2319 safe_free(p
->sslkey
);
2320 p
->sslkey
= xstrdup(token
+ 7);
2321 } else if (strncmp(token
, "sslversion=", 11) == 0) {
2322 p
->sslversion
= atoi(token
+ 11);
2323 } else if (strncmp(token
, "ssloptions=", 11) == 0) {
2324 safe_free(p
->ssloptions
);
2325 p
->ssloptions
= xstrdup(token
+ 11);
2326 } else if (strncmp(token
, "sslcipher=", 10) == 0) {
2327 safe_free(p
->sslcipher
);
2328 p
->sslcipher
= xstrdup(token
+ 10);
2329 } else if (strncmp(token
, "sslcafile=", 10) == 0) {
2330 safe_free(p
->sslcafile
);
2331 p
->sslcafile
= xstrdup(token
+ 10);
2332 } else if (strncmp(token
, "sslcapath=", 10) == 0) {
2333 safe_free(p
->sslcapath
);
2334 p
->sslcapath
= xstrdup(token
+ 10);
2335 } else if (strncmp(token
, "sslcrlfile=", 11) == 0) {
2336 safe_free(p
->sslcrlfile
);
2337 p
->sslcapath
= xstrdup(token
+ 10);
2338 } else if (strncmp(token
, "sslflags=", 9) == 0) {
2339 safe_free(p
->sslflags
);
2340 p
->sslflags
= xstrdup(token
+ 9);
2341 } else if (strncmp(token
, "ssldomain=", 10) == 0) {
2342 safe_free(p
->ssldomain
);
2343 p
->ssldomain
= xstrdup(token
+ 10);
2346 } else if (strcmp(token
, "front-end-https") == 0) {
2347 p
->front_end_https
= 1;
2348 } else if (strcmp(token
, "front-end-https=on") == 0) {
2349 p
->front_end_https
= 1;
2350 } else if (strcmp(token
, "front-end-https=auto") == 0) {
2351 p
->front_end_https
= 2;
2352 } else if (strcmp(token
, "connection-auth=off") == 0) {
2353 p
->connection_auth
= 0;
2354 } else if (strcmp(token
, "connection-auth") == 0) {
2355 p
->connection_auth
= 1;
2356 } else if (strcmp(token
, "connection-auth=on") == 0) {
2357 p
->connection_auth
= 1;
2358 } else if (strcmp(token
, "connection-auth=auto") == 0) {
2359 p
->connection_auth
= 2;
2361 debugs(3, 0, "parse_peer: token='" << token
<< "'");
2366 if (peerFindByName(p
->name
))
2367 fatalf("ERROR: cache_peer %s specified twice\n", p
->name
);
2372 if (p
->connect_fail_limit
< 1)
2373 p
->connect_fail_limit
= 10;
2375 p
->icp
.version
= ICP_VERSION_CURRENT
;
2377 p
->testing_now
= false;
2379 #if USE_CACHE_DIGESTS
2381 if (!p
->options
.no_digest
) {
2382 /* XXX This looks odd.. who has the original pointer
2385 PeerDigest
*pd
= peerDigestCreate(p
);
2386 p
->digest
= cbdataReference(pd
);
2391 p
->index
= ++Config
.npeers
;
2393 while (*head
!= NULL
)
2394 head
= &(*head
)->next
;
2402 free_peer(peer
** P
)
2406 while ((p
= *P
) != NULL
) {
2408 #if USE_CACHE_DIGESTS
2410 cbdataReferenceDone(p
->digest
);
2420 dump_cachemgrpasswd(StoreEntry
* entry
, const char *name
, cachemgr_passwd
* list
)
2424 while (list
!= NULL
) {
2425 if (strcmp(list
->passwd
, "none") && strcmp(list
->passwd
, "disable"))
2426 storeAppendPrintf(entry
, "%s XXXXXXXXXX", name
);
2428 storeAppendPrintf(entry
, "%s %s", name
, list
->passwd
);
2430 for (w
= list
->actions
; w
!= NULL
; w
= w
->next
) {
2431 storeAppendPrintf(entry
, " %s", w
->key
);
2434 storeAppendPrintf(entry
, "\n");
2440 parse_cachemgrpasswd(cachemgr_passwd
** head
)
2442 char *passwd
= NULL
;
2443 wordlist
*actions
= NULL
;
2445 cachemgr_passwd
**P
;
2446 parse_string(&passwd
);
2447 parse_wordlist(&actions
);
2448 p
= static_cast<cachemgr_passwd
*>(xcalloc(1, sizeof(cachemgr_passwd
)));
2450 p
->actions
= actions
;
2452 for (P
= head
; *P
; P
= &(*P
)->next
) {
2454 * See if any of the actions from this line already have a
2455 * password from previous lines. The password checking
2456 * routines in cache_manager.c take the the password from
2457 * the first cachemgr_passwd struct that contains the
2458 * requested action. Thus, we should warn users who might
2459 * think they can have two passwords for the same action.
2464 for (w
= (*P
)->actions
; w
; w
= w
->next
) {
2465 for (u
= actions
; u
; u
= u
->next
) {
2466 if (strcmp(w
->key
, u
->key
))
2469 debugs(0, 0, "WARNING: action '" << u
->key
<< "' (line " << config_lineno
<< ") already has a password");
2478 free_cachemgrpasswd(cachemgr_passwd
** head
)
2482 while ((p
= *head
) != NULL
) {
2485 wordlistDestroy(&p
->actions
);
2491 dump_denyinfo(StoreEntry
* entry
, const char *name
, acl_deny_info_list
* var
)
2495 while (var
!= NULL
) {
2496 storeAppendPrintf(entry
, "%s %s", name
, var
->err_page_name
);
2498 for (a
= var
->acl_list
; a
!= NULL
; a
= a
->next
)
2499 storeAppendPrintf(entry
, " %s", a
->name
);
2501 storeAppendPrintf(entry
, "\n");
2508 parse_denyinfo(acl_deny_info_list
** var
)
2510 aclParseDenyInfoLine(var
);
2514 free_denyinfo(acl_deny_info_list
** list
)
2516 acl_deny_info_list
*a
= NULL
;
2517 acl_deny_info_list
*a_next
= NULL
;
2518 acl_name_list
*l
= NULL
;
2519 acl_name_list
*l_next
= NULL
;
2521 for (a
= *list
; a
; a
= a_next
) {
2522 for (l
= a
->acl_list
; l
; l
= l_next
) {
2524 memFree(l
, MEM_ACL_NAME_LIST
);
2529 memFree(a
, MEM_ACL_DENY_INFO_LIST
);
2537 parse_peer_access(void)
2542 if (!(host
= strtok(NULL
, w_space
)))
2545 if ((p
= peerFindByName(host
)) == NULL
) {
2546 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2550 aclParseAccessLine(LegacyParser
, &p
->access
);
2554 parse_hostdomain(void)
2557 char *domain
= NULL
;
2559 if (!(host
= strtok(NULL
, w_space
)))
2562 while ((domain
= strtok(NULL
, list_sep
))) {
2563 domain_ping
*l
= NULL
;
2564 domain_ping
**L
= NULL
;
2567 if ((p
= peerFindByName(host
)) == NULL
) {
2568 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2572 l
= static_cast<domain_ping
*>(xcalloc(1, sizeof(domain_ping
)));
2575 if (*domain
== '!') { /* check for !.edu */
2580 l
->domain
= xstrdup(domain
);
2582 for (L
= &(p
->peer_domain
); *L
; L
= &((*L
)->next
));
2588 parse_hostdomaintype(void)
2592 char *domain
= NULL
;
2594 if (!(host
= strtok(NULL
, w_space
)))
2597 if (!(type
= strtok(NULL
, w_space
)))
2600 while ((domain
= strtok(NULL
, list_sep
))) {
2601 domain_type
*l
= NULL
;
2602 domain_type
**L
= NULL
;
2605 if ((p
= peerFindByName(host
)) == NULL
) {
2606 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2610 l
= static_cast<domain_type
*>(xcalloc(1, sizeof(domain_type
)));
2611 l
->type
= parseNeighborType(type
);
2612 l
->domain
= xstrdup(domain
);
2614 for (L
= &(p
->typelist
); *L
; L
= &((*L
)->next
));
2620 dump_int(StoreEntry
* entry
, const char *name
, int var
)
2622 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2640 dump_onoff(StoreEntry
* entry
, const char *name
, int var
)
2642 storeAppendPrintf(entry
, "%s %s\n", name
, var
? "on" : "off");
2646 parse_onoff(int *var
)
2648 char *token
= strtok(NULL
, w_space
);
2653 if (!strcasecmp(token
, "on") || !strcasecmp(token
, "enable"))
2659 #define free_onoff free_int
2662 dump_tristate(StoreEntry
* entry
, const char *name
, int var
)
2673 storeAppendPrintf(entry
, "%s %s\n", name
, state
);
2677 parse_tristate(int *var
)
2679 char *token
= strtok(NULL
, w_space
);
2684 if (!strcasecmp(token
, "on") || !strcasecmp(token
, "enable"))
2686 else if (!strcasecmp(token
, "warn"))
2692 #define free_tristate free_int
2695 dump_refreshpattern(StoreEntry
* entry
, const char *name
, refresh_t
* head
)
2697 while (head
!= NULL
) {
2698 storeAppendPrintf(entry
, "%s%s %s %d %d%% %d",
2700 head
->flags
.icase
? " -i" : null_string
,
2702 (int) head
->min
/ 60,
2703 (int) (100.0 * head
->pct
+ 0.5),
2704 (int) head
->max
/ 60);
2706 if (head
->max_stale
>= 0)
2707 storeAppendPrintf(entry
, " max-stale=%d", head
->max_stale
);
2709 if (head
->flags
.refresh_ims
)
2710 storeAppendPrintf(entry
, " refresh-ims");
2712 if (head
->flags
.store_stale
)
2713 storeAppendPrintf(entry
, " store-stale");
2715 #if USE_HTTP_VIOLATIONS
2717 if (head
->flags
.override_expire
)
2718 storeAppendPrintf(entry
, " override-expire");
2720 if (head
->flags
.override_lastmod
)
2721 storeAppendPrintf(entry
, " override-lastmod");
2723 if (head
->flags
.reload_into_ims
)
2724 storeAppendPrintf(entry
, " reload-into-ims");
2726 if (head
->flags
.ignore_reload
)
2727 storeAppendPrintf(entry
, " ignore-reload");
2729 if (head
->flags
.ignore_no_cache
)
2730 storeAppendPrintf(entry
, " ignore-no-cache");
2732 if (head
->flags
.ignore_no_store
)
2733 storeAppendPrintf(entry
, " ignore-no-store");
2735 if (head
->flags
.ignore_must_revalidate
)
2736 storeAppendPrintf(entry
, " ignore-must-revalidate");
2738 if (head
->flags
.ignore_private
)
2739 storeAppendPrintf(entry
, " ignore-private");
2741 if (head
->flags
.ignore_auth
)
2742 storeAppendPrintf(entry
, " ignore-auth");
2746 storeAppendPrintf(entry
, "\n");
2753 parse_refreshpattern(refresh_t
** head
)
2760 int refresh_ims
= 0;
2761 int store_stale
= 0;
2764 #if USE_HTTP_VIOLATIONS
2766 int override_expire
= 0;
2767 int override_lastmod
= 0;
2768 int reload_into_ims
= 0;
2769 int ignore_reload
= 0;
2770 int ignore_no_cache
= 0;
2771 int ignore_no_store
= 0;
2772 int ignore_must_revalidate
= 0;
2773 int ignore_private
= 0;
2774 int ignore_auth
= 0;
2781 int flags
= REG_EXTENDED
| REG_NOSUB
;
2783 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
2788 if (strcmp(token
, "-i") == 0) {
2790 token
= strtok(NULL
, w_space
);
2791 } else if (strcmp(token
, "+i") == 0) {
2792 flags
&= ~REG_ICASE
;
2793 token
= strtok(NULL
, w_space
);
2796 if (token
== NULL
) {
2801 pattern
= xstrdup(token
);
2803 i
= GetInteger(); /* token: min */
2805 /* catch negative and insanely huge values close to 32-bit wrap */
2807 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age negative. Cropped back to zero.");
2810 if (i
> 60*24*365) {
2811 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age too high. Cropped back to 1 year.");
2815 min
= (time_t) (i
* 60); /* convert minutes to seconds */
2817 i
= GetInteger(); /* token: pct */
2819 pct
= (double) i
/ 100.0;
2821 i
= GetInteger(); /* token: max */
2823 /* catch negative and insanely huge values close to 32-bit wrap */
2825 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age negative. Cropped back to zero.");
2828 if (i
> 60*24*365) {
2829 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age too high. Cropped back to 1 year.");
2833 max
= (time_t) (i
* 60); /* convert minutes to seconds */
2836 while ((token
= strtok(NULL
, w_space
)) != NULL
) {
2837 if (!strcmp(token
, "refresh-ims")) {
2839 } else if (!strcmp(token
, "store-stale")) {
2841 } else if (!strncmp(token
, "max-stale=", 10)) {
2842 max_stale
= atoi(token
+ 10);
2843 #if USE_HTTP_VIOLATIONS
2845 } else if (!strcmp(token
, "override-expire"))
2846 override_expire
= 1;
2847 else if (!strcmp(token
, "override-lastmod"))
2848 override_lastmod
= 1;
2849 else if (!strcmp(token
, "ignore-no-cache"))
2850 ignore_no_cache
= 1;
2851 else if (!strcmp(token
, "ignore-no-store"))
2852 ignore_no_store
= 1;
2853 else if (!strcmp(token
, "ignore-must-revalidate"))
2854 ignore_must_revalidate
= 1;
2855 else if (!strcmp(token
, "ignore-private"))
2857 else if (!strcmp(token
, "ignore-auth"))
2859 else if (!strcmp(token
, "reload-into-ims")) {
2860 reload_into_ims
= 1;
2861 refresh_nocache_hack
= 1;
2862 /* tell client_side.c that this is used */
2863 } else if (!strcmp(token
, "ignore-reload")) {
2865 refresh_nocache_hack
= 1;
2866 /* tell client_side.c that this is used */
2870 debugs(22, 0, "refreshAddToList: Unknown option '" << pattern
<< "': " << token
);
2873 if ((errcode
= regcomp(&comp
, pattern
, flags
)) != 0) {
2875 regerror(errcode
, &comp
, errbuf
, sizeof errbuf
);
2876 debugs(22, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
2877 debugs(22, 0, "refreshAddToList: Invalid regular expression '" << pattern
<< "': " << errbuf
);
2881 pct
= pct
< 0.0 ? 0.0 : pct
;
2882 max
= max
< 0 ? 0 : max
;
2883 t
= static_cast<refresh_t
*>(xcalloc(1, sizeof(refresh_t
)));
2884 t
->pattern
= (char *) xstrdup(pattern
);
2885 t
->compiled_pattern
= comp
;
2890 if (flags
& REG_ICASE
)
2894 t
->flags
.refresh_ims
= 1;
2897 t
->flags
.store_stale
= 1;
2899 t
->max_stale
= max_stale
;
2901 #if USE_HTTP_VIOLATIONS
2903 if (override_expire
)
2904 t
->flags
.override_expire
= 1;
2906 if (override_lastmod
)
2907 t
->flags
.override_lastmod
= 1;
2909 if (reload_into_ims
)
2910 t
->flags
.reload_into_ims
= 1;
2913 t
->flags
.ignore_reload
= 1;
2915 if (ignore_no_cache
)
2916 t
->flags
.ignore_no_cache
= 1;
2918 if (ignore_no_store
)
2919 t
->flags
.ignore_no_store
= 1;
2921 if (ignore_must_revalidate
)
2922 t
->flags
.ignore_must_revalidate
= 1;
2925 t
->flags
.ignore_private
= 1;
2928 t
->flags
.ignore_auth
= 1;
2935 head
= &(*head
)->next
;
2943 free_refreshpattern(refresh_t
** head
)
2947 while ((t
= *head
) != NULL
) {
2949 safe_free(t
->pattern
);
2950 regfree(&t
->compiled_pattern
);
2954 #if USE_HTTP_VIOLATIONS
2955 refresh_nocache_hack
= 0;
2961 dump_string(StoreEntry
* entry
, const char *name
, char *var
)
2964 storeAppendPrintf(entry
, "%s %s\n", name
, var
);
2968 parse_string(char **var
)
2970 char *token
= strtok(NULL
, w_space
);
2976 *var
= xstrdup(token
);
2980 ConfigParser::ParseString(char **var
)
2986 ConfigParser::ParseString(String
*var
)
2988 char *token
= strtok(NULL
, w_space
);
2997 free_string(char **var
)
3003 parse_eol(char *volatile *var
)
3010 unsigned char *token
= (unsigned char *) strtok(NULL
, null_string
);
3018 while (*token
&& xisspace(*token
))
3026 *var
= xstrdup((char *) token
);
3029 #define dump_eol dump_string
3030 #define free_eol free_string
3033 dump_time_t(StoreEntry
* entry
, const char *name
, time_t var
)
3035 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int) var
);
3039 parse_time_t(time_t * var
)
3042 parseTimeLine(&tval
, T_SECOND_STR
, false);
3043 *var
= static_cast<time_t>(tval
/1000);
3047 free_time_t(time_t * var
)
3053 dump_time_msec(StoreEntry
* entry
, const char *name
, time_msec_t var
)
3056 storeAppendPrintf(entry
, "%s %"PRId64
" milliseconds\n", name
, var
);
3058 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int)(var
/1000) );
3062 parse_time_msec(time_msec_t
* var
)
3064 parseTimeLine(var
, T_SECOND_STR
, true);
3068 free_time_msec(time_msec_t
* var
)
3075 dump_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3077 storeAppendPrintf(entry
, "%s %d\n", name
, (int) var
);
3082 dump_b_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3084 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
3089 dump_b_ssize_t(StoreEntry
* entry
, const char *name
, ssize_t var
)
3091 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
3097 dump_kb_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
3099 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_KBYTES_STR
);
3104 dump_b_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
3106 storeAppendPrintf(entry
, "%s %"PRId64
" %s\n", name
, var
, B_BYTES_STR
);
3110 dump_kb_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
3112 storeAppendPrintf(entry
, "%s %"PRId64
" %s\n", name
, var
, B_KBYTES_STR
);
3117 parse_size_t(size_t * var
)
3126 parse_b_size_t(size_t * var
)
3128 parseBytesLine(var
, B_BYTES_STR
);
3133 parse_b_ssize_t(ssize_t
* var
)
3135 parseBytesLineSigned(var
, B_BYTES_STR
);
3141 parse_kb_size_t(size_t * var
)
3143 parseBytesLine(var
, B_KBYTES_STR
);
3148 parse_b_int64_t(int64_t * var
)
3150 parseBytesLine64(var
, B_BYTES_STR
);
3154 parse_kb_int64_t(int64_t * var
)
3156 parseBytesLine64(var
, B_KBYTES_STR
);
3160 free_size_t(size_t * var
)
3167 free_ssize_t(ssize_t
* var
)
3174 free_b_int64_t(int64_t * var
)
3179 #define free_b_size_t free_size_t
3180 #define free_b_ssize_t free_ssize_t
3181 #define free_kb_size_t free_size_t
3182 #define free_mb_size_t free_size_t
3183 #define free_gb_size_t free_size_t
3184 #define free_kb_int64_t free_b_int64_t
3187 dump_u_short(StoreEntry
* entry
, const char *name
, unsigned short var
)
3189 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
3193 free_u_short(unsigned short * u
)
3199 parse_u_short(unsigned short * var
)
3201 ConfigParser::ParseUShort(var
);
3205 ConfigParser::ParseUShort(unsigned short *var
)
3211 ConfigParser::ParseBool(bool *var
)
3213 int i
= GetInteger();
3224 dump_wordlist(StoreEntry
* entry
, const char *name
, wordlist
* list
)
3226 while (list
!= NULL
) {
3227 storeAppendPrintf(entry
, "%s %s\n", name
, list
->key
);
3233 ConfigParser::ParseWordList(wordlist
** list
)
3235 parse_wordlist(list
);
3239 parse_wordlist(wordlist
** list
)
3242 char *t
= strtok(NULL
, "");
3244 while ((token
= strwordtok(NULL
, &t
)))
3245 wordlistAdd(list
, token
);
3248 #if 0 /* now unused */
3250 check_null_wordlist(wordlist
* w
)
3257 check_null_acl_access(acl_access
* a
)
3262 #define free_wordlist wordlistDestroy
3264 #define free_uri_whitespace free_int
3267 parse_uri_whitespace(int *var
)
3269 char *token
= strtok(NULL
, w_space
);
3274 if (!strcasecmp(token
, "strip"))
3275 *var
= URI_WHITESPACE_STRIP
;
3276 else if (!strcasecmp(token
, "deny"))
3277 *var
= URI_WHITESPACE_DENY
;
3278 else if (!strcasecmp(token
, "allow"))
3279 *var
= URI_WHITESPACE_ALLOW
;
3280 else if (!strcasecmp(token
, "encode"))
3281 *var
= URI_WHITESPACE_ENCODE
;
3282 else if (!strcasecmp(token
, "chop"))
3283 *var
= URI_WHITESPACE_CHOP
;
3289 dump_uri_whitespace(StoreEntry
* entry
, const char *name
, int var
)
3293 if (var
== URI_WHITESPACE_ALLOW
)
3295 else if (var
== URI_WHITESPACE_ENCODE
)
3297 else if (var
== URI_WHITESPACE_CHOP
)
3299 else if (var
== URI_WHITESPACE_DENY
)
3304 storeAppendPrintf(entry
, "%s %s\n", name
, s
);
3308 free_removalpolicy(RemovalPolicySettings
** settings
)
3313 free_string(&(*settings
)->type
);
3315 free_wordlist(&(*settings
)->args
);
3323 parse_removalpolicy(RemovalPolicySettings
** settings
)
3326 free_removalpolicy(settings
);
3328 *settings
= new RemovalPolicySettings
;
3330 parse_string(&(*settings
)->type
);
3332 parse_wordlist(&(*settings
)->args
);
3336 dump_removalpolicy(StoreEntry
* entry
, const char *name
, RemovalPolicySettings
* settings
)
3339 storeAppendPrintf(entry
, "%s %s", name
, settings
->type
);
3340 args
= settings
->args
;
3343 storeAppendPrintf(entry
, " %s", args
->key
);
3347 storeAppendPrintf(entry
, "\n");
3351 YesNoNone::configure(bool beSet
)
3353 option
= beSet
? +1 : -1;
3356 YesNoNone::operator void*() const
3358 assert(option
!= 0); // must call configure() first
3359 return option
> 0 ? (void*)this : NULL
;
3364 free_YesNoNone(YesNoNone
*)
3366 // do nothing: no explicit cleanup is required
3370 parse_YesNoNone(YesNoNone
*option
)
3373 parse_onoff(&value
);
3374 option
->configure(value
> 0);
3378 dump_YesNoNone(StoreEntry
* entry
, const char *name
, YesNoNone
&option
)
3380 if (option
.configured())
3381 dump_onoff(entry
, name
, option
? 1 : 0);
3385 free_memcachemode(SquidConfig
* config
)
3391 parse_memcachemode(SquidConfig
* config
)
3393 char *token
= strtok(NULL
, w_space
);
3397 if (strcmp(token
, "always") == 0) {
3398 Config
.onoff
.memory_cache_first
= 1;
3399 Config
.onoff
.memory_cache_disk
= 1;
3400 } else if (strcmp(token
, "disk") == 0) {
3401 Config
.onoff
.memory_cache_first
= 0;
3402 Config
.onoff
.memory_cache_disk
= 1;
3403 } else if (strncmp(token
, "net", 3) == 0) {
3404 Config
.onoff
.memory_cache_first
= 1;
3405 Config
.onoff
.memory_cache_disk
= 0;
3406 } else if (strcmp(token
, "never") == 0) {
3407 Config
.onoff
.memory_cache_first
= 0;
3408 Config
.onoff
.memory_cache_disk
= 0;
3414 dump_memcachemode(StoreEntry
* entry
, const char *name
, SquidConfig
&config
)
3416 storeAppendPrintf(entry
, "%s ", name
);
3417 if (Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3418 storeAppendPrintf(entry
, "always");
3419 else if (!Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3420 storeAppendPrintf(entry
, "disk");
3421 else if (Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3422 storeAppendPrintf(entry
, "network");
3423 else if (!Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3424 storeAppendPrintf(entry
, "none");
3425 storeAppendPrintf(entry
, "\n");
3428 #include "cf_parser.cci"
3431 parseNeighborType(const char *s
)
3433 if (!strcasecmp(s
, "parent"))
3436 if (!strcasecmp(s
, "neighbor"))
3437 return PEER_SIBLING
;
3439 if (!strcasecmp(s
, "neighbour"))
3440 return PEER_SIBLING
;
3442 if (!strcasecmp(s
, "sibling"))
3443 return PEER_SIBLING
;
3445 if (!strcasecmp(s
, "multicast"))
3446 return PEER_MULTICAST
;
3448 debugs(15, 0, "WARNING: Unknown neighbor type: " << s
);
3450 return PEER_SIBLING
;
3455 parse_IpAddress_list(Ip::Address_list
** head
)
3458 Ip::Address_list
*s
;
3461 while ((token
= strtok(NULL
, w_space
))) {
3462 if (GetHostWithPort(token
, &ipa
)) {
3465 head
= &(*head
)->next
;
3467 s
= static_cast<Ip::Address_list
*>(xcalloc(1, sizeof(*s
)));
3477 dump_IpAddress_list(StoreEntry
* e
, const char *n
, const Ip::Address_list
* s
)
3479 char ntoabuf
[MAX_IPSTRLEN
];
3482 storeAppendPrintf(e
, "%s %s\n",
3484 s
->s
.NtoA(ntoabuf
,MAX_IPSTRLEN
));
3490 free_IpAddress_list(Ip::Address_list
** head
)
3492 if (*head
) delete *head
;
3496 #if CURRENTLY_UNUSED
3497 /* This code was previously used by http_port. Left as it really should
3498 * be used by icp_port and htcp_port
3501 check_null_IpAddress_list(const Ip::Address_list
* s
)
3506 #endif /* CURRENTLY_UNUSED */
3507 #endif /* USE_WCCPv2 */
3509 CBDATA_CLASS_INIT(http_port_list
);
3512 parse_http_port_specification(http_port_list
* s
, char *token
)
3515 unsigned short port
= 0;
3519 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3520 s
->name
= xstrdup(token
);
3521 s
->connection_auth_disabled
= false;
3523 if (*token
== '[') {
3526 t
= strchr(host
, ']');
3528 debugs(3, 0, "http(s)_port: missing ']' on IPv6 address: " << token
);
3533 debugs(3, 0, "http(s)_port: missing Port in: " << token
);
3536 if (!Ip::EnableIpv6
) {
3537 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 is not available.");
3540 port
= xatos(t
+ 1);
3541 } else if ((t
= strchr(token
, ':'))) {
3546 port
= xatos(t
+ 1);
3548 } else if ((port
= strtol(token
, &junk
, 10)), !*junk
) {
3550 debugs(3, 3, "http(s)_port: found Listen on Port: " << port
);
3552 debugs(3, 0, "http(s)_port: missing Port: " << token
);
3557 debugs(3, 0, "http(s)_port: Port cannot be 0: " << token
);
3564 if (!Ip::EnableIpv6
)
3566 debugs(3, 3, "http(s)_port: found Listen on wildcard address: *:" << s
->s
.GetPort() );
3567 } else if ( (s
->s
= host
) ) { /* check/parse numeric IPA */
3569 if (!Ip::EnableIpv6
)
3571 debugs(3, 3, "http(s)_port: Listen on Host/IP: " << host
<< " --> " << s
->s
);
3572 } else if ( s
->s
.GetHostByName(host
) ) { /* check/parse for FQDN */
3573 /* dont use ipcache */
3574 s
->defaultsite
= xstrdup(host
);
3576 if (!Ip::EnableIpv6
)
3578 debugs(3, 3, "http(s)_port: found Listen as Host " << s
->defaultsite
<< " on IP: " << s
->s
);
3580 debugs(3, 0, "http(s)_port: failed to resolve Host/IP: " << host
);
3586 parse_http_port_option(http_port_list
* s
, char *token
)
3590 if (strcmp(token
, "accel") == 0) {
3591 if (s
->intercepted
|| s
->spoof_client_ip
) {
3592 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: Accelerator mode requires its own port. It cannot be shared with other modes.");
3595 s
->accel
= s
->vhost
= 1;
3596 } else if (strcmp(token
, "transparent") == 0 || strcmp(token
, "intercept") == 0) {
3597 if (s
->accel
|| s
->spoof_client_ip
) {
3598 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: Intercept mode requires its own interception port. It cannot be shared with other modes.");
3602 Ip::Interceptor
.StartInterception();
3603 /* Log information regarding the port modes under interception. */
3604 debugs(3, DBG_IMPORTANT
, "Starting Authentication on port " << s
->s
);
3605 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (interception enabled)");
3607 /* INET6: until transparent REDIRECT works on IPv6 SOCKET, force wildcard to IPv4 */
3609 debugs(3, DBG_IMPORTANT
, "Disabling IPv6 on port " << s
->s
<< " (interception enabled)");
3610 if ( !s
->s
.SetIPv4() ) {
3611 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 addresses cannot NAT intercept (protocol does not provide NAT)" << s
->s
);
3614 } else if (strcmp(token
, "tproxy") == 0) {
3615 if (s
->intercepted
|| s
->accel
) {
3616 debugs(3,DBG_CRITICAL
, "FATAL: http(s)_port: TPROXY option requires its own interception port. It cannot be shared with other modes.");
3619 s
->spoof_client_ip
= 1;
3620 Ip::Interceptor
.StartTransparency();
3621 /* Log information regarding the port modes under transparency. */
3622 debugs(3, DBG_IMPORTANT
, "Starting IP Spoofing on port " << s
->s
);
3623 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (IP spoofing enabled)");
3625 if (!Ip::Interceptor
.ProbeForTproxy(s
->s
)) {
3626 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: TPROXY support in the system does not work.");
3630 } else if (strncmp(token
, "defaultsite=", 12) == 0) {
3632 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: defaultsite option requires Acceleration mode flag.");
3635 safe_free(s
->defaultsite
);
3636 s
->defaultsite
= xstrdup(token
+ 12);
3637 } else if (strcmp(token
, "vhost") == 0) {
3639 debugs(3, DBG_CRITICAL
, "WARNING: http(s)_port: vhost option is deprecated. Use 'accel' mode flag instead.");
3641 s
->accel
= s
->vhost
= 1;
3642 } else if (strcmp(token
, "no-vhost") == 0) {
3644 debugs(3, DBG_IMPORTANT
, "ERROR: http(s)_port: no-vhost option requires Acceleration mode flag.");
3647 } else if (strcmp(token
, "vport") == 0) {
3649 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3653 } else if (strncmp(token
, "vport=", 6) == 0) {
3655 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3658 s
->vport
= xatos(token
+ 6);
3659 } else if (strncmp(token
, "protocol=", 9) == 0) {
3661 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: protocol option requires Acceleration mode flag.");
3664 s
->protocol
= xstrdup(token
+ 9);
3665 } else if (strcmp(token
, "allow-direct") == 0) {
3667 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: allow-direct option requires Acceleration mode flag.");
3670 s
->allow_direct
= 1;
3671 } else if (strcmp(token
, "act-as-origin") == 0) {
3673 debugs(3, DBG_IMPORTANT
, "ERROR: http(s)_port: act-as-origin option requires Acceleration mode flag.");
3676 } else if (strcmp(token
, "ignore-cc") == 0) {
3677 #if !USE_HTTP_VIOLATIONS
3679 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: ignore-cc option requires Scceleration mode flag.");
3684 } else if (strncmp(token
, "name=", 5) == 0) {
3686 s
->name
= xstrdup(token
+ 5);
3687 } else if (strcmp(token
, "no-connection-auth") == 0) {
3688 s
->connection_auth_disabled
= true;
3689 } else if (strcmp(token
, "connection-auth=off") == 0) {
3690 s
->connection_auth_disabled
= true;
3691 } else if (strcmp(token
, "connection-auth") == 0) {
3692 s
->connection_auth_disabled
= false;
3693 } else if (strcmp(token
, "connection-auth=on") == 0) {
3694 s
->connection_auth_disabled
= false;
3695 } else if (strncmp(token
, "disable-pmtu-discovery=", 23) == 0) {
3696 if (!strcasecmp(token
+ 23, "off"))
3697 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3698 else if (!strcasecmp(token
+ 23, "transparent"))
3699 s
->disable_pmtu_discovery
= DISABLE_PMTU_TRANSPARENT
;
3700 else if (!strcasecmp(token
+ 23, "always"))
3701 s
->disable_pmtu_discovery
= DISABLE_PMTU_ALWAYS
;
3704 } else if (strcmp(token
, "ipv4") == 0) {
3705 if ( !s
->s
.SetIPv4() ) {
3706 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 addresses cannot be used as IPv4-Only. " << s
->s
);
3709 } else if (strcmp(token
, "tcpkeepalive") == 0) {
3710 s
->tcp_keepalive
.enabled
= 1;
3711 } else if (strncmp(token
, "tcpkeepalive=", 13) == 0) {
3712 char *t
= token
+ 13;
3713 s
->tcp_keepalive
.enabled
= 1;
3714 s
->tcp_keepalive
.idle
= atoi(t
);
3718 s
->tcp_keepalive
.interval
= atoi(t
);
3723 s
->tcp_keepalive
.timeout
= atoi(t
);
3727 } else if (strcasecmp(token
, "sslBump") == 0) {
3728 debugs(3, DBG_CRITICAL
, "WARNING: '" << token
<< "' is deprecated " <<
3729 "in http_port. Use 'ssl-bump' instead.");
3730 s
->sslBump
= 1; // accelerated when bumped, otherwise not
3731 } else if (strcmp(token
, "ssl-bump") == 0) {
3732 s
->sslBump
= 1; // accelerated when bumped, otherwise not
3733 } else if (strncmp(token
, "cert=", 5) == 0) {
3735 s
->cert
= xstrdup(token
+ 5);
3736 } else if (strncmp(token
, "key=", 4) == 0) {
3738 s
->key
= xstrdup(token
+ 4);
3739 } else if (strncmp(token
, "version=", 8) == 0) {
3740 s
->version
= xatoi(token
+ 8);
3741 if (s
->version
< 1 || s
->version
> 4)
3743 } else if (strncmp(token
, "options=", 8) == 0) {
3744 safe_free(s
->options
);
3745 s
->options
= xstrdup(token
+ 8);
3746 } else if (strncmp(token
, "cipher=", 7) == 0) {
3747 safe_free(s
->cipher
);
3748 s
->cipher
= xstrdup(token
+ 7);
3749 } else if (strncmp(token
, "clientca=", 9) == 0) {
3750 safe_free(s
->clientca
);
3751 s
->clientca
= xstrdup(token
+ 9);
3752 } else if (strncmp(token
, "cafile=", 7) == 0) {
3753 safe_free(s
->cafile
);
3754 s
->cafile
= xstrdup(token
+ 7);
3755 } else if (strncmp(token
, "capath=", 7) == 0) {
3756 safe_free(s
->capath
);
3757 s
->capath
= xstrdup(token
+ 7);
3758 } else if (strncmp(token
, "crlfile=", 8) == 0) {
3759 safe_free(s
->crlfile
);
3760 s
->crlfile
= xstrdup(token
+ 8);
3761 } else if (strncmp(token
, "dhparams=", 9) == 0) {
3762 safe_free(s
->dhfile
);
3763 s
->dhfile
= xstrdup(token
+ 9);
3764 } else if (strncmp(token
, "sslflags=", 9) == 0) {
3765 safe_free(s
->sslflags
);
3766 s
->sslflags
= xstrdup(token
+ 9);
3767 } else if (strncmp(token
, "sslcontext=", 11) == 0) {
3768 safe_free(s
->sslContextSessionId
);
3769 s
->sslContextSessionId
= xstrdup(token
+ 11);
3770 } else if (strcmp(token
, "generate-host-certificates") == 0) {
3771 s
->generateHostCertificates
= true;
3772 } else if (strcmp(token
, "generate-host-certificates=on") == 0) {
3773 s
->generateHostCertificates
= true;
3774 } else if (strcmp(token
, "generate-host-certificates=off") == 0) {
3775 s
->generateHostCertificates
= false;
3776 } else if (strncmp(token
, "dynamic_cert_mem_cache_size=", 28) == 0) {
3777 parseBytesOptionValue(&s
->dynamicCertMemCacheSize
, B_BYTES_STR
, token
+ 28);
3784 static http_port_list
*
3785 create_http_port(char *portspec
)
3787 http_port_list
*s
= new http_port_list("http");
3788 parse_http_port_specification(s
, portspec
);
3793 add_http_port(char *portspec
)
3795 http_port_list
*s
= create_http_port(portspec
);
3796 // we may need to merge better of the above returns a list with clones
3797 assert(s
->next
== NULL
);
3798 s
->next
= Config
.Sockaddr
.http
;
3799 Config
.Sockaddr
.http
= s
;
3803 clone_http_port_list(http_port_list
*a
)
3805 http_port_list
*b
= new http_port_list(a
->protocol
);
3809 b
->name
= xstrdup(a
->name
);
3811 b
->defaultsite
= xstrdup(a
->defaultsite
);
3813 b
->intercepted
= a
->intercepted
;
3814 b
->spoof_client_ip
= a
->spoof_client_ip
;
3815 b
->accel
= a
->accel
;
3816 b
->allow_direct
= a
->allow_direct
;
3817 b
->vhost
= a
->vhost
;
3818 b
->sslBump
= a
->sslBump
;
3819 b
->vport
= a
->vport
;
3820 b
->connection_auth_disabled
= a
->connection_auth_disabled
;
3821 b
->disable_pmtu_discovery
= a
->disable_pmtu_discovery
;
3823 memcpy( &(b
->tcp_keepalive
), &(a
->tcp_keepalive
), sizeof(a
->tcp_keepalive
));
3826 // AYJ: 2009-07-18: for now SSL does not clone. Configure separate ports with IPs and SSL settings
3829 // XXX: temporary hack to ease move of SSL options to http_port
3830 http_port_list
&http
;
3843 char *sslContextSessionId
;
3844 SSL_CTX
*sslContext
;
3853 parse_http_port_list(http_port_list
** head
)
3855 char *token
= strtok(NULL
, w_space
);
3862 http_port_list
*s
= create_http_port(token
);
3864 /* parse options ... */
3865 while ((token
= strtok(NULL
, w_space
))) {
3866 parse_http_port_option(s
, token
);
3869 if (Ip::EnableIpv6
&IPV6_SPECIAL_SPLITSTACK
&& s
->s
.IsAnyAddr()) {
3870 // clone the port options from *s to *(s->next)
3871 s
->next
= clone_http_port_list(s
);
3872 s
->next
->s
.SetIPv4();
3873 debugs(3, 3, "http(s)_port: clone wildcard address for split-stack: " << s
->s
<< " and " << s
->next
->s
);
3877 head
= &(*head
)->next
;
3883 dump_generic_http_port(StoreEntry
* e
, const char *n
, const http_port_list
* s
)
3885 char buf
[MAX_IPSTRLEN
];
3887 storeAppendPrintf(e
, "%s %s",
3889 s
->s
.ToURL(buf
,MAX_IPSTRLEN
));
3891 // MODES and specific sub-options.
3893 storeAppendPrintf(e
, " intercept");
3895 else if (s
->spoof_client_ip
)
3896 storeAppendPrintf(e
, " tproxy");
3898 else if (s
->accel
) {
3899 storeAppendPrintf(e
, " accel");
3902 storeAppendPrintf(e
, " vhost");
3905 storeAppendPrintf(e
, " vport");
3906 else if (s
->vport
> 0)
3907 storeAppendPrintf(e
, " vport=%d", s
->vport
);
3910 storeAppendPrintf(e
, " defaultsite=%s", s
->defaultsite
);
3912 if (s
->protocol
&& strcmp(s
->protocol
,"http") != 0)
3913 storeAppendPrintf(e
, " protocol=%s", s
->protocol
);
3915 if (s
->allow_direct
)
3916 storeAppendPrintf(e
, " allow-direct");
3919 storeAppendPrintf(e
, " ignore-cc");
3923 // Generic independent options
3926 storeAppendPrintf(e
, " name=%s", s
->name
);
3928 #if USE_HTTP_VIOLATIONS
3929 if (!s
->accel
&& s
->ignore_cc
)
3930 storeAppendPrintf(e
, " ignore-cc");
3933 if (s
->connection_auth_disabled
)
3934 storeAppendPrintf(e
, " connection-auth=off");
3936 storeAppendPrintf(e
, " connection-auth=on");
3938 if (s
->disable_pmtu_discovery
!= DISABLE_PMTU_OFF
) {
3941 if (s
->disable_pmtu_discovery
== DISABLE_PMTU_ALWAYS
)
3944 pmtu
= "transparent";
3946 storeAppendPrintf(e
, " disable-pmtu-discovery=%s", pmtu
);
3949 if (s
->s
.IsAnyAddr() && !s
->s
.IsIPv6())
3950 storeAppendPrintf(e
, " ipv4");
3952 if (s
->tcp_keepalive
.enabled
) {
3953 if (s
->tcp_keepalive
.idle
|| s
->tcp_keepalive
.interval
|| s
->tcp_keepalive
.timeout
) {
3954 storeAppendPrintf(e
, " tcpkeepalive=%d,%d,%d", s
->tcp_keepalive
.idle
, s
->tcp_keepalive
.interval
, s
->tcp_keepalive
.timeout
);
3956 storeAppendPrintf(e
, " tcpkeepalive");
3962 storeAppendPrintf(e
, " ssl-bump");
3965 storeAppendPrintf(e
, " cert=%s", s
->cert
);
3968 storeAppendPrintf(e
, " key=%s", s
->key
);
3971 storeAppendPrintf(e
, " version=%d", s
->version
);
3974 storeAppendPrintf(e
, " options=%s", s
->options
);
3977 storeAppendPrintf(e
, " cipher=%s", s
->cipher
);
3980 storeAppendPrintf(e
, " cafile=%s", s
->cafile
);
3983 storeAppendPrintf(e
, " capath=%s", s
->capath
);
3986 storeAppendPrintf(e
, " crlfile=%s", s
->crlfile
);
3989 storeAppendPrintf(e
, " dhparams=%s", s
->dhfile
);
3992 storeAppendPrintf(e
, " sslflags=%s", s
->sslflags
);
3994 if (s
->sslContextSessionId
)
3995 storeAppendPrintf(e
, " sslcontext=%s", s
->sslContextSessionId
);
3997 if (s
->generateHostCertificates
)
3998 storeAppendPrintf(e
, " generate-host-certificates");
4000 if (s
->dynamicCertMemCacheSize
!= std::numeric_limits
<size_t>::max())
4001 storeAppendPrintf(e
, "dynamic_cert_mem_cache_size=%lu%s\n", (unsigned long)s
->dynamicCertMemCacheSize
, B_BYTES_STR
);
4006 dump_http_port_list(StoreEntry
* e
, const char *n
, const http_port_list
* s
)
4009 dump_generic_http_port(e
, n
, s
);
4010 storeAppendPrintf(e
, "\n");
4016 free_http_port_list(http_port_list
** head
)
4020 while ((s
= *head
) != NULL
) {
4028 // TODO: merge better with parse_http_port_list
4030 parse_https_port_list(https_port_list
** head
)
4035 token
= strtok(NULL
, w_space
);
4040 s
= new https_port_list
;
4041 parse_http_port_specification(&s
->http
, token
);
4043 /* parse options ... */
4044 while ((token
= strtok(NULL
, w_space
))) {
4045 parse_http_port_option(s
, token
);
4049 http_port_list
** headTmp
= &(*head
)->http
.next
;
4050 head
= (https_port_list
**)headTmp
;
4057 dump_https_port_list(StoreEntry
* e
, const char *n
, const https_port_list
* s
)
4059 dump_http_port_list(e
, n
, s
);
4063 free_https_port_list(https_port_list
** head
)
4065 free_http_port_list((http_port_list
**)head
);
4070 check_null_https_port_list(const https_port_list
* s
)
4077 #endif /* USE_SSL */
4080 configFreeMemory(void)
4084 SSL_CTX_free(Config
.ssl_client
.sslContext
);
4089 requirePathnameExists(const char *name
, const char *path
)
4093 char pathbuf
[BUFSIZ
];
4094 assert(path
!= NULL
);
4096 if (Config
.chroot_dir
&& (geteuid() == 0)) {
4097 snprintf(pathbuf
, BUFSIZ
, "%s/%s", Config
.chroot_dir
, path
);
4101 if (stat(path
, &sb
) < 0) {
4102 debugs(0, DBG_CRITICAL
, (opt_parse_cfg_only
?"FATAL ":"") << "ERROR: " << name
<< " " << path
<< ": " << xstrerror());
4103 // keep going to find more issues if we are only checking the config file with "-k parse"
4104 if (opt_parse_cfg_only
)
4106 // this is fatal if it is found during startup or reconfigure
4107 if (opt_send_signal
== -1 || opt_send_signal
== SIGHUP
)
4108 fatalf("%s %s: %s", name
, path
, xstrerror());
4115 return ConfigParser::strtokFile();
4118 #include "AccessLogEntry.h"
4121 parse_access_log(customlog
** logs
)
4123 const char *filename
, *logdef_name
;
4125 customlog
*cl
= (customlog
*)xcalloc(1, sizeof(*cl
));
4127 if ((filename
= strtok(NULL
, w_space
)) == NULL
) {
4132 if (strcmp(filename
, "none") == 0) {
4133 cl
->type
= Log::Format::CLF_NONE
;
4134 aclParseAclList(LegacyParser
, &cl
->aclList
);
4136 logs
= &(*logs
)->next
;
4141 if ((logdef_name
= strtok(NULL
, w_space
)) == NULL
)
4142 logdef_name
= "squid";
4144 debugs(3, 9, "Log definition name '" << logdef_name
<< "' file '" << filename
<< "'");
4146 cl
->filename
= xstrdup(filename
);
4148 /* look for the definition pointer corresponding to this name */
4149 Format::Format
*lf
= Log::TheConfig
.logformats
;
4151 while (lf
!= NULL
) {
4152 debugs(3, 9, "Comparing against '" << lf
->name
<< "'");
4154 if (strcmp(lf
->name
, logdef_name
) == 0)
4161 cl
->type
= Log::Format::CLF_CUSTOM
;
4163 } else if (strcmp(logdef_name
, "auto") == 0) {
4164 debugs(0,0, "WARNING: Log format 'auto' no longer exists. Using 'squid' instead.");
4165 cl
->type
= Log::Format::CLF_SQUID
;
4166 } else if (strcmp(logdef_name
, "squid") == 0) {
4167 cl
->type
= Log::Format::CLF_SQUID
;
4168 } else if (strcmp(logdef_name
, "common") == 0) {
4169 cl
->type
= Log::Format::CLF_COMMON
;
4170 } else if (strcmp(logdef_name
, "combined") == 0) {
4171 cl
->type
= Log::Format::CLF_COMBINED
;
4173 } else if (strcmp(logdef_name
, "icap_squid") == 0) {
4174 cl
->type
= Log::Format::CLF_ICAP_SQUID
;
4176 } else if (strcmp(logdef_name
, "useragent") == 0) {
4177 cl
->type
= Log::Format::CLF_USERAGENT
;
4178 } else if (strcmp(logdef_name
, "referrer") == 0) {
4179 cl
->type
= Log::Format::CLF_REFERER
;
4181 debugs(3, 0, "Log format '" << logdef_name
<< "' is not defined");
4186 aclParseAclList(LegacyParser
, &cl
->aclList
);
4189 logs
= &(*logs
)->next
;
4195 check_null_access_log(customlog
*customlog_definitions
)
4197 return customlog_definitions
== NULL
;
4201 dump_access_log(StoreEntry
* entry
, const char *name
, customlog
* logs
)
4205 for (log
= logs
; log
; log
= log
->next
) {
4206 storeAppendPrintf(entry
, "%s ", name
);
4208 switch (log
->type
) {
4210 case Log::Format::CLF_CUSTOM
:
4211 storeAppendPrintf(entry
, "%s %s", log
->filename
, log
->logFormat
->name
);
4214 case Log::Format::CLF_NONE
:
4215 storeAppendPrintf(entry
, "none");
4218 case Log::Format::CLF_SQUID
:
4219 storeAppendPrintf(entry
, "%s squid", log
->filename
);
4222 case Log::Format::CLF_COMBINED
:
4223 storeAppendPrintf(entry
, "%s combined", log
->filename
);
4226 case Log::Format::CLF_COMMON
:
4227 storeAppendPrintf(entry
, "%s common", log
->filename
);
4231 case Log::Format::CLF_ICAP_SQUID
:
4232 storeAppendPrintf(entry
, "%s icap_squid", log
->filename
);
4235 case Log::Format::CLF_USERAGENT
:
4236 storeAppendPrintf(entry
, "%s useragent", log
->filename
);
4239 case Log::Format::CLF_REFERER
:
4240 storeAppendPrintf(entry
, "%s referrer", log
->filename
);
4243 case Log::Format::CLF_UNKNOWN
:
4248 dump_acl_list(entry
, log
->aclList
);
4250 storeAppendPrintf(entry
, "\n");
4255 free_access_log(customlog
** definitions
)
4257 while (*definitions
) {
4258 customlog
*log
= *definitions
;
4259 *definitions
= log
->next
;
4261 log
->logFormat
= NULL
;
4262 log
->type
= Log::Format::CLF_UNKNOWN
;
4265 aclDestroyAclList(&log
->aclList
);
4267 safe_free(log
->filename
);
4273 /// parses list of integers form name=N1,N2,N3,...
4275 parseNamedIntList(const char *data
, const String
&name
, Vector
<int> &list
)
4277 if (data
&& (strncmp(data
, name
.rawBuf(), name
.size()) == 0)) {
4278 data
+= name
.size();
4283 if (!StringToInt(data
, value
, &data
, 10))
4285 list
.push_back(value
);
4286 if (*data
== '\0' || *data
!= ',')
4291 return data
&& *data
== '\0';
4295 parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4297 #if !HAVE_CPU_AFFINITY
4298 debugs(3, DBG_CRITICAL
, "FATAL: Squid built with no CPU affinity " <<
4299 "support, do not set 'cpu_affinity_map'");
4301 #endif /* HAVE_CPU_AFFINITY */
4303 if (!*cpuAffinityMap
)
4304 *cpuAffinityMap
= new CpuAffinityMap
;
4306 const char *const pToken
= strtok(NULL
, w_space
);
4307 const char *const cToken
= strtok(NULL
, w_space
);
4308 Vector
<int> processes
, cores
;
4309 if (!parseNamedIntList(pToken
, "process_numbers", processes
)) {
4310 debugs(3, DBG_CRITICAL
, "FATAL: bad 'process_numbers' parameter " <<
4311 "in 'cpu_affinity_map'");
4313 } else if (!parseNamedIntList(cToken
, "cores", cores
)) {
4314 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cores' parameter in " <<
4315 "'cpu_affinity_map'");
4317 } else if (!(*cpuAffinityMap
)->add(processes
, cores
)) {
4318 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cpu_affinity_map'; " <<
4319 "process_numbers and cores lists differ in length or " <<
4320 "contain numbers <= 0");
4326 dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
)
4328 if (cpuAffinityMap
) {
4329 storeAppendPrintf(entry
, "%s process_numbers=", name
);
4330 for (size_t i
= 0; i
< cpuAffinityMap
->processes().size(); ++i
) {
4331 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4332 cpuAffinityMap
->processes()[i
]);
4334 storeAppendPrintf(entry
, " cores=");
4335 for (size_t i
= 0; i
< cpuAffinityMap
->processes().size(); ++i
) {
4336 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4337 cpuAffinityMap
->cores()[i
]);
4339 storeAppendPrintf(entry
, "\n");
4344 free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4346 delete *cpuAffinityMap
;
4347 *cpuAffinityMap
= NULL
;
4353 parse_adaptation_service_set_type()
4355 Adaptation::Config::ParseServiceSet();
4359 parse_adaptation_service_chain_type()
4361 Adaptation::Config::ParseServiceChain();
4365 parse_adaptation_access_type()
4367 Adaptation::Config::ParseAccess(LegacyParser
);
4370 #endif /* USE_ADAPTATION */
4376 parse_icap_service_type(Adaptation::Icap::Config
* cfg
)
4378 cfg
->parseService();
4382 free_icap_service_type(Adaptation::Icap::Config
* cfg
)
4388 dump_icap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4390 cfg
.dumpService(entry
, name
);
4394 parse_icap_class_type()
4396 debugs(93, 0, "WARNING: 'icap_class' is depricated. " <<
4397 "Use 'adaptation_service_set' instead");
4398 Adaptation::Config::ParseServiceSet();
4402 parse_icap_access_type()
4404 debugs(93, 0, "WARNING: 'icap_access' is depricated. " <<
4405 "Use 'adaptation_access' instead");
4406 Adaptation::Config::ParseAccess(LegacyParser
);
4415 parse_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4417 cfg
->parseService();
4421 free_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4427 dump_ecap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Ecap::Config
&cfg
)
4429 cfg
.dumpService(entry
, name
);
4432 #endif /* USE_ECAP */
4435 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4440 cfg
->service_failure_limit
= GetInteger();
4442 if ((token
= strtok(NULL
, w_space
)) == NULL
)
4445 if (strcmp(token
,"in") != 0) {
4446 debugs(3, 0, "expecting 'in' on'" << config_input_line
<< "'");
4450 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
4454 d
= static_cast<time_t> (xatoi(token
));
4456 m
= static_cast<time_t> (1);
4460 else if ((token
= strtok(NULL
, w_space
)) == NULL
) {
4461 debugs(3, 0, "No time-units on '" << config_input_line
<< "'");
4463 } else if ((m
= parseTimeUnits(token
, false)) == 0)
4466 cfg
->oldest_service_failure
= (m
* d
);
4469 static void dump_icap_service_failure_limit(StoreEntry
*entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4471 storeAppendPrintf(entry
, "%s %d", name
, cfg
.service_failure_limit
);
4472 if (cfg
.oldest_service_failure
> 0) {
4473 storeAppendPrintf(entry
, " in %d seconds", (int)cfg
.oldest_service_failure
);
4475 storeAppendPrintf(entry
, "\n");
4478 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4480 cfg
->oldest_service_failure
= 0;
4481 cfg
->service_failure_limit
= 0;