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"
86 static void parse_adaptation_service_set_type();
87 static void parse_adaptation_service_chain_type();
88 static void parse_adaptation_access_type();
92 static void parse_icap_service_type(Adaptation::Icap::Config
*);
93 static void dump_icap_service_type(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
94 static void free_icap_service_type(Adaptation::Icap::Config
*);
95 static void parse_icap_class_type();
96 static void parse_icap_access_type();
98 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*);
99 static void dump_icap_service_failure_limit(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
100 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*);
104 static void parse_ecap_service_type(Adaptation::Ecap::Config
*);
105 static void dump_ecap_service_type(StoreEntry
*, const char *, const Adaptation::Ecap::Config
&);
106 static void free_ecap_service_type(Adaptation::Ecap::Config
*);
111 static const char *const T_SECOND_STR
= "second";
112 static const char *const T_MINUTE_STR
= "minute";
113 static const char *const T_HOUR_STR
= "hour";
114 static const char *const T_DAY_STR
= "day";
115 static const char *const T_WEEK_STR
= "week";
116 static const char *const T_FORTNIGHT_STR
= "fortnight";
117 static const char *const T_MONTH_STR
= "month";
118 static const char *const T_YEAR_STR
= "year";
119 static const char *const T_DECADE_STR
= "decade";
121 static const char *const B_BYTES_STR
= "bytes";
122 static const char *const B_KBYTES_STR
= "KB";
123 static const char *const B_MBYTES_STR
= "MB";
124 static const char *const B_GBYTES_STR
= "GB";
126 static const char *const list_sep
= ", \t\n\r";
128 static void parse_logformat(logformat
** logformat_definitions
);
129 static void parse_access_log(customlog
** customlog_definitions
);
130 static int check_null_access_log(customlog
*customlog_definitions
);
132 static void dump_logformat(StoreEntry
* entry
, const char *name
, logformat
* definitions
);
133 static void dump_access_log(StoreEntry
* entry
, const char *name
, customlog
* definitions
);
134 static void free_logformat(logformat
** definitions
);
135 static void free_access_log(customlog
** definitions
);
137 static void update_maxobjsize(void);
138 static void configDoConfigure(void);
139 static void parse_refreshpattern(refresh_t
**);
140 static int parseTimeUnits(const char *unit
);
141 static void parseTimeLine(time_t * tptr
, const char *units
);
142 static void parse_ushort(u_short
* var
);
143 static void parse_string(char **);
144 static void default_all(void);
145 static void defaults_if_none(void);
146 static int parse_line(char *);
147 static void parseBytesLine(size_t * bptr
, const char *units
);
149 static void parseBytesLineSigned(ssize_t
* bptr
, const char *units
);
151 static size_t parseBytesUnits(const char *unit
);
152 static void free_all(void);
153 void requirePathnameExists(const char *name
, const char *path
);
154 static OBJH dump_config
;
155 #if USE_HTTP_VIOLATIONS
156 static void dump_http_header_access(StoreEntry
* entry
, const char *name
, header_mangler header
[]);
157 static void parse_http_header_access(header_mangler header
[]);
158 static void free_http_header_access(header_mangler header
[]);
159 static void dump_http_header_replace(StoreEntry
* entry
, const char *name
, header_mangler header
[]);
160 static void parse_http_header_replace(header_mangler
* header
);
161 static void free_http_header_replace(header_mangler
* header
);
163 static void parse_denyinfo(acl_deny_info_list
** var
);
164 static void dump_denyinfo(StoreEntry
* entry
, const char *name
, acl_deny_info_list
* var
);
165 static void free_denyinfo(acl_deny_info_list
** var
);
168 static void parse_IpAddress_list(Ip::Address_list
**);
169 static void dump_IpAddress_list(StoreEntry
*, const char *, const Ip::Address_list
*);
170 static void free_IpAddress_list(Ip::Address_list
**);
172 static int check_null_IpAddress_list(const Ip::Address_list
*);
173 #endif /* CURRENTLY_UNUSED */
174 #endif /* USE_WCCPv2 */
176 static void parse_http_port_list(http_port_list
**);
177 static void dump_http_port_list(StoreEntry
*, const char *, const http_port_list
*);
178 static void free_http_port_list(http_port_list
**);
181 static void parse_https_port_list(https_port_list
**);
182 static void dump_https_port_list(StoreEntry
*, const char *, const https_port_list
*);
183 static void free_https_port_list(https_port_list
**);
185 static int check_null_https_port_list(const https_port_list
*);
189 static void parse_b_size_t(size_t * var
);
190 static void parse_b_int64_t(int64_t * var
);
192 static bool parseNamedIntList(const char *data
, const String
&name
, Vector
<int> &list
);
194 static void parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
195 static void dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
);
196 static void free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
);
198 static int parseOneConfigFile(const char *file_name
, unsigned int depth
);
201 * LegacyParser is a parser for legacy code that uses the global
202 * approach. This is static so that it is only exposed to cache_cf.
203 * Other modules needing access to a ConfigParser should have it
204 * provided to them in their parserFOO methods.
206 static ConfigParser LegacyParser
= ConfigParser();
211 LegacyParser
.destruct();
215 update_maxobjsize(void)
220 for (i
= 0; i
< Config
.cacheSwap
.n_configured
; i
++) {
221 assert (Config
.cacheSwap
.swapDirs
[i
].getRaw());
223 if (dynamic_cast<SwapDir
*>(Config
.cacheSwap
.swapDirs
[i
].getRaw())->
225 ms
= dynamic_cast<SwapDir
*>(Config
.cacheSwap
.swapDirs
[i
].getRaw())->max_objsize
;
227 store_maxobjsize
= ms
;
231 SetConfigFilename(char const *file_name
, bool is_pipe
)
233 cfg_filename
= file_name
;
238 cfg_filename
= file_name
+ 1;
239 else if ((token
= strrchr(cfg_filename
, '/')))
240 cfg_filename
= token
+ 1;
244 skip_ws(const char* s
)
253 parseManyConfigFiles(char* files
, int depth
)
256 char* saveptr
= NULL
;
261 memset(&globbuf
, 0, sizeof(globbuf
));
262 for (path
= strwordtok(files
, &saveptr
); path
; path
= strwordtok(NULL
, &saveptr
)) {
263 if (glob(path
, globbuf
.gl_pathc
? GLOB_APPEND
: 0, NULL
, &globbuf
) != 0) {
264 fatalf("Unable to find configuration file: %s: %s",
268 for (i
= 0; i
< (int)globbuf
.gl_pathc
; i
++) {
269 error_count
+= parseOneConfigFile(globbuf
.gl_pathv
[i
], depth
);
273 char* file
= strwordtok(files
, &saveptr
);
274 while (file
!= NULL
) {
275 error_count
+= parseOneConfigFile(file
, depth
);
276 file
= strwordtok(NULL
, &saveptr
);
278 #endif /* HAVE_GLOB */
283 ReplaceSubstr(char*& str
, int& len
, unsigned substrIdx
, unsigned substrLen
, const char* newSubstr
)
286 assert(newSubstr
!= NULL
);
288 unsigned newSubstrLen
= strlen(newSubstr
);
289 if (newSubstrLen
> substrLen
)
290 str
= (char*)realloc(str
, len
- substrLen
+ newSubstrLen
+ 1);
292 // move tail part including zero
293 memmove(str
+ substrIdx
+ newSubstrLen
, str
+ substrIdx
+ substrLen
, len
- substrIdx
- substrLen
+ 1);
294 // copy new substring in place
295 memcpy(str
+ substrIdx
, newSubstr
, newSubstrLen
);
301 SubstituteMacro(char*& line
, int& len
, const char* macroName
, const char* substStr
)
303 assert(line
!= NULL
);
304 assert(macroName
!= NULL
);
305 assert(substStr
!= NULL
);
306 unsigned macroNameLen
= strlen(macroName
);
307 while (const char* macroPos
= strstr(line
, macroName
)) // we would replace all occurrences
308 ReplaceSubstr(line
, len
, macroPos
- line
, macroNameLen
, substStr
);
312 ProcessMacros(char*& line
, int& len
)
314 SubstituteMacro(line
, len
, "${process_name}", TheKidName
);
315 SubstituteMacro(line
, len
, "${process_number}", xitoa(KidIdentifier
));
319 trim_trailing_ws(char* str
)
322 unsigned i
= strlen(str
);
323 while ((i
> 0) && xisspace(str
[i
- 1]))
329 FindStatement(const char* line
, const char* statement
)
331 assert(line
!= NULL
);
332 assert(statement
!= NULL
);
334 const char* str
= skip_ws(line
);
335 unsigned len
= strlen(statement
);
336 if (strncmp(str
, statement
, len
) == 0) {
340 else if (xisspace(*str
))
348 StrToInt(const char* str
, long& number
)
353 number
= strtol(str
, &end
, 0);
355 return (end
!= str
) && (*end
== '\0'); // returns true if string contains nothing except number
359 EvalBoolExpr(const char* expr
)
361 assert(expr
!= NULL
);
362 if (strcmp(expr
, "true") == 0) {
364 } else if (strcmp(expr
, "false") == 0) {
366 } else if (const char* equation
= strchr(expr
, '=')) {
367 const char* rvalue
= skip_ws(equation
+ 1);
368 char* lvalue
= (char*)xmalloc(equation
- expr
+ 1);
369 xstrncpy(lvalue
, expr
, equation
- expr
+ 1);
370 trim_trailing_ws(lvalue
);
373 if (!StrToInt(lvalue
, number1
))
374 fatalf("String is not a integer number: '%s'\n", lvalue
);
376 if (!StrToInt(rvalue
, number2
))
377 fatalf("String is not a integer number: '%s'\n", rvalue
);
380 return number1
== number2
;
382 fatalf("Unable to evaluate expression '%s'\n", expr
);
383 return false; // this place cannot be reached
387 parseOneConfigFile(const char *file_name
, unsigned int depth
)
390 const char *orig_cfg_filename
= cfg_filename
;
391 const int orig_config_lineno
= config_lineno
;
393 char *tmp_line
= NULL
;
394 int tmp_line_len
= 0;
398 debugs(3, 1, "Processing Configuration File: " << file_name
<< " (depth " << depth
<< ")");
400 fatalf("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name
);
404 if (file_name
[0] == '!' || file_name
[0] == '|') {
405 fp
= popen(file_name
+ 1, "r");
408 fp
= fopen(file_name
, "r");
412 fatalf("Unable to open configuration file: %s: %s", file_name
, xstrerror());
416 setmode(fileno(fp
), O_TEXT
);
420 SetConfigFilename(file_name
, bool(is_pipe
));
422 memset(config_input_line
, '\0', BUFSIZ
);
426 Vector
<bool> if_states
;
427 while (fgets(config_input_line
, BUFSIZ
, fp
)) {
430 if ((token
= strchr(config_input_line
, '\n')))
433 if ((token
= strchr(config_input_line
, '\r')))
436 if (strncmp(config_input_line
, "#line ", 6) == 0) {
437 static char new_file_name
[1024];
439 static char new_lineno
;
440 token
= config_input_line
+ 6;
441 new_lineno
= strtol(token
, &file
, 0) - 1;
444 continue; /* Not a valid #line directive, may be a comment */
446 while (*file
&& xisspace((unsigned char) *file
))
451 continue; /* Not a valid #line directive, may be a comment */
453 xstrncpy(new_file_name
, file
+ 1, sizeof(new_file_name
));
455 if ((token
= strchr(new_file_name
, '"')))
458 cfg_filename
= new_file_name
;
461 config_lineno
= new_lineno
;
464 if (config_input_line
[0] == '#')
467 if (config_input_line
[0] == '\0')
470 const char* append
= tmp_line_len
? skip_ws(config_input_line
) : config_input_line
;
472 size_t append_len
= strlen(append
);
474 tmp_line
= (char*)xrealloc(tmp_line
, tmp_line_len
+ append_len
+ 1);
476 strcpy(tmp_line
+ tmp_line_len
, append
);
478 tmp_line_len
+= append_len
;
480 if (tmp_line
[tmp_line_len
-1] == '\\') {
481 debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line
<< "'");
482 tmp_line
[--tmp_line_len
] = '\0';
486 trim_trailing_ws(tmp_line
);
487 ProcessMacros(tmp_line
, tmp_line_len
);
488 debugs(3, 5, "Processing: '" << tmp_line
<< "'");
490 if (const char* expr
= FindStatement(tmp_line
, "if")) {
491 if_states
.push_back(EvalBoolExpr(expr
)); // store last if-statement meaning
492 } else if (FindStatement(tmp_line
, "endif")) {
493 if (!if_states
.empty())
494 if_states
.pop_back(); // remove last if-statement meaning
496 fatalf("'endif' without 'if'\n");
497 } else if (FindStatement(tmp_line
, "else")) {
498 if (!if_states
.empty())
499 if_states
.back() = !if_states
.back();
501 fatalf("'else' without 'if'\n");
502 } else if (if_states
.empty() || if_states
.back()) { // test last if-statement meaning if present
503 /* Handle includes here */
504 if (tmp_line_len
>= 9 && strncmp(tmp_line
, "include", 7) == 0 && xisspace(tmp_line
[7])) {
505 err_count
+= parseManyConfigFiles(tmp_line
+ 8, depth
+ 1);
506 } else if (!parse_line(tmp_line
)) {
507 debugs(3, 0, HERE
<< cfg_filename
<< ":" << config_lineno
<< " unrecognized: '" << tmp_line
<< "'");
516 if (!if_states
.empty())
517 fatalf("if-statement without 'endif'\n");
520 int ret
= pclose(fp
);
523 fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name
, ret
);
528 cfg_filename
= orig_cfg_filename
;
529 config_lineno
= orig_config_lineno
;
535 parseConfigFile(const char *file_name
)
538 CacheManager
*manager
=CacheManager::GetInstance();
544 ACLMethodData::ThePurgeCount
= 0;
547 err_count
= parseOneConfigFile(file_name
, 0);
552 * We must call configDoConfigure() before leave_suid() because
553 * configDoConfigure() is where we turn username strings into
558 if (!Config
.chroot_dir
) {
560 setUmask(Config
.umask
);
561 _db_init(Debug::cache_log
, Debug::debugOptions
);
565 if (opt_send_signal
== -1) {
566 manager
->registerAction("config",
567 "Current Squid Configuration",
577 configDoConfigure(void)
579 memset(&Config2
, '\0', sizeof(SquidConfig2
));
580 /* init memory as early as possible */
584 if (Config
.cacheSwap
.swapDirs
== NULL
) {
585 /* Memory-only cache probably in effect. */
586 /* turn off the cache rebuild delays... */
587 StoreController::store_dirs_rebuilding
= 0;
590 if (Debug::rotateNumber
< 0) {
591 Debug::rotateNumber
= Config
.Log
.rotateNumber
;
594 #if SIZEOF_OFF_T <= 4
595 if (Config
.Store
.maxObjectSize
> 0x7FFF0000) {
596 debugs(3, 0, "WARNING: This Squid binary can not handle files larger than 2GB. Limiting maximum_object_size to just below 2GB");
597 Config
.Store
.maxObjectSize
= 0x7FFF0000;
600 if (0 == Store::Root().maxSize())
601 /* people might want a zero-sized cache on purpose */
603 else if (Store::Root().maxSize() < (Config
.memMaxSize
>> 10))
604 /* This is bogus. folk with NULL caches will want this */
605 debugs(3, 0, "WARNING cache_mem is larger than total disk cache space!");
607 if (Config
.Announce
.period
> 0) {
608 Config
.onoff
.announce
= 1;
609 } else if (Config
.Announce
.period
< 1) {
610 Config
.Announce
.period
= 86400 * 365; /* one year */
611 Config
.onoff
.announce
= 0;
614 if (Config
.onoff
.httpd_suppress_version_string
)
615 visible_appname_string
= (char *)appname_string
;
617 visible_appname_string
= (char const *)APP_FULLNAME
;
621 if (Config
.dnsChildren
.n_max
< 1)
622 fatal("No dnsservers allocated");
626 if (Config
.Program
.redirect
) {
627 if (Config
.redirectChildren
.n_max
< 1) {
628 Config
.redirectChildren
.n_max
= 0;
629 wordlistDestroy(&Config
.Program
.redirect
);
633 if (Config
.appendDomain
)
634 if (*Config
.appendDomain
!= '.')
635 fatal("append_domain must begin with a '.'");
637 if (Config
.errHtmlText
== NULL
)
638 Config
.errHtmlText
= xstrdup(null_string
);
642 snprintf(ThisCache
, sizeof(ThisCache
), "%s (%s)",
644 visible_appname_string
);
647 * the extra space is for loop detection in client_side.c -- we search
648 * for substrings in the Via header.
650 snprintf(ThisCache2
, sizeof(ThisCache
), " %s (%s)",
652 visible_appname_string
);
654 /* Use visible_hostname as default surrogate_id */
655 if (!Config
.Accel
.surrogate_id
) {
656 const char *t
= getMyHostname();
657 Config
.Accel
.surrogate_id
= xstrdup( (t
?t
:"unset-id") );
660 if (!Config
.udpMaxHitObjsz
|| Config
.udpMaxHitObjsz
> SQUID_UDP_SO_SNDBUF
)
661 Config
.udpMaxHitObjsz
= SQUID_UDP_SO_SNDBUF
;
663 if (Config
.appendDomain
)
664 Config
.appendDomainLen
= strlen(Config
.appendDomain
);
666 Config
.appendDomainLen
= 0;
668 if (Config
.retry
.maxtries
> 10)
669 fatal("maximum_single_addr_tries cannot be larger than 10");
671 if (Config
.retry
.maxtries
< 1) {
672 debugs(3, 0, "WARNING: resetting 'maximum_single_addr_tries to 1");
673 Config
.retry
.maxtries
= 1;
676 requirePathnameExists("MIME Config Table", Config
.mimeTablePathname
);
679 requirePathnameExists("cache_dns_program", Config
.Program
.dnsserver
);
683 requirePathnameExists("unlinkd_program", Config
.Program
.unlinkd
);
685 requirePathnameExists("logfile_daemon", Log::TheConfig
.logfile_daemon
);
686 if (Config
.Program
.redirect
)
687 requirePathnameExists("redirect_program", Config
.Program
.redirect
->key
);
689 requirePathnameExists("Icon Directory", Config
.icons
.directory
);
691 if (Config
.errorDirectory
)
692 requirePathnameExists("Error Directory", Config
.errorDirectory
);
694 #if USE_HTTP_VIOLATIONS
699 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
700 if (!R
->flags
.override_expire
)
703 debugs(22, 1, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP");
708 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
709 if (!R
->flags
.override_lastmod
)
712 debugs(22, 1, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP");
717 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
718 if (!R
->flags
.reload_into_ims
)
721 debugs(22, 1, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP");
726 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
727 if (!R
->flags
.ignore_reload
)
730 debugs(22, 1, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP");
735 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
736 if (!R
->flags
.ignore_no_cache
)
739 debugs(22, 1, "WARNING: use of 'ignore-no-cache' in 'refresh_pattern' violates HTTP");
744 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
745 if (!R
->flags
.ignore_no_store
)
748 debugs(22, 1, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP");
753 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
754 if (!R
->flags
.ignore_must_revalidate
)
756 debugs(22, 1, "WARNING: use of 'ignore-must-revalidate' in 'refresh_pattern' violates HTTP");
760 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
761 if (!R
->flags
.ignore_private
)
764 debugs(22, 1, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP");
769 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
770 if (!R
->flags
.ignore_auth
)
773 debugs(22, 1, "WARNING: use of 'ignore-auth' in 'refresh_pattern' violates HTTP");
780 #if !USE_HTTP_VIOLATIONS
781 Config
.onoff
.via
= 1;
784 if (!Config
.onoff
.via
)
785 debugs(22, 1, "WARNING: HTTP requires the use of Via");
789 // we enable runtime PURGE checks if there is at least one PURGE method ACL
790 // TODO: replace with a dedicated "purge" ACL option?
791 Config2
.onoff
.enable_purge
= (ACLMethodData::ThePurgeCount
> 0);
793 Config2
.onoff
.mangle_request_headers
= httpReqHdrManglersConfigured();
795 if (geteuid() == 0) {
796 if (NULL
!= Config
.effectiveUser
) {
798 struct passwd
*pwd
= getpwnam(Config
.effectiveUser
);
802 * Andres Kroonmaa <andre@online.ee>:
803 * Some getpwnam() implementations (Solaris?) require
804 * an available FD < 256 for opening a FILE* to the
807 * This should be safe at startup, but might still fail
808 * during reconfigure.
810 fatalf("getpwnam failed to find userid for effective user '%s'",
811 Config
.effectiveUser
);
815 Config2
.effectiveUserID
= pwd
->pw_uid
;
817 Config2
.effectiveGroupID
= pwd
->pw_gid
;
821 if (pwd
->pw_dir
&& *pwd
->pw_dir
) {
823 char *env_str
= (char *)xcalloc((len
= strlen(pwd
->pw_dir
) + 6), 1);
824 snprintf(env_str
, len
, "HOME=%s", pwd
->pw_dir
);
832 Config2
.effectiveUserID
= geteuid();
833 Config2
.effectiveGroupID
= getegid();
836 if (NULL
!= Config
.effectiveGroup
) {
838 struct group
*grp
= getgrnam(Config
.effectiveGroup
);
841 fatalf("getgrnam failed to find groupid for effective group '%s'",
842 Config
.effectiveGroup
);
846 Config2
.effectiveGroupID
= grp
->gr_gid
;
849 HttpRequestMethod::Configure(Config
);
852 debugs(3, 1, "Initializing https proxy context");
854 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
);
860 for (p
= Config
.peers
; p
!= NULL
; p
= p
->next
) {
862 debugs(3, 1, "Initializing cache_peer " << p
->name
<< " SSL context");
863 p
->sslContext
= sslCreateClientContext(p
->sslcert
, p
->sslkey
, p
->sslversion
, p
->sslcipher
, p
->ssloptions
, p
->sslflags
, p
->sslcafile
, p
->sslcapath
, p
->sslcrlfile
);
872 for (s
= Config
.Sockaddr
.http
; s
!= NULL
; s
= (http_port_list
*) s
->next
) {
873 if (!s
->cert
&& !s
->key
)
876 debugs(3, 1, "Initializing http_port " << s
->http
.s
<< " SSL context");
878 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 for (s
= Config
.Sockaddr
.https
; s
!= NULL
; s
= (https_port_list
*) s
->http
.next
) {
887 debugs(3, 1, "Initializing https_port " << s
->http
.s
<< " SSL context");
889 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
);
896 /* Parse a time specification from the config file. Store the
897 * result in 'tptr', after converting it to 'units' */
899 parseTimeLine(time_t * tptr
, const char *units
)
906 if ((u
= parseTimeUnits(units
)) == 0)
909 if ((token
= strtok(NULL
, w_space
)) == NULL
)
914 m
= u
; /* default to 'units' if none specified */
918 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
919 debugs(3, 0, "WARNING: No units on '" <<
920 config_input_line
<< "', assuming " <<
922 else if ((m
= parseTimeUnits(token
)) == 0)
925 *tptr
= static_cast<time_t> (m
* d
/ u
);
929 parseTimeUnits(const char *unit
)
931 if (!strncasecmp(unit
, T_SECOND_STR
, strlen(T_SECOND_STR
)))
934 if (!strncasecmp(unit
, T_MINUTE_STR
, strlen(T_MINUTE_STR
)))
937 if (!strncasecmp(unit
, T_HOUR_STR
, strlen(T_HOUR_STR
)))
940 if (!strncasecmp(unit
, T_DAY_STR
, strlen(T_DAY_STR
)))
943 if (!strncasecmp(unit
, T_WEEK_STR
, strlen(T_WEEK_STR
)))
946 if (!strncasecmp(unit
, T_FORTNIGHT_STR
, strlen(T_FORTNIGHT_STR
)))
949 if (!strncasecmp(unit
, T_MONTH_STR
, strlen(T_MONTH_STR
)))
952 if (!strncasecmp(unit
, T_YEAR_STR
, strlen(T_YEAR_STR
)))
953 return static_cast<int>(86400 * 365.2522);
955 if (!strncasecmp(unit
, T_DECADE_STR
, strlen(T_DECADE_STR
)))
956 return static_cast<int>(86400 * 365.2522 * 10);
958 debugs(3, 1, "parseTimeUnits: unknown time unit '" << unit
<< "'");
964 parseBytesLine64(int64_t * bptr
, const char *units
)
971 if ((u
= parseBytesUnits(units
)) == 0) {
976 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
981 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
988 m
= u
; /* default to 'units' if none specified */
992 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
993 debugs(3, 0, "WARNING: No units on '" <<
994 config_input_line
<< "', assuming " <<
996 else if ((m
= parseBytesUnits(token
)) == 0) {
1001 *bptr
= static_cast<int64_t>(m
* d
/ u
);
1003 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
1009 parseBytesLine(size_t * bptr
, const char *units
)
1016 if ((u
= parseBytesUnits(units
)) == 0) {
1021 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
1026 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1027 *bptr
= static_cast<size_t>(-1);
1033 m
= u
; /* default to 'units' if none specified */
1037 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1038 debugs(3, 0, "WARNING: No units on '" <<
1039 config_input_line
<< "', assuming " <<
1040 d
<< " " << units
);
1041 else if ((m
= parseBytesUnits(token
)) == 0) {
1046 *bptr
= static_cast<size_t>(m
* d
/ u
);
1048 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
1054 parseBytesLineSigned(ssize_t
* bptr
, const char *units
)
1061 if ((u
= parseBytesUnits(units
)) == 0) {
1066 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
1071 if (strcmp(token
, "none") == 0 || token
[0] == '-' /* -N */) {
1078 m
= u
; /* default to 'units' if none specified */
1082 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1083 debugs(3, 0, "WARNING: No units on '" <<
1084 config_input_line
<< "', assuming " <<
1085 d
<< " " << units
);
1086 else if ((m
= parseBytesUnits(token
)) == 0) {
1091 *bptr
= static_cast<size_t>(m
* d
/ u
);
1093 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
1099 parseBytesUnits(const char *unit
)
1101 if (!strncasecmp(unit
, B_BYTES_STR
, strlen(B_BYTES_STR
)))
1104 if (!strncasecmp(unit
, B_KBYTES_STR
, strlen(B_KBYTES_STR
)))
1107 if (!strncasecmp(unit
, B_MBYTES_STR
, strlen(B_MBYTES_STR
)))
1110 if (!strncasecmp(unit
, B_GBYTES_STR
, strlen(B_GBYTES_STR
)))
1113 debugs(3, DBG_CRITICAL
, "WARNING: Unknown bytes unit '" << unit
<< "'");
1118 /*****************************************************************************
1120 *****************************************************************************/
1123 dump_acl(StoreEntry
* entry
, const char *name
, ACL
* ae
)
1128 while (ae
!= NULL
) {
1129 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
);
1130 storeAppendPrintf(entry
, "%s %s %s ",
1137 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
<< " " << v
->key
);
1138 storeAppendPrintf(entry
, "%s ", v
->key
);
1142 storeAppendPrintf(entry
, "\n");
1143 wordlistDestroy(&w
);
1149 parse_acl(ACL
** ae
)
1151 ACL::ParseAclLine(LegacyParser
, ae
);
1161 dump_acl_list(StoreEntry
* entry
, ACLList
* head
)
1165 for (l
= head
; l
; l
= l
->next
) {
1166 storeAppendPrintf(entry
, " %s%s",
1167 l
->op
? null_string
: "!",
1173 dump_acl_access(StoreEntry
* entry
, const char *name
, acl_access
* head
)
1177 for (l
= head
; l
; l
= l
->next
) {
1178 storeAppendPrintf(entry
, "%s %s",
1180 l
->allow
? "Allow" : "Deny");
1181 dump_acl_list(entry
, l
->aclList
);
1182 storeAppendPrintf(entry
, "\n");
1187 parse_acl_access(acl_access
** head
)
1189 aclParseAccessLine(LegacyParser
, head
);
1193 free_acl_access(acl_access
** head
)
1195 aclDestroyAccessList(head
);
1199 dump_address(StoreEntry
* entry
, const char *name
, Ip::Address
&addr
)
1201 char buf
[MAX_IPSTRLEN
];
1202 storeAppendPrintf(entry
, "%s %s\n", name
, addr
.NtoA(buf
,MAX_IPSTRLEN
) );
1206 parse_address(Ip::Address
*addr
)
1208 char *token
= strtok(NULL
, w_space
);
1215 if (!strcmp(token
,"any_addr")) {
1218 } else if ( (!strcmp(token
,"no_addr")) || (!strcmp(token
,"full_mask")) ) {
1226 free_address(Ip::Address
*addr
)
1231 CBDATA_TYPE(acl_address
);
1234 dump_acl_address(StoreEntry
* entry
, const char *name
, acl_address
* head
)
1236 char buf
[MAX_IPSTRLEN
];
1239 for (l
= head
; l
; l
= l
->next
) {
1240 if (!l
->addr
.IsAnyAddr())
1241 storeAppendPrintf(entry
, "%s %s", name
, l
->addr
.NtoA(buf
,MAX_IPSTRLEN
));
1243 storeAppendPrintf(entry
, "%s autoselect", name
);
1245 dump_acl_list(entry
, l
->aclList
);
1247 storeAppendPrintf(entry
, "\n");
1252 freed_acl_address(void *data
)
1254 acl_address
*l
= static_cast<acl_address
*>(data
);
1255 aclDestroyAclList(&l
->aclList
);
1259 parse_acl_address(acl_address
** head
)
1262 acl_address
**tail
= head
; /* sane name below */
1263 CBDATA_INIT_TYPE_FREECB(acl_address
, freed_acl_address
);
1264 l
= cbdataAlloc(acl_address
);
1265 parse_address(&l
->addr
);
1266 aclParseAclList(LegacyParser
, &l
->aclList
);
1269 tail
= &(*tail
)->next
;
1275 free_acl_address(acl_address
** head
)
1278 acl_address
*l
= *head
;
1284 CBDATA_TYPE(acl_tos
);
1287 dump_acl_tos(StoreEntry
* entry
, const char *name
, acl_tos
* head
)
1291 for (l
= head
; l
; l
= l
->next
) {
1293 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->tos
);
1295 storeAppendPrintf(entry
, "%s none", name
);
1297 dump_acl_list(entry
, l
->aclList
);
1299 storeAppendPrintf(entry
, "\n");
1304 freed_acl_tos(void *data
)
1306 acl_tos
*l
= static_cast<acl_tos
*>(data
);
1307 aclDestroyAclList(&l
->aclList
);
1311 parse_acl_tos(acl_tos
** head
)
1314 acl_tos
**tail
= head
; /* sane name below */
1315 unsigned int tos
; /* Initially uint for strtoui. Casted to tos_t before return */
1316 char *token
= strtok(NULL
, w_space
);
1323 if (!xstrtoui(token
, NULL
, &tos
, 0, std::numeric_limits
<tos_t
>::max())) {
1328 CBDATA_INIT_TYPE_FREECB(acl_tos
, freed_acl_tos
);
1330 l
= cbdataAlloc(acl_tos
);
1332 l
->tos
= (tos_t
)tos
;
1334 aclParseAclList(LegacyParser
, &l
->aclList
);
1337 tail
= &(*tail
)->next
;
1343 free_acl_tos(acl_tos
** head
)
1353 #if defined(SO_MARK)
1355 CBDATA_TYPE(acl_nfmark
);
1358 dump_acl_nfmark(StoreEntry
* entry
, const char *name
, acl_nfmark
* head
)
1362 for (l
= head
; l
; l
= l
->next
) {
1364 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->nfmark
);
1366 storeAppendPrintf(entry
, "%s none", name
);
1368 dump_acl_list(entry
, l
->aclList
);
1370 storeAppendPrintf(entry
, "\n");
1375 freed_acl_nfmark(void *data
)
1377 acl_nfmark
*l
= static_cast<acl_nfmark
*>(data
);
1378 aclDestroyAclList(&l
->aclList
);
1382 parse_acl_nfmark(acl_nfmark
** head
)
1385 acl_nfmark
**tail
= head
; /* sane name below */
1387 char *token
= strtok(NULL
, w_space
);
1394 if (!xstrtoui(token
, NULL
, &mark
, 0, std::numeric_limits
<nfmark_t
>::max())) {
1399 CBDATA_INIT_TYPE_FREECB(acl_nfmark
, freed_acl_nfmark
);
1401 l
= cbdataAlloc(acl_nfmark
);
1405 aclParseAclList(LegacyParser
, &l
->aclList
);
1408 tail
= &(*tail
)->next
;
1414 free_acl_nfmark(acl_nfmark
** head
)
1417 acl_nfmark
*l
= *head
;
1423 #endif /* SO_MARK */
1425 CBDATA_TYPE(acl_size_t
);
1428 dump_acl_b_size_t(StoreEntry
* entry
, const char *name
, acl_size_t
* head
)
1432 for (l
= head
; l
; l
= l
->next
) {
1434 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) l
->size
, B_BYTES_STR
);
1436 storeAppendPrintf(entry
, "%s none", name
);
1438 dump_acl_list(entry
, l
->aclList
);
1440 storeAppendPrintf(entry
, "\n");
1445 freed_acl_b_size_t(void *data
)
1447 acl_size_t
*l
= static_cast<acl_size_t
*>(data
);
1448 aclDestroyAclList(&l
->aclList
);
1452 parse_acl_b_size_t(acl_size_t
** head
)
1455 acl_size_t
**tail
= head
; /* sane name below */
1457 CBDATA_INIT_TYPE_FREECB(acl_size_t
, freed_acl_b_size_t
);
1459 l
= cbdataAlloc(acl_size_t
);
1461 parse_b_int64_t(&l
->size
);
1463 aclParseAclList(LegacyParser
, &l
->aclList
);
1466 tail
= &(*tail
)->next
;
1472 free_acl_b_size_t(acl_size_t
** head
)
1475 acl_size_t
*l
= *head
;
1484 #include "DelayPools.h"
1485 #include "DelayConfig.h"
1486 /* do nothing - free_delay_pool_count is the magic free function.
1487 * this is why delay_pool_count isn't just marked TYPE: ushort
1489 #define free_delay_pool_class(X)
1490 #define free_delay_pool_access(X)
1491 #define free_delay_pool_rates(X)
1492 #define dump_delay_pool_class(X, Y, Z)
1493 #define dump_delay_pool_access(X, Y, Z)
1494 #define dump_delay_pool_rates(X, Y, Z)
1497 free_delay_pool_count(DelayConfig
* cfg
)
1499 cfg
->freePoolCount();
1503 dump_delay_pool_count(StoreEntry
* entry
, const char *name
, DelayConfig
&cfg
)
1505 cfg
.dumpPoolCount (entry
, name
);
1509 parse_delay_pool_count(DelayConfig
* cfg
)
1511 cfg
->parsePoolCount();
1515 parse_delay_pool_class(DelayConfig
* cfg
)
1517 cfg
->parsePoolClass();
1521 parse_delay_pool_rates(DelayConfig
* cfg
)
1523 cfg
->parsePoolRates();
1527 parse_delay_pool_access(DelayConfig
* cfg
)
1529 cfg
->parsePoolAccess(LegacyParser
);
1534 #if USE_HTTP_VIOLATIONS
1536 dump_http_header_access(StoreEntry
* entry
, const char *name
, header_mangler header
[])
1540 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1541 if (header
[i
].access_list
!= NULL
) {
1542 storeAppendPrintf(entry
, "%s ", name
);
1543 dump_acl_access(entry
, httpHeaderNameById(i
),
1544 header
[i
].access_list
);
1550 parse_http_header_access(header_mangler header
[])
1555 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1556 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1557 debugs(3, 0, "parse_http_header_access: missing header name.");
1561 /* Now lookup index of header. */
1562 id
= httpHeaderIdByNameDef(t
, strlen(t
));
1564 if (strcmp(t
, "All") == 0)
1566 else if (strcmp(t
, "Other") == 0)
1568 else if (id
== -1) {
1569 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1570 debugs(3, 0, "parse_http_header_access: unknown header name '" << t
<< "'");
1574 if (id
!= HDR_ENUM_END
) {
1575 parse_acl_access(&header
[id
].access_list
);
1577 char *next_string
= t
+ strlen(t
) - 1;
1579 *(next_string
+ 1) = ' ';
1581 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1582 char *new_string
= xstrdup(next_string
);
1583 strtok(new_string
, w_space
);
1584 parse_acl_access(&header
[i
].access_list
);
1585 safe_free(new_string
);
1591 free_http_header_access(header_mangler header
[])
1595 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1596 free_acl_access(&header
[i
].access_list
);
1601 dump_http_header_replace(StoreEntry
* entry
, const char *name
, header_mangler
1606 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1607 if (NULL
== header
[i
].replacement
)
1610 storeAppendPrintf(entry
, "%s %s %s\n", name
, httpHeaderNameById(i
),
1611 header
[i
].replacement
);
1616 parse_http_header_replace(header_mangler header
[])
1621 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1622 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1623 debugs(3, 0, "parse_http_header_replace: missing header name.");
1627 /* Now lookup index of header. */
1628 id
= httpHeaderIdByNameDef(t
, strlen(t
));
1630 if (strcmp(t
, "All") == 0)
1632 else if (strcmp(t
, "Other") == 0)
1634 else if (id
== -1) {
1635 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1636 debugs(3, 0, "parse_http_header_replace: unknown header name " << t
<< ".");
1641 if (id
!= HDR_ENUM_END
) {
1642 if (header
[id
].replacement
!= NULL
)
1643 safe_free(header
[id
].replacement
);
1645 header
[id
].replacement
= xstrdup(t
+ strlen(t
) + 1);
1647 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1648 if (header
[i
].replacement
!= NULL
)
1649 safe_free(header
[i
].replacement
);
1651 header
[i
].replacement
= xstrdup(t
+ strlen(t
) + 1);
1657 free_http_header_replace(header_mangler header
[])
1661 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1662 if (header
[i
].replacement
!= NULL
)
1663 safe_free(header
[i
].replacement
);
1670 dump_cachedir(StoreEntry
* entry
, const char *name
, SquidConfig::_cacheSwap swap
)
1676 for (i
= 0; i
< swap
.n_configured
; i
++) {
1677 s
= dynamic_cast<SwapDir
*>(swap
.swapDirs
[i
].getRaw());
1679 storeAppendPrintf(entry
, "%s %s %s", name
, s
->type(), s
->path
);
1681 storeAppendPrintf(entry
, "\n");
1686 check_null_string(char *s
)
1692 parse_authparam(Auth::authConfig
* config
)
1697 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1700 if ((param_str
= strtok(NULL
, w_space
)) == NULL
)
1703 /* find a configuration for the scheme in the currently parsed configs... */
1704 AuthConfig
*schemeCfg
= AuthConfig::Find(type_str
);
1706 if (schemeCfg
== NULL
) {
1707 /* Create a configuration based on the scheme info */
1708 AuthScheme::Pointer theScheme
= AuthScheme::Find(type_str
);
1710 if (theScheme
== NULL
) {
1711 debugs(3, DBG_CRITICAL
, "Parsing Config File: Unknown authentication scheme '" << type_str
<< "'.");
1715 config
->push_back(theScheme
->createConfig());
1716 schemeCfg
= AuthConfig::Find(type_str
);
1717 if (schemeCfg
== NULL
) {
1718 debugs(3, DBG_CRITICAL
, "Parsing Config File: Corruption configuring authentication scheme '" << type_str
<< "'.");
1723 schemeCfg
->parse(schemeCfg
, config
->size(), param_str
);
1727 free_authparam(Auth::authConfig
* cfg
)
1729 /* Wipe the Auth globals and Detach/Destruct component config + state. */
1732 /* remove our pointers to the probably-dead sub-configs */
1733 while (cfg
->size()) {
1737 /* on reconfigure initialize new auth schemes for the new config. */
1738 if (reconfiguring
) {
1744 dump_authparam(StoreEntry
* entry
, const char *name
, authConfig cfg
)
1746 for (authConfig::iterator i
= cfg
.begin(); i
!= cfg
.end(); ++i
)
1747 (*i
)->dump(entry
, name
, (*i
));
1750 /* TODO: just return the object, the # is irrelevant */
1752 find_fstype(char *type
)
1754 for (size_t i
= 0; i
< StoreFileSystem::FileSystems().size(); ++i
)
1755 if (strcasecmp(type
, StoreFileSystem::FileSystems().items
[i
]->type()) == 0)
1762 parse_cachedir(SquidConfig::_cacheSwap
* swap
)
1764 // The workers option must preceed cache_dir for the IamWorkerProcess check
1765 // below to work. TODO: Redo IamWorkerProcess to work w/o Config and remove
1766 if (KidIdentifier
> 1 && Config
.workers
== 1) {
1767 debugs(3, DBG_CRITICAL
,
1768 "FATAL: cache_dir found before the workers option. Reorder.");
1772 // Among all processes, only workers may need and can handle cache_dir.
1773 if (!IamWorkerProcess())
1778 RefCount
<SwapDir
> sd
;
1782 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1785 if ((path_str
= strtok(NULL
, w_space
)) == NULL
)
1788 fs
= find_fstype(type_str
);
1793 /* reconfigure existing dir */
1795 for (i
= 0; i
< swap
->n_configured
; i
++) {
1796 assert (swap
->swapDirs
[i
].getRaw());
1798 if ((strcasecmp(path_str
, dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw())->path
)) == 0) {
1799 /* this is specific to on-fs Stores. The right
1800 * way to handle this is probably to have a mapping
1801 * from paths to stores, and have on-fs stores
1802 * register with that, and lookip in that in their
1803 * own setup logic. RBC 20041225. TODO.
1806 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw());
1808 if (sd
->type() != StoreFileSystem::FileSystems().items
[fs
]->type()) {
1809 debugs(3, 0, "ERROR: Can't change type of existing cache_dir " <<
1810 sd
->type() << " " << sd
->path
<< " to " << type_str
<< ". Restart required");
1814 sd
->reconfigure (i
, path_str
);
1816 update_maxobjsize();
1823 if (swap
->n_configured
> 63) {
1824 /* 7 bits, signed */
1825 debugs(3, DBG_CRITICAL
, "WARNING: There is a fixed maximum of 63 cache_dir entries Squid can handle.");
1826 debugs(3, DBG_CRITICAL
, "WARNING: '" << path_str
<< "' is one to many.");
1831 allocate_new_swapdir(swap
);
1833 swap
->swapDirs
[swap
->n_configured
] = StoreFileSystem::FileSystems().items
[fs
]->createSwapDir();
1835 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[swap
->n_configured
].getRaw());
1837 /* parse the FS parameters and options */
1838 sd
->parse(swap
->n_configured
, path_str
);
1840 ++swap
->n_configured
;
1842 /* Update the max object size */
1843 update_maxobjsize();
1847 peer_type_str(const peer_t type
)
1849 const char * result
;
1861 case PEER_MULTICAST
:
1862 result
= "multicast";
1874 dump_peer(StoreEntry
* entry
, const char *name
, peer
* p
)
1878 LOCAL_ARRAY(char, xname
, 128);
1881 storeAppendPrintf(entry
, "%s %s %s %d %d name=%s",
1888 dump_peer_options(entry
, p
);
1890 for (d
= p
->peer_domain
; d
; d
= d
->next
) {
1891 storeAppendPrintf(entry
, "cache_peer_domain %s %s%s\n",
1893 d
->do_ping
? null_string
: "!",
1898 snprintf(xname
, 128, "cache_peer_access %s", p
->name
);
1899 dump_acl_access(entry
, xname
, p
->access
);
1902 for (t
= p
->typelist
; t
; t
= t
->next
) {
1903 storeAppendPrintf(entry
, "neighbor_type_domain %s %s %s\n",
1905 peer_type_str(t
->type
),
1914 * utility function to prevent getservbyname() being called with a numeric value
1915 * on Windows at least it returns garage results.
1918 isUnsignedNumeric(const char *str
, size_t len
)
1920 if (len
< 1) return false;
1922 for (; len
>0 && *str
; str
++, len
--) {
1923 if (! isdigit(*str
))
1930 \param proto 'tcp' or 'udp' for protocol
1931 \returns Port the named service is supposed to be listening on.
1934 GetService(const char *proto
)
1936 struct servent
*port
= NULL
;
1937 /** Parses a port number or service name from the squid.conf */
1938 char *token
= strtok(NULL
, w_space
);
1939 if (token
== NULL
) {
1941 return 0; /* NEVER REACHED */
1943 /** Returns either the service port number from /etc/services */
1944 if ( !isUnsignedNumeric(token
, strlen(token
)) )
1945 port
= getservbyname(token
, proto
);
1947 return ntohs((u_short
)port
->s_port
);
1949 /** Or a numeric translation of the config text. */
1950 return xatos(token
);
1954 \returns Port the named TCP service is supposed to be listening on.
1955 \copydoc GetService(const char *proto)
1960 return GetService("tcp");
1964 \returns Port the named UDP service is supposed to be listening on.
1965 \copydoc GetService(const char *proto)
1970 return GetService("udp");
1974 parse_peer(peer
** head
)
1978 CBDATA_INIT_TYPE_FREECB(peer
, peerDestroy
);
1979 p
= cbdataAlloc(peer
);
1980 p
->http_port
= CACHE_HTTP_PORT
;
1981 p
->icp
.port
= CACHE_ICP_PORT
;
1984 p
->stats
.logged_state
= PEER_ALIVE
;
1986 if ((token
= strtok(NULL
, w_space
)) == NULL
)
1989 p
->host
= xstrdup(token
);
1991 p
->name
= xstrdup(token
);
1993 if ((token
= strtok(NULL
, w_space
)) == NULL
)
1996 p
->type
= parseNeighborType(token
);
1998 if (p
->type
== PEER_MULTICAST
) {
1999 p
->options
.no_digest
= 1;
2000 p
->options
.no_netdb_exchange
= 1;
2003 p
->http_port
= GetTcpService();
2008 p
->icp
.port
= GetUdpService();
2009 p
->connection_auth
= 2; /* auto */
2011 while ((token
= strtok(NULL
, w_space
))) {
2012 if (!strcasecmp(token
, "proxy-only")) {
2013 p
->options
.proxy_only
= 1;
2014 } else if (!strcasecmp(token
, "no-query")) {
2015 p
->options
.no_query
= 1;
2016 } else if (!strcasecmp(token
, "background-ping")) {
2017 p
->options
.background_ping
= 1;
2018 } else if (!strcasecmp(token
, "no-digest")) {
2019 p
->options
.no_digest
= 1;
2020 } else if (!strcasecmp(token
, "no-tproxy")) {
2021 p
->options
.no_tproxy
= 1;
2022 } else if (!strcasecmp(token
, "multicast-responder")) {
2023 p
->options
.mcast_responder
= 1;
2024 #if PEER_MULTICAST_SIBLINGS
2025 } else if (!strcasecmp(token
, "multicast-siblings")) {
2026 p
->options
.mcast_siblings
= 1;
2028 } else if (!strncasecmp(token
, "weight=", 7)) {
2029 p
->weight
= xatoi(token
+ 7);
2030 } else if (!strncasecmp(token
, "basetime=", 9)) {
2031 p
->basetime
= xatoi(token
+ 9);
2032 } else if (!strcasecmp(token
, "closest-only")) {
2033 p
->options
.closest_only
= 1;
2034 } else if (!strncasecmp(token
, "ttl=", 4)) {
2035 p
->mcast
.ttl
= xatoi(token
+ 4);
2037 if (p
->mcast
.ttl
< 0)
2040 if (p
->mcast
.ttl
> 128)
2042 } else if (!strcasecmp(token
, "default")) {
2043 p
->options
.default_parent
= 1;
2044 } else if (!strcasecmp(token
, "round-robin")) {
2045 p
->options
.roundrobin
= 1;
2046 } else if (!strcasecmp(token
, "weighted-round-robin")) {
2047 p
->options
.weighted_roundrobin
= 1;
2049 } else if (!strcasecmp(token
, "htcp")) {
2050 p
->options
.htcp
= 1;
2051 } else if (!strncasecmp(token
, "htcp=", 5) || !strncasecmp(token
, "htcp-", 5)) {
2052 /* Note: The htcp- form is deprecated, replaced by htcp= */
2053 p
->options
.htcp
= 1;
2054 char *tmp
= xstrdup(token
+5);
2055 char *mode
, *nextmode
;
2056 for (mode
= nextmode
= tmp
; mode
; mode
= nextmode
) {
2057 nextmode
= strchr(mode
, ',');
2060 if (!strcasecmp(mode
, "no-clr")) {
2061 if (p
->options
.htcp_only_clr
)
2062 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
2063 p
->options
.htcp_no_clr
= 1;
2064 } else if (!strcasecmp(mode
, "no-purge-clr")) {
2065 p
->options
.htcp_no_purge_clr
= 1;
2066 } else if (!strcasecmp(mode
, "only-clr")) {
2067 if (p
->options
.htcp_no_clr
)
2068 fatalf("parse_peer: can't set htcp no-clr and only-clr simultaneously");
2069 p
->options
.htcp_only_clr
= 1;
2070 } else if (!strcasecmp(mode
, "forward-clr")) {
2071 p
->options
.htcp_forward_clr
= 1;
2072 } else if (!strcasecmp(mode
, "oldsquid")) {
2073 p
->options
.htcp_oldsquid
= 1;
2075 fatalf("invalid HTCP mode '%s'", mode
);
2080 } else if (!strcasecmp(token
, "no-netdb-exchange")) {
2081 p
->options
.no_netdb_exchange
= 1;
2083 } else if (!strcasecmp(token
, "carp")) {
2084 if (p
->type
!= PEER_PARENT
)
2085 fatalf("parse_peer: non-parent carp peer %s/%d\n", p
->host
, p
->http_port
);
2087 p
->options
.carp
= 1;
2089 } else if (!strcasecmp(token
, "userhash")) {
2090 if (p
->type
!= PEER_PARENT
)
2091 fatalf("parse_peer: non-parent userhash peer %s/%d\n", p
->host
, p
->http_port
);
2093 p
->options
.userhash
= 1;
2095 } else if (!strcasecmp(token
, "sourcehash")) {
2096 if (p
->type
!= PEER_PARENT
)
2097 fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p
->host
, p
->http_port
);
2099 p
->options
.sourcehash
= 1;
2103 } else if (!strcasecmp(token
, "no-delay")) {
2104 p
->options
.no_delay
= 1;
2107 } else if (!strncasecmp(token
, "login=", 6)) {
2108 p
->login
= xstrdup(token
+ 6);
2109 rfc1738_unescape(p
->login
);
2110 } else if (!strncasecmp(token
, "connect-timeout=", 16)) {
2111 p
->connect_timeout
= xatoi(token
+ 16);
2112 } else if (!strncasecmp(token
, "connect-fail-limit=", 19)) {
2113 p
->connect_fail_limit
= xatoi(token
+ 19);
2114 #if USE_CACHE_DIGESTS
2115 } else if (!strncasecmp(token
, "digest-url=", 11)) {
2116 p
->digest_url
= xstrdup(token
+ 11);
2119 } else if (!strcasecmp(token
, "allow-miss")) {
2120 p
->options
.allow_miss
= 1;
2121 } else if (!strncasecmp(token
, "max-conn=", 9)) {
2122 p
->max_conn
= xatoi(token
+ 9);
2123 } else if (!strcasecmp(token
, "originserver")) {
2124 p
->options
.originserver
= 1;
2125 } else if (!strncasecmp(token
, "name=", 5)) {
2129 p
->name
= xstrdup(token
+ 5);
2130 } else if (!strncasecmp(token
, "forceddomain=", 13)) {
2131 safe_free(p
->domain
);
2134 p
->domain
= xstrdup(token
+ 13);
2138 } else if (strcmp(token
, "ssl") == 0) {
2140 } else if (strncmp(token
, "sslcert=", 8) == 0) {
2141 safe_free(p
->sslcert
);
2142 p
->sslcert
= xstrdup(token
+ 8);
2143 } else if (strncmp(token
, "sslkey=", 7) == 0) {
2144 safe_free(p
->sslkey
);
2145 p
->sslkey
= xstrdup(token
+ 7);
2146 } else if (strncmp(token
, "sslversion=", 11) == 0) {
2147 p
->sslversion
= atoi(token
+ 11);
2148 } else if (strncmp(token
, "ssloptions=", 11) == 0) {
2149 safe_free(p
->ssloptions
);
2150 p
->ssloptions
= xstrdup(token
+ 11);
2151 } else if (strncmp(token
, "sslcipher=", 10) == 0) {
2152 safe_free(p
->sslcipher
);
2153 p
->sslcipher
= xstrdup(token
+ 10);
2154 } else if (strncmp(token
, "sslcafile=", 10) == 0) {
2155 safe_free(p
->sslcafile
);
2156 p
->sslcafile
= xstrdup(token
+ 10);
2157 } else if (strncmp(token
, "sslcapath=", 10) == 0) {
2158 safe_free(p
->sslcapath
);
2159 p
->sslcapath
= xstrdup(token
+ 10);
2160 } else if (strncmp(token
, "sslcrlfile=", 11) == 0) {
2161 safe_free(p
->sslcrlfile
);
2162 p
->sslcapath
= xstrdup(token
+ 10);
2163 } else if (strncmp(token
, "sslflags=", 9) == 0) {
2164 safe_free(p
->sslflags
);
2165 p
->sslflags
= xstrdup(token
+ 9);
2166 } else if (strncmp(token
, "ssldomain=", 10) == 0) {
2167 safe_free(p
->ssldomain
);
2168 p
->ssldomain
= xstrdup(token
+ 10);
2171 } else if (strcmp(token
, "front-end-https") == 0) {
2172 p
->front_end_https
= 1;
2173 } else if (strcmp(token
, "front-end-https=on") == 0) {
2174 p
->front_end_https
= 1;
2175 } else if (strcmp(token
, "front-end-https=auto") == 0) {
2176 p
->front_end_https
= 2;
2177 } else if (strcmp(token
, "connection-auth=off") == 0) {
2178 p
->connection_auth
= 0;
2179 } else if (strcmp(token
, "connection-auth") == 0) {
2180 p
->connection_auth
= 1;
2181 } else if (strcmp(token
, "connection-auth=on") == 0) {
2182 p
->connection_auth
= 1;
2183 } else if (strcmp(token
, "connection-auth=auto") == 0) {
2184 p
->connection_auth
= 2;
2186 debugs(3, 0, "parse_peer: token='" << token
<< "'");
2191 if (peerFindByName(p
->name
))
2192 fatalf("ERROR: cache_peer %s specified twice\n", p
->name
);
2197 if (p
->connect_fail_limit
< 1)
2198 p
->connect_fail_limit
= 10;
2200 p
->icp
.version
= ICP_VERSION_CURRENT
;
2204 #if USE_CACHE_DIGESTS
2206 if (!p
->options
.no_digest
) {
2207 /* XXX This looks odd.. who has the original pointer
2210 PeerDigest
*pd
= peerDigestCreate(p
);
2211 p
->digest
= cbdataReference(pd
);
2216 p
->index
= ++Config
.npeers
;
2218 while (*head
!= NULL
)
2219 head
= &(*head
)->next
;
2227 free_peer(peer
** P
)
2231 while ((p
= *P
) != NULL
) {
2233 #if USE_CACHE_DIGESTS
2235 cbdataReferenceDone(p
->digest
);
2245 dump_cachemgrpasswd(StoreEntry
* entry
, const char *name
, cachemgr_passwd
* list
)
2249 while (list
!= NULL
) {
2250 if (strcmp(list
->passwd
, "none") && strcmp(list
->passwd
, "disable"))
2251 storeAppendPrintf(entry
, "%s XXXXXXXXXX", name
);
2253 storeAppendPrintf(entry
, "%s %s", name
, list
->passwd
);
2255 for (w
= list
->actions
; w
!= NULL
; w
= w
->next
) {
2256 storeAppendPrintf(entry
, " %s", w
->key
);
2259 storeAppendPrintf(entry
, "\n");
2265 parse_cachemgrpasswd(cachemgr_passwd
** head
)
2267 char *passwd
= NULL
;
2268 wordlist
*actions
= NULL
;
2270 cachemgr_passwd
**P
;
2271 parse_string(&passwd
);
2272 parse_wordlist(&actions
);
2273 p
= static_cast<cachemgr_passwd
*>(xcalloc(1, sizeof(cachemgr_passwd
)));
2275 p
->actions
= actions
;
2277 for (P
= head
; *P
; P
= &(*P
)->next
) {
2279 * See if any of the actions from this line already have a
2280 * password from previous lines. The password checking
2281 * routines in cache_manager.c take the the password from
2282 * the first cachemgr_passwd struct that contains the
2283 * requested action. Thus, we should warn users who might
2284 * think they can have two passwords for the same action.
2289 for (w
= (*P
)->actions
; w
; w
= w
->next
) {
2290 for (u
= actions
; u
; u
= u
->next
) {
2291 if (strcmp(w
->key
, u
->key
))
2294 debugs(0, 0, "WARNING: action '" << u
->key
<< "' (line " << config_lineno
<< ") already has a password");
2303 free_cachemgrpasswd(cachemgr_passwd
** head
)
2307 while ((p
= *head
) != NULL
) {
2310 wordlistDestroy(&p
->actions
);
2316 dump_denyinfo(StoreEntry
* entry
, const char *name
, acl_deny_info_list
* var
)
2320 while (var
!= NULL
) {
2321 storeAppendPrintf(entry
, "%s %s", name
, var
->err_page_name
);
2323 for (a
= var
->acl_list
; a
!= NULL
; a
= a
->next
)
2324 storeAppendPrintf(entry
, " %s", a
->name
);
2326 storeAppendPrintf(entry
, "\n");
2333 parse_denyinfo(acl_deny_info_list
** var
)
2335 aclParseDenyInfoLine(var
);
2339 free_denyinfo(acl_deny_info_list
** list
)
2341 acl_deny_info_list
*a
= NULL
;
2342 acl_deny_info_list
*a_next
= NULL
;
2343 acl_name_list
*l
= NULL
;
2344 acl_name_list
*l_next
= NULL
;
2346 for (a
= *list
; a
; a
= a_next
) {
2347 for (l
= a
->acl_list
; l
; l
= l_next
) {
2349 memFree(l
, MEM_ACL_NAME_LIST
);
2354 memFree(a
, MEM_ACL_DENY_INFO_LIST
);
2362 parse_peer_access(void)
2367 if (!(host
= strtok(NULL
, w_space
)))
2370 if ((p
= peerFindByName(host
)) == NULL
) {
2371 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2375 aclParseAccessLine(LegacyParser
, &p
->access
);
2379 parse_hostdomain(void)
2382 char *domain
= NULL
;
2384 if (!(host
= strtok(NULL
, w_space
)))
2387 while ((domain
= strtok(NULL
, list_sep
))) {
2388 domain_ping
*l
= NULL
;
2389 domain_ping
**L
= NULL
;
2392 if ((p
= peerFindByName(host
)) == NULL
) {
2393 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2397 l
= static_cast<domain_ping
*>(xcalloc(1, sizeof(domain_ping
)));
2400 if (*domain
== '!') { /* check for !.edu */
2405 l
->domain
= xstrdup(domain
);
2407 for (L
= &(p
->peer_domain
); *L
; L
= &((*L
)->next
));
2413 parse_hostdomaintype(void)
2417 char *domain
= NULL
;
2419 if (!(host
= strtok(NULL
, w_space
)))
2422 if (!(type
= strtok(NULL
, w_space
)))
2425 while ((domain
= strtok(NULL
, list_sep
))) {
2426 domain_type
*l
= NULL
;
2427 domain_type
**L
= NULL
;
2430 if ((p
= peerFindByName(host
)) == NULL
) {
2431 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2435 l
= static_cast<domain_type
*>(xcalloc(1, sizeof(domain_type
)));
2436 l
->type
= parseNeighborType(type
);
2437 l
->domain
= xstrdup(domain
);
2439 for (L
= &(p
->typelist
); *L
; L
= &((*L
)->next
));
2445 dump_int(StoreEntry
* entry
, const char *name
, int var
)
2447 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2465 dump_onoff(StoreEntry
* entry
, const char *name
, int var
)
2467 storeAppendPrintf(entry
, "%s %s\n", name
, var
? "on" : "off");
2471 parse_onoff(int *var
)
2473 char *token
= strtok(NULL
, w_space
);
2478 if (!strcasecmp(token
, "on") || !strcasecmp(token
, "enable"))
2484 #define free_onoff free_int
2487 dump_tristate(StoreEntry
* entry
, const char *name
, int var
)
2498 storeAppendPrintf(entry
, "%s %s\n", name
, state
);
2502 parse_tristate(int *var
)
2504 char *token
= strtok(NULL
, w_space
);
2509 if (!strcasecmp(token
, "on") || !strcasecmp(token
, "enable"))
2511 else if (!strcasecmp(token
, "warn"))
2517 #define free_tristate free_int
2520 dump_refreshpattern(StoreEntry
* entry
, const char *name
, refresh_t
* head
)
2522 while (head
!= NULL
) {
2523 storeAppendPrintf(entry
, "%s%s %s %d %d%% %d",
2525 head
->flags
.icase
? " -i" : null_string
,
2527 (int) head
->min
/ 60,
2528 (int) (100.0 * head
->pct
+ 0.5),
2529 (int) head
->max
/ 60);
2531 if (head
->flags
.refresh_ims
)
2532 storeAppendPrintf(entry
, " refresh-ims");
2534 if (head
->flags
.store_stale
)
2535 storeAppendPrintf(entry
, " store-stale");
2537 #if USE_HTTP_VIOLATIONS
2539 if (head
->flags
.override_expire
)
2540 storeAppendPrintf(entry
, " override-expire");
2542 if (head
->flags
.override_lastmod
)
2543 storeAppendPrintf(entry
, " override-lastmod");
2545 if (head
->flags
.reload_into_ims
)
2546 storeAppendPrintf(entry
, " reload-into-ims");
2548 if (head
->flags
.ignore_reload
)
2549 storeAppendPrintf(entry
, " ignore-reload");
2551 if (head
->flags
.ignore_no_cache
)
2552 storeAppendPrintf(entry
, " ignore-no-cache");
2554 if (head
->flags
.ignore_no_store
)
2555 storeAppendPrintf(entry
, " ignore-no-store");
2557 if (head
->flags
.ignore_must_revalidate
)
2558 storeAppendPrintf(entry
, " ignore-must-revalidate");
2560 if (head
->flags
.ignore_private
)
2561 storeAppendPrintf(entry
, " ignore-private");
2563 if (head
->flags
.ignore_auth
)
2564 storeAppendPrintf(entry
, " ignore-auth");
2568 storeAppendPrintf(entry
, "\n");
2575 parse_refreshpattern(refresh_t
** head
)
2582 int refresh_ims
= 0;
2583 int store_stale
= 0;
2585 #if USE_HTTP_VIOLATIONS
2587 int override_expire
= 0;
2588 int override_lastmod
= 0;
2589 int reload_into_ims
= 0;
2590 int ignore_reload
= 0;
2591 int ignore_no_cache
= 0;
2592 int ignore_no_store
= 0;
2593 int ignore_must_revalidate
= 0;
2594 int ignore_private
= 0;
2595 int ignore_auth
= 0;
2602 int flags
= REG_EXTENDED
| REG_NOSUB
;
2604 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
2609 if (strcmp(token
, "-i") == 0) {
2611 token
= strtok(NULL
, w_space
);
2612 } else if (strcmp(token
, "+i") == 0) {
2613 flags
&= ~REG_ICASE
;
2614 token
= strtok(NULL
, w_space
);
2617 if (token
== NULL
) {
2622 pattern
= xstrdup(token
);
2624 i
= GetInteger(); /* token: min */
2626 /* catch negative and insanely huge values close to 32-bit wrap */
2628 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age negative. Cropped back to zero.");
2631 if (i
> 60*24*365) {
2632 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age too high. Cropped back to 1 year.");
2636 min
= (time_t) (i
* 60); /* convert minutes to seconds */
2638 i
= GetInteger(); /* token: pct */
2640 pct
= (double) i
/ 100.0;
2642 i
= GetInteger(); /* token: max */
2644 /* catch negative and insanely huge values close to 32-bit wrap */
2646 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age negative. Cropped back to zero.");
2649 if (i
> 60*24*365) {
2650 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age too high. Cropped back to 1 year.");
2654 max
= (time_t) (i
* 60); /* convert minutes to seconds */
2657 while ((token
= strtok(NULL
, w_space
)) != NULL
) {
2658 if (!strcmp(token
, "refresh-ims")) {
2660 } else if (!strcmp(token
, "store-stale")) {
2662 #if USE_HTTP_VIOLATIONS
2664 } else if (!strcmp(token
, "override-expire"))
2665 override_expire
= 1;
2666 else if (!strcmp(token
, "override-lastmod"))
2667 override_lastmod
= 1;
2668 else if (!strcmp(token
, "ignore-no-cache"))
2669 ignore_no_cache
= 1;
2670 else if (!strcmp(token
, "ignore-no-store"))
2671 ignore_no_store
= 1;
2672 else if (!strcmp(token
, "ignore-must-revalidate"))
2673 ignore_must_revalidate
= 1;
2674 else if (!strcmp(token
, "ignore-private"))
2676 else if (!strcmp(token
, "ignore-auth"))
2678 else if (!strcmp(token
, "reload-into-ims")) {
2679 reload_into_ims
= 1;
2680 refresh_nocache_hack
= 1;
2681 /* tell client_side.c that this is used */
2682 } else if (!strcmp(token
, "ignore-reload")) {
2684 refresh_nocache_hack
= 1;
2685 /* tell client_side.c that this is used */
2689 debugs(22, 0, "redreshAddToList: Unknown option '" << pattern
<< "': " << token
);
2692 if ((errcode
= regcomp(&comp
, pattern
, flags
)) != 0) {
2694 regerror(errcode
, &comp
, errbuf
, sizeof errbuf
);
2695 debugs(22, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
2696 debugs(22, 0, "refreshAddToList: Invalid regular expression '" << pattern
<< "': " << errbuf
);
2700 pct
= pct
< 0.0 ? 0.0 : pct
;
2701 max
= max
< 0 ? 0 : max
;
2702 t
= static_cast<refresh_t
*>(xcalloc(1, sizeof(refresh_t
)));
2703 t
->pattern
= (char *) xstrdup(pattern
);
2704 t
->compiled_pattern
= comp
;
2709 if (flags
& REG_ICASE
)
2713 t
->flags
.refresh_ims
= 1;
2716 t
->flags
.store_stale
= 1;
2718 #if USE_HTTP_VIOLATIONS
2720 if (override_expire
)
2721 t
->flags
.override_expire
= 1;
2723 if (override_lastmod
)
2724 t
->flags
.override_lastmod
= 1;
2726 if (reload_into_ims
)
2727 t
->flags
.reload_into_ims
= 1;
2730 t
->flags
.ignore_reload
= 1;
2732 if (ignore_no_cache
)
2733 t
->flags
.ignore_no_cache
= 1;
2735 if (ignore_no_store
)
2736 t
->flags
.ignore_no_store
= 1;
2738 if (ignore_must_revalidate
)
2739 t
->flags
.ignore_must_revalidate
= 1;
2742 t
->flags
.ignore_private
= 1;
2745 t
->flags
.ignore_auth
= 1;
2752 head
= &(*head
)->next
;
2760 free_refreshpattern(refresh_t
** head
)
2764 while ((t
= *head
) != NULL
) {
2766 safe_free(t
->pattern
);
2767 regfree(&t
->compiled_pattern
);
2771 #if USE_HTTP_VIOLATIONS
2772 refresh_nocache_hack
= 0;
2778 dump_string(StoreEntry
* entry
, const char *name
, char *var
)
2781 storeAppendPrintf(entry
, "%s %s\n", name
, var
);
2785 parse_string(char **var
)
2787 char *token
= strtok(NULL
, w_space
);
2793 *var
= xstrdup(token
);
2797 ConfigParser::ParseString(char **var
)
2803 ConfigParser::ParseString(String
*var
)
2805 char *token
= strtok(NULL
, w_space
);
2814 free_string(char **var
)
2820 parse_eol(char *volatile *var
)
2822 unsigned char *token
= (unsigned char *) strtok(NULL
, null_string
);
2830 while (*token
&& xisspace(*token
))
2838 *var
= xstrdup((char *) token
);
2841 #define dump_eol dump_string
2842 #define free_eol free_string
2845 dump_time_t(StoreEntry
* entry
, const char *name
, time_t var
)
2847 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int) var
);
2851 parse_time_t(time_t * var
)
2853 parseTimeLine(var
, T_SECOND_STR
);
2857 free_time_t(time_t * var
)
2864 dump_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
2866 storeAppendPrintf(entry
, "%s %d\n", name
, (int) var
);
2871 dump_b_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
2873 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
2878 dump_b_ssize_t(StoreEntry
* entry
, const char *name
, ssize_t var
)
2880 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
2886 dump_kb_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
2888 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_KBYTES_STR
);
2893 dump_b_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
2895 storeAppendPrintf(entry
, "%s %"PRId64
" %s\n", name
, var
, B_BYTES_STR
);
2899 dump_kb_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
2901 storeAppendPrintf(entry
, "%s %"PRId64
" %s\n", name
, var
, B_KBYTES_STR
);
2906 parse_size_t(size_t * var
)
2915 parse_b_size_t(size_t * var
)
2917 parseBytesLine(var
, B_BYTES_STR
);
2922 parse_b_ssize_t(ssize_t
* var
)
2924 parseBytesLineSigned(var
, B_BYTES_STR
);
2930 parse_kb_size_t(size_t * var
)
2932 parseBytesLine(var
, B_KBYTES_STR
);
2937 parse_b_int64_t(int64_t * var
)
2939 parseBytesLine64(var
, B_BYTES_STR
);
2943 parse_kb_int64_t(int64_t * var
)
2945 parseBytesLine64(var
, B_KBYTES_STR
);
2949 free_size_t(size_t * var
)
2956 free_ssize_t(ssize_t
* var
)
2963 free_b_int64_t(int64_t * var
)
2968 #define free_b_size_t free_size_t
2969 #define free_b_ssize_t free_ssize_t
2970 #define free_kb_size_t free_size_t
2971 #define free_mb_size_t free_size_t
2972 #define free_gb_size_t free_size_t
2973 #define free_kb_int64_t free_b_int64_t
2976 dump_ushort(StoreEntry
* entry
, const char *name
, u_short var
)
2978 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2982 free_ushort(u_short
* u
)
2988 parse_ushort(u_short
* var
)
2990 ConfigParser::ParseUShort(var
);
2994 ConfigParser::ParseUShort(u_short
*var
)
3000 ConfigParser::ParseBool(bool *var
)
3002 int i
= GetInteger();
3013 dump_wordlist(StoreEntry
* entry
, const char *name
, wordlist
* list
)
3015 while (list
!= NULL
) {
3016 storeAppendPrintf(entry
, "%s %s\n", name
, list
->key
);
3022 ConfigParser::ParseWordList(wordlist
** list
)
3024 parse_wordlist(list
);
3028 parse_wordlist(wordlist
** list
)
3031 char *t
= strtok(NULL
, "");
3033 while ((token
= strwordtok(NULL
, &t
)))
3034 wordlistAdd(list
, token
);
3037 #if 0 /* now unused */
3039 check_null_wordlist(wordlist
* w
)
3046 check_null_acl_access(acl_access
* a
)
3051 #define free_wordlist wordlistDestroy
3053 #define free_uri_whitespace free_int
3056 parse_uri_whitespace(int *var
)
3058 char *token
= strtok(NULL
, w_space
);
3063 if (!strcasecmp(token
, "strip"))
3064 *var
= URI_WHITESPACE_STRIP
;
3065 else if (!strcasecmp(token
, "deny"))
3066 *var
= URI_WHITESPACE_DENY
;
3067 else if (!strcasecmp(token
, "allow"))
3068 *var
= URI_WHITESPACE_ALLOW
;
3069 else if (!strcasecmp(token
, "encode"))
3070 *var
= URI_WHITESPACE_ENCODE
;
3071 else if (!strcasecmp(token
, "chop"))
3072 *var
= URI_WHITESPACE_CHOP
;
3078 dump_uri_whitespace(StoreEntry
* entry
, const char *name
, int var
)
3082 if (var
== URI_WHITESPACE_ALLOW
)
3084 else if (var
== URI_WHITESPACE_ENCODE
)
3086 else if (var
== URI_WHITESPACE_CHOP
)
3088 else if (var
== URI_WHITESPACE_DENY
)
3093 storeAppendPrintf(entry
, "%s %s\n", name
, s
);
3097 free_removalpolicy(RemovalPolicySettings
** settings
)
3102 free_string(&(*settings
)->type
);
3104 free_wordlist(&(*settings
)->args
);
3112 parse_removalpolicy(RemovalPolicySettings
** settings
)
3115 free_removalpolicy(settings
);
3117 *settings
= new RemovalPolicySettings
;
3119 parse_string(&(*settings
)->type
);
3121 parse_wordlist(&(*settings
)->args
);
3125 dump_removalpolicy(StoreEntry
* entry
, const char *name
, RemovalPolicySettings
* settings
)
3128 storeAppendPrintf(entry
, "%s %s", name
, settings
->type
);
3129 args
= settings
->args
;
3132 storeAppendPrintf(entry
, " %s", args
->key
);
3136 storeAppendPrintf(entry
, "\n");
3140 free_memcachemode(SquidConfig
* config
)
3146 parse_memcachemode(SquidConfig
* config
)
3148 char *token
= strtok(NULL
, w_space
);
3152 if (strcmp(token
, "always") == 0) {
3153 Config
.onoff
.memory_cache_first
= 1;
3154 Config
.onoff
.memory_cache_disk
= 1;
3155 } else if (strcmp(token
, "disk") == 0) {
3156 Config
.onoff
.memory_cache_first
= 0;
3157 Config
.onoff
.memory_cache_disk
= 1;
3158 } else if (strncmp(token
, "net", 3) == 0) {
3159 Config
.onoff
.memory_cache_first
= 1;
3160 Config
.onoff
.memory_cache_disk
= 0;
3161 } else if (strcmp(token
, "never") == 0) {
3162 Config
.onoff
.memory_cache_first
= 0;
3163 Config
.onoff
.memory_cache_disk
= 0;
3169 dump_memcachemode(StoreEntry
* entry
, const char *name
, SquidConfig
&config
)
3171 storeAppendPrintf(entry
, "%s ", name
);
3172 if (Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3173 storeAppendPrintf(entry
, "always");
3174 else if (!Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3175 storeAppendPrintf(entry
, "disk");
3176 else if (Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3177 storeAppendPrintf(entry
, "network");
3178 else if (!Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3179 storeAppendPrintf(entry
, "none");
3180 storeAppendPrintf(entry
, "\n");
3183 #include "cf_parser.cci"
3186 parseNeighborType(const char *s
)
3188 if (!strcasecmp(s
, "parent"))
3191 if (!strcasecmp(s
, "neighbor"))
3192 return PEER_SIBLING
;
3194 if (!strcasecmp(s
, "neighbour"))
3195 return PEER_SIBLING
;
3197 if (!strcasecmp(s
, "sibling"))
3198 return PEER_SIBLING
;
3200 if (!strcasecmp(s
, "multicast"))
3201 return PEER_MULTICAST
;
3203 debugs(15, 0, "WARNING: Unknown neighbor type: " << s
);
3205 return PEER_SIBLING
;
3210 parse_IpAddress_list(Ip::Address_list
** head
)
3213 Ip::Address_list
*s
;
3216 while ((token
= strtok(NULL
, w_space
))) {
3217 if (GetHostWithPort(token
, &ipa
)) {
3220 head
= &(*head
)->next
;
3222 s
= static_cast<Ip::Address_list
*>(xcalloc(1, sizeof(*s
)));
3232 dump_IpAddress_list(StoreEntry
* e
, const char *n
, const Ip::Address_list
* s
)
3234 char ntoabuf
[MAX_IPSTRLEN
];
3237 storeAppendPrintf(e
, "%s %s\n",
3239 s
->s
.NtoA(ntoabuf
,MAX_IPSTRLEN
));
3245 free_IpAddress_list(Ip::Address_list
** head
)
3247 if (*head
) delete *head
;
3251 #if CURRENTLY_UNUSED
3252 /* This code was previously used by http_port. Left as it really should
3253 * be used by icp_port and htcp_port
3256 check_null_IpAddress_list(const Ip::Address_list
* s
)
3261 #endif /* CURRENTLY_UNUSED */
3262 #endif /* USE_WCCPv2 */
3264 CBDATA_CLASS_INIT(http_port_list
);
3267 parse_http_port_specification(http_port_list
* s
, char *token
)
3270 unsigned short port
= 0;
3274 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3275 s
->name
= xstrdup(token
);
3276 s
->connection_auth_disabled
= false;
3278 if (*token
== '[') {
3281 t
= strchr(host
, ']');
3283 debugs(3, 0, "http(s)_port: missing ']' on IPv6 address: " << token
);
3288 debugs(3, 0, "http(s)_port: missing Port in: " << token
);
3291 if (!Ip::EnableIpv6
) {
3292 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 is not available.");
3295 port
= xatos(t
+ 1);
3296 } else if ((t
= strchr(token
, ':'))) {
3301 port
= xatos(t
+ 1);
3303 } else if ((port
= strtol(token
, &junk
, 10)), !*junk
) {
3305 debugs(3, 3, "http(s)_port: found Listen on Port: " << port
);
3307 debugs(3, 0, "http(s)_port: missing Port: " << token
);
3312 debugs(3, 0, "http(s)_port: Port cannot be 0: " << token
);
3319 if (!Ip::EnableIpv6
)
3321 debugs(3, 3, "http(s)_port: found Listen on wildcard address: *:" << s
->s
.GetPort() );
3322 } else if ( s
->s
= host
) { /* check/parse numeric IPA */
3324 if (!Ip::EnableIpv6
)
3326 debugs(3, 3, "http(s)_port: Listen on Host/IP: " << host
<< " --> " << s
->s
);
3327 } else if ( s
->s
.GetHostByName(host
) ) { /* check/parse for FQDN */
3328 /* dont use ipcache */
3329 s
->defaultsite
= xstrdup(host
);
3331 if (!Ip::EnableIpv6
)
3333 debugs(3, 3, "http(s)_port: found Listen as Host " << s
->defaultsite
<< " on IP: " << s
->s
);
3335 debugs(3, 0, "http(s)_port: failed to resolve Host/IP: " << host
);
3341 parse_http_port_option(http_port_list
* s
, char *token
)
3345 if (strcmp(token
, "accel") == 0) {
3346 if (s
->intercepted
|| s
->spoof_client_ip
) {
3347 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: Accelerator mode requires its own port. It cannot be shared with other modes.");
3351 } else if (strcmp(token
, "transparent") == 0 || strcmp(token
, "intercept") == 0) {
3352 if (s
->accel
|| s
->spoof_client_ip
) {
3353 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: Intercept mode requires its own interception port. It cannot be shared with other modes.");
3357 Ip::Interceptor
.StartInterception();
3358 /* Log information regarding the port modes under interception. */
3359 debugs(3, DBG_IMPORTANT
, "Starting Authentication on port " << s
->s
);
3360 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (interception enabled)");
3362 /* INET6: until transparent REDIRECT works on IPv6 SOCKET, force wildcard to IPv4 */
3364 debugs(3, DBG_IMPORTANT
, "Disabling IPv6 on port " << s
->s
<< " (interception enabled)");
3365 if ( !s
->s
.SetIPv4() ) {
3366 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 addresses cannot be transparent (protocol does not provide NAT)" << s
->s
);
3369 } else if (strcmp(token
, "tproxy") == 0) {
3370 if (s
->intercepted
|| s
->accel
) {
3371 debugs(3,DBG_CRITICAL
, "FATAL: http(s)_port: TPROXY option requires its own interception port. It cannot be shared with other modes.");
3374 s
->spoof_client_ip
= 1;
3375 Ip::Interceptor
.StartTransparency();
3376 /* Log information regarding the port modes under transparency. */
3377 debugs(3, DBG_IMPORTANT
, "Starting IP Spoofing on port " << s
->s
);
3378 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (IP spoofing enabled)");
3380 if (!Ip::Interceptor
.ProbeForTproxy(s
->s
)) {
3381 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: TPROXY support in the system does not work.");
3385 } else if (strncmp(token
, "defaultsite=", 12) == 0) {
3387 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: defaultsite option requires Acceleration mode flag.");
3390 safe_free(s
->defaultsite
);
3391 s
->defaultsite
= xstrdup(token
+ 12);
3392 } else if (strcmp(token
, "vhost") == 0) {
3394 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vhost option requires Acceleration mode flag.");
3398 } else if (strcmp(token
, "vport") == 0) {
3400 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3404 } else if (strncmp(token
, "vport=", 6) == 0) {
3406 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3409 s
->vport
= xatos(token
+ 6);
3410 } else if (strncmp(token
, "protocol=", 9) == 0) {
3412 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: protocol option requires Acceleration mode flag.");
3415 s
->protocol
= xstrdup(token
+ 9);
3416 } else if (strcmp(token
, "allow-direct") == 0) {
3418 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3421 s
->allow_direct
= 1;
3422 } else if (strcmp(token
, "ignore-cc") == 0) {
3423 #if !USE_HTTP_VIOLATIONS
3425 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: ignore-cc option requires Scceleration mode flag.");
3430 } else if (strncmp(token
, "name=", 5) == 0) {
3432 s
->name
= xstrdup(token
+ 5);
3433 } else if (strcmp(token
, "no-connection-auth") == 0) {
3434 s
->connection_auth_disabled
= true;
3435 } else if (strcmp(token
, "connection-auth=off") == 0) {
3436 s
->connection_auth_disabled
= true;
3437 } else if (strcmp(token
, "connection-auth") == 0) {
3438 s
->connection_auth_disabled
= false;
3439 } else if (strcmp(token
, "connection-auth=on") == 0) {
3440 s
->connection_auth_disabled
= false;
3441 } else if (strncmp(token
, "disable-pmtu-discovery=", 23) == 0) {
3442 if (!strcasecmp(token
+ 23, "off"))
3443 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3444 else if (!strcasecmp(token
+ 23, "transparent"))
3445 s
->disable_pmtu_discovery
= DISABLE_PMTU_TRANSPARENT
;
3446 else if (!strcasecmp(token
+ 23, "always"))
3447 s
->disable_pmtu_discovery
= DISABLE_PMTU_ALWAYS
;
3450 } else if (strcmp(token
, "ipv4") == 0) {
3451 if ( !s
->s
.SetIPv4() ) {
3452 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 addresses cannot be used as IPv4-Only. " << s
->s
);
3455 } else if (strcmp(token
, "tcpkeepalive") == 0) {
3456 s
->tcp_keepalive
.enabled
= 1;
3457 } else if (strncmp(token
, "tcpkeepalive=", 13) == 0) {
3458 char *t
= token
+ 13;
3459 s
->tcp_keepalive
.enabled
= 1;
3460 s
->tcp_keepalive
.idle
= atoi(t
);
3464 s
->tcp_keepalive
.interval
= atoi(t
);
3469 s
->tcp_keepalive
.timeout
= atoi(t
);
3473 } else if (strcasecmp(token
, "sslBump") == 0) {
3474 debugs(3, DBG_CRITICAL
, "WARNING: '" << token
<< "' is deprecated " <<
3475 "in http_port. Use 'ssl-bump' instead.");
3476 s
->sslBump
= 1; // accelerated when bumped, otherwise not
3477 } else if (strcmp(token
, "ssl-bump") == 0) {
3478 s
->sslBump
= 1; // accelerated when bumped, otherwise not
3479 } else if (strncmp(token
, "cert=", 5) == 0) {
3481 s
->cert
= xstrdup(token
+ 5);
3482 } else if (strncmp(token
, "key=", 4) == 0) {
3484 s
->key
= xstrdup(token
+ 4);
3485 } else if (strncmp(token
, "version=", 8) == 0) {
3486 s
->version
= xatoi(token
+ 8);
3487 if (s
->version
< 1 || s
->version
> 4)
3489 } else if (strncmp(token
, "options=", 8) == 0) {
3490 safe_free(s
->options
);
3491 s
->options
= xstrdup(token
+ 8);
3492 } else if (strncmp(token
, "cipher=", 7) == 0) {
3493 safe_free(s
->cipher
);
3494 s
->cipher
= xstrdup(token
+ 7);
3495 } else if (strncmp(token
, "clientca=", 9) == 0) {
3496 safe_free(s
->clientca
);
3497 s
->clientca
= xstrdup(token
+ 9);
3498 } else if (strncmp(token
, "cafile=", 7) == 0) {
3499 safe_free(s
->cafile
);
3500 s
->cafile
= xstrdup(token
+ 7);
3501 } else if (strncmp(token
, "capath=", 7) == 0) {
3502 safe_free(s
->capath
);
3503 s
->capath
= xstrdup(token
+ 7);
3504 } else if (strncmp(token
, "crlfile=", 8) == 0) {
3505 safe_free(s
->crlfile
);
3506 s
->crlfile
= xstrdup(token
+ 8);
3507 } else if (strncmp(token
, "dhparams=", 9) == 0) {
3508 safe_free(s
->dhfile
);
3509 s
->dhfile
= xstrdup(token
+ 9);
3510 } else if (strncmp(token
, "sslflags=", 9) == 0) {
3511 safe_free(s
->sslflags
);
3512 s
->sslflags
= xstrdup(token
+ 9);
3513 } else if (strncmp(token
, "sslcontext=", 11) == 0) {
3514 safe_free(s
->sslcontext
);
3515 s
->sslcontext
= xstrdup(token
+ 11);
3522 static http_port_list
*
3523 create_http_port(char *portspec
)
3525 http_port_list
*s
= new http_port_list("http");
3526 parse_http_port_specification(s
, portspec
);
3531 add_http_port(char *portspec
)
3533 http_port_list
*s
= create_http_port(portspec
);
3534 // we may need to merge better of the above returns a list with clones
3535 assert(s
->next
== NULL
);
3536 s
->next
= Config
.Sockaddr
.http
;
3537 Config
.Sockaddr
.http
= s
;
3541 clone_http_port_list(http_port_list
*a
)
3543 http_port_list
*b
= new http_port_list(a
->protocol
);
3547 b
->name
= xstrdup(a
->name
);
3549 b
->defaultsite
= xstrdup(a
->defaultsite
);
3551 b
->intercepted
= a
->intercepted
;
3552 b
->spoof_client_ip
= a
->spoof_client_ip
;
3553 b
->accel
= a
->accel
;
3554 b
->allow_direct
= a
->allow_direct
;
3555 b
->vhost
= a
->vhost
;
3556 b
->sslBump
= a
->sslBump
;
3557 b
->vport
= a
->vport
;
3558 b
->connection_auth_disabled
= a
->connection_auth_disabled
;
3559 b
->disable_pmtu_discovery
= a
->disable_pmtu_discovery
;
3561 memcpy( &(b
->tcp_keepalive
), &(a
->tcp_keepalive
), sizeof(a
->tcp_keepalive
));
3564 // AYJ: 2009-07-18: for now SSL does not clone. Configure separate ports with IPs and SSL settings
3567 // XXX: temporary hack to ease move of SSL options to http_port
3568 http_port_list
&http
;
3582 SSL_CTX
*sslContext
;
3591 parse_http_port_list(http_port_list
** head
)
3593 char *token
= strtok(NULL
, w_space
);
3600 http_port_list
*s
= create_http_port(token
);
3602 /* parse options ... */
3603 while ((token
= strtok(NULL
, w_space
))) {
3604 parse_http_port_option(s
, token
);
3607 if (Ip::EnableIpv6
&IPV6_SPECIAL_SPLITSTACK
&& s
->s
.IsAnyAddr()) {
3608 // clone the port options from *s to *(s->next)
3609 s
->next
= clone_http_port_list(s
);
3610 s
->next
->s
.SetIPv4();
3611 debugs(3, 3, "http(s)_port: clone wildcard address for split-stack: " << s
->s
<< " and " << s
->next
->s
);
3615 head
= &(*head
)->next
;
3621 dump_generic_http_port(StoreEntry
* e
, const char *n
, const http_port_list
* s
)
3623 char buf
[MAX_IPSTRLEN
];
3625 storeAppendPrintf(e
, "%s %s",
3627 s
->s
.ToURL(buf
,MAX_IPSTRLEN
));
3630 storeAppendPrintf(e
, " intercept");
3632 if (s
->spoof_client_ip
)
3633 storeAppendPrintf(e
, " tproxy");
3636 storeAppendPrintf(e
, " accel");
3639 storeAppendPrintf(e
, " vhost");
3642 storeAppendPrintf(e
, " vport");
3645 storeAppendPrintf(e
, " defaultsite=%s", s
->defaultsite
);
3647 if (s
->connection_auth_disabled
)
3648 storeAppendPrintf(e
, " connection-auth=off");
3650 storeAppendPrintf(e
, " connection-auth=on");
3652 if (s
->disable_pmtu_discovery
!= DISABLE_PMTU_OFF
) {
3655 if (s
->disable_pmtu_discovery
== DISABLE_PMTU_ALWAYS
)
3658 pmtu
= "transparent";
3660 storeAppendPrintf(e
, " disable-pmtu-discovery=%s", pmtu
);
3663 if (s
->tcp_keepalive
.enabled
) {
3664 if (s
->tcp_keepalive
.idle
|| s
->tcp_keepalive
.interval
|| s
->tcp_keepalive
.timeout
) {
3665 storeAppendPrintf(e
, " tcpkeepalive=%d,%d,%d", s
->tcp_keepalive
.idle
, s
->tcp_keepalive
.interval
, s
->tcp_keepalive
.timeout
);
3667 storeAppendPrintf(e
, " tcpkeepalive");
3673 storeAppendPrintf(e
, " sslBump");
3676 storeAppendPrintf(e
, " cert=%s", s
->cert
);
3679 storeAppendPrintf(e
, " key=%s", s
->key
);
3682 storeAppendPrintf(e
, " version=%d", s
->version
);
3685 storeAppendPrintf(e
, " options=%s", s
->options
);
3688 storeAppendPrintf(e
, " cipher=%s", s
->cipher
);
3691 storeAppendPrintf(e
, " cafile=%s", s
->cafile
);
3694 storeAppendPrintf(e
, " capath=%s", s
->capath
);
3697 storeAppendPrintf(e
, " crlfile=%s", s
->crlfile
);
3700 storeAppendPrintf(e
, " dhparams=%s", s
->dhfile
);
3703 storeAppendPrintf(e
, " sslflags=%s", s
->sslflags
);
3706 storeAppendPrintf(e
, " sslcontext=%s", s
->sslcontext
);
3711 dump_http_port_list(StoreEntry
* e
, const char *n
, const http_port_list
* s
)
3714 dump_generic_http_port(e
, n
, s
);
3715 storeAppendPrintf(e
, "\n");
3721 free_http_port_list(http_port_list
** head
)
3725 while ((s
= *head
) != NULL
) {
3733 // TODO: merge better with parse_http_port_list
3735 parse_https_port_list(https_port_list
** head
)
3740 token
= strtok(NULL
, w_space
);
3745 s
= new https_port_list
;
3746 parse_http_port_specification(&s
->http
, token
);
3748 /* parse options ... */
3749 while ((token
= strtok(NULL
, w_space
))) {
3750 parse_http_port_option(s
, token
);
3754 http_port_list
** headTmp
= &(*head
)->http
.next
;
3755 head
= (https_port_list
**)headTmp
;
3762 dump_https_port_list(StoreEntry
* e
, const char *n
, const https_port_list
* s
)
3764 dump_http_port_list(e
, n
, s
);
3768 free_https_port_list(https_port_list
** head
)
3770 free_http_port_list((http_port_list
**)head
);
3775 check_null_https_port_list(const https_port_list
* s
)
3782 #endif /* USE_SSL */
3785 configFreeMemory(void)
3791 requirePathnameExists(const char *name
, const char *path
)
3795 char pathbuf
[BUFSIZ
];
3796 assert(path
!= NULL
);
3798 if (Config
.chroot_dir
&& (geteuid() == 0)) {
3799 snprintf(pathbuf
, BUFSIZ
, "%s/%s", Config
.chroot_dir
, path
);
3803 if (stat(path
, &sb
) < 0) {
3804 if (opt_send_signal
== -1 || opt_send_signal
== SIGHUP
)
3805 fatalf("%s %s: %s", name
, path
, xstrerror());
3807 fprintf(stderr
, "WARNING: %s %s: %s\n", name
, path
, xstrerror());
3814 return ConfigParser::strtokFile();
3817 #include "AccessLogEntry.h"
3818 /* TODO: split out parsing somehow ...*/
3820 parse_logformat(logformat
** logformat_definitions
)
3825 if ((name
= strtok(NULL
, w_space
)) == NULL
)
3828 if ((def
= strtok(NULL
, "\r\n")) == NULL
) {
3833 debugs(3, 2, "Logformat for '" << name
<< "' is '" << def
<< "'");
3835 nlf
= (logformat
*)xcalloc(1, sizeof(logformat
));
3837 nlf
->name
= xstrdup(name
);
3839 if (!accessLogParseLogFormat(&nlf
->format
, def
)) {
3844 nlf
->next
= *logformat_definitions
;
3846 *logformat_definitions
= nlf
;
3850 parse_access_log(customlog
** logs
)
3852 const char *filename
, *logdef_name
;
3856 cl
= (customlog
*)xcalloc(1, sizeof(*cl
));
3858 if ((filename
= strtok(NULL
, w_space
)) == NULL
) {
3863 if (strcmp(filename
, "none") == 0) {
3864 cl
->type
= CLF_NONE
;
3868 if ((logdef_name
= strtok(NULL
, w_space
)) == NULL
)
3869 logdef_name
= "auto";
3871 debugs(3, 9, "Log definition name '" << logdef_name
<< "' file '" << filename
<< "'");
3873 cl
->filename
= xstrdup(filename
);
3875 /* look for the definition pointer corresponding to this name */
3876 lf
= Config
.Log
.logformats
;
3878 while (lf
!= NULL
) {
3879 debugs(3, 9, "Comparing against '" << lf
->name
<< "'");
3881 if (strcmp(lf
->name
, logdef_name
) == 0)
3888 cl
->type
= CLF_CUSTOM
;
3890 } else if (strcmp(logdef_name
, "auto") == 0) {
3891 cl
->type
= CLF_AUTO
;
3892 } else if (strcmp(logdef_name
, "squid") == 0) {
3893 cl
->type
= CLF_SQUID
;
3894 } else if (strcmp(logdef_name
, "common") == 0) {
3895 cl
->type
= CLF_COMMON
;
3897 } else if (strcmp(logdef_name
, "icap_squid") == 0) {
3898 cl
->type
= CLF_ICAP_SQUID
;
3901 debugs(3, 0, "Log format '" << logdef_name
<< "' is not defined");
3907 aclParseAclList(LegacyParser
, &cl
->aclList
);
3910 logs
= &(*logs
)->next
;
3916 check_null_access_log(customlog
*customlog_definitions
)
3918 return customlog_definitions
== NULL
;
3922 dump_logformat(StoreEntry
* entry
, const char *name
, logformat
* definitions
)
3924 accessLogDumpLogFormat(entry
, name
, definitions
);
3928 dump_access_log(StoreEntry
* entry
, const char *name
, customlog
* logs
)
3932 for (log
= logs
; log
; log
= log
->next
) {
3933 storeAppendPrintf(entry
, "%s ", name
);
3935 switch (log
->type
) {
3938 storeAppendPrintf(entry
, "%s %s", log
->filename
, log
->logFormat
->name
);
3942 storeAppendPrintf(entry
, "none");
3946 storeAppendPrintf(entry
, "%s squid", log
->filename
);
3950 storeAppendPrintf(entry
, "%s squid", log
->filename
);
3953 case CLF_ICAP_SQUID
:
3954 storeAppendPrintf(entry
, "%s icap_squid", log
->filename
);
3960 storeAppendPrintf(entry
, "%s auto", log
->filename
);
3962 storeAppendPrintf(entry
, "%s", log
->filename
);
3971 dump_acl_list(entry
, log
->aclList
);
3973 storeAppendPrintf(entry
, "\n");
3978 free_logformat(logformat
** definitions
)
3980 while (*definitions
) {
3981 logformat
*format
= *definitions
;
3982 *definitions
= format
->next
;
3983 safe_free(format
->name
);
3984 accessLogFreeLogFormat(&format
->format
);
3990 free_access_log(customlog
** definitions
)
3992 while (*definitions
) {
3993 customlog
*log
= *definitions
;
3994 *definitions
= log
->next
;
3996 log
->logFormat
= NULL
;
3997 log
->type
= CLF_UNKNOWN
;
4000 aclDestroyAclList(&log
->aclList
);
4002 safe_free(log
->filename
);
4008 /// parses list of integers form name=N1,N2,N3,...
4010 parseNamedIntList(const char *data
, const String
&name
, Vector
<int> &list
)
4012 if (data
&& (strncmp(data
, name
.rawBuf(), name
.size()) == 0)) {
4013 data
+= name
.size();
4018 if (!StringToInt(data
, value
, &data
, 10))
4020 list
.push_back(value
);
4021 if (*data
== '\0' || *data
!= ',')
4026 return data
&& *data
== '\0';
4030 parse_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4032 #if !HAVE_CPU_AFFINITY
4033 debugs(3, DBG_CRITICAL
, "FATAL: Squid built with no CPU affinity " <<
4034 "support, do not set 'cpu_affinity_map'");
4036 #endif /* HAVE_CPU_AFFINITY */
4038 if (!*cpuAffinityMap
)
4039 *cpuAffinityMap
= new CpuAffinityMap
;
4041 const char *const pToken
= strtok(NULL
, w_space
);
4042 const char *const cToken
= strtok(NULL
, w_space
);
4043 Vector
<int> processes
, cores
;
4044 if (!parseNamedIntList(pToken
, "process_numbers", processes
)) {
4045 debugs(3, DBG_CRITICAL
, "FATAL: bad 'process_numbers' parameter " <<
4046 "in 'cpu_affinity_map'");
4048 } else if (!parseNamedIntList(cToken
, "cores", cores
)) {
4049 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cores' parameter in " <<
4050 "'cpu_affinity_map'");
4052 } else if (!(*cpuAffinityMap
)->add(processes
, cores
)) {
4053 debugs(3, DBG_CRITICAL
, "FATAL: bad 'cpu_affinity_map'; " <<
4054 "process_numbers and cores lists differ in length or " <<
4055 "contain numbers <= 0");
4061 dump_CpuAffinityMap(StoreEntry
*const entry
, const char *const name
, const CpuAffinityMap
*const cpuAffinityMap
)
4063 if (cpuAffinityMap
) {
4064 storeAppendPrintf(entry
, "%s process_numbers=", name
);
4065 for (size_t i
= 0; i
< cpuAffinityMap
->processes().size(); ++i
) {
4066 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4067 cpuAffinityMap
->processes()[i
]);
4069 storeAppendPrintf(entry
, " cores=");
4070 for (size_t i
= 0; i
< cpuAffinityMap
->processes().size(); ++i
) {
4071 storeAppendPrintf(entry
, "%s%i", (i
? "," : ""),
4072 cpuAffinityMap
->cores()[i
]);
4074 storeAppendPrintf(entry
, "\n");
4079 free_CpuAffinityMap(CpuAffinityMap
**const cpuAffinityMap
)
4081 delete *cpuAffinityMap
;
4082 *cpuAffinityMap
= NULL
;
4088 parse_adaptation_service_set_type()
4090 Adaptation::Config::ParseServiceSet();
4094 parse_adaptation_service_chain_type()
4096 Adaptation::Config::ParseServiceChain();
4100 parse_adaptation_access_type()
4102 Adaptation::Config::ParseAccess(LegacyParser
);
4105 #endif /* USE_ADAPTATION */
4111 parse_icap_service_type(Adaptation::Icap::Config
* cfg
)
4113 cfg
->parseService();
4117 free_icap_service_type(Adaptation::Icap::Config
* cfg
)
4123 dump_icap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4125 cfg
.dumpService(entry
, name
);
4129 parse_icap_class_type()
4131 debugs(93, 0, "WARNING: 'icap_class' is depricated. " <<
4132 "Use 'adaptation_service_set' instead");
4133 Adaptation::Config::ParseServiceSet();
4137 parse_icap_access_type()
4139 debugs(93, 0, "WARNING: 'icap_access' is depricated. " <<
4140 "Use 'adaptation_access' instead");
4141 Adaptation::Config::ParseAccess(LegacyParser
);
4150 parse_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4152 cfg
->parseService();
4156 free_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
4162 dump_ecap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Ecap::Config
&cfg
)
4164 cfg
.dumpService(entry
, name
);
4167 #endif /* USE_ECAP */
4170 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4175 cfg
->service_failure_limit
= GetInteger();
4177 if ((token
= strtok(NULL
, w_space
)) == NULL
)
4180 if (strcmp(token
,"in") != 0) {
4181 debugs(3, 0, "expecting 'in' on'" << config_input_line
<< "'");
4185 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
4189 d
= static_cast<time_t> (xatoi(token
));
4191 m
= static_cast<time_t> (1);
4195 else if ((token
= strtok(NULL
, w_space
)) == NULL
) {
4196 debugs(3, 0, "No time-units on '" << config_input_line
<< "'");
4198 } else if ((m
= parseTimeUnits(token
)) == 0)
4201 cfg
->oldest_service_failure
= (m
* d
);
4204 static void dump_icap_service_failure_limit(StoreEntry
*entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
4206 storeAppendPrintf(entry
, "%s %d", name
, cfg
.service_failure_limit
);
4207 if (cfg
.oldest_service_failure
> 0) {
4208 storeAppendPrintf(entry
, " in %d seconds", (int)cfg
.oldest_service_failure
);
4210 storeAppendPrintf(entry
, "\n");
4213 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
4215 cfg
->oldest_service_failure
= 0;
4216 cfg
->service_failure_limit
= 0;