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"
49 #include "auth/Config.h"
50 #include "auth/Scheme.h"
51 #include "CacheManager.h"
52 #include "ConfigParser.h"
53 #include "CpuAffinityMap.h"
54 #include "eui/Config.h"
56 #include "esi/Parser.h"
58 #include "HttpRequestMethod.h"
59 #include "ident/Config.h"
60 #include "ip/Intercept.h"
61 #include "ip/QosConfig.h"
63 #include "log/Config.h"
66 #include "ProtoPort.h"
72 #include "StoreFileSystem.h"
82 static void parse_adaptation_service_set_type();
83 static void parse_adaptation_service_chain_type();
84 static void parse_adaptation_access_type();
88 static void parse_icap_service_type(Adaptation::Icap::Config
*);
89 static void dump_icap_service_type(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
90 static void free_icap_service_type(Adaptation::Icap::Config
*);
91 static void parse_icap_class_type();
92 static void parse_icap_access_type();
94 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*);
95 static void dump_icap_service_failure_limit(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
96 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*);
100 static void parse_ecap_service_type(Adaptation::Ecap::Config
*);
101 static void dump_ecap_service_type(StoreEntry
*, const char *, const Adaptation::Ecap::Config
&);
102 static void free_ecap_service_type(Adaptation::Ecap::Config
*);
107 static const char *const T_SECOND_STR
= "second";
108 static const char *const T_MINUTE_STR
= "minute";
109 static const char *const T_HOUR_STR
= "hour";
110 static const char *const T_DAY_STR
= "day";
111 static const char *const T_WEEK_STR
= "week";
112 static const char *const T_FORTNIGHT_STR
= "fortnight";
113 static const char *const T_MONTH_STR
= "month";
114 static const char *const T_YEAR_STR
= "year";
115 static const char *const T_DECADE_STR
= "decade";
117 static const char *const B_BYTES_STR
= "bytes";
118 static const char *const B_KBYTES_STR
= "KB";
119 static const char *const B_MBYTES_STR
= "MB";
120 static const char *const B_GBYTES_STR
= "GB";
122 static const char *const list_sep
= ", \t\n\r";
124 static void parse_logformat(logformat
** logformat_definitions
);
125 static void parse_access_log(customlog
** customlog_definitions
);
126 static int check_null_access_log(customlog
*customlog_definitions
);
128 static void dump_logformat(StoreEntry
* entry
, const char *name
, logformat
* definitions
);
129 static void dump_access_log(StoreEntry
* entry
, const char *name
, customlog
* definitions
);
130 static void free_logformat(logformat
** definitions
);
131 static void free_access_log(customlog
** definitions
);
133 static void update_maxobjsize(void);
134 static void configDoConfigure(void);
135 static void parse_refreshpattern(refresh_t
**);
136 static int parseTimeUnits(const char *unit
);
137 static void parseTimeLine(time_t * tptr
, const char *units
);
138 static void parse_ushort(u_short
* var
);
139 static void parse_string(char **);
140 static void default_all(void);
141 static void defaults_if_none(void);
142 static int parse_line(char *);
143 static void parseBytesLine(size_t * bptr
, const char *units
);
144 static size_t parseBytesUnits(const char *unit
);
145 static void free_all(void);
146 void requirePathnameExists(const char *name
, const char *path
);
147 static OBJH dump_config
;
148 #if USE_HTTP_VIOLATIONS
149 static void dump_http_header_access(StoreEntry
* entry
, const char *name
, header_mangler header
[]);
150 static void parse_http_header_access(header_mangler header
[]);
151 static void free_http_header_access(header_mangler header
[]);
152 static void dump_http_header_replace(StoreEntry
* entry
, const char *name
, header_mangler header
[]);
153 static void parse_http_header_replace(header_mangler
* header
);
154 static void free_http_header_replace(header_mangler
* header
);
156 static void parse_denyinfo(acl_deny_info_list
** var
);
157 static void dump_denyinfo(StoreEntry
* entry
, const char *name
, acl_deny_info_list
* var
);
158 static void free_denyinfo(acl_deny_info_list
** var
);
161 static void parse_IpAddress_list(Ip::Address_list
**);
162 static void dump_IpAddress_list(StoreEntry
*, const char *, const Ip::Address_list
*);
163 static void free_IpAddress_list(Ip::Address_list
**);
165 static int check_null_IpAddress_list(const Ip::Address_list
*);
166 #endif /* CURRENTLY_UNUSED */
167 #endif /* USE_WCCPv2 */
169 static void parse_http_port_list(http_port_list
**);
170 static void dump_http_port_list(StoreEntry
*, const char *, const http_port_list
*);
171 static void free_http_port_list(http_port_list
**);
174 static void parse_https_port_list(https_port_list
**);
175 static void dump_https_port_list(StoreEntry
*, const char *, const https_port_list
*);
176 static void free_https_port_list(https_port_list
**);
178 static int check_null_https_port_list(const https_port_list
*);
182 static void parse_b_size_t(size_t * var
);
183 static void parse_b_int64_t(int64_t * var
);
185 static bool parseNamedIntList(const char *data
, const String
&name
, Vector
<int> &list
);
187 static void parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
188 static void dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
);
189 static void free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
191 static int parseOneConfigFile(const char *file_name
, unsigned int depth
);
194 * LegacyParser is a parser for legacy code that uses the global
195 * approach. This is static so that it is only exposed to cache_cf.
196 * Other modules needing access to a ConfigParser should have it
197 * provided to them in their parserFOO methods.
199 static ConfigParser LegacyParser
= ConfigParser();
204 LegacyParser
.destruct();
208 update_maxobjsize(void)
213 for (i
= 0; i
< Config
.cacheSwap
.n_configured
; i
++) {
214 assert (Config
.cacheSwap
.swapDirs
[i
].getRaw());
216 if (dynamic_cast<SwapDir
*>(Config
.cacheSwap
.swapDirs
[i
].getRaw())->
218 ms
= dynamic_cast<SwapDir
*>(Config
.cacheSwap
.swapDirs
[i
].getRaw())->max_objsize
;
220 store_maxobjsize
= ms
;
224 SetConfigFilename(char const *file_name
, bool is_pipe
)
226 cfg_filename
= file_name
;
231 cfg_filename
= file_name
+ 1;
232 else if ((token
= strrchr(cfg_filename
, '/')))
233 cfg_filename
= token
+ 1;
237 skip_ws(const char* s
)
246 parseManyConfigFiles(char* files
, int depth
)
249 char* saveptr
= NULL
;
254 memset(&globbuf
, 0, sizeof(globbuf
));
255 for (path
= strwordtok(files
, &saveptr
); path
; path
= strwordtok(NULL
, &saveptr
)) {
256 if (glob(path
, globbuf
.gl_pathc
? GLOB_APPEND
: 0, NULL
, &globbuf
) != 0) {
257 fatalf("Unable to find configuration file: %s: %s",
261 for (i
= 0; i
< (int)globbuf
.gl_pathc
; i
++) {
262 error_count
+= parseOneConfigFile(globbuf
.gl_pathv
[i
], depth
);
266 char* file
= strwordtok(files
, &saveptr
);
267 while (file
!= NULL
) {
268 error_count
+= parseOneConfigFile(file
, depth
);
269 file
= strwordtok(NULL
, &saveptr
);
271 #endif /* HAVE_GLOB */
276 ReplaceSubstr(char*& str
, int& len
, unsigned substrIdx
, unsigned substrLen
, const char* newSubstr
)
279 assert(newSubstr
!= NULL
);
281 unsigned newSubstrLen
= strlen(newSubstr
);
282 if (newSubstrLen
> substrLen
)
283 str
= (char*)realloc(str
, len
- substrLen
+ newSubstrLen
+ 1);
285 // move tail part including zero
286 memmove(str
+ substrIdx
+ newSubstrLen
, str
+ substrIdx
+ substrLen
, len
- substrIdx
- substrLen
+ 1);
287 // copy new substring in place
288 memcpy(str
+ substrIdx
, newSubstr
, newSubstrLen
);
294 SubstituteMacro(char*& line
, int& len
, const char* macroName
, const char* substStr
)
296 assert(line
!= NULL
);
297 assert(macroName
!= NULL
);
298 assert(substStr
!= NULL
);
299 unsigned macroNameLen
= strlen(macroName
);
300 while (const char* macroPos
= strstr(line
, macroName
)) // we would replace all occurrences
301 ReplaceSubstr(line
, len
, macroPos
- line
, macroNameLen
, substStr
);
305 ProcessMacros(char*& line
, int& len
)
307 SubstituteMacro(line
, len
, "${process_name}", TheKidName
);
308 SubstituteMacro(line
, len
, "${process_number}", xitoa(KidIdentifier
));
312 trim_trailing_ws(char* str
)
315 unsigned i
= strlen(str
);
316 while ((i
> 0) && xisspace(str
[i
- 1]))
322 FindStatement(const char* line
, const char* statement
)
324 assert(line
!= NULL
);
325 assert(statement
!= NULL
);
327 const char* str
= skip_ws(line
);
328 unsigned len
= strlen(statement
);
329 if (strncmp(str
, statement
, len
) == 0) {
333 else if (xisspace(*str
))
341 StrToInt(const char* str
, long& number
)
346 number
= strtol(str
, &end
, 0);
348 return (end
!= str
) && (*end
== '\0'); // returns true if string contains nothing except number
352 EvalBoolExpr(const char* expr
)
354 assert(expr
!= NULL
);
355 if (strcmp(expr
, "true") == 0) {
357 } else if (strcmp(expr
, "false") == 0) {
359 } else if (const char* equation
= strchr(expr
, '=')) {
360 const char* rvalue
= skip_ws(equation
+ 1);
361 char* lvalue
= (char*)xmalloc(equation
- expr
+ 1);
362 xstrncpy(lvalue
, expr
, equation
- expr
+ 1);
363 trim_trailing_ws(lvalue
);
366 if (!StrToInt(lvalue
, number1
))
367 fatalf("String is not a integer number: '%s'\n", lvalue
);
369 if (!StrToInt(rvalue
, number2
))
370 fatalf("String is not a integer number: '%s'\n", rvalue
);
373 return number1
== number2
;
375 fatalf("Unable to evaluate expression '%s'\n", expr
);
376 return false; // this place cannot be reached
380 parseOneConfigFile(const char *file_name
, unsigned int depth
)
383 const char *orig_cfg_filename
= cfg_filename
;
384 const int orig_config_lineno
= config_lineno
;
386 char *tmp_line
= NULL
;
387 int tmp_line_len
= 0;
391 debugs(3, 1, "Processing Configuration File: " << file_name
<< " (depth " << depth
<< ")");
393 fatalf("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name
);
397 if (file_name
[0] == '!' || file_name
[0] == '|') {
398 fp
= popen(file_name
+ 1, "r");
401 fp
= fopen(file_name
, "r");
405 fatalf("Unable to open configuration file: %s: %s", file_name
, xstrerror());
409 setmode(fileno(fp
), O_TEXT
);
413 SetConfigFilename(file_name
, bool(is_pipe
));
415 memset(config_input_line
, '\0', BUFSIZ
);
419 Vector
<bool> if_states
;
420 while (fgets(config_input_line
, BUFSIZ
, fp
)) {
423 if ((token
= strchr(config_input_line
, '\n')))
426 if ((token
= strchr(config_input_line
, '\r')))
429 if (strncmp(config_input_line
, "#line ", 6) == 0) {
430 static char new_file_name
[1024];
432 static char new_lineno
;
433 token
= config_input_line
+ 6;
434 new_lineno
= strtol(token
, &file
, 0) - 1;
437 continue; /* Not a valid #line directive, may be a comment */
439 while (*file
&& xisspace((unsigned char) *file
))
444 continue; /* Not a valid #line directive, may be a comment */
446 xstrncpy(new_file_name
, file
+ 1, sizeof(new_file_name
));
448 if ((token
= strchr(new_file_name
, '"')))
451 cfg_filename
= new_file_name
;
454 config_lineno
= new_lineno
;
457 if (config_input_line
[0] == '#')
460 if (config_input_line
[0] == '\0')
463 const char* append
= tmp_line_len
? skip_ws(config_input_line
) : config_input_line
;
465 size_t append_len
= strlen(append
);
467 tmp_line
= (char*)xrealloc(tmp_line
, tmp_line_len
+ append_len
+ 1);
469 strcpy(tmp_line
+ tmp_line_len
, append
);
471 tmp_line_len
+= append_len
;
473 if (tmp_line
[tmp_line_len
-1] == '\\') {
474 debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line
<< "'");
475 tmp_line
[--tmp_line_len
] = '\0';
479 trim_trailing_ws(tmp_line
);
480 ProcessMacros(tmp_line
, tmp_line_len
);
481 debugs(3, 5, "Processing: '" << tmp_line
<< "'");
483 if (const char* expr
= FindStatement(tmp_line
, "if")) {
484 if_states
.push_back(EvalBoolExpr(expr
)); // store last if-statement meaning
485 } else if (FindStatement(tmp_line
, "endif")) {
486 if (!if_states
.empty())
487 if_states
.pop_back(); // remove last if-statement meaning
489 fatalf("'endif' without 'if'\n");
490 } else if (FindStatement(tmp_line
, "else")) {
491 if (!if_states
.empty())
492 if_states
.back() = !if_states
.back();
494 fatalf("'else' without 'if'\n");
495 } else if (if_states
.empty() || if_states
.back()) { // test last if-statement meaning if present
496 /* Handle includes here */
497 if (tmp_line_len
>= 9 && strncmp(tmp_line
, "include", 7) == 0 && xisspace(tmp_line
[7])) {
498 err_count
+= parseManyConfigFiles(tmp_line
+ 8, depth
+ 1);
499 } else if (!parse_line(tmp_line
)) {
500 debugs(3, 0, HERE
<< cfg_filename
<< ":" << config_lineno
<< " unrecognized: '" << tmp_line
<< "'");
509 if (!if_states
.empty())
510 fatalf("if-statement without 'endif'\n");
513 int ret
= pclose(fp
);
516 fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name
, ret
);
521 cfg_filename
= orig_cfg_filename
;
522 config_lineno
= orig_config_lineno
;
528 parseConfigFile(const char *file_name
)
531 CacheManager
*manager
=CacheManager::GetInstance();
537 ACLMethodData::ThePurgeCount
= 0;
540 err_count
= parseOneConfigFile(file_name
, 0);
545 * We must call configDoConfigure() before leave_suid() because
546 * configDoConfigure() is where we turn username strings into
551 if (!Config
.chroot_dir
) {
553 setUmask(Config
.umask
);
554 _db_init(Debug::cache_log
, Debug::debugOptions
);
558 if (opt_send_signal
== -1) {
559 manager
->registerAction("config",
560 "Current Squid Configuration",
570 configDoConfigure(void)
572 memset(&Config2
, '\0', sizeof(SquidConfig2
));
573 /* init memory as early as possible */
577 if (Config
.cacheSwap
.swapDirs
== NULL
) {
578 /* Memory-only cache probably in effect. */
579 /* turn off the cache rebuild delays... */
580 StoreController::store_dirs_rebuilding
= 0;
583 if (Debug::rotateNumber
< 0) {
584 Debug::rotateNumber
= Config
.Log
.rotateNumber
;
587 #if SIZEOF_OFF_T <= 4
588 if (Config
.Store
.maxObjectSize
> 0x7FFF0000) {
589 debugs(3, 0, "WARNING: This Squid binary can not handle files larger than 2GB. Limiting maximum_object_size to just below 2GB");
590 Config
.Store
.maxObjectSize
= 0x7FFF0000;
593 if (0 == Store::Root().maxSize())
594 /* people might want a zero-sized cache on purpose */
596 else if (Store::Root().maxSize() < (Config
.memMaxSize
>> 10))
597 /* This is bogus. folk with NULL caches will want this */
598 debugs(3, 0, "WARNING cache_mem is larger than total disk cache space!");
600 if (Config
.Announce
.period
> 0) {
601 Config
.onoff
.announce
= 1;
602 } else if (Config
.Announce
.period
< 1) {
603 Config
.Announce
.period
= 86400 * 365; /* one year */
604 Config
.onoff
.announce
= 0;
607 if (Config
.onoff
.httpd_suppress_version_string
)
608 visible_appname_string
= (char *)appname_string
;
610 visible_appname_string
= (char const *)APP_FULLNAME
;
614 if (Config
.dnsChildren
.n_max
< 1)
615 fatal("No dnsservers allocated");
619 if (Config
.Program
.redirect
) {
620 if (Config
.redirectChildren
.n_max
< 1) {
621 Config
.redirectChildren
.n_max
= 0;
622 wordlistDestroy(&Config
.Program
.redirect
);
626 if (Config
.appendDomain
)
627 if (*Config
.appendDomain
!= '.')
628 fatal("append_domain must begin with a '.'");
630 if (Config
.errHtmlText
== NULL
)
631 Config
.errHtmlText
= xstrdup(null_string
);
635 snprintf(ThisCache
, sizeof(ThisCache
), "%s (%s)",
637 visible_appname_string
);
640 * the extra space is for loop detection in client_side.c -- we search
641 * for substrings in the Via header.
643 snprintf(ThisCache2
, sizeof(ThisCache
), " %s (%s)",
645 visible_appname_string
);
647 /* Use visible_hostname as default surrogate_id */
648 if (!Config
.Accel
.surrogate_id
) {
649 const char *t
= getMyHostname();
650 Config
.Accel
.surrogate_id
= xstrdup( (t
?t
:"unset-id") );
653 if (!Config
.udpMaxHitObjsz
|| Config
.udpMaxHitObjsz
> SQUID_UDP_SO_SNDBUF
)
654 Config
.udpMaxHitObjsz
= SQUID_UDP_SO_SNDBUF
;
656 if (Config
.appendDomain
)
657 Config
.appendDomainLen
= strlen(Config
.appendDomain
);
659 Config
.appendDomainLen
= 0;
661 if (Config
.connect_retries
> 10) {
662 debugs(0,DBG_CRITICAL
, "WARNING: connect_retries cannot be larger than 10. Resetting to 10.");
663 Config
.connect_retries
= 10;
666 requirePathnameExists("MIME Config Table", Config
.mimeTablePathname
);
669 requirePathnameExists("cache_dns_program", Config
.Program
.dnsserver
);
673 requirePathnameExists("unlinkd_program", Config
.Program
.unlinkd
);
675 requirePathnameExists("logfile_daemon", Log::TheConfig
.logfile_daemon
);
676 if (Config
.Program
.redirect
)
677 requirePathnameExists("redirect_program", Config
.Program
.redirect
->key
);
679 requirePathnameExists("Icon Directory", Config
.icons
.directory
);
681 if (Config
.errorDirectory
)
682 requirePathnameExists("Error Directory", Config
.errorDirectory
);
684 #if USE_HTTP_VIOLATIONS
689 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
690 if (!R
->flags
.override_expire
)
693 debugs(22, 1, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP");
698 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
699 if (!R
->flags
.override_lastmod
)
702 debugs(22, 1, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP");
707 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
708 if (!R
->flags
.reload_into_ims
)
711 debugs(22, 1, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP");
716 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
717 if (!R
->flags
.ignore_reload
)
720 debugs(22, 1, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP");
725 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
726 if (!R
->flags
.ignore_no_cache
)
729 debugs(22, 1, "WARNING: use of 'ignore-no-cache' in 'refresh_pattern' violates HTTP");
734 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
735 if (!R
->flags
.ignore_no_store
)
738 debugs(22, 1, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP");
743 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
744 if (!R
->flags
.ignore_must_revalidate
)
746 debugs(22, 1, "WARNING: use of 'ignore-must-revalidate' in 'refresh_pattern' violates HTTP");
750 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
751 if (!R
->flags
.ignore_private
)
754 debugs(22, 1, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP");
759 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
760 if (!R
->flags
.ignore_auth
)
763 debugs(22, 1, "WARNING: use of 'ignore-auth' in 'refresh_pattern' violates HTTP");
770 #if !USE_HTTP_VIOLATIONS
771 Config
.onoff
.via
= 1;
774 if (!Config
.onoff
.via
)
775 debugs(22, 1, "WARNING: HTTP requires the use of Via");
779 // we enable runtime PURGE checks if there is at least one PURGE method ACL
780 // TODO: replace with a dedicated "purge" ACL option?
781 Config2
.onoff
.enable_purge
= (ACLMethodData::ThePurgeCount
> 0);
783 Config2
.onoff
.mangle_request_headers
= httpReqHdrManglersConfigured();
785 if (geteuid() == 0) {
786 if (NULL
!= Config
.effectiveUser
) {
788 struct passwd
*pwd
= getpwnam(Config
.effectiveUser
);
792 * Andres Kroonmaa <andre@online.ee>:
793 * Some getpwnam() implementations (Solaris?) require
794 * an available FD < 256 for opening a FILE* to the
797 * This should be safe at startup, but might still fail
798 * during reconfigure.
800 fatalf("getpwnam failed to find userid for effective user '%s'",
801 Config
.effectiveUser
);
805 Config2
.effectiveUserID
= pwd
->pw_uid
;
807 Config2
.effectiveGroupID
= pwd
->pw_gid
;
811 if (pwd
->pw_dir
&& *pwd
->pw_dir
) {
813 char *env_str
= (char *)xcalloc((len
= strlen(pwd
->pw_dir
) + 6), 1);
814 snprintf(env_str
, len
, "HOME=%s", pwd
->pw_dir
);
822 Config2
.effectiveUserID
= geteuid();
823 Config2
.effectiveGroupID
= getegid();
826 if (NULL
!= Config
.effectiveGroup
) {
828 struct group
*grp
= getgrnam(Config
.effectiveGroup
);
831 fatalf("getgrnam failed to find groupid for effective group '%s'",
832 Config
.effectiveGroup
);
836 Config2
.effectiveGroupID
= grp
->gr_gid
;
839 HttpRequestMethod::Configure(Config
);
842 debugs(3, 1, "Initializing https proxy context");
844 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
);
850 for (p
= Config
.peers
; p
!= NULL
; p
= p
->next
) {
852 debugs(3, 1, "Initializing cache_peer " << p
->name
<< " SSL context");
853 p
->sslContext
= sslCreateClientContext(p
->sslcert
, p
->sslkey
, p
->sslversion
, p
->sslcipher
, p
->ssloptions
, p
->sslflags
, p
->sslcafile
, p
->sslcapath
, p
->sslcrlfile
);
862 for (s
= Config
.Sockaddr
.http
; s
!= NULL
; s
= (http_port_list
*) s
->next
) {
863 if (!s
->cert
&& !s
->key
)
866 debugs(3, 1, "Initializing http_port " << s
->http
.s
<< " SSL context");
868 s
->sslContext
= sslCreateServerContext(s
->cert
, s
->key
, s
->version
, s
->cipher
, s
->options
, s
->sslflags
, s
->clientca
, s
->cafile
, s
->capath
, s
->crlfile
, s
->dhfile
, s
->sslcontext
);
876 for (s
= Config
.Sockaddr
.https
; s
!= NULL
; s
= (https_port_list
*) s
->http
.next
) {
877 debugs(3, 1, "Initializing https_port " << s
->http
.s
<< " SSL context");
879 s
->sslContext
= sslCreateServerContext(s
->cert
, s
->key
, s
->version
, s
->cipher
, s
->options
, s
->sslflags
, s
->clientca
, s
->cafile
, s
->capath
, s
->crlfile
, s
->dhfile
, s
->sslcontext
);
886 /* Parse a time specification from the config file. Store the
887 * result in 'tptr', after converting it to 'units' */
889 parseTimeLine(time_t * tptr
, const char *units
)
896 if ((u
= parseTimeUnits(units
)) == 0)
899 if ((token
= strtok(NULL
, w_space
)) == NULL
)
904 m
= u
; /* default to 'units' if none specified */
908 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
909 debugs(3, 0, "WARNING: No units on '" <<
910 config_input_line
<< "', assuming " <<
912 else if ((m
= parseTimeUnits(token
)) == 0)
915 *tptr
= static_cast<time_t> (m
* d
/ u
);
919 parseTimeUnits(const char *unit
)
921 if (!strncasecmp(unit
, T_SECOND_STR
, strlen(T_SECOND_STR
)))
924 if (!strncasecmp(unit
, T_MINUTE_STR
, strlen(T_MINUTE_STR
)))
927 if (!strncasecmp(unit
, T_HOUR_STR
, strlen(T_HOUR_STR
)))
930 if (!strncasecmp(unit
, T_DAY_STR
, strlen(T_DAY_STR
)))
933 if (!strncasecmp(unit
, T_WEEK_STR
, strlen(T_WEEK_STR
)))
936 if (!strncasecmp(unit
, T_FORTNIGHT_STR
, strlen(T_FORTNIGHT_STR
)))
939 if (!strncasecmp(unit
, T_MONTH_STR
, strlen(T_MONTH_STR
)))
942 if (!strncasecmp(unit
, T_YEAR_STR
, strlen(T_YEAR_STR
)))
943 return static_cast<int>(86400 * 365.2522);
945 if (!strncasecmp(unit
, T_DECADE_STR
, strlen(T_DECADE_STR
)))
946 return static_cast<int>(86400 * 365.2522 * 10);
948 debugs(3, 1, "parseTimeUnits: unknown time unit '" << unit
<< "'");
954 parseBytesLine64(int64_t * bptr
, const char *units
)
961 if ((u
= parseBytesUnits(units
)) == 0) {
966 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
971 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
978 m
= u
; /* default to 'units' if none specified */
982 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
983 debugs(3, 0, "WARNING: No units on '" <<
984 config_input_line
<< "', assuming " <<
986 else if ((m
= parseBytesUnits(token
)) == 0) {
991 *bptr
= static_cast<int64_t>(m
* d
/ u
);
993 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
999 parseBytesLine(size_t * bptr
, const char *units
)
1006 if ((u
= parseBytesUnits(units
)) == 0) {
1011 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
1016 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1017 *bptr
= static_cast<size_t>(-1);
1023 m
= u
; /* default to 'units' if none specified */
1027 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1028 debugs(3, 0, "WARNING: No units on '" <<
1029 config_input_line
<< "', assuming " <<
1030 d
<< " " << units
);
1031 else if ((m
= parseBytesUnits(token
)) == 0) {
1036 *bptr
= static_cast<size_t>(m
* d
/ u
);
1038 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
1043 parseBytesUnits(const char *unit
)
1045 if (!strncasecmp(unit
, B_BYTES_STR
, strlen(B_BYTES_STR
)))
1048 if (!strncasecmp(unit
, B_KBYTES_STR
, strlen(B_KBYTES_STR
)))
1051 if (!strncasecmp(unit
, B_MBYTES_STR
, strlen(B_MBYTES_STR
)))
1054 if (!strncasecmp(unit
, B_GBYTES_STR
, strlen(B_GBYTES_STR
)))
1057 debugs(3, DBG_CRITICAL
, "WARNING: Unknown bytes unit '" << unit
<< "'");
1062 /*****************************************************************************
1064 *****************************************************************************/
1067 dump_acl(StoreEntry
* entry
, const char *name
, ACL
* ae
)
1072 while (ae
!= NULL
) {
1073 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
);
1074 storeAppendPrintf(entry
, "%s %s %s ",
1081 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
<< " " << v
->key
);
1082 storeAppendPrintf(entry
, "%s ", v
->key
);
1086 storeAppendPrintf(entry
, "\n");
1087 wordlistDestroy(&w
);
1093 parse_acl(ACL
** ae
)
1095 ACL::ParseAclLine(LegacyParser
, ae
);
1105 dump_acl_list(StoreEntry
* entry
, ACLList
* head
)
1109 for (l
= head
; l
; l
= l
->next
) {
1110 storeAppendPrintf(entry
, " %s%s",
1111 l
->op
? null_string
: "!",
1117 dump_acl_access(StoreEntry
* entry
, const char *name
, acl_access
* head
)
1121 for (l
= head
; l
; l
= l
->next
) {
1122 storeAppendPrintf(entry
, "%s %s",
1124 l
->allow
? "Allow" : "Deny");
1125 dump_acl_list(entry
, l
->aclList
);
1126 storeAppendPrintf(entry
, "\n");
1131 parse_acl_access(acl_access
** head
)
1133 aclParseAccessLine(LegacyParser
, head
);
1137 free_acl_access(acl_access
** head
)
1139 aclDestroyAccessList(head
);
1143 dump_address(StoreEntry
* entry
, const char *name
, Ip::Address
&addr
)
1145 char buf
[MAX_IPSTRLEN
];
1146 storeAppendPrintf(entry
, "%s %s\n", name
, addr
.NtoA(buf
,MAX_IPSTRLEN
) );
1150 parse_address(Ip::Address
*addr
)
1152 char *token
= strtok(NULL
, w_space
);
1159 if (!strcmp(token
,"any_addr")) {
1162 } else if ( (!strcmp(token
,"no_addr")) || (!strcmp(token
,"full_mask")) ) {
1170 free_address(Ip::Address
*addr
)
1175 CBDATA_TYPE(acl_address
);
1178 dump_acl_address(StoreEntry
* entry
, const char *name
, acl_address
* head
)
1180 char buf
[MAX_IPSTRLEN
];
1183 for (l
= head
; l
; l
= l
->next
) {
1184 if (!l
->addr
.IsAnyAddr())
1185 storeAppendPrintf(entry
, "%s %s", name
, l
->addr
.NtoA(buf
,MAX_IPSTRLEN
));
1187 storeAppendPrintf(entry
, "%s autoselect", name
);
1189 dump_acl_list(entry
, l
->aclList
);
1191 storeAppendPrintf(entry
, "\n");
1196 freed_acl_address(void *data
)
1198 acl_address
*l
= static_cast<acl_address
*>(data
);
1199 aclDestroyAclList(&l
->aclList
);
1203 parse_acl_address(acl_address
** head
)
1206 acl_address
**tail
= head
; /* sane name below */
1207 CBDATA_INIT_TYPE_FREECB(acl_address
, freed_acl_address
);
1208 l
= cbdataAlloc(acl_address
);
1209 parse_address(&l
->addr
);
1210 aclParseAclList(LegacyParser
, &l
->aclList
);
1213 tail
= &(*tail
)->next
;
1219 free_acl_address(acl_address
** head
)
1222 acl_address
*l
= *head
;
1228 CBDATA_TYPE(acl_tos
);
1231 dump_acl_tos(StoreEntry
* entry
, const char *name
, acl_tos
* head
)
1235 for (l
= head
; l
; l
= l
->next
) {
1237 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->tos
);
1239 storeAppendPrintf(entry
, "%s none", name
);
1241 dump_acl_list(entry
, l
->aclList
);
1243 storeAppendPrintf(entry
, "\n");
1248 freed_acl_tos(void *data
)
1250 acl_tos
*l
= static_cast<acl_tos
*>(data
);
1251 aclDestroyAclList(&l
->aclList
);
1255 parse_acl_tos(acl_tos
** head
)
1258 acl_tos
**tail
= head
; /* sane name below */
1261 char *token
= strtok(NULL
, w_space
);
1268 if (sscanf(token
, "0x%x%c", &tos
, &junk
) != 1) {
1273 if (tos
< 0 || tos
> 255) {
1278 CBDATA_INIT_TYPE_FREECB(acl_tos
, freed_acl_tos
);
1280 l
= cbdataAlloc(acl_tos
);
1284 aclParseAclList(LegacyParser
, &l
->aclList
);
1287 tail
= &(*tail
)->next
;
1293 free_acl_tos(acl_tos
** head
)
1303 CBDATA_TYPE(acl_size_t
);
1306 dump_acl_b_size_t(StoreEntry
* entry
, const char *name
, acl_size_t
* head
)
1310 for (l
= head
; l
; l
= l
->next
) {
1312 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) l
->size
, B_BYTES_STR
);
1314 storeAppendPrintf(entry
, "%s none", name
);
1316 dump_acl_list(entry
, l
->aclList
);
1318 storeAppendPrintf(entry
, "\n");
1323 freed_acl_b_size_t(void *data
)
1325 acl_size_t
*l
= static_cast<acl_size_t
*>(data
);
1326 aclDestroyAclList(&l
->aclList
);
1330 parse_acl_b_size_t(acl_size_t
** head
)
1333 acl_size_t
**tail
= head
; /* sane name below */
1335 CBDATA_INIT_TYPE_FREECB(acl_size_t
, freed_acl_b_size_t
);
1337 l
= cbdataAlloc(acl_size_t
);
1339 parse_b_int64_t(&l
->size
);
1341 aclParseAclList(LegacyParser
, &l
->aclList
);
1344 tail
= &(*tail
)->next
;
1350 free_acl_b_size_t(acl_size_t
** head
)
1353 acl_size_t
*l
= *head
;
1362 #include "DelayPools.h"
1363 #include "DelayConfig.h"
1364 /* do nothing - free_delay_pool_count is the magic free function.
1365 * this is why delay_pool_count isn't just marked TYPE: ushort
1367 #define free_delay_pool_class(X)
1368 #define free_delay_pool_access(X)
1369 #define free_delay_pool_rates(X)
1370 #define dump_delay_pool_class(X, Y, Z)
1371 #define dump_delay_pool_access(X, Y, Z)
1372 #define dump_delay_pool_rates(X, Y, Z)
1375 free_delay_pool_count(DelayConfig
* cfg
)
1377 cfg
->freePoolCount();
1381 dump_delay_pool_count(StoreEntry
* entry
, const char *name
, DelayConfig
&cfg
)
1383 cfg
.dumpPoolCount (entry
, name
);
1387 parse_delay_pool_count(DelayConfig
* cfg
)
1389 cfg
->parsePoolCount();
1393 parse_delay_pool_class(DelayConfig
* cfg
)
1395 cfg
->parsePoolClass();
1399 parse_delay_pool_rates(DelayConfig
* cfg
)
1401 cfg
->parsePoolRates();
1405 parse_delay_pool_access(DelayConfig
* cfg
)
1407 cfg
->parsePoolAccess(LegacyParser
);
1412 #if USE_HTTP_VIOLATIONS
1414 dump_http_header_access(StoreEntry
* entry
, const char *name
, header_mangler header
[])
1418 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1419 if (header
[i
].access_list
!= NULL
) {
1420 storeAppendPrintf(entry
, "%s ", name
);
1421 dump_acl_access(entry
, httpHeaderNameById(i
),
1422 header
[i
].access_list
);
1428 parse_http_header_access(header_mangler header
[])
1433 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1434 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1435 debugs(3, 0, "parse_http_header_access: missing header name.");
1439 /* Now lookup index of header. */
1440 id
= httpHeaderIdByNameDef(t
, strlen(t
));
1442 if (strcmp(t
, "All") == 0)
1444 else if (strcmp(t
, "Other") == 0)
1446 else if (id
== -1) {
1447 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1448 debugs(3, 0, "parse_http_header_access: unknown header name '" << t
<< "'");
1452 if (id
!= HDR_ENUM_END
) {
1453 parse_acl_access(&header
[id
].access_list
);
1455 char *next_string
= t
+ strlen(t
) - 1;
1457 *(next_string
+ 1) = ' ';
1459 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1460 char *new_string
= xstrdup(next_string
);
1461 strtok(new_string
, w_space
);
1462 parse_acl_access(&header
[i
].access_list
);
1463 safe_free(new_string
);
1469 free_http_header_access(header_mangler header
[])
1473 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1474 free_acl_access(&header
[i
].access_list
);
1479 dump_http_header_replace(StoreEntry
* entry
, const char *name
, header_mangler
1484 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1485 if (NULL
== header
[i
].replacement
)
1488 storeAppendPrintf(entry
, "%s %s %s\n", name
, httpHeaderNameById(i
),
1489 header
[i
].replacement
);
1494 parse_http_header_replace(header_mangler header
[])
1499 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1500 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1501 debugs(3, 0, "parse_http_header_replace: missing header name.");
1505 /* Now lookup index of header. */
1506 id
= httpHeaderIdByNameDef(t
, strlen(t
));
1508 if (strcmp(t
, "All") == 0)
1510 else if (strcmp(t
, "Other") == 0)
1512 else if (id
== -1) {
1513 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1514 debugs(3, 0, "parse_http_header_replace: unknown header name " << t
<< ".");
1519 if (id
!= HDR_ENUM_END
) {
1520 if (header
[id
].replacement
!= NULL
)
1521 safe_free(header
[id
].replacement
);
1523 header
[id
].replacement
= xstrdup(t
+ strlen(t
) + 1);
1525 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1526 if (header
[i
].replacement
!= NULL
)
1527 safe_free(header
[i
].replacement
);
1529 header
[i
].replacement
= xstrdup(t
+ strlen(t
) + 1);
1535 free_http_header_replace(header_mangler header
[])
1539 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1540 if (header
[i
].replacement
!= NULL
)
1541 safe_free(header
[i
].replacement
);
1548 dump_cachedir(StoreEntry
* entry
, const char *name
, SquidConfig::_cacheSwap swap
)
1554 for (i
= 0; i
< swap
.n_configured
; i
++) {
1555 s
= dynamic_cast<SwapDir
*>(swap
.swapDirs
[i
].getRaw());
1557 storeAppendPrintf(entry
, "%s %s %s", name
, s
->type(), s
->path
);
1559 storeAppendPrintf(entry
, "\n");
1564 check_null_string(char *s
)
1570 parse_authparam(Auth::authConfig
* config
)
1575 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1578 if ((param_str
= strtok(NULL
, w_space
)) == NULL
)
1581 /* find a configuration for the scheme in the currently parsed configs... */
1582 AuthConfig
*schemeCfg
= AuthConfig::Find(type_str
);
1584 if (schemeCfg
== NULL
) {
1585 /* Create a configuration based on the scheme info */
1586 AuthScheme::Pointer theScheme
= AuthScheme::Find(type_str
);
1588 if (theScheme
== NULL
) {
1589 debugs(3, DBG_CRITICAL
, "Parsing Config File: Unknown authentication scheme '" << type_str
<< "'.");
1593 config
->push_back(theScheme
->createConfig());
1594 schemeCfg
= AuthConfig::Find(type_str
);
1595 if (schemeCfg
== NULL
) {
1596 debugs(3, DBG_CRITICAL
, "Parsing Config File: Corruption configuring authentication scheme '" << type_str
<< "'.");
1601 schemeCfg
->parse(schemeCfg
, config
->size(), param_str
);
1605 free_authparam(Auth::authConfig
* cfg
)
1607 /* Wipe the Auth globals and Detach/Destruct component config + state. */
1610 /* remove our pointers to the probably-dead sub-configs */
1611 while (cfg
->size()) {
1615 /* on reconfigure initialize new auth schemes for the new config. */
1616 if (reconfiguring
) {
1622 dump_authparam(StoreEntry
* entry
, const char *name
, authConfig cfg
)
1624 for (authConfig::iterator i
= cfg
.begin(); i
!= cfg
.end(); ++i
)
1625 (*i
)->dump(entry
, name
, (*i
));
1628 /* TODO: just return the object, the # is irrelevant */
1630 find_fstype(char *type
)
1632 for (size_t i
= 0; i
< StoreFileSystem::FileSystems().size(); ++i
)
1633 if (strcasecmp(type
, StoreFileSystem::FileSystems().items
[i
]->type()) == 0)
1640 parse_cachedir(SquidConfig::_cacheSwap
* swap
)
1644 RefCount
<SwapDir
> sd
;
1648 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1651 if ((path_str
= strtok(NULL
, w_space
)) == NULL
)
1654 fs
= find_fstype(type_str
);
1659 /* reconfigure existing dir */
1661 for (i
= 0; i
< swap
->n_configured
; i
++) {
1662 assert (swap
->swapDirs
[i
].getRaw());
1664 if ((strcasecmp(path_str
, dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw())->path
)) == 0) {
1665 /* this is specific to on-fs Stores. The right
1666 * way to handle this is probably to have a mapping
1667 * from paths to stores, and have on-fs stores
1668 * register with that, and lookip in that in their
1669 * own setup logic. RBC 20041225. TODO.
1672 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw());
1674 if (sd
->type() != StoreFileSystem::FileSystems().items
[fs
]->type()) {
1675 debugs(3, 0, "ERROR: Can't change type of existing cache_dir " <<
1676 sd
->type() << " " << sd
->path
<< " to " << type_str
<< ". Restart required");
1680 sd
->reconfigure (i
, path_str
);
1682 update_maxobjsize();
1689 if (swap
->n_configured
> 63) {
1690 /* 7 bits, signed */
1691 debugs(3, DBG_CRITICAL
, "WARNING: There is a fixed maximum of 63 cache_dir entries Squid can handle.");
1692 debugs(3, DBG_CRITICAL
, "WARNING: '" << path_str
<< "' is one to many.");
1697 allocate_new_swapdir(swap
);
1699 swap
->swapDirs
[swap
->n_configured
] = StoreFileSystem::FileSystems().items
[fs
]->createSwapDir();
1701 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[swap
->n_configured
].getRaw());
1703 /* parse the FS parameters and options */
1704 sd
->parse(swap
->n_configured
, path_str
);
1706 ++swap
->n_configured
;
1708 /* Update the max object size */
1709 update_maxobjsize();
1713 peer_type_str(const peer_t type
)
1715 const char * result
;
1727 case PEER_MULTICAST
:
1728 result
= "multicast";
1740 dump_peer(StoreEntry
* entry
, const char *name
, peer
* p
)
1744 LOCAL_ARRAY(char, xname
, 128);
1747 storeAppendPrintf(entry
, "%s %s %s %d %d name=%s",
1754 dump_peer_options(entry
, p
);
1756 for (d
= p
->peer_domain
; d
; d
= d
->next
) {
1757 storeAppendPrintf(entry
, "cache_peer_domain %s %s%s\n",
1759 d
->do_ping
? null_string
: "!",
1764 snprintf(xname
, 128, "cache_peer_access %s", p
->name
);
1765 dump_acl_access(entry
, xname
, p
->access
);
1768 for (t
= p
->typelist
; t
; t
= t
->next
) {
1769 storeAppendPrintf(entry
, "neighbor_type_domain %s %s %s\n",
1771 peer_type_str(t
->type
),
1780 * utility function to prevent getservbyname() being called with a numeric value
1781 * on Windows at least it returns garage results.
1784 isUnsignedNumeric(const char *str
, size_t len
)
1786 if (len
< 1) return false;
1788 for (; len
>0 && *str
; str
++, len
--) {
1789 if (! isdigit(*str
))
1796 \param proto 'tcp' or 'udp' for protocol
1797 \returns Port the named service is supposed to be listening on.
1800 GetService(const char *proto
)
1802 struct servent
*port
= NULL
;
1803 /** Parses a port number or service name from the squid.conf */
1804 char *token
= strtok(NULL
, w_space
);
1805 if (token
== NULL
) {
1807 return 0; /* NEVER REACHED */
1809 /** Returns either the service port number from /etc/services */
1810 if ( !isUnsignedNumeric(token
, strlen(token
)) )
1811 port
= getservbyname(token
, proto
);
1813 return ntohs((u_short
)port
->s_port
);
1815 /** Or a numeric translation of the config text. */
1816 return xatos(token
);
1820 \returns Port the named TCP service is supposed to be listening on.
1821 \copydoc GetService(const char *proto)
1826 return GetService("tcp");
1830 \returns Port the named UDP service is supposed to be listening on.
1831 \copydoc GetService(const char *proto)
1836 return GetService("udp");
1840 parse_peer(peer
** head
)
1844 CBDATA_INIT_TYPE_FREECB(peer
, peerDestroy
);
1845 p
= cbdataAlloc(peer
);
1846 p
->http_port
= CACHE_HTTP_PORT
;
1847 p
->icp
.port
= CACHE_ICP_PORT
;
1850 p
->stats
.logged_state
= PEER_ALIVE
;
1852 if ((token
= strtok(NULL
, w_space
)) == NULL
)
1855 p
->host
= xstrdup(token
);
1857 p
->name
= xstrdup(token
);
1859 if ((token
= strtok(NULL
, w_space
)) == NULL
)
1862 p
->type
= parseNeighborType(token
);
1864 if (p
->type
== PEER_MULTICAST
) {
1865 p
->options
.no_digest
= 1;
1866 p
->options
.no_netdb_exchange
= 1;
1869 p
->http_port
= GetTcpService();
1874 p
->icp
.port
= GetUdpService();
1875 p
->connection_auth
= 2; /* auto */
1877 while ((token
= strtok(NULL
, w_space
))) {
1878 if (!strcasecmp(token
, "proxy-only")) {
1879 p
->options
.proxy_only
= 1;
1880 } else if (!strcasecmp(token
, "no-query")) {
1881 p
->options
.no_query
= 1;
1882 } else if (!strcasecmp(token
, "background-ping")) {
1883 p
->options
.background_ping
= 1;
1884 } else if (!strcasecmp(token
, "no-digest")) {
1885 p
->options
.no_digest
= 1;
1886 } else if (!strcasecmp(token
, "no-tproxy")) {
1887 p
->options
.no_tproxy
= 1;
1888 } else if (!strcasecmp(token
, "multicast-responder")) {
1889 p
->options
.mcast_responder
= 1;
1890 #if PEER_MULTICAST_SIBLINGS
1891 } else if (!strcasecmp(token
, "multicast-siblings")) {
1892 p
->options
.mcast_siblings
= 1;
1894 } else if (!strncasecmp(token
, "weight=", 7)) {
1895 p
->weight
= xatoi(token
+ 7);
1896 } else if (!strncasecmp(token
, "basetime=", 9)) {
1897 p
->basetime
= xatoi(token
+ 9);
1898 } else if (!strcasecmp(token
, "closest-only")) {
1899 p
->options
.closest_only
= 1;
1900 } else if (!strncasecmp(token
, "ttl=", 4)) {
1901 p
->mcast
.ttl
= xatoi(token
+ 4);
1903 if (p
->mcast
.ttl
< 0)
1906 if (p
->mcast
.ttl
> 128)
1908 } else if (!strcasecmp(token
, "default")) {
1909 p
->options
.default_parent
= 1;
1910 } else if (!strcasecmp(token
, "round-robin")) {
1911 p
->options
.roundrobin
= 1;
1912 } else if (!strcasecmp(token
, "weighted-round-robin")) {
1913 p
->options
.weighted_roundrobin
= 1;
1915 } else if (!strcasecmp(token
, "htcp")) {
1916 p
->options
.htcp
= 1;
1917 } else if (!strncasecmp(token
, "htcp=", 5) || !strncasecmp(token
, "htcp-", 5)) {
1918 /* Note: The htcp- form is deprecated, replaced by htcp= */
1919 p
->options
.htcp
= 1;
1920 char *tmp
= xstrdup(token
+5);
1921 char *mode
, *nextmode
;
1922 for (mode
= nextmode
= tmp
; mode
; mode
= nextmode
) {
1923 nextmode
= strchr(mode
, ',');
1926 if (!strcasecmp(mode
, "no-clr")) {
1927 if (p
->options
.htcp_only_clr
)
1928 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
1929 p
->options
.htcp_no_clr
= 1;
1930 } else if (!strcasecmp(mode
, "no-purge-clr")) {
1931 p
->options
.htcp_no_purge_clr
= 1;
1932 } else if (!strcasecmp(mode
, "only-clr")) {
1933 if (p
->options
.htcp_no_clr
)
1934 fatalf("parse_peer: can't set htcp no-clr and only-clr simultaneously");
1935 p
->options
.htcp_only_clr
= 1;
1936 } else if (!strcasecmp(mode
, "forward-clr")) {
1937 p
->options
.htcp_forward_clr
= 1;
1938 } else if (!strcasecmp(mode
, "oldsquid")) {
1939 p
->options
.htcp_oldsquid
= 1;
1941 fatalf("invalid HTCP mode '%s'", mode
);
1946 } else if (!strcasecmp(token
, "no-netdb-exchange")) {
1947 p
->options
.no_netdb_exchange
= 1;
1949 } else if (!strcasecmp(token
, "carp")) {
1950 if (p
->type
!= PEER_PARENT
)
1951 fatalf("parse_peer: non-parent carp peer %s/%d\n", p
->host
, p
->http_port
);
1953 p
->options
.carp
= 1;
1955 } else if (!strcasecmp(token
, "userhash")) {
1956 if (p
->type
!= PEER_PARENT
)
1957 fatalf("parse_peer: non-parent userhash peer %s/%d\n", p
->host
, p
->http_port
);
1959 p
->options
.userhash
= 1;
1961 } else if (!strcasecmp(token
, "sourcehash")) {
1962 if (p
->type
!= PEER_PARENT
)
1963 fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p
->host
, p
->http_port
);
1965 p
->options
.sourcehash
= 1;
1969 } else if (!strcasecmp(token
, "no-delay")) {
1970 p
->options
.no_delay
= 1;
1973 } else if (!strncasecmp(token
, "login=", 6)) {
1974 p
->login
= xstrdup(token
+ 6);
1975 rfc1738_unescape(p
->login
);
1976 } else if (!strncasecmp(token
, "connect-timeout=", 16)) {
1977 p
->connect_timeout
= xatoi(token
+ 16);
1978 } else if (!strncasecmp(token
, "connect-fail-limit=", 19)) {
1979 p
->connect_fail_limit
= xatoi(token
+ 19);
1980 #if USE_CACHE_DIGESTS
1981 } else if (!strncasecmp(token
, "digest-url=", 11)) {
1982 p
->digest_url
= xstrdup(token
+ 11);
1985 } else if (!strcasecmp(token
, "allow-miss")) {
1986 p
->options
.allow_miss
= 1;
1987 } else if (!strncasecmp(token
, "max-conn=", 9)) {
1988 p
->max_conn
= xatoi(token
+ 9);
1989 } else if (!strcasecmp(token
, "originserver")) {
1990 p
->options
.originserver
= 1;
1991 } else if (!strncasecmp(token
, "name=", 5)) {
1995 p
->name
= xstrdup(token
+ 5);
1996 } else if (!strncasecmp(token
, "forceddomain=", 13)) {
1997 safe_free(p
->domain
);
2000 p
->domain
= xstrdup(token
+ 13);
2004 } else if (strcmp(token
, "ssl") == 0) {
2006 } else if (strncmp(token
, "sslcert=", 8) == 0) {
2007 safe_free(p
->sslcert
);
2008 p
->sslcert
= xstrdup(token
+ 8);
2009 } else if (strncmp(token
, "sslkey=", 7) == 0) {
2010 safe_free(p
->sslkey
);
2011 p
->sslkey
= xstrdup(token
+ 7);
2012 } else if (strncmp(token
, "sslversion=", 11) == 0) {
2013 p
->sslversion
= atoi(token
+ 11);
2014 } else if (strncmp(token
, "ssloptions=", 11) == 0) {
2015 safe_free(p
->ssloptions
);
2016 p
->ssloptions
= xstrdup(token
+ 11);
2017 } else if (strncmp(token
, "sslcipher=", 10) == 0) {
2018 safe_free(p
->sslcipher
);
2019 p
->sslcipher
= xstrdup(token
+ 10);
2020 } else if (strncmp(token
, "sslcafile=", 10) == 0) {
2021 safe_free(p
->sslcafile
);
2022 p
->sslcafile
= xstrdup(token
+ 10);
2023 } else if (strncmp(token
, "sslcapath=", 10) == 0) {
2024 safe_free(p
->sslcapath
);
2025 p
->sslcapath
= xstrdup(token
+ 10);
2026 } else if (strncmp(token
, "sslcrlfile=", 11) == 0) {
2027 safe_free(p
->sslcrlfile
);
2028 p
->sslcapath
= xstrdup(token
+ 10);
2029 } else if (strncmp(token
, "sslflags=", 9) == 0) {
2030 safe_free(p
->sslflags
);
2031 p
->sslflags
= xstrdup(token
+ 9);
2032 } else if (strncmp(token
, "ssldomain=", 10) == 0) {
2033 safe_free(p
->ssldomain
);
2034 p
->ssldomain
= xstrdup(token
+ 10);
2037 } else if (strcmp(token
, "front-end-https") == 0) {
2038 p
->front_end_https
= 1;
2039 } else if (strcmp(token
, "front-end-https=on") == 0) {
2040 p
->front_end_https
= 1;
2041 } else if (strcmp(token
, "front-end-https=auto") == 0) {
2042 p
->front_end_https
= 2;
2043 } else if (strcmp(token
, "connection-auth=off") == 0) {
2044 p
->connection_auth
= 0;
2045 } else if (strcmp(token
, "connection-auth") == 0) {
2046 p
->connection_auth
= 1;
2047 } else if (strcmp(token
, "connection-auth=on") == 0) {
2048 p
->connection_auth
= 1;
2049 } else if (strcmp(token
, "connection-auth=auto") == 0) {
2050 p
->connection_auth
= 2;
2052 debugs(3, 0, "parse_peer: token='" << token
<< "'");
2057 if (peerFindByName(p
->name
))
2058 fatalf("ERROR: cache_peer %s specified twice\n", p
->name
);
2063 if (p
->connect_fail_limit
< 1)
2064 p
->connect_fail_limit
= 10;
2066 p
->icp
.version
= ICP_VERSION_CURRENT
;
2068 p
->testing_now
= false;
2070 #if USE_CACHE_DIGESTS
2072 if (!p
->options
.no_digest
) {
2073 /* XXX This looks odd.. who has the original pointer
2076 PeerDigest
*pd
= peerDigestCreate(p
);
2077 p
->digest
= cbdataReference(pd
);
2082 p
->index
= ++Config
.npeers
;
2084 while (*head
!= NULL
)
2085 head
= &(*head
)->next
;
2093 free_peer(peer
** P
)
2097 while ((p
= *P
) != NULL
) {
2099 #if USE_CACHE_DIGESTS
2101 cbdataReferenceDone(p
->digest
);
2111 dump_cachemgrpasswd(StoreEntry
* entry
, const char *name
, cachemgr_passwd
* list
)
2115 while (list
!= NULL
) {
2116 if (strcmp(list
->passwd
, "none") && strcmp(list
->passwd
, "disable"))
2117 storeAppendPrintf(entry
, "%s XXXXXXXXXX", name
);
2119 storeAppendPrintf(entry
, "%s %s", name
, list
->passwd
);
2121 for (w
= list
->actions
; w
!= NULL
; w
= w
->next
) {
2122 storeAppendPrintf(entry
, " %s", w
->key
);
2125 storeAppendPrintf(entry
, "\n");
2131 parse_cachemgrpasswd(cachemgr_passwd
** head
)
2133 char *passwd
= NULL
;
2134 wordlist
*actions
= NULL
;
2136 cachemgr_passwd
**P
;
2137 parse_string(&passwd
);
2138 parse_wordlist(&actions
);
2139 p
= static_cast<cachemgr_passwd
*>(xcalloc(1, sizeof(cachemgr_passwd
)));
2141 p
->actions
= actions
;
2143 for (P
= head
; *P
; P
= &(*P
)->next
) {
2145 * See if any of the actions from this line already have a
2146 * password from previous lines. The password checking
2147 * routines in cache_manager.c take the the password from
2148 * the first cachemgr_passwd struct that contains the
2149 * requested action. Thus, we should warn users who might
2150 * think they can have two passwords for the same action.
2155 for (w
= (*P
)->actions
; w
; w
= w
->next
) {
2156 for (u
= actions
; u
; u
= u
->next
) {
2157 if (strcmp(w
->key
, u
->key
))
2160 debugs(0, 0, "WARNING: action '" << u
->key
<< "' (line " << config_lineno
<< ") already has a password");
2169 free_cachemgrpasswd(cachemgr_passwd
** head
)
2173 while ((p
= *head
) != NULL
) {
2176 wordlistDestroy(&p
->actions
);
2182 dump_denyinfo(StoreEntry
* entry
, const char *name
, acl_deny_info_list
* var
)
2186 while (var
!= NULL
) {
2187 storeAppendPrintf(entry
, "%s %s", name
, var
->err_page_name
);
2189 for (a
= var
->acl_list
; a
!= NULL
; a
= a
->next
)
2190 storeAppendPrintf(entry
, " %s", a
->name
);
2192 storeAppendPrintf(entry
, "\n");
2199 parse_denyinfo(acl_deny_info_list
** var
)
2201 aclParseDenyInfoLine(var
);
2205 free_denyinfo(acl_deny_info_list
** list
)
2207 acl_deny_info_list
*a
= NULL
;
2208 acl_deny_info_list
*a_next
= NULL
;
2209 acl_name_list
*l
= NULL
;
2210 acl_name_list
*l_next
= NULL
;
2212 for (a
= *list
; a
; a
= a_next
) {
2213 for (l
= a
->acl_list
; l
; l
= l_next
) {
2215 memFree(l
, MEM_ACL_NAME_LIST
);
2220 memFree(a
, MEM_ACL_DENY_INFO_LIST
);
2228 parse_peer_access(void)
2233 if (!(host
= strtok(NULL
, w_space
)))
2236 if ((p
= peerFindByName(host
)) == NULL
) {
2237 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2241 aclParseAccessLine(LegacyParser
, &p
->access
);
2245 parse_hostdomain(void)
2248 char *domain
= NULL
;
2250 if (!(host
= strtok(NULL
, w_space
)))
2253 while ((domain
= strtok(NULL
, list_sep
))) {
2254 domain_ping
*l
= NULL
;
2255 domain_ping
**L
= NULL
;
2258 if ((p
= peerFindByName(host
)) == NULL
) {
2259 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2263 l
= static_cast<domain_ping
*>(xcalloc(1, sizeof(domain_ping
)));
2266 if (*domain
== '!') { /* check for !.edu */
2271 l
->domain
= xstrdup(domain
);
2273 for (L
= &(p
->peer_domain
); *L
; L
= &((*L
)->next
));
2279 parse_hostdomaintype(void)
2283 char *domain
= NULL
;
2285 if (!(host
= strtok(NULL
, w_space
)))
2288 if (!(type
= strtok(NULL
, w_space
)))
2291 while ((domain
= strtok(NULL
, list_sep
))) {
2292 domain_type
*l
= NULL
;
2293 domain_type
**L
= NULL
;
2296 if ((p
= peerFindByName(host
)) == NULL
) {
2297 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2301 l
= static_cast<domain_type
*>(xcalloc(1, sizeof(domain_type
)));
2302 l
->type
= parseNeighborType(type
);
2303 l
->domain
= xstrdup(domain
);
2305 for (L
= &(p
->typelist
); *L
; L
= &((*L
)->next
));
2311 dump_int(StoreEntry
* entry
, const char *name
, int var
)
2313 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2331 dump_onoff(StoreEntry
* entry
, const char *name
, int var
)
2333 storeAppendPrintf(entry
, "%s %s\n", name
, var
? "on" : "off");
2337 parse_onoff(int *var
)
2339 char *token
= strtok(NULL
, w_space
);
2344 if (!strcasecmp(token
, "on") || !strcasecmp(token
, "enable"))
2350 #define free_onoff free_int
2353 dump_tristate(StoreEntry
* entry
, const char *name
, int var
)
2364 storeAppendPrintf(entry
, "%s %s\n", name
, state
);
2368 parse_tristate(int *var
)
2370 char *token
= strtok(NULL
, w_space
);
2375 if (!strcasecmp(token
, "on") || !strcasecmp(token
, "enable"))
2377 else if (!strcasecmp(token
, "warn"))
2383 #define free_tristate free_int
2386 dump_refreshpattern(StoreEntry
* entry
, const char *name
, refresh_t
* head
)
2388 while (head
!= NULL
) {
2389 storeAppendPrintf(entry
, "%s%s %s %d %d%% %d",
2391 head
->flags
.icase
? " -i" : null_string
,
2393 (int) head
->min
/ 60,
2394 (int) (100.0 * head
->pct
+ 0.5),
2395 (int) head
->max
/ 60);
2397 if (head
->flags
.refresh_ims
)
2398 storeAppendPrintf(entry
, " refresh-ims");
2400 if (head
->flags
.store_stale
)
2401 storeAppendPrintf(entry
, " store-stale");
2403 #if USE_HTTP_VIOLATIONS
2405 if (head
->flags
.override_expire
)
2406 storeAppendPrintf(entry
, " override-expire");
2408 if (head
->flags
.override_lastmod
)
2409 storeAppendPrintf(entry
, " override-lastmod");
2411 if (head
->flags
.reload_into_ims
)
2412 storeAppendPrintf(entry
, " reload-into-ims");
2414 if (head
->flags
.ignore_reload
)
2415 storeAppendPrintf(entry
, " ignore-reload");
2417 if (head
->flags
.ignore_no_cache
)
2418 storeAppendPrintf(entry
, " ignore-no-cache");
2420 if (head
->flags
.ignore_no_store
)
2421 storeAppendPrintf(entry
, " ignore-no-store");
2423 if (head
->flags
.ignore_must_revalidate
)
2424 storeAppendPrintf(entry
, " ignore-must-revalidate");
2426 if (head
->flags
.ignore_private
)
2427 storeAppendPrintf(entry
, " ignore-private");
2429 if (head
->flags
.ignore_auth
)
2430 storeAppendPrintf(entry
, " ignore-auth");
2434 storeAppendPrintf(entry
, "\n");
2441 parse_refreshpattern(refresh_t
** head
)
2448 int refresh_ims
= 0;
2449 int store_stale
= 0;
2451 #if USE_HTTP_VIOLATIONS
2453 int override_expire
= 0;
2454 int override_lastmod
= 0;
2455 int reload_into_ims
= 0;
2456 int ignore_reload
= 0;
2457 int ignore_no_cache
= 0;
2458 int ignore_no_store
= 0;
2459 int ignore_must_revalidate
= 0;
2460 int ignore_private
= 0;
2461 int ignore_auth
= 0;
2468 int flags
= REG_EXTENDED
| REG_NOSUB
;
2470 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
2475 if (strcmp(token
, "-i") == 0) {
2477 token
= strtok(NULL
, w_space
);
2478 } else if (strcmp(token
, "+i") == 0) {
2479 flags
&= ~REG_ICASE
;
2480 token
= strtok(NULL
, w_space
);
2483 if (token
== NULL
) {
2488 pattern
= xstrdup(token
);
2490 i
= GetInteger(); /* token: min */
2492 /* catch negative and insanely huge values close to 32-bit wrap */
2494 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age negative. Cropped back to zero.");
2497 if (i
> 60*24*365) {
2498 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age too high. Cropped back to 1 year.");
2502 min
= (time_t) (i
* 60); /* convert minutes to seconds */
2504 i
= GetInteger(); /* token: pct */
2506 pct
= (double) i
/ 100.0;
2508 i
= GetInteger(); /* token: max */
2510 /* catch negative and insanely huge values close to 32-bit wrap */
2512 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age negative. Cropped back to zero.");
2515 if (i
> 60*24*365) {
2516 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age too high. Cropped back to 1 year.");
2520 max
= (time_t) (i
* 60); /* convert minutes to seconds */
2523 while ((token
= strtok(NULL
, w_space
)) != NULL
) {
2524 if (!strcmp(token
, "refresh-ims")) {
2526 } else if (!strcmp(token
, "store-stale")) {
2528 #if USE_HTTP_VIOLATIONS
2530 } else if (!strcmp(token
, "override-expire"))
2531 override_expire
= 1;
2532 else if (!strcmp(token
, "override-lastmod"))
2533 override_lastmod
= 1;
2534 else if (!strcmp(token
, "ignore-no-cache"))
2535 ignore_no_cache
= 1;
2536 else if (!strcmp(token
, "ignore-no-store"))
2537 ignore_no_store
= 1;
2538 else if (!strcmp(token
, "ignore-must-revalidate"))
2539 ignore_must_revalidate
= 1;
2540 else if (!strcmp(token
, "ignore-private"))
2542 else if (!strcmp(token
, "ignore-auth"))
2544 else if (!strcmp(token
, "reload-into-ims")) {
2545 reload_into_ims
= 1;
2546 refresh_nocache_hack
= 1;
2547 /* tell client_side.c that this is used */
2548 } else if (!strcmp(token
, "ignore-reload")) {
2550 refresh_nocache_hack
= 1;
2551 /* tell client_side.c that this is used */
2555 debugs(22, 0, "redreshAddToList: Unknown option '" << pattern
<< "': " << token
);
2558 if ((errcode
= regcomp(&comp
, pattern
, flags
)) != 0) {
2560 regerror(errcode
, &comp
, errbuf
, sizeof errbuf
);
2561 debugs(22, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
2562 debugs(22, 0, "refreshAddToList: Invalid regular expression '" << pattern
<< "': " << errbuf
);
2566 pct
= pct
< 0.0 ? 0.0 : pct
;
2567 max
= max
< 0 ? 0 : max
;
2568 t
= static_cast<refresh_t
*>(xcalloc(1, sizeof(refresh_t
)));
2569 t
->pattern
= (char *) xstrdup(pattern
);
2570 t
->compiled_pattern
= comp
;
2575 if (flags
& REG_ICASE
)
2579 t
->flags
.refresh_ims
= 1;
2582 t
->flags
.store_stale
= 1;
2584 #if USE_HTTP_VIOLATIONS
2586 if (override_expire
)
2587 t
->flags
.override_expire
= 1;
2589 if (override_lastmod
)
2590 t
->flags
.override_lastmod
= 1;
2592 if (reload_into_ims
)
2593 t
->flags
.reload_into_ims
= 1;
2596 t
->flags
.ignore_reload
= 1;
2598 if (ignore_no_cache
)
2599 t
->flags
.ignore_no_cache
= 1;
2601 if (ignore_no_store
)
2602 t
->flags
.ignore_no_store
= 1;
2604 if (ignore_must_revalidate
)
2605 t
->flags
.ignore_must_revalidate
= 1;
2608 t
->flags
.ignore_private
= 1;
2611 t
->flags
.ignore_auth
= 1;
2618 head
= &(*head
)->next
;
2626 free_refreshpattern(refresh_t
** head
)
2630 while ((t
= *head
) != NULL
) {
2632 safe_free(t
->pattern
);
2633 regfree(&t
->compiled_pattern
);
2637 #if USE_HTTP_VIOLATIONS
2638 refresh_nocache_hack
= 0;
2644 dump_string(StoreEntry
* entry
, const char *name
, char *var
)
2647 storeAppendPrintf(entry
, "%s %s\n", name
, var
);
2651 parse_string(char **var
)
2653 char *token
= strtok(NULL
, w_space
);
2659 *var
= xstrdup(token
);
2663 ConfigParser::ParseString(char **var
)
2669 ConfigParser::ParseString(String
*var
)
2671 char *token
= strtok(NULL
, w_space
);
2680 free_string(char **var
)
2686 parse_eol(char *volatile *var
)
2688 unsigned char *token
= (unsigned char *) strtok(NULL
, null_string
);
2696 while (*token
&& xisspace(*token
))
2704 *var
= xstrdup((char *) token
);
2707 #define dump_eol dump_string
2708 #define free_eol free_string
2711 dump_time_t(StoreEntry
* entry
, const char *name
, time_t var
)
2713 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int) var
);
2717 parse_time_t(time_t * var
)
2719 parseTimeLine(var
, T_SECOND_STR
);
2723 free_time_t(time_t * var
)
2730 dump_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
2732 storeAppendPrintf(entry
, "%s %d\n", name
, (int) var
);
2737 dump_b_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
2739 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
2744 dump_kb_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
2746 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_KBYTES_STR
);
2751 dump_b_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
2753 storeAppendPrintf(entry
, "%s %"PRId64
" %s\n", name
, var
, B_BYTES_STR
);
2757 dump_kb_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
2759 storeAppendPrintf(entry
, "%s %"PRId64
" %s\n", name
, var
, B_KBYTES_STR
);
2764 parse_size_t(size_t * var
)
2773 parse_b_size_t(size_t * var
)
2775 parseBytesLine(var
, B_BYTES_STR
);
2780 parse_kb_size_t(size_t * var
)
2782 parseBytesLine(var
, B_KBYTES_STR
);
2787 parse_b_int64_t(int64_t * var
)
2789 parseBytesLine64(var
, B_BYTES_STR
);
2793 parse_kb_int64_t(int64_t * var
)
2795 parseBytesLine64(var
, B_KBYTES_STR
);
2799 free_size_t(size_t * var
)
2805 free_b_int64_t(int64_t * var
)
2810 #define free_b_size_t free_size_t
2811 #define free_kb_size_t free_size_t
2812 #define free_mb_size_t free_size_t
2813 #define free_gb_size_t free_size_t
2814 #define free_kb_int64_t free_b_int64_t
2817 dump_ushort(StoreEntry
* entry
, const char *name
, u_short var
)
2819 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2823 free_ushort(u_short
* u
)
2829 parse_ushort(u_short
* var
)
2831 ConfigParser::ParseUShort(var
);
2835 ConfigParser::ParseUShort(u_short
*var
)
2841 ConfigParser::ParseBool(bool *var
)
2843 int i
= GetInteger();
2854 dump_wordlist(StoreEntry
* entry
, const char *name
, wordlist
* list
)
2856 while (list
!= NULL
) {
2857 storeAppendPrintf(entry
, "%s %s\n", name
, list
->key
);
2863 ConfigParser::ParseWordList(wordlist
** list
)
2865 parse_wordlist(list
);
2869 parse_wordlist(wordlist
** list
)
2872 char *t
= strtok(NULL
, "");
2874 while ((token
= strwordtok(NULL
, &t
)))
2875 wordlistAdd(list
, token
);
2878 #if 0 /* now unused */
2880 check_null_wordlist(wordlist
* w
)
2887 check_null_acl_access(acl_access
* a
)
2892 #define free_wordlist wordlistDestroy
2894 #define free_uri_whitespace free_int
2897 parse_uri_whitespace(int *var
)
2899 char *token
= strtok(NULL
, w_space
);
2904 if (!strcasecmp(token
, "strip"))
2905 *var
= URI_WHITESPACE_STRIP
;
2906 else if (!strcasecmp(token
, "deny"))
2907 *var
= URI_WHITESPACE_DENY
;
2908 else if (!strcasecmp(token
, "allow"))
2909 *var
= URI_WHITESPACE_ALLOW
;
2910 else if (!strcasecmp(token
, "encode"))
2911 *var
= URI_WHITESPACE_ENCODE
;
2912 else if (!strcasecmp(token
, "chop"))
2913 *var
= URI_WHITESPACE_CHOP
;
2919 dump_uri_whitespace(StoreEntry
* entry
, const char *name
, int var
)
2923 if (var
== URI_WHITESPACE_ALLOW
)
2925 else if (var
== URI_WHITESPACE_ENCODE
)
2927 else if (var
== URI_WHITESPACE_CHOP
)
2929 else if (var
== URI_WHITESPACE_DENY
)
2934 storeAppendPrintf(entry
, "%s %s\n", name
, s
);
2938 free_removalpolicy(RemovalPolicySettings
** settings
)
2943 free_string(&(*settings
)->type
);
2945 free_wordlist(&(*settings
)->args
);
2953 parse_removalpolicy(RemovalPolicySettings
** settings
)
2956 free_removalpolicy(settings
);
2958 *settings
= new RemovalPolicySettings
;
2960 parse_string(&(*settings
)->type
);
2962 parse_wordlist(&(*settings
)->args
);
2966 dump_removalpolicy(StoreEntry
* entry
, const char *name
, RemovalPolicySettings
* settings
)
2969 storeAppendPrintf(entry
, "%s %s", name
, settings
->type
);
2970 args
= settings
->args
;
2973 storeAppendPrintf(entry
, " %s", args
->key
);
2977 storeAppendPrintf(entry
, "\n");
2981 free_memcachemode(SquidConfig
* config
)
2987 parse_memcachemode(SquidConfig
* config
)
2989 char *token
= strtok(NULL
, w_space
);
2993 if (strcmp(token
, "always") == 0) {
2994 Config
.onoff
.memory_cache_first
= 1;
2995 Config
.onoff
.memory_cache_disk
= 1;
2996 } else if (strcmp(token
, "disk") == 0) {
2997 Config
.onoff
.memory_cache_first
= 0;
2998 Config
.onoff
.memory_cache_disk
= 1;
2999 } else if (strncmp(token
, "net", 3) == 0) {
3000 Config
.onoff
.memory_cache_first
= 1;
3001 Config
.onoff
.memory_cache_disk
= 0;
3002 } else if (strcmp(token
, "never") == 0) {
3003 Config
.onoff
.memory_cache_first
= 0;
3004 Config
.onoff
.memory_cache_disk
= 0;
3010 dump_memcachemode(StoreEntry
* entry
, const char *name
, SquidConfig
&config
)
3012 storeAppendPrintf(entry
, "%s ", name
);
3013 if (Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3014 storeAppendPrintf(entry
, "always");
3015 else if (!Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3016 storeAppendPrintf(entry
, "disk");
3017 else if (Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3018 storeAppendPrintf(entry
, "network");
3019 else if (!Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3020 storeAppendPrintf(entry
, "none");
3021 storeAppendPrintf(entry
, "\n");
3024 #include "cf_parser.cci"
3027 parseNeighborType(const char *s
)
3029 if (!strcasecmp(s
, "parent"))
3032 if (!strcasecmp(s
, "neighbor"))
3033 return PEER_SIBLING
;
3035 if (!strcasecmp(s
, "neighbour"))
3036 return PEER_SIBLING
;
3038 if (!strcasecmp(s
, "sibling"))
3039 return PEER_SIBLING
;
3041 if (!strcasecmp(s
, "multicast"))
3042 return PEER_MULTICAST
;
3044 debugs(15, 0, "WARNING: Unknown neighbor type: " << s
);
3046 return PEER_SIBLING
;
3051 parse_IpAddress_list(Ip::Address_list
** head
)
3054 Ip::Address_list
*s
;
3057 while ((token
= strtok(NULL
, w_space
))) {
3058 if (GetHostWithPort(token
, &ipa
)) {
3061 head
= &(*head
)->next
;
3063 s
= static_cast<Ip::Address_list
*>(xcalloc(1, sizeof(*s
)));
3073 dump_IpAddress_list(StoreEntry
* e
, const char *n
, const Ip::Address_list
* s
)
3075 char ntoabuf
[MAX_IPSTRLEN
];
3078 storeAppendPrintf(e
, "%s %s\n",
3080 s
->s
.NtoA(ntoabuf
,MAX_IPSTRLEN
));
3086 free_IpAddress_list(Ip::Address_list
** head
)
3088 if (*head
) delete *head
;
3092 #if CURRENTLY_UNUSED
3093 /* This code was previously used by http_port. Left as it really should
3094 * be used by icp_port and htcp_port
3097 check_null_IpAddress_list(const Ip::Address_list
* s
)
3102 #endif /* CURRENTLY_UNUSED */
3103 #endif /* USE_WCCPv2 */
3105 CBDATA_CLASS_INIT(http_port_list
);
3108 parse_http_port_specification(http_port_list
* s
, char *token
)
3111 unsigned short port
= 0;
3115 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3116 s
->name
= xstrdup(token
);
3117 s
->connection_auth_disabled
= false;
3119 if (*token
== '[') {
3122 t
= strchr(host
, ']');
3124 debugs(3, 0, "http(s)_port: missing ']' on IPv6 address: " << token
);
3129 debugs(3, 0, "http(s)_port: missing Port in: " << token
);
3132 if (!Ip::EnableIpv6
) {
3133 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 is not available.");
3136 port
= xatos(t
+ 1);
3137 } else if ((t
= strchr(token
, ':'))) {
3142 port
= xatos(t
+ 1);
3144 } else if ((port
= strtol(token
, &junk
, 10)), !*junk
) {
3146 debugs(3, 3, "http(s)_port: found Listen on Port: " << port
);
3148 debugs(3, 0, "http(s)_port: missing Port: " << token
);
3153 debugs(3, 0, "http(s)_port: Port cannot be 0: " << token
);
3160 if (!Ip::EnableIpv6
)
3162 debugs(3, 3, "http(s)_port: found Listen on wildcard address: *:" << s
->s
.GetPort() );
3163 } else if ( s
->s
= host
) { /* check/parse numeric IPA */
3165 if (!Ip::EnableIpv6
)
3167 debugs(3, 3, "http(s)_port: Listen on Host/IP: " << host
<< " --> " << s
->s
);
3168 } else if ( s
->s
.GetHostByName(host
) ) { /* check/parse for FQDN */
3169 /* dont use ipcache */
3170 s
->defaultsite
= xstrdup(host
);
3172 if (!Ip::EnableIpv6
)
3174 debugs(3, 3, "http(s)_port: found Listen as Host " << s
->defaultsite
<< " on IP: " << s
->s
);
3176 debugs(3, 0, "http(s)_port: failed to resolve Host/IP: " << host
);
3182 parse_http_port_option(http_port_list
* s
, char *token
)
3186 if (strcmp(token
, "accel") == 0) {
3187 if (s
->intercepted
|| s
->spoof_client_ip
) {
3188 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: Accelerator mode requires its own port. It cannot be shared with other modes.");
3192 } else if (strcmp(token
, "transparent") == 0 || strcmp(token
, "intercept") == 0) {
3193 if (s
->accel
|| s
->spoof_client_ip
) {
3194 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: Intercept mode requires its own interception port. It cannot be shared with other modes.");
3198 Ip::Interceptor
.StartInterception();
3199 /* Log information regarding the port modes under interception. */
3200 debugs(3, DBG_IMPORTANT
, "Starting Authentication on port " << s
->s
);
3201 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (interception enabled)");
3203 /* INET6: until transparent REDIRECT works on IPv6 SOCKET, force wildcard to IPv4 */
3205 debugs(3, DBG_IMPORTANT
, "Disabling IPv6 on port " << s
->s
<< " (interception enabled)");
3206 if ( !s
->s
.SetIPv4() ) {
3207 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 addresses cannot be transparent (protocol does not provide NAT)" << s
->s
);
3210 } else if (strcmp(token
, "tproxy") == 0) {
3211 if (s
->intercepted
|| s
->accel
) {
3212 debugs(3,DBG_CRITICAL
, "FATAL: http(s)_port: TPROXY option requires its own interception port. It cannot be shared with other modes.");
3215 s
->spoof_client_ip
= 1;
3216 Ip::Interceptor
.StartTransparency();
3217 /* Log information regarding the port modes under transparency. */
3218 debugs(3, DBG_IMPORTANT
, "Starting IP Spoofing on port " << s
->s
);
3219 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (IP spoofing enabled)");
3221 if (!Ip::Interceptor
.ProbeForTproxy(s
->s
)) {
3222 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: TPROXY support in the system does not work.");
3226 } else if (strncmp(token
, "defaultsite=", 12) == 0) {
3228 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: defaultsite option requires Acceleration mode flag.");
3231 safe_free(s
->defaultsite
);
3232 s
->defaultsite
= xstrdup(token
+ 12);
3233 } else if (strcmp(token
, "vhost") == 0) {
3235 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vhost option requires Acceleration mode flag.");
3239 } else if (strcmp(token
, "vport") == 0) {
3241 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3245 } else if (strncmp(token
, "vport=", 6) == 0) {
3247 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3250 s
->vport
= xatos(token
+ 6);
3251 } else if (strncmp(token
, "protocol=", 9) == 0) {
3253 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: protocol option requires Acceleration mode flag.");
3256 s
->protocol
= xstrdup(token
+ 9);
3257 } else if (strcmp(token
, "allow-direct") == 0) {
3259 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3262 s
->allow_direct
= 1;
3263 } else if (strcmp(token
, "ignore-cc") == 0) {
3264 #if !USE_HTTP_VIOLATIONS
3266 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: ignore-cc option requires Scceleration mode flag.");
3271 } else if (strncmp(token
, "name=", 5) == 0) {
3273 s
->name
= xstrdup(token
+ 5);
3274 } else if (strcmp(token
, "no-connection-auth") == 0) {
3275 s
->connection_auth_disabled
= true;
3276 } else if (strcmp(token
, "connection-auth=off") == 0) {
3277 s
->connection_auth_disabled
= true;
3278 } else if (strcmp(token
, "connection-auth") == 0) {
3279 s
->connection_auth_disabled
= false;
3280 } else if (strcmp(token
, "connection-auth=on") == 0) {
3281 s
->connection_auth_disabled
= false;
3282 } else if (strncmp(token
, "disable-pmtu-discovery=", 23) == 0) {
3283 if (!strcasecmp(token
+ 23, "off"))
3284 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3285 else if (!strcasecmp(token
+ 23, "transparent"))
3286 s
->disable_pmtu_discovery
= DISABLE_PMTU_TRANSPARENT
;
3287 else if (!strcasecmp(token
+ 23, "always"))
3288 s
->disable_pmtu_discovery
= DISABLE_PMTU_ALWAYS
;
3291 } else if (strcmp(token
, "ipv4") == 0) {
3292 if ( !s
->s
.SetIPv4() ) {
3293 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 addresses cannot be used as IPv4-Only. " << s
->s
);
3296 } else if (strcmp(token
, "tcpkeepalive") == 0) {
3297 s
->tcp_keepalive
.enabled
= 1;
3298 } else if (strncmp(token
, "tcpkeepalive=", 13) == 0) {
3299 char *t
= token
+ 13;
3300 s
->tcp_keepalive
.enabled
= 1;
3301 s
->tcp_keepalive
.idle
= atoi(t
);
3305 s
->tcp_keepalive
.interval
= atoi(t
);
3310 s
->tcp_keepalive
.timeout
= atoi(t
);
3314 } else if (strcasecmp(token
, "sslBump") == 0) {
3315 debugs(3, DBG_CRITICAL
, "WARNING: '" << token
<< "' is deprecated " <<
3316 "in http_port. Use 'ssl-bump' instead.");
3317 s
->sslBump
= 1; // accelerated when bumped, otherwise not
3318 } else if (strcmp(token
, "ssl-bump") == 0) {
3319 s
->sslBump
= 1; // accelerated when bumped, otherwise not
3320 } else if (strncmp(token
, "cert=", 5) == 0) {
3322 s
->cert
= xstrdup(token
+ 5);
3323 } else if (strncmp(token
, "key=", 4) == 0) {
3325 s
->key
= xstrdup(token
+ 4);
3326 } else if (strncmp(token
, "version=", 8) == 0) {
3327 s
->version
= xatoi(token
+ 8);
3328 if (s
->version
< 1 || s
->version
> 4)
3330 } else if (strncmp(token
, "options=", 8) == 0) {
3331 safe_free(s
->options
);
3332 s
->options
= xstrdup(token
+ 8);
3333 } else if (strncmp(token
, "cipher=", 7) == 0) {
3334 safe_free(s
->cipher
);
3335 s
->cipher
= xstrdup(token
+ 7);
3336 } else if (strncmp(token
, "clientca=", 9) == 0) {
3337 safe_free(s
->clientca
);
3338 s
->clientca
= xstrdup(token
+ 9);
3339 } else if (strncmp(token
, "cafile=", 7) == 0) {
3340 safe_free(s
->cafile
);
3341 s
->cafile
= xstrdup(token
+ 7);
3342 } else if (strncmp(token
, "capath=", 7) == 0) {
3343 safe_free(s
->capath
);
3344 s
->capath
= xstrdup(token
+ 7);
3345 } else if (strncmp(token
, "crlfile=", 8) == 0) {
3346 safe_free(s
->crlfile
);
3347 s
->crlfile
= xstrdup(token
+ 8);
3348 } else if (strncmp(token
, "dhparams=", 9) == 0) {
3349 safe_free(s
->dhfile
);
3350 s
->dhfile
= xstrdup(token
+ 9);
3351 } else if (strncmp(token
, "sslflags=", 9) == 0) {
3352 safe_free(s
->sslflags
);
3353 s
->sslflags
= xstrdup(token
+ 9);
3354 } else if (strncmp(token
, "sslcontext=", 11) == 0) {
3355 safe_free(s
->sslcontext
);
3356 s
->sslcontext
= xstrdup(token
+ 11);
3363 static http_port_list
*
3364 create_http_port(char *portspec
)
3366 http_port_list
*s
= new http_port_list("http");
3367 parse_http_port_specification(s
, portspec
);
3372 add_http_port(char *portspec
)
3374 http_port_list
*s
= create_http_port(portspec
);
3375 // we may need to merge better of the above returns a list with clones
3376 assert(s
->next
== NULL
);
3377 s
->next
= Config
.Sockaddr
.http
;
3378 Config
.Sockaddr
.http
= s
;
3382 clone_http_port_list(http_port_list
*a
)
3384 http_port_list
*b
= new http_port_list(a
->protocol
);
3388 b
->name
= xstrdup(a
->name
);
3390 b
->defaultsite
= xstrdup(a
->defaultsite
);
3392 b
->intercepted
= a
->intercepted
;
3393 b
->spoof_client_ip
= a
->spoof_client_ip
;
3394 b
->accel
= a
->accel
;
3395 b
->allow_direct
= a
->allow_direct
;
3396 b
->vhost
= a
->vhost
;
3397 b
->sslBump
= a
->sslBump
;
3398 b
->vport
= a
->vport
;
3399 b
->connection_auth_disabled
= a
->connection_auth_disabled
;
3400 b
->disable_pmtu_discovery
= a
->disable_pmtu_discovery
;
3402 memcpy( &(b
->tcp_keepalive
), &(a
->tcp_keepalive
), sizeof(a
->tcp_keepalive
));
3405 // AYJ: 2009-07-18: for now SSL does not clone. Configure separate ports with IPs and SSL settings
3408 // XXX: temporary hack to ease move of SSL options to http_port
3409 http_port_list
&http
;
3423 SSL_CTX
*sslContext
;
3432 parse_http_port_list(http_port_list
** head
)
3434 char *token
= strtok(NULL
, w_space
);
3441 http_port_list
*s
= create_http_port(token
);
3443 /* parse options ... */
3444 while ((token
= strtok(NULL
, w_space
))) {
3445 parse_http_port_option(s
, token
);
3448 if (Ip::EnableIpv6
&IPV6_SPECIAL_SPLITSTACK
&& s
->s
.IsAnyAddr()) {
3449 // clone the port options from *s to *(s->next)
3450 s
->next
= clone_http_port_list(s
);
3451 s
->next
->s
.SetIPv4();
3452 debugs(3, 3, "http(s)_port: clone wildcard address for split-stack: " << s
->s
<< " and " << s
->next
->s
);
3456 head
= &(*head
)->next
;
3462 dump_generic_http_port(StoreEntry
* e
, const char *n
, const http_port_list
* s
)
3464 char buf
[MAX_IPSTRLEN
];
3466 storeAppendPrintf(e
, "%s %s",
3468 s
->s
.ToURL(buf
,MAX_IPSTRLEN
));
3471 storeAppendPrintf(e
, " intercept");
3473 if (s
->spoof_client_ip
)
3474 storeAppendPrintf(e
, " tproxy");
3477 storeAppendPrintf(e
, " accel");
3480 storeAppendPrintf(e
, " vhost");
3483 storeAppendPrintf(e
, " vport");
3486 storeAppendPrintf(e
, " defaultsite=%s", s
->defaultsite
);
3488 if (s
->connection_auth_disabled
)
3489 storeAppendPrintf(e
, " connection-auth=off");
3491 storeAppendPrintf(e
, " connection-auth=on");
3493 if (s
->disable_pmtu_discovery
!= DISABLE_PMTU_OFF
) {
3496 if (s
->disable_pmtu_discovery
== DISABLE_PMTU_ALWAYS
)
3499 pmtu
= "transparent";
3501 storeAppendPrintf(e
, " disable-pmtu-discovery=%s", pmtu
);
3504 if (s
->tcp_keepalive
.enabled
) {
3505 if (s
->tcp_keepalive
.idle
|| s
->tcp_keepalive
.interval
|| s
->tcp_keepalive
.timeout
) {
3506 storeAppendPrintf(e
, " tcpkeepalive=%d,%d,%d", s
->tcp_keepalive
.idle
, s
->tcp_keepalive
.interval
, s
->tcp_keepalive
.timeout
);
3508 storeAppendPrintf(e
, " tcpkeepalive");
3514 storeAppendPrintf(e
, " sslBump");
3517 storeAppendPrintf(e
, " cert=%s", s
->cert
);
3520 storeAppendPrintf(e
, " key=%s", s
->key
);
3523 storeAppendPrintf(e
, " version=%d", s
->version
);
3526 storeAppendPrintf(e
, " options=%s", s
->options
);
3529 storeAppendPrintf(e
, " cipher=%s", s
->cipher
);
3532 storeAppendPrintf(e
, " cafile=%s", s
->cafile
);
3535 storeAppendPrintf(e
, " capath=%s", s
->capath
);
3538 storeAppendPrintf(e
, " crlfile=%s", s
->crlfile
);
3541 storeAppendPrintf(e
, " dhparams=%s", s
->dhfile
);
3544 storeAppendPrintf(e
, " sslflags=%s", s
->sslflags
);
3547 storeAppendPrintf(e
, " sslcontext=%s", s
->sslcontext
);
3552 dump_http_port_list(StoreEntry
* e
, const char *n
, const http_port_list
* s
)
3555 dump_generic_http_port(e
, n
, s
);
3556 storeAppendPrintf(e
, "\n");
3562 free_http_port_list(http_port_list
** head
)
3566 while ((s
= *head
) != NULL
) {
3574 // TODO: merge better with parse_http_port_list
3576 parse_https_port_list(https_port_list
** head
)
3581 token
= strtok(NULL
, w_space
);
3586 s
= new https_port_list
;
3587 parse_http_port_specification(&s
->http
, token
);
3589 /* parse options ... */
3590 while ((token
= strtok(NULL
, w_space
))) {
3591 parse_http_port_option(s
, token
);
3595 http_port_list
** headTmp
= &(*head
)->http
.next
;
3596 head
= (https_port_list
**)headTmp
;
3603 dump_https_port_list(StoreEntry
* e
, const char *n
, const https_port_list
* s
)
3605 dump_http_port_list(e
, n
, s
);
3609 free_https_port_list(https_port_list
** head
)
3611 free_http_port_list((http_port_list
**)head
);
3616 check_null_https_port_list(const https_port_list
* s
)
3623 #endif /* USE_SSL */
3626 configFreeMemory(void)
3632 requirePathnameExists(const char *name
, const char *path
)
3636 char pathbuf
[BUFSIZ
];
3637 assert(path
!= NULL
);
3639 if (Config
.chroot_dir
&& (geteuid() == 0)) {
3640 snprintf(pathbuf
, BUFSIZ
, "%s/%s", Config
.chroot_dir
, path
);
3644 if (stat(path
, &sb
) < 0) {
3645 if (opt_send_signal
== -1 || opt_send_signal
== SIGHUP
)
3646 fatalf("%s %s: %s", name
, path
, xstrerror());
3648 fprintf(stderr
, "WARNING: %s %s: %s\n", name
, path
, xstrerror());
3655 return ConfigParser::strtokFile();
3658 #include "AccessLogEntry.h"
3659 /* TODO: split out parsing somehow ...*/
3661 parse_logformat(logformat
** logformat_definitions
)
3666 if ((name
= strtok(NULL
, w_space
)) == NULL
)
3669 if ((def
= strtok(NULL
, "\r\n")) == NULL
) {
3674 debugs(3, 2, "Logformat for '" << name
<< "' is '" << def
<< "'");
3676 nlf
= (logformat
*)xcalloc(1, sizeof(logformat
));
3678 nlf
->name
= xstrdup(name
);
3680 if (!accessLogParseLogFormat(&nlf
->format
, def
)) {
3685 nlf
->next
= *logformat_definitions
;
3687 *logformat_definitions
= nlf
;
3691 parse_access_log(customlog
** logs
)
3693 const char *filename
, *logdef_name
;
3697 cl
= (customlog
*)xcalloc(1, sizeof(*cl
));
3699 if ((filename
= strtok(NULL
, w_space
)) == NULL
) {
3704 if (strcmp(filename
, "none") == 0) {
3705 cl
->type
= CLF_NONE
;
3709 if ((logdef_name
= strtok(NULL
, w_space
)) == NULL
)
3710 logdef_name
= "auto";
3712 debugs(3, 9, "Log definition name '" << logdef_name
<< "' file '" << filename
<< "'");
3714 cl
->filename
= xstrdup(filename
);
3716 /* look for the definition pointer corresponding to this name */
3717 lf
= Config
.Log
.logformats
;
3719 while (lf
!= NULL
) {
3720 debugs(3, 9, "Comparing against '" << lf
->name
<< "'");
3722 if (strcmp(lf
->name
, logdef_name
) == 0)
3729 cl
->type
= CLF_CUSTOM
;
3731 } else if (strcmp(logdef_name
, "auto") == 0) {
3732 cl
->type
= CLF_AUTO
;
3733 } else if (strcmp(logdef_name
, "squid") == 0) {
3734 cl
->type
= CLF_SQUID
;
3735 } else if (strcmp(logdef_name
, "common") == 0) {
3736 cl
->type
= CLF_COMMON
;
3738 } else if (strcmp(logdef_name
, "icap_squid") == 0) {
3739 cl
->type
= CLF_ICAP_SQUID
;
3742 debugs(3, 0, "Log format '" << logdef_name
<< "' is not defined");
3748 aclParseAclList(LegacyParser
, &cl
->aclList
);
3751 logs
= &(*logs
)->next
;
3757 check_null_access_log(customlog
*customlog_definitions
)
3759 return customlog_definitions
== NULL
;
3763 dump_logformat(StoreEntry
* entry
, const char *name
, logformat
* definitions
)
3765 accessLogDumpLogFormat(entry
, name
, definitions
);
3769 dump_access_log(StoreEntry
* entry
, const char *name
, customlog
* logs
)
3773 for (log
= logs
; log
; log
= log
->next
) {
3774 storeAppendPrintf(entry
, "%s ", name
);
3776 switch (log
->type
) {
3779 storeAppendPrintf(entry
, "%s %s", log
->filename
, log
->logFormat
->name
);
3783 storeAppendPrintf(entry
, "none");
3787 storeAppendPrintf(entry
, "%s squid", log
->filename
);
3791 storeAppendPrintf(entry
, "%s squid", log
->filename
);
3794 case CLF_ICAP_SQUID
:
3795 storeAppendPrintf(entry
, "%s icap_squid", log
->filename
);
3801 storeAppendPrintf(entry
, "%s auto", log
->filename
);
3803 storeAppendPrintf(entry
, "%s", log
->filename
);
3812 dump_acl_list(entry
, log
->aclList
);
3814 storeAppendPrintf(entry
, "\n");
3819 free_logformat(logformat
** definitions
)
3821 while (*definitions
) {
3822 logformat
*format
= *definitions
;
3823 *definitions
= format
->next
;
3824 safe_free(format
->name
);
3825 accessLogFreeLogFormat(&format
->format
);
3831 free_access_log(customlog
** definitions
)
3833 while (*definitions
) {
3834 customlog
*log
= *definitions
;
3835 *definitions
= log
->next
;
3837 log
->logFormat
= NULL
;
3838 log
->type
= CLF_UNKNOWN
;
3841 aclDestroyAclList(&log
->aclList
);
3843 safe_free(log
->filename
);
3849 /// parses list of integers form name=N1,N2,N3,...
3851 parseNamedIntList(const char *data
, const String
&name
, Vector
<int> &list
)
3853 if (data
&& (strncmp(data
, name
.rawBuf(), name
.size()) == 0)) {
3854 data
+= name
.size();
3859 if (!StringToInt(data
, value
, &data
, 10))
3861 list
.push_back(value
);
3862 if (*data
== '\0' || *data
!= ',')
3867 return data
&& *data
== '\0';
3871 parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
3873 #if !HAVE_CPU_AFFINITY
3874 debugs(3, DBG_CRITICAL
, "FATAL: Squid built with no CPU affinity " <<
3875 "support, do not set 'cpu_affinity_map'");
3877 #endif /* HAVE_CPU_AFFINITY */
3879 if (!*cpuAffinityMap
)
3880 *cpuAffinityMap
= new CpuAffinityMap
;
3882 const char *const pToken
= strtok(NULL
, w_space
);
3883 const char *const cToken
= strtok(NULL
, w_space
);
3884 Vector
<int> processes
, cores
;
3885 if (!parseNamedIntList(pToken
, "process_numbers", processes
)) {
3886 debugs(3, DBG_CRITICAL
, "FATAL: bad 'process_numbers' parameter " <<
3887 "in 'cpu_affinity_map'");
3889 } else if (!parseNamedIntList(cToken
, "cores", cores
)) {
3890 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cores' parameter in " <<
3891 "'cpu_affinity_map'");
3893 } else if (!(*cpuAffinityMap
)->add(processes
, cores
)) {
3894 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cpu_affinity_map'; " <<
3895 "process_numbers and cores lists differ in length or " <<
3896 "contain numbers <= 0");
3902 dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
)
3904 if (cpuAffinityMap
) {
3905 storeAppendPrintf(entry
, "%s process_numbers=", name
);
3906 for (size_t i
= 0; i
< cpuAffinityMap
->processes().size(); ++i
) {
3907 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
3908 cpuAffinityMap
->processes()[i
]);
3910 storeAppendPrintf(entry
, " cores=");
3911 for (size_t i
= 0; i
< cpuAffinityMap
->processes().size(); ++i
) {
3912 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
3913 cpuAffinityMap
->cores()[i
]);
3915 storeAppendPrintf(entry
, "\n");
3920 free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
3922 delete *cpuAffinityMap
;
3923 *cpuAffinityMap
= NULL
;
3929 parse_adaptation_service_set_type()
3931 Adaptation::Config::ParseServiceSet();
3935 parse_adaptation_service_chain_type()
3937 Adaptation::Config::ParseServiceChain();
3941 parse_adaptation_access_type()
3943 Adaptation::Config::ParseAccess(LegacyParser
);
3946 #endif /* USE_ADAPTATION */
3952 parse_icap_service_type(Adaptation::Icap::Config
* cfg
)
3954 cfg
->parseService();
3958 free_icap_service_type(Adaptation::Icap::Config
* cfg
)
3964 dump_icap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
3966 cfg
.dumpService(entry
, name
);
3970 parse_icap_class_type()
3972 debugs(93, 0, "WARNING: 'icap_class' is depricated. " <<
3973 "Use 'adaptation_service_set' instead");
3974 Adaptation::Config::ParseServiceSet();
3978 parse_icap_access_type()
3980 debugs(93, 0, "WARNING: 'icap_access' is depricated. " <<
3981 "Use 'adaptation_access' instead");
3982 Adaptation::Config::ParseAccess(LegacyParser
);
3991 parse_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
3993 cfg
->parseService();
3997 free_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4003 dump_ecap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Ecap::Config
&cfg
)
4005 cfg
.dumpService(entry
, name
);
4008 #endif /* USE_ECAP */
4011 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4016 cfg
->service_failure_limit
= GetInteger();
4018 if ((token
= strtok(NULL
, w_space
)) == NULL
)
4021 if (strcmp(token
,"in") != 0) {
4022 debugs(3, 0, "expecting 'in' on'" << config_input_line
<< "'");
4026 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
4030 d
= static_cast<time_t> (xatoi(token
));
4032 m
= static_cast<time_t> (1);
4036 else if ((token
= strtok(NULL
, w_space
)) == NULL
) {
4037 debugs(3, 0, "No time-units on '" << config_input_line
<< "'");
4039 } else if ((m
= parseTimeUnits(token
)) == 0)
4042 cfg
->oldest_service_failure
= (m
* d
);
4045 static void dump_icap_service_failure_limit(StoreEntry
*entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4047 storeAppendPrintf(entry
, "%s %d", name
, cfg
.service_failure_limit
);
4048 if (cfg
.oldest_service_failure
> 0) {
4049 storeAppendPrintf(entry
, " in %d seconds", (int)cfg
.oldest_service_failure
);
4051 storeAppendPrintf(entry
, "\n");
4054 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4056 cfg
->oldest_service_failure
= 0;
4057 cfg
->service_failure_limit
= 0;