4 * DEBUG: section 3 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 "eui/Config.h"
55 #include "esi/Parser.h"
57 #include "HttpRequestMethod.h"
58 #include "ident/Config.h"
59 #include "ip/IpIntercept.h"
60 #include "log/Config.h"
63 #include "ProtoPort.h"
69 #include "StoreFileSystem.h"
78 static void parse_adaptation_service_set_type();
79 static void parse_adaptation_service_chain_type();
80 static void parse_adaptation_access_type();
84 static void parse_icap_service_type(Adaptation::Icap::Config
*);
85 static void dump_icap_service_type(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
86 static void free_icap_service_type(Adaptation::Icap::Config
*);
87 static void parse_icap_class_type();
88 static void parse_icap_access_type();
92 static void parse_ecap_service_type(Adaptation::Ecap::Config
*);
93 static void dump_ecap_service_type(StoreEntry
*, const char *, const Adaptation::Ecap::Config
&);
94 static void free_ecap_service_type(Adaptation::Ecap::Config
*);
99 static const char *const T_SECOND_STR
= "second";
100 static const char *const T_MINUTE_STR
= "minute";
101 static const char *const T_HOUR_STR
= "hour";
102 static const char *const T_DAY_STR
= "day";
103 static const char *const T_WEEK_STR
= "week";
104 static const char *const T_FORTNIGHT_STR
= "fortnight";
105 static const char *const T_MONTH_STR
= "month";
106 static const char *const T_YEAR_STR
= "year";
107 static const char *const T_DECADE_STR
= "decade";
109 static const char *const B_BYTES_STR
= "bytes";
110 static const char *const B_KBYTES_STR
= "KB";
111 static const char *const B_MBYTES_STR
= "MB";
112 static const char *const B_GBYTES_STR
= "GB";
114 static const char *const list_sep
= ", \t\n\r";
116 static void parse_logformat(logformat
** logformat_definitions
);
117 static void parse_access_log(customlog
** customlog_definitions
);
118 static int check_null_access_log(customlog
*customlog_definitions
);
120 static void dump_logformat(StoreEntry
* entry
, const char *name
, logformat
* definitions
);
121 static void dump_access_log(StoreEntry
* entry
, const char *name
, customlog
* definitions
);
122 static void free_logformat(logformat
** definitions
);
123 static void free_access_log(customlog
** definitions
);
125 static void update_maxobjsize(void);
126 static void configDoConfigure(void);
127 static void parse_refreshpattern(refresh_t
**);
128 static int parseTimeUnits(const char *unit
);
129 static void parseTimeLine(time_t * tptr
, const char *units
);
130 static void parse_ushort(u_short
* var
);
131 static void parse_string(char **);
132 static void default_all(void);
133 static void defaults_if_none(void);
134 static int parse_line(char *);
135 static void parseBytesLine(size_t * bptr
, const char *units
);
136 static size_t parseBytesUnits(const char *unit
);
137 static void free_all(void);
138 void requirePathnameExists(const char *name
, const char *path
);
139 static OBJH dump_config
;
141 static void dump_http_header_access(StoreEntry
* entry
, const char *name
, header_mangler header
[]);
142 static void parse_http_header_access(header_mangler header
[]);
143 static void free_http_header_access(header_mangler header
[]);
144 static void dump_http_header_replace(StoreEntry
* entry
, const char *name
, header_mangler header
[]);
145 static void parse_http_header_replace(header_mangler
* header
);
146 static void free_http_header_replace(header_mangler
* header
);
148 static void parse_denyinfo(acl_deny_info_list
** var
);
149 static void dump_denyinfo(StoreEntry
* entry
, const char *name
, acl_deny_info_list
* var
);
150 static void free_denyinfo(acl_deny_info_list
** var
);
153 static void parse_IpAddress_list(IpAddress_list
**);
154 static void dump_IpAddress_list(StoreEntry
*, const char *, const IpAddress_list
*);
155 static void free_IpAddress_list(IpAddress_list
**);
157 static int check_null_IpAddress_list(const IpAddress_list
*);
158 #endif /* CURRENTLY_UNUSED */
159 #endif /* USE_WCCPv2 */
161 static void parse_http_port_list(http_port_list
**);
162 static void dump_http_port_list(StoreEntry
*, const char *, const http_port_list
*);
163 static void free_http_port_list(http_port_list
**);
166 static void parse_https_port_list(https_port_list
**);
167 static void dump_https_port_list(StoreEntry
*, const char *, const https_port_list
*);
168 static void free_https_port_list(https_port_list
**);
170 static int check_null_https_port_list(const https_port_list
*);
174 static void parse_b_size_t(size_t * var
);
175 static void parse_b_int64_t(int64_t * var
);
177 static int parseOneConfigFile(const char *file_name
, unsigned int depth
);
180 * LegacyParser is a parser for legacy code that uses the global
181 * approach. This is static so that it is only exposed to cache_cf.
182 * Other modules needing access to a ConfigParser should have it
183 * provided to them in their parserFOO methods.
185 static ConfigParser LegacyParser
= ConfigParser();
190 LegacyParser
.destruct();
194 update_maxobjsize(void)
199 for (i
= 0; i
< Config
.cacheSwap
.n_configured
; i
++) {
200 assert (Config
.cacheSwap
.swapDirs
[i
].getRaw());
202 if (dynamic_cast<SwapDir
*>(Config
.cacheSwap
.swapDirs
[i
].getRaw())->
204 ms
= dynamic_cast<SwapDir
*>(Config
.cacheSwap
.swapDirs
[i
].getRaw())->max_objsize
;
206 store_maxobjsize
= ms
;
210 SetConfigFilename(char const *file_name
, bool is_pipe
)
212 cfg_filename
= file_name
;
217 cfg_filename
= file_name
+ 1;
218 else if ((token
= strrchr(cfg_filename
, '/')))
219 cfg_filename
= token
+ 1;
223 skip_ws(const char* s
)
232 parseManyConfigFiles(char* files
, int depth
)
235 char* saveptr
= NULL
;
240 memset(&globbuf
, 0, sizeof(globbuf
));
241 for (path
= strwordtok(files
, &saveptr
); path
; path
= strwordtok(NULL
, &saveptr
)) {
242 if (glob(path
, globbuf
.gl_pathc
? GLOB_APPEND
: 0, NULL
, &globbuf
) != 0) {
243 fatalf("Unable to find configuration file: %s: %s",
247 for (i
= 0; i
< (int)globbuf
.gl_pathc
; i
++) {
248 error_count
+= parseOneConfigFile(globbuf
.gl_pathv
[i
], depth
);
252 char* file
= strwordtok(files
, &saveptr
);
253 while (file
!= NULL
) {
254 error_count
+= parseOneConfigFile(file
, depth
);
255 file
= strwordtok(NULL
, &saveptr
);
257 #endif /* HAVE_GLOB */
262 ReplaceSubstr(char*& str
, int& len
, unsigned substrIdx
, unsigned substrLen
, const char* newSubstr
)
265 assert(newSubstr
!= NULL
);
267 unsigned newSubstrLen
= strlen(newSubstr
);
268 if (newSubstrLen
> substrLen
)
269 str
= (char*)realloc(str
, len
- substrLen
+ newSubstrLen
+ 1);
271 // move tail part including zero
272 memmove(str
+ substrIdx
+ newSubstrLen
, str
+ substrIdx
+ substrLen
, len
- substrIdx
- substrLen
+ 1);
273 // copy new substring in place
274 memcpy(str
+ substrIdx
, newSubstr
, newSubstrLen
);
280 SubstituteMacro(char*& line
, int& len
, const char* macroName
, const char* substStr
)
282 assert(line
!= NULL
);
283 assert(macroName
!= NULL
);
284 assert(substStr
!= NULL
);
285 unsigned macroNameLen
= strlen(macroName
);
286 while (const char* macroPos
= strstr(line
, macroName
)) // we would replace all occurrences
287 ReplaceSubstr(line
, len
, macroPos
- line
, macroNameLen
, substStr
);
291 ProcessMacros(char*& line
, int& len
)
293 SubstituteMacro(line
, len
, "${process_name}", KidName
.termedBuf());
294 SubstituteMacro(line
, len
, "${process_number}", xitoa(KidIdentifier
));
298 parseOneConfigFile(const char *file_name
, unsigned int depth
)
301 const char *orig_cfg_filename
= cfg_filename
;
302 const int orig_config_lineno
= config_lineno
;
304 char *tmp_line
= NULL
;
305 int tmp_line_len
= 0;
309 debugs(3, 1, "Processing Configuration File: " << file_name
<< " (depth " << depth
<< ")");
311 fatalf("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name
);
315 if (file_name
[0] == '!' || file_name
[0] == '|') {
316 fp
= popen(file_name
+ 1, "r");
319 fp
= fopen(file_name
, "r");
323 fatalf("Unable to open configuration file: %s: %s", file_name
, xstrerror());
327 setmode(fileno(fp
), O_TEXT
);
331 SetConfigFilename(file_name
, bool(is_pipe
));
333 memset(config_input_line
, '\0', BUFSIZ
);
337 while (fgets(config_input_line
, BUFSIZ
, fp
)) {
340 if ((token
= strchr(config_input_line
, '\n')))
343 if ((token
= strchr(config_input_line
, '\r')))
346 if (strncmp(config_input_line
, "#line ", 6) == 0) {
347 static char new_file_name
[1024];
349 static char new_lineno
;
350 token
= config_input_line
+ 6;
351 new_lineno
= strtol(token
, &file
, 0) - 1;
354 continue; /* Not a valid #line directive, may be a comment */
356 while (*file
&& xisspace((unsigned char) *file
))
361 continue; /* Not a valid #line directive, may be a comment */
363 xstrncpy(new_file_name
, file
+ 1, sizeof(new_file_name
));
365 if ((token
= strchr(new_file_name
, '"')))
368 cfg_filename
= new_file_name
;
371 config_lineno
= new_lineno
;
374 if (config_input_line
[0] == '#')
377 if (config_input_line
[0] == '\0')
380 const char* append
= tmp_line_len
? skip_ws(config_input_line
) : config_input_line
;
382 size_t append_len
= strlen(append
);
384 tmp_line
= (char*)xrealloc(tmp_line
, tmp_line_len
+ append_len
+ 1);
386 strcpy(tmp_line
+ tmp_line_len
, append
);
388 tmp_line_len
+= append_len
;
390 if (tmp_line
[tmp_line_len
-1] == '\\') {
391 debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line
<< "'");
392 tmp_line
[--tmp_line_len
] = '\0';
396 ProcessMacros(tmp_line
, tmp_line_len
);
397 debugs(3, 5, "Processing: '" << tmp_line
<< "'");
399 /* Handle includes here */
400 if (tmp_line_len
>= 9 && strncmp(tmp_line
, "include", 7) == 0 && xisspace(tmp_line
[7])) {
401 err_count
+= parseManyConfigFiles(tmp_line
+ 8, depth
+ 1);
402 } else if (!parse_line(tmp_line
)) {
403 debugs(3, 0, HERE
<< cfg_filename
<< ":" << config_lineno
<< " unrecognized: '" << tmp_line
<< "'");
413 int ret
= pclose(fp
);
416 fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name
, ret
);
421 cfg_filename
= orig_cfg_filename
;
422 config_lineno
= orig_config_lineno
;
428 parseConfigFile(const char *file_name
)
431 CacheManager
*manager
=CacheManager::GetInstance();
435 ACLMethodData::ThePurgeCount
= 0;
438 err_count
= parseOneConfigFile(file_name
, 0);
443 * We must call configDoConfigure() before leave_suid() because
444 * configDoConfigure() is where we turn username strings into
449 if (!Config
.chroot_dir
) {
451 setUmask(Config
.umask
);
452 _db_init(Debug::cache_log
, Debug::debugOptions
);
456 if (opt_send_signal
== -1) {
457 manager
->registerAction("config",
458 "Current Squid Configuration",
468 configDoConfigure(void)
470 memset(&Config2
, '\0', sizeof(SquidConfig2
));
471 /* init memory as early as possible */
475 if (Config
.cacheSwap
.swapDirs
== NULL
) {
476 /* Memory-only cache probably in effect. */
477 /* turn off the cache rebuild delays... */
478 StoreController::store_dirs_rebuilding
= 0;
481 if (Debug::rotateNumber
< 0) {
482 Debug::rotateNumber
= Config
.Log
.rotateNumber
;
485 #if SIZEOF_OFF_T <= 4
486 if (Config
.Store
.maxObjectSize
> 0x7FFF0000) {
487 debugs(3, 0, "WARNING: This Squid binary can not handle files larger than 2GB. Limiting maximum_object_size to just below 2GB");
488 Config
.Store
.maxObjectSize
= 0x7FFF0000;
491 if (0 == Store::Root().maxSize())
492 /* people might want a zero-sized cache on purpose */
494 else if (Store::Root().maxSize() < (Config
.memMaxSize
>> 10))
495 /* This is bogus. folk with NULL caches will want this */
496 debugs(3, 0, "WARNING cache_mem is larger than total disk cache space!");
498 if (Config
.Announce
.period
> 0) {
499 Config
.onoff
.announce
= 1;
500 } else if (Config
.Announce
.period
< 1) {
501 Config
.Announce
.period
= 86400 * 365; /* one year */
502 Config
.onoff
.announce
= 0;
505 if (Config
.onoff
.httpd_suppress_version_string
)
506 visible_appname_string
= (char *)appname_string
;
508 visible_appname_string
= (char const *)APP_FULLNAME
;
512 if (Config
.dnsChildren
.n_max
< 1)
513 fatal("No dnsservers allocated");
517 if (Config
.Program
.redirect
) {
518 if (Config
.redirectChildren
.n_max
< 1) {
519 Config
.redirectChildren
.n_max
= 0;
520 wordlistDestroy(&Config
.Program
.redirect
);
524 if (Config
.appendDomain
)
525 if (*Config
.appendDomain
!= '.')
526 fatal("append_domain must begin with a '.'");
528 if (Config
.errHtmlText
== NULL
)
529 Config
.errHtmlText
= xstrdup(null_string
);
533 snprintf(ThisCache
, sizeof(ThisCache
), "%s (%s)",
535 visible_appname_string
);
538 * the extra space is for loop detection in client_side.c -- we search
539 * for substrings in the Via header.
541 snprintf(ThisCache2
, sizeof(ThisCache
), " %s (%s)",
543 visible_appname_string
);
545 if (!Config
.udpMaxHitObjsz
|| Config
.udpMaxHitObjsz
> SQUID_UDP_SO_SNDBUF
)
546 Config
.udpMaxHitObjsz
= SQUID_UDP_SO_SNDBUF
;
548 if (Config
.appendDomain
)
549 Config
.appendDomainLen
= strlen(Config
.appendDomain
);
551 Config
.appendDomainLen
= 0;
553 if (Config
.retry
.maxtries
> 10)
554 fatal("maximum_single_addr_tries cannot be larger than 10");
556 if (Config
.retry
.maxtries
< 1) {
557 debugs(3, 0, "WARNING: resetting 'maximum_single_addr_tries to 1");
558 Config
.retry
.maxtries
= 1;
561 requirePathnameExists("MIME Config Table", Config
.mimeTablePathname
);
564 requirePathnameExists("cache_dns_program", Config
.Program
.dnsserver
);
568 requirePathnameExists("unlinkd_program", Config
.Program
.unlinkd
);
570 requirePathnameExists("logfile_daemon", Log::TheConfig
.logfile_daemon
);
571 if (Config
.Program
.redirect
)
572 requirePathnameExists("redirect_program", Config
.Program
.redirect
->key
);
574 requirePathnameExists("Icon Directory", Config
.icons
.directory
);
576 if (Config
.errorDirectory
)
577 requirePathnameExists("Error Directory", Config
.errorDirectory
);
584 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
585 if (!R
->flags
.override_expire
)
588 debugs(22, 1, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP");
593 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
594 if (!R
->flags
.override_lastmod
)
597 debugs(22, 1, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP");
602 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
603 if (!R
->flags
.reload_into_ims
)
606 debugs(22, 1, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP");
611 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
612 if (!R
->flags
.ignore_reload
)
615 debugs(22, 1, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP");
620 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
621 if (!R
->flags
.ignore_no_cache
)
624 debugs(22, 1, "WARNING: use of 'ignore-no-cache' in 'refresh_pattern' violates HTTP");
629 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
630 if (!R
->flags
.ignore_no_store
)
633 debugs(22, 1, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP");
638 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
639 if (!R
->flags
.ignore_must_revalidate
)
641 debugs(22, 1, "WARNING: use of 'ignore-must-revalidate' in 'refresh_pattern' violates HTTP");
645 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
646 if (!R
->flags
.ignore_private
)
649 debugs(22, 1, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP");
654 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
655 if (!R
->flags
.ignore_auth
)
658 debugs(22, 1, "WARNING: use of 'ignore-auth' in 'refresh_pattern' violates HTTP");
666 Config
.onoff
.via
= 1;
669 if (!Config
.onoff
.via
)
670 debugs(22, 1, "WARNING: HTTP requires the use of Via");
674 // we enable runtime PURGE checks if there is at least one PURGE method ACL
675 // TODO: replace with a dedicated "purge" ACL option?
676 Config2
.onoff
.enable_purge
= (ACLMethodData::ThePurgeCount
> 0);
678 Config2
.onoff
.mangle_request_headers
= httpReqHdrManglersConfigured();
680 if (geteuid() == 0) {
681 if (NULL
!= Config
.effectiveUser
) {
683 struct passwd
*pwd
= getpwnam(Config
.effectiveUser
);
687 * Andres Kroonmaa <andre@online.ee>:
688 * Some getpwnam() implementations (Solaris?) require
689 * an available FD < 256 for opening a FILE* to the
692 * This should be safe at startup, but might still fail
693 * during reconfigure.
695 fatalf("getpwnam failed to find userid for effective user '%s'",
696 Config
.effectiveUser
);
700 Config2
.effectiveUserID
= pwd
->pw_uid
;
702 Config2
.effectiveGroupID
= pwd
->pw_gid
;
706 if (pwd
->pw_dir
&& *pwd
->pw_dir
) {
708 char *env_str
= (char *)xcalloc((len
= strlen(pwd
->pw_dir
) + 6), 1);
709 snprintf(env_str
, len
, "HOME=%s", pwd
->pw_dir
);
717 Config2
.effectiveUserID
= geteuid();
718 Config2
.effectiveGroupID
= getegid();
721 if (NULL
!= Config
.effectiveGroup
) {
723 struct group
*grp
= getgrnam(Config
.effectiveGroup
);
726 fatalf("getgrnam failed to find groupid for effective group '%s'",
727 Config
.effectiveGroup
);
731 Config2
.effectiveGroupID
= grp
->gr_gid
;
734 HttpRequestMethod::Configure(Config
);
737 debugs(3, 1, "Initializing https proxy context");
739 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
);
745 for (p
= Config
.peers
; p
!= NULL
; p
= p
->next
) {
747 debugs(3, 1, "Initializing cache_peer " << p
->name
<< " SSL context");
748 p
->sslContext
= sslCreateClientContext(p
->sslcert
, p
->sslkey
, p
->sslversion
, p
->sslcipher
, p
->ssloptions
, p
->sslflags
, p
->sslcafile
, p
->sslcapath
, p
->sslcrlfile
);
757 for (s
= Config
.Sockaddr
.http
; s
!= NULL
; s
= (http_port_list
*) s
->next
) {
758 if (!s
->cert
&& !s
->key
)
761 debugs(3, 1, "Initializing http_port " << s
->http
.s
<< " SSL context");
763 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
);
771 for (s
= Config
.Sockaddr
.https
; s
!= NULL
; s
= (https_port_list
*) s
->http
.next
) {
772 debugs(3, 1, "Initializing https_port " << s
->http
.s
<< " SSL context");
774 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
);
781 /* Parse a time specification from the config file. Store the
782 * result in 'tptr', after converting it to 'units' */
784 parseTimeLine(time_t * tptr
, const char *units
)
791 if ((u
= parseTimeUnits(units
)) == 0)
794 if ((token
= strtok(NULL
, w_space
)) == NULL
)
799 m
= u
; /* default to 'units' if none specified */
803 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
804 debugs(3, 0, "WARNING: No units on '" <<
805 config_input_line
<< "', assuming " <<
807 else if ((m
= parseTimeUnits(token
)) == 0)
810 *tptr
= static_cast<time_t> (m
* d
/ u
);
814 parseTimeUnits(const char *unit
)
816 if (!strncasecmp(unit
, T_SECOND_STR
, strlen(T_SECOND_STR
)))
819 if (!strncasecmp(unit
, T_MINUTE_STR
, strlen(T_MINUTE_STR
)))
822 if (!strncasecmp(unit
, T_HOUR_STR
, strlen(T_HOUR_STR
)))
825 if (!strncasecmp(unit
, T_DAY_STR
, strlen(T_DAY_STR
)))
828 if (!strncasecmp(unit
, T_WEEK_STR
, strlen(T_WEEK_STR
)))
831 if (!strncasecmp(unit
, T_FORTNIGHT_STR
, strlen(T_FORTNIGHT_STR
)))
834 if (!strncasecmp(unit
, T_MONTH_STR
, strlen(T_MONTH_STR
)))
837 if (!strncasecmp(unit
, T_YEAR_STR
, strlen(T_YEAR_STR
)))
838 return static_cast<int>(86400 * 365.2522);
840 if (!strncasecmp(unit
, T_DECADE_STR
, strlen(T_DECADE_STR
)))
841 return static_cast<int>(86400 * 365.2522 * 10);
843 debugs(3, 1, "parseTimeUnits: unknown time unit '" << unit
<< "'");
849 parseBytesLine64(int64_t * bptr
, const char *units
)
856 if ((u
= parseBytesUnits(units
)) == 0) {
861 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
866 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
873 m
= u
; /* default to 'units' if none specified */
877 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
878 debugs(3, 0, "WARNING: No units on '" <<
879 config_input_line
<< "', assuming " <<
881 else if ((m
= parseBytesUnits(token
)) == 0) {
886 *bptr
= static_cast<int64_t>(m
* d
/ u
);
888 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
894 parseBytesLine(size_t * bptr
, const char *units
)
901 if ((u
= parseBytesUnits(units
)) == 0) {
906 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
911 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
912 *bptr
= static_cast<size_t>(-1);
918 m
= u
; /* default to 'units' if none specified */
922 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
923 debugs(3, 0, "WARNING: No units on '" <<
924 config_input_line
<< "', assuming " <<
926 else if ((m
= parseBytesUnits(token
)) == 0) {
931 *bptr
= static_cast<size_t>(m
* d
/ u
);
933 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
938 parseBytesUnits(const char *unit
)
940 if (!strncasecmp(unit
, B_BYTES_STR
, strlen(B_BYTES_STR
)))
943 if (!strncasecmp(unit
, B_KBYTES_STR
, strlen(B_KBYTES_STR
)))
946 if (!strncasecmp(unit
, B_MBYTES_STR
, strlen(B_MBYTES_STR
)))
949 if (!strncasecmp(unit
, B_GBYTES_STR
, strlen(B_GBYTES_STR
)))
952 debugs(3, DBG_CRITICAL
, "WARNING: Unknown bytes unit '" << unit
<< "'");
957 /*****************************************************************************
959 *****************************************************************************/
962 dump_acl(StoreEntry
* entry
, const char *name
, ACL
* ae
)
968 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
);
969 storeAppendPrintf(entry
, "%s %s %s ",
976 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
<< " " << v
->key
);
977 storeAppendPrintf(entry
, "%s ", v
->key
);
981 storeAppendPrintf(entry
, "\n");
990 ACL::ParseAclLine(LegacyParser
, ae
);
1000 dump_acl_list(StoreEntry
* entry
, ACLList
* head
)
1004 for (l
= head
; l
; l
= l
->next
) {
1005 storeAppendPrintf(entry
, " %s%s",
1006 l
->op
? null_string
: "!",
1012 dump_acl_access(StoreEntry
* entry
, const char *name
, acl_access
* head
)
1016 for (l
= head
; l
; l
= l
->next
) {
1017 storeAppendPrintf(entry
, "%s %s",
1019 l
->allow
? "Allow" : "Deny");
1020 dump_acl_list(entry
, l
->aclList
);
1021 storeAppendPrintf(entry
, "\n");
1026 parse_acl_access(acl_access
** head
)
1028 aclParseAccessLine(LegacyParser
, head
);
1032 free_acl_access(acl_access
** head
)
1034 aclDestroyAccessList(head
);
1038 dump_address(StoreEntry
* entry
, const char *name
, IpAddress
&addr
)
1040 char buf
[MAX_IPSTRLEN
];
1041 storeAppendPrintf(entry
, "%s %s\n", name
, addr
.NtoA(buf
,MAX_IPSTRLEN
) );
1045 parse_address(IpAddress
*addr
)
1047 char *token
= strtok(NULL
, w_space
);
1054 if (!strcmp(token
,"any_addr")) {
1057 } else if ( (!strcmp(token
,"no_addr")) || (!strcmp(token
,"full_mask")) ) {
1065 free_address(IpAddress
*addr
)
1070 CBDATA_TYPE(acl_address
);
1073 dump_acl_address(StoreEntry
* entry
, const char *name
, acl_address
* head
)
1075 char buf
[MAX_IPSTRLEN
];
1078 for (l
= head
; l
; l
= l
->next
) {
1079 if (!l
->addr
.IsAnyAddr())
1080 storeAppendPrintf(entry
, "%s %s", name
, l
->addr
.NtoA(buf
,MAX_IPSTRLEN
));
1082 storeAppendPrintf(entry
, "%s autoselect", name
);
1084 dump_acl_list(entry
, l
->aclList
);
1086 storeAppendPrintf(entry
, "\n");
1091 freed_acl_address(void *data
)
1093 acl_address
*l
= static_cast<acl_address
*>(data
);
1094 aclDestroyAclList(&l
->aclList
);
1098 parse_acl_address(acl_address
** head
)
1101 acl_address
**tail
= head
; /* sane name below */
1102 CBDATA_INIT_TYPE_FREECB(acl_address
, freed_acl_address
);
1103 l
= cbdataAlloc(acl_address
);
1104 parse_address(&l
->addr
);
1105 aclParseAclList(LegacyParser
, &l
->aclList
);
1108 tail
= &(*tail
)->next
;
1114 free_acl_address(acl_address
** head
)
1117 acl_address
*l
= *head
;
1123 CBDATA_TYPE(acl_tos
);
1126 dump_acl_tos(StoreEntry
* entry
, const char *name
, acl_tos
* head
)
1130 for (l
= head
; l
; l
= l
->next
) {
1132 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->tos
);
1134 storeAppendPrintf(entry
, "%s none", name
);
1136 dump_acl_list(entry
, l
->aclList
);
1138 storeAppendPrintf(entry
, "\n");
1143 freed_acl_tos(void *data
)
1145 acl_tos
*l
= static_cast<acl_tos
*>(data
);
1146 aclDestroyAclList(&l
->aclList
);
1150 parse_acl_tos(acl_tos
** head
)
1153 acl_tos
**tail
= head
; /* sane name below */
1156 char *token
= strtok(NULL
, w_space
);
1163 if (sscanf(token
, "0x%x%c", &tos
, &junk
) != 1) {
1168 if (tos
< 0 || tos
> 255) {
1173 CBDATA_INIT_TYPE_FREECB(acl_tos
, freed_acl_tos
);
1175 l
= cbdataAlloc(acl_tos
);
1179 aclParseAclList(LegacyParser
, &l
->aclList
);
1182 tail
= &(*tail
)->next
;
1188 free_acl_tos(acl_tos
** head
)
1198 CBDATA_TYPE(acl_size_t
);
1201 dump_acl_b_size_t(StoreEntry
* entry
, const char *name
, acl_size_t
* head
)
1205 for (l
= head
; l
; l
= l
->next
) {
1207 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) l
->size
, B_BYTES_STR
);
1209 storeAppendPrintf(entry
, "%s none", name
);
1211 dump_acl_list(entry
, l
->aclList
);
1213 storeAppendPrintf(entry
, "\n");
1218 freed_acl_b_size_t(void *data
)
1220 acl_size_t
*l
= static_cast<acl_size_t
*>(data
);
1221 aclDestroyAclList(&l
->aclList
);
1225 parse_acl_b_size_t(acl_size_t
** head
)
1228 acl_size_t
**tail
= head
; /* sane name below */
1230 CBDATA_INIT_TYPE_FREECB(acl_size_t
, freed_acl_b_size_t
);
1232 l
= cbdataAlloc(acl_size_t
);
1234 parse_b_int64_t(&l
->size
);
1236 aclParseAclList(LegacyParser
, &l
->aclList
);
1239 tail
= &(*tail
)->next
;
1245 free_acl_b_size_t(acl_size_t
** head
)
1248 acl_size_t
*l
= *head
;
1257 #include "DelayPools.h"
1258 #include "DelayConfig.h"
1259 /* do nothing - free_delay_pool_count is the magic free function.
1260 * this is why delay_pool_count isn't just marked TYPE: ushort
1262 #define free_delay_pool_class(X)
1263 #define free_delay_pool_access(X)
1264 #define free_delay_pool_rates(X)
1265 #define dump_delay_pool_class(X, Y, Z)
1266 #define dump_delay_pool_access(X, Y, Z)
1267 #define dump_delay_pool_rates(X, Y, Z)
1270 free_delay_pool_count(DelayConfig
* cfg
)
1272 cfg
->freePoolCount();
1276 dump_delay_pool_count(StoreEntry
* entry
, const char *name
, DelayConfig
&cfg
)
1278 cfg
.dumpPoolCount (entry
, name
);
1282 parse_delay_pool_count(DelayConfig
* cfg
)
1284 cfg
->parsePoolCount();
1288 parse_delay_pool_class(DelayConfig
* cfg
)
1290 cfg
->parsePoolClass();
1294 parse_delay_pool_rates(DelayConfig
* cfg
)
1296 cfg
->parsePoolRates();
1300 parse_delay_pool_access(DelayConfig
* cfg
)
1302 cfg
->parsePoolAccess(LegacyParser
);
1309 dump_http_header_access(StoreEntry
* entry
, const char *name
, header_mangler header
[])
1313 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1314 if (header
[i
].access_list
!= NULL
) {
1315 storeAppendPrintf(entry
, "%s ", name
);
1316 dump_acl_access(entry
, httpHeaderNameById(i
),
1317 header
[i
].access_list
);
1323 parse_http_header_access(header_mangler header
[])
1328 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1329 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1330 debugs(3, 0, "parse_http_header_access: missing header name.");
1334 /* Now lookup index of header. */
1335 id
= httpHeaderIdByNameDef(t
, strlen(t
));
1337 if (strcmp(t
, "All") == 0)
1339 else if (strcmp(t
, "Other") == 0)
1341 else if (id
== -1) {
1342 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1343 debugs(3, 0, "parse_http_header_access: unknown header name '" << t
<< "'");
1347 if (id
!= HDR_ENUM_END
) {
1348 parse_acl_access(&header
[id
].access_list
);
1350 char *next_string
= t
+ strlen(t
) - 1;
1352 *(next_string
+ 1) = ' ';
1354 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1355 char *new_string
= xstrdup(next_string
);
1356 strtok(new_string
, w_space
);
1357 parse_acl_access(&header
[i
].access_list
);
1358 safe_free(new_string
);
1364 free_http_header_access(header_mangler header
[])
1368 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1369 free_acl_access(&header
[i
].access_list
);
1374 dump_http_header_replace(StoreEntry
* entry
, const char *name
, header_mangler
1379 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1380 if (NULL
== header
[i
].replacement
)
1383 storeAppendPrintf(entry
, "%s %s %s\n", name
, httpHeaderNameById(i
),
1384 header
[i
].replacement
);
1389 parse_http_header_replace(header_mangler header
[])
1394 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1395 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1396 debugs(3, 0, "parse_http_header_replace: missing header name.");
1400 /* Now lookup index of header. */
1401 id
= httpHeaderIdByNameDef(t
, strlen(t
));
1403 if (strcmp(t
, "All") == 0)
1405 else if (strcmp(t
, "Other") == 0)
1407 else if (id
== -1) {
1408 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1409 debugs(3, 0, "parse_http_header_replace: unknown header name " << t
<< ".");
1414 if (id
!= HDR_ENUM_END
) {
1415 if (header
[id
].replacement
!= NULL
)
1416 safe_free(header
[id
].replacement
);
1418 header
[id
].replacement
= xstrdup(t
+ strlen(t
) + 1);
1420 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1421 if (header
[i
].replacement
!= NULL
)
1422 safe_free(header
[i
].replacement
);
1424 header
[i
].replacement
= xstrdup(t
+ strlen(t
) + 1);
1430 free_http_header_replace(header_mangler header
[])
1434 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1435 if (header
[i
].replacement
!= NULL
)
1436 safe_free(header
[i
].replacement
);
1443 dump_cachedir(StoreEntry
* entry
, const char *name
, SquidConfig::_cacheSwap swap
)
1449 for (i
= 0; i
< swap
.n_configured
; i
++) {
1450 s
= dynamic_cast<SwapDir
*>(swap
.swapDirs
[i
].getRaw());
1452 storeAppendPrintf(entry
, "%s %s %s", name
, s
->type(), s
->path
);
1454 storeAppendPrintf(entry
, "\n");
1459 check_null_string(char *s
)
1465 parse_authparam(authConfig
* config
)
1470 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1473 if ((param_str
= strtok(NULL
, w_space
)) == NULL
)
1476 /* find a configuration for the scheme */
1477 AuthConfig
*scheme
= AuthConfig::Find (type_str
);
1479 if (scheme
== NULL
) {
1480 /* Create a configuration */
1481 AuthScheme
*theScheme
;
1483 if ((theScheme
= AuthScheme::Find(type_str
)) == NULL
) {
1484 debugs(3, 0, "Parsing Config File: Unknown authentication scheme '" << type_str
<< "'.");
1488 config
->push_back(theScheme
->createConfig());
1489 scheme
= config
->back();
1493 scheme
->parse(scheme
, config
->size(), param_str
);
1497 free_authparam(authConfig
* cfg
)
1500 /* DON'T FREE THESE FOR RECONFIGURE */
1505 while (cfg
->size()) {
1506 scheme
= cfg
->pop_back();
1512 dump_authparam(StoreEntry
* entry
, const char *name
, authConfig cfg
)
1514 for (authConfig::iterator i
= cfg
.begin(); i
!= cfg
.end(); ++i
)
1515 (*i
)->dump(entry
, name
, (*i
));
1518 /* TODO: just return the object, the # is irrelevant */
1520 find_fstype(char *type
)
1522 for (size_t i
= 0; i
< StoreFileSystem::FileSystems().size(); ++i
)
1523 if (strcasecmp(type
, StoreFileSystem::FileSystems().items
[i
]->type()) == 0)
1530 parse_cachedir(SquidConfig::_cacheSwap
* swap
)
1534 RefCount
<SwapDir
> sd
;
1538 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1541 if ((path_str
= strtok(NULL
, w_space
)) == NULL
)
1544 fs
= find_fstype(type_str
);
1549 /* reconfigure existing dir */
1551 for (i
= 0; i
< swap
->n_configured
; i
++) {
1552 assert (swap
->swapDirs
[i
].getRaw());
1554 if ((strcasecmp(path_str
, dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw())->path
)) == 0) {
1555 /* this is specific to on-fs Stores. The right
1556 * way to handle this is probably to have a mapping
1557 * from paths to stores, and have on-fs stores
1558 * register with that, and lookip in that in their
1559 * own setup logic. RBC 20041225. TODO.
1562 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw());
1564 if (sd
->type() != StoreFileSystem::FileSystems().items
[fs
]->type()) {
1565 debugs(3, 0, "ERROR: Can't change type of existing cache_dir " <<
1566 sd
->type() << " " << sd
->path
<< " to " << type_str
<< ". Restart required");
1570 sd
->reconfigure (i
, path_str
);
1572 update_maxobjsize();
1579 if (swap
->n_configured
> 63) {
1580 /* 7 bits, signed */
1581 debugs(3, DBG_CRITICAL
, "WARNING: There is a fixed maximum of 63 cache_dir entries Squid can handle.");
1582 debugs(3, DBG_CRITICAL
, "WARNING: '" << path_str
<< "' is one to many.");
1587 allocate_new_swapdir(swap
);
1589 swap
->swapDirs
[swap
->n_configured
] = StoreFileSystem::FileSystems().items
[fs
]->createSwapDir();
1591 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[swap
->n_configured
].getRaw());
1593 /* parse the FS parameters and options */
1594 sd
->parse(swap
->n_configured
, path_str
);
1596 ++swap
->n_configured
;
1598 /* Update the max object size */
1599 update_maxobjsize();
1603 peer_type_str(const peer_t type
)
1605 const char * result
;
1617 case PEER_MULTICAST
:
1618 result
= "multicast";
1630 dump_peer(StoreEntry
* entry
, const char *name
, peer
* p
)
1634 LOCAL_ARRAY(char, xname
, 128);
1637 storeAppendPrintf(entry
, "%s %s %s %d %d name=%s",
1644 dump_peer_options(entry
, p
);
1646 for (d
= p
->peer_domain
; d
; d
= d
->next
) {
1647 storeAppendPrintf(entry
, "cache_peer_domain %s %s%s\n",
1649 d
->do_ping
? null_string
: "!",
1654 snprintf(xname
, 128, "cache_peer_access %s", p
->name
);
1655 dump_acl_access(entry
, xname
, p
->access
);
1658 for (t
= p
->typelist
; t
; t
= t
->next
) {
1659 storeAppendPrintf(entry
, "neighbor_type_domain %s %s %s\n",
1661 peer_type_str(t
->type
),
1670 * utility function to prevent getservbyname() being called with a numeric value
1671 * on Windows at least it returns garage results.
1674 isUnsignedNumeric(const char *str
, size_t len
)
1676 if (len
< 1) return false;
1678 for (; len
>0 && *str
; str
++, len
--) {
1679 if (! isdigit(*str
))
1686 \param proto 'tcp' or 'udp' for protocol
1687 \returns Port the named service is supposed to be listening on.
1690 GetService(const char *proto
)
1692 struct servent
*port
= NULL
;
1693 /** Parses a port number or service name from the squid.conf */
1694 char *token
= strtok(NULL
, w_space
);
1695 if (token
== NULL
) {
1697 return 0; /* NEVER REACHED */
1699 /** Returns either the service port number from /etc/services */
1700 if ( !isUnsignedNumeric(token
, strlen(token
)) )
1701 port
= getservbyname(token
, proto
);
1703 return ntohs((u_short
)port
->s_port
);
1705 /** Or a numeric translation of the config text. */
1706 return xatos(token
);
1710 \returns Port the named TCP service is supposed to be listening on.
1711 \copydoc GetService(const char *proto)
1716 return GetService("tcp");
1720 \returns Port the named UDP service is supposed to be listening on.
1721 \copydoc GetService(const char *proto)
1726 return GetService("udp");
1730 parse_peer(peer
** head
)
1734 CBDATA_INIT_TYPE_FREECB(peer
, peerDestroy
);
1735 p
= cbdataAlloc(peer
);
1736 p
->http_port
= CACHE_HTTP_PORT
;
1737 p
->icp
.port
= CACHE_ICP_PORT
;
1740 p
->stats
.logged_state
= PEER_ALIVE
;
1742 if ((token
= strtok(NULL
, w_space
)) == NULL
)
1745 p
->host
= xstrdup(token
);
1747 p
->name
= xstrdup(token
);
1749 if ((token
= strtok(NULL
, w_space
)) == NULL
)
1752 p
->type
= parseNeighborType(token
);
1754 if (p
->type
== PEER_MULTICAST
) {
1755 p
->options
.no_digest
= 1;
1756 p
->options
.no_netdb_exchange
= 1;
1759 p
->http_port
= GetTcpService();
1764 p
->icp
.port
= GetUdpService();
1765 p
->connection_auth
= 2; /* auto */
1767 while ((token
= strtok(NULL
, w_space
))) {
1768 if (!strcasecmp(token
, "proxy-only")) {
1769 p
->options
.proxy_only
= 1;
1770 } else if (!strcasecmp(token
, "no-query")) {
1771 p
->options
.no_query
= 1;
1772 } else if (!strcasecmp(token
, "background-ping")) {
1773 p
->options
.background_ping
= 1;
1774 } else if (!strcasecmp(token
, "no-digest")) {
1775 p
->options
.no_digest
= 1;
1776 } else if (!strcasecmp(token
, "no-tproxy")) {
1777 p
->options
.no_tproxy
= 1;
1778 } else if (!strcasecmp(token
, "multicast-responder")) {
1779 p
->options
.mcast_responder
= 1;
1780 #if PEER_MULTICAST_SIBLINGS
1781 } else if (!strcasecmp(token
, "multicast-siblings")) {
1782 p
->options
.mcast_siblings
= 1;
1784 } else if (!strncasecmp(token
, "weight=", 7)) {
1785 p
->weight
= xatoi(token
+ 7);
1786 } else if (!strncasecmp(token
, "basetime=", 9)) {
1787 p
->basetime
= xatoi(token
+ 9);
1788 } else if (!strcasecmp(token
, "closest-only")) {
1789 p
->options
.closest_only
= 1;
1790 } else if (!strncasecmp(token
, "ttl=", 4)) {
1791 p
->mcast
.ttl
= xatoi(token
+ 4);
1793 if (p
->mcast
.ttl
< 0)
1796 if (p
->mcast
.ttl
> 128)
1798 } else if (!strcasecmp(token
, "default")) {
1799 p
->options
.default_parent
= 1;
1800 } else if (!strcasecmp(token
, "round-robin")) {
1801 p
->options
.roundrobin
= 1;
1802 } else if (!strcasecmp(token
, "weighted-round-robin")) {
1803 p
->options
.weighted_roundrobin
= 1;
1806 } else if (!strcasecmp(token
, "htcp")) {
1807 p
->options
.htcp
= 1;
1808 } else if (!strcasecmp(token
, "htcp-oldsquid")) {
1809 p
->options
.htcp
= 1;
1810 p
->options
.htcp_oldsquid
= 1;
1811 } else if (!strcasecmp(token
, "htcp-no-clr")) {
1812 if (p
->options
.htcp_only_clr
)
1813 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
1814 p
->options
.htcp
= 1;
1815 p
->options
.htcp_no_clr
= 1;
1816 } else if (!strcasecmp(token
, "htcp-no-purge-clr")) {
1817 p
->options
.htcp
= 1;
1818 p
->options
.htcp_no_purge_clr
= 1;
1819 } else if (!strcasecmp(token
, "htcp-only-clr")) {
1820 if (p
->options
.htcp_no_clr
)
1821 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
1822 p
->options
.htcp
= 1;
1823 p
->options
.htcp_only_clr
= 1;
1824 } else if (!strcasecmp(token
, "htcp-forward-clr")) {
1825 p
->options
.htcp
= 1;
1826 p
->options
.htcp_forward_clr
= 1;
1829 } else if (!strcasecmp(token
, "no-netdb-exchange")) {
1830 p
->options
.no_netdb_exchange
= 1;
1832 } else if (!strcasecmp(token
, "carp")) {
1833 if (p
->type
!= PEER_PARENT
)
1834 fatalf("parse_peer: non-parent carp peer %s/%d\n", p
->host
, p
->http_port
);
1836 p
->options
.carp
= 1;
1838 } else if (!strcasecmp(token
, "userhash")) {
1839 if (p
->type
!= PEER_PARENT
)
1840 fatalf("parse_peer: non-parent userhash peer %s/%d\n", p
->host
, p
->http_port
);
1842 p
->options
.userhash
= 1;
1844 } else if (!strcasecmp(token
, "sourcehash")) {
1845 if (p
->type
!= PEER_PARENT
)
1846 fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p
->host
, p
->http_port
);
1848 p
->options
.sourcehash
= 1;
1852 } else if (!strcasecmp(token
, "no-delay")) {
1853 p
->options
.no_delay
= 1;
1856 } else if (!strncasecmp(token
, "login=", 6)) {
1857 p
->login
= xstrdup(token
+ 6);
1858 rfc1738_unescape(p
->login
);
1859 } else if (!strncasecmp(token
, "connect-timeout=", 16)) {
1860 p
->connect_timeout
= xatoi(token
+ 16);
1861 } else if (!strncasecmp(token
, "connect-fail-limit=", 19)) {
1862 p
->connect_fail_limit
= xatoi(token
+ 19);
1863 #if USE_CACHE_DIGESTS
1864 } else if (!strncasecmp(token
, "digest-url=", 11)) {
1865 p
->digest_url
= xstrdup(token
+ 11);
1868 } else if (!strcasecmp(token
, "allow-miss")) {
1869 p
->options
.allow_miss
= 1;
1870 } else if (!strncasecmp(token
, "max-conn=", 9)) {
1871 p
->max_conn
= xatoi(token
+ 9);
1872 } else if (!strcasecmp(token
, "originserver")) {
1873 p
->options
.originserver
= 1;
1874 } else if (!strncasecmp(token
, "name=", 5)) {
1878 p
->name
= xstrdup(token
+ 5);
1879 } else if (!strncasecmp(token
, "forceddomain=", 13)) {
1880 safe_free(p
->domain
);
1883 p
->domain
= xstrdup(token
+ 13);
1887 } else if (strcmp(token
, "ssl") == 0) {
1889 } else if (strncmp(token
, "sslcert=", 8) == 0) {
1890 safe_free(p
->sslcert
);
1891 p
->sslcert
= xstrdup(token
+ 8);
1892 } else if (strncmp(token
, "sslkey=", 7) == 0) {
1893 safe_free(p
->sslkey
);
1894 p
->sslkey
= xstrdup(token
+ 7);
1895 } else if (strncmp(token
, "sslversion=", 11) == 0) {
1896 p
->sslversion
= atoi(token
+ 11);
1897 } else if (strncmp(token
, "ssloptions=", 11) == 0) {
1898 safe_free(p
->ssloptions
);
1899 p
->ssloptions
= xstrdup(token
+ 11);
1900 } else if (strncmp(token
, "sslcipher=", 10) == 0) {
1901 safe_free(p
->sslcipher
);
1902 p
->sslcipher
= xstrdup(token
+ 10);
1903 } else if (strncmp(token
, "sslcafile=", 10) == 0) {
1904 safe_free(p
->sslcafile
);
1905 p
->sslcafile
= xstrdup(token
+ 10);
1906 } else if (strncmp(token
, "sslcapath=", 10) == 0) {
1907 safe_free(p
->sslcapath
);
1908 p
->sslcapath
= xstrdup(token
+ 10);
1909 } else if (strncmp(token
, "sslcrlfile=", 11) == 0) {
1910 safe_free(p
->sslcrlfile
);
1911 p
->sslcapath
= xstrdup(token
+ 10);
1912 } else if (strncmp(token
, "sslflags=", 9) == 0) {
1913 safe_free(p
->sslflags
);
1914 p
->sslflags
= xstrdup(token
+ 9);
1915 } else if (strncmp(token
, "ssldomain=", 10) == 0) {
1916 safe_free(p
->ssldomain
);
1917 p
->ssldomain
= xstrdup(token
+ 10);
1920 } else if (strcmp(token
, "front-end-https") == 0) {
1921 p
->front_end_https
= 1;
1922 } else if (strcmp(token
, "front-end-https=on") == 0) {
1923 p
->front_end_https
= 1;
1924 } else if (strcmp(token
, "front-end-https=auto") == 0) {
1925 p
->front_end_https
= 2;
1926 } else if (strcmp(token
, "connection-auth=off") == 0) {
1927 p
->connection_auth
= 0;
1928 } else if (strcmp(token
, "connection-auth") == 0) {
1929 p
->connection_auth
= 1;
1930 } else if (strcmp(token
, "connection-auth=on") == 0) {
1931 p
->connection_auth
= 1;
1932 } else if (strcmp(token
, "connection-auth=auto") == 0) {
1933 p
->connection_auth
= 2;
1935 debugs(3, 0, "parse_peer: token='" << token
<< "'");
1940 if (peerFindByName(p
->name
))
1941 fatalf("ERROR: cache_peer %s specified twice\n", p
->name
);
1946 if (p
->connect_fail_limit
< 1)
1947 p
->connect_fail_limit
= 10;
1949 p
->icp
.version
= ICP_VERSION_CURRENT
;
1953 #if USE_CACHE_DIGESTS
1955 if (!p
->options
.no_digest
) {
1956 /* XXX This looks odd.. who has the original pointer
1959 PeerDigest
*pd
= peerDigestCreate(p
);
1960 p
->digest
= cbdataReference(pd
);
1965 p
->index
= ++Config
.npeers
;
1967 while (*head
!= NULL
)
1968 head
= &(*head
)->next
;
1976 free_peer(peer
** P
)
1980 while ((p
= *P
) != NULL
) {
1982 #if USE_CACHE_DIGESTS
1984 cbdataReferenceDone(p
->digest
);
1994 dump_cachemgrpasswd(StoreEntry
* entry
, const char *name
, cachemgr_passwd
* list
)
1998 while (list
!= NULL
) {
1999 if (strcmp(list
->passwd
, "none") && strcmp(list
->passwd
, "disable"))
2000 storeAppendPrintf(entry
, "%s XXXXXXXXXX", name
);
2002 storeAppendPrintf(entry
, "%s %s", name
, list
->passwd
);
2004 for (w
= list
->actions
; w
!= NULL
; w
= w
->next
) {
2005 storeAppendPrintf(entry
, " %s", w
->key
);
2008 storeAppendPrintf(entry
, "\n");
2014 parse_cachemgrpasswd(cachemgr_passwd
** head
)
2016 char *passwd
= NULL
;
2017 wordlist
*actions
= NULL
;
2019 cachemgr_passwd
**P
;
2020 parse_string(&passwd
);
2021 parse_wordlist(&actions
);
2022 p
= static_cast<cachemgr_passwd
*>(xcalloc(1, sizeof(cachemgr_passwd
)));
2024 p
->actions
= actions
;
2026 for (P
= head
; *P
; P
= &(*P
)->next
) {
2028 * See if any of the actions from this line already have a
2029 * password from previous lines. The password checking
2030 * routines in cache_manager.c take the the password from
2031 * the first cachemgr_passwd struct that contains the
2032 * requested action. Thus, we should warn users who might
2033 * think they can have two passwords for the same action.
2038 for (w
= (*P
)->actions
; w
; w
= w
->next
) {
2039 for (u
= actions
; u
; u
= u
->next
) {
2040 if (strcmp(w
->key
, u
->key
))
2043 debugs(0, 0, "WARNING: action '" << u
->key
<< "' (line " << config_lineno
<< ") already has a password");
2052 free_cachemgrpasswd(cachemgr_passwd
** head
)
2056 while ((p
= *head
) != NULL
) {
2059 wordlistDestroy(&p
->actions
);
2065 dump_denyinfo(StoreEntry
* entry
, const char *name
, acl_deny_info_list
* var
)
2069 while (var
!= NULL
) {
2070 storeAppendPrintf(entry
, "%s %s", name
, var
->err_page_name
);
2072 for (a
= var
->acl_list
; a
!= NULL
; a
= a
->next
)
2073 storeAppendPrintf(entry
, " %s", a
->name
);
2075 storeAppendPrintf(entry
, "\n");
2082 parse_denyinfo(acl_deny_info_list
** var
)
2084 aclParseDenyInfoLine(var
);
2088 free_denyinfo(acl_deny_info_list
** list
)
2090 acl_deny_info_list
*a
= NULL
;
2091 acl_deny_info_list
*a_next
= NULL
;
2092 acl_name_list
*l
= NULL
;
2093 acl_name_list
*l_next
= NULL
;
2095 for (a
= *list
; a
; a
= a_next
) {
2096 for (l
= a
->acl_list
; l
; l
= l_next
) {
2098 memFree(l
, MEM_ACL_NAME_LIST
);
2103 memFree(a
, MEM_ACL_DENY_INFO_LIST
);
2111 parse_peer_access(void)
2116 if (!(host
= strtok(NULL
, w_space
)))
2119 if ((p
= peerFindByName(host
)) == NULL
) {
2120 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2124 aclParseAccessLine(LegacyParser
, &p
->access
);
2128 parse_hostdomain(void)
2131 char *domain
= NULL
;
2133 if (!(host
= strtok(NULL
, w_space
)))
2136 while ((domain
= strtok(NULL
, list_sep
))) {
2137 domain_ping
*l
= NULL
;
2138 domain_ping
**L
= NULL
;
2141 if ((p
= peerFindByName(host
)) == NULL
) {
2142 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2146 l
= static_cast<domain_ping
*>(xcalloc(1, sizeof(domain_ping
)));
2149 if (*domain
== '!') { /* check for !.edu */
2154 l
->domain
= xstrdup(domain
);
2156 for (L
= &(p
->peer_domain
); *L
; L
= &((*L
)->next
));
2162 parse_hostdomaintype(void)
2166 char *domain
= NULL
;
2168 if (!(host
= strtok(NULL
, w_space
)))
2171 if (!(type
= strtok(NULL
, w_space
)))
2174 while ((domain
= strtok(NULL
, list_sep
))) {
2175 domain_type
*l
= NULL
;
2176 domain_type
**L
= NULL
;
2179 if ((p
= peerFindByName(host
)) == NULL
) {
2180 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2184 l
= static_cast<domain_type
*>(xcalloc(1, sizeof(domain_type
)));
2185 l
->type
= parseNeighborType(type
);
2186 l
->domain
= xstrdup(domain
);
2188 for (L
= &(p
->typelist
); *L
; L
= &((*L
)->next
));
2194 dump_int(StoreEntry
* entry
, const char *name
, int var
)
2196 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2214 dump_onoff(StoreEntry
* entry
, const char *name
, int var
)
2216 storeAppendPrintf(entry
, "%s %s\n", name
, var
? "on" : "off");
2220 parse_onoff(int *var
)
2222 char *token
= strtok(NULL
, w_space
);
2227 if (!strcasecmp(token
, "on") || !strcasecmp(token
, "enable"))
2233 #define free_onoff free_int
2236 dump_tristate(StoreEntry
* entry
, const char *name
, int var
)
2247 storeAppendPrintf(entry
, "%s %s\n", name
, state
);
2251 parse_tristate(int *var
)
2253 char *token
= strtok(NULL
, w_space
);
2258 if (!strcasecmp(token
, "on") || !strcasecmp(token
, "enable"))
2260 else if (!strcasecmp(token
, "warn"))
2266 #define free_tristate free_int
2269 dump_refreshpattern(StoreEntry
* entry
, const char *name
, refresh_t
* head
)
2271 while (head
!= NULL
) {
2272 storeAppendPrintf(entry
, "%s%s %s %d %d%% %d\n",
2274 head
->flags
.icase
? " -i" : null_string
,
2276 (int) head
->min
/ 60,
2277 (int) (100.0 * head
->pct
+ 0.5),
2278 (int) head
->max
/ 60);
2280 if (head
->flags
.refresh_ims
)
2281 storeAppendPrintf(entry
, " refresh-ims");
2285 if (head
->flags
.override_expire
)
2286 storeAppendPrintf(entry
, " override-expire");
2288 if (head
->flags
.override_lastmod
)
2289 storeAppendPrintf(entry
, " override-lastmod");
2291 if (head
->flags
.reload_into_ims
)
2292 storeAppendPrintf(entry
, " reload-into-ims");
2294 if (head
->flags
.ignore_reload
)
2295 storeAppendPrintf(entry
, " ignore-reload");
2297 if (head
->flags
.ignore_no_cache
)
2298 storeAppendPrintf(entry
, " ignore-no-cache");
2300 if (head
->flags
.ignore_no_store
)
2301 storeAppendPrintf(entry
, " ignore-no-store");
2303 if (head
->flags
.ignore_must_revalidate
)
2304 storeAppendPrintf(entry
, " ignore-must-revalidate");
2306 if (head
->flags
.ignore_private
)
2307 storeAppendPrintf(entry
, " ignore-private");
2309 if (head
->flags
.ignore_auth
)
2310 storeAppendPrintf(entry
, " ignore-auth");
2314 storeAppendPrintf(entry
, "\n");
2321 parse_refreshpattern(refresh_t
** head
)
2328 int refresh_ims
= 0;
2331 int override_expire
= 0;
2332 int override_lastmod
= 0;
2333 int reload_into_ims
= 0;
2334 int ignore_reload
= 0;
2335 int ignore_no_cache
= 0;
2336 int ignore_no_store
= 0;
2337 int ignore_must_revalidate
= 0;
2338 int ignore_private
= 0;
2339 int ignore_auth
= 0;
2346 int flags
= REG_EXTENDED
| REG_NOSUB
;
2348 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
2353 if (strcmp(token
, "-i") == 0) {
2355 token
= strtok(NULL
, w_space
);
2356 } else if (strcmp(token
, "+i") == 0) {
2357 flags
&= ~REG_ICASE
;
2358 token
= strtok(NULL
, w_space
);
2361 if (token
== NULL
) {
2366 pattern
= xstrdup(token
);
2368 i
= GetInteger(); /* token: min */
2370 min
= (time_t) (i
* 60); /* convert minutes to seconds */
2372 i
= GetInteger(); /* token: pct */
2374 pct
= (double) i
/ 100.0;
2376 i
= GetInteger(); /* token: max */
2378 max
= (time_t) (i
* 60); /* convert minutes to seconds */
2381 while ((token
= strtok(NULL
, w_space
)) != NULL
) {
2382 if (!strcmp(token
, "refresh-ims")) {
2386 } else if (!strcmp(token
, "override-expire"))
2387 override_expire
= 1;
2388 else if (!strcmp(token
, "override-lastmod"))
2389 override_lastmod
= 1;
2390 else if (!strcmp(token
, "ignore-no-cache"))
2391 ignore_no_cache
= 1;
2392 else if (!strcmp(token
, "ignore-no-store"))
2393 ignore_no_store
= 1;
2394 else if (!strcmp(token
, "ignore-must-revalidate"))
2395 ignore_must_revalidate
= 1;
2396 else if (!strcmp(token
, "ignore-private"))
2398 else if (!strcmp(token
, "ignore-auth"))
2400 else if (!strcmp(token
, "reload-into-ims")) {
2401 reload_into_ims
= 1;
2402 refresh_nocache_hack
= 1;
2403 /* tell client_side.c that this is used */
2404 } else if (!strcmp(token
, "ignore-reload")) {
2406 refresh_nocache_hack
= 1;
2407 /* tell client_side.c that this is used */
2411 debugs(22, 0, "redreshAddToList: Unknown option '" << pattern
<< "': " << token
);
2414 if ((errcode
= regcomp(&comp
, pattern
, flags
)) != 0) {
2416 regerror(errcode
, &comp
, errbuf
, sizeof errbuf
);
2417 debugs(22, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
2418 debugs(22, 0, "refreshAddToList: Invalid regular expression '" << pattern
<< "': " << errbuf
);
2422 pct
= pct
< 0.0 ? 0.0 : pct
;
2423 max
= max
< 0 ? 0 : max
;
2424 t
= static_cast<refresh_t
*>(xcalloc(1, sizeof(refresh_t
)));
2425 t
->pattern
= (char *) xstrdup(pattern
);
2426 t
->compiled_pattern
= comp
;
2431 if (flags
& REG_ICASE
)
2435 t
->flags
.refresh_ims
= 1;
2439 if (override_expire
)
2440 t
->flags
.override_expire
= 1;
2442 if (override_lastmod
)
2443 t
->flags
.override_lastmod
= 1;
2445 if (reload_into_ims
)
2446 t
->flags
.reload_into_ims
= 1;
2449 t
->flags
.ignore_reload
= 1;
2451 if (ignore_no_cache
)
2452 t
->flags
.ignore_no_cache
= 1;
2454 if (ignore_no_store
)
2455 t
->flags
.ignore_no_store
= 1;
2457 if (ignore_must_revalidate
)
2458 t
->flags
.ignore_must_revalidate
= 1;
2461 t
->flags
.ignore_private
= 1;
2464 t
->flags
.ignore_auth
= 1;
2471 head
= &(*head
)->next
;
2479 free_refreshpattern(refresh_t
** head
)
2483 while ((t
= *head
) != NULL
) {
2485 safe_free(t
->pattern
);
2486 regfree(&t
->compiled_pattern
);
2491 refresh_nocache_hack
= 0;
2497 dump_string(StoreEntry
* entry
, const char *name
, char *var
)
2500 storeAppendPrintf(entry
, "%s %s\n", name
, var
);
2504 parse_string(char **var
)
2506 char *token
= strtok(NULL
, w_space
);
2512 *var
= xstrdup(token
);
2516 ConfigParser::ParseString(char **var
)
2522 ConfigParser::ParseString(String
*var
)
2524 char *token
= strtok(NULL
, w_space
);
2533 free_string(char **var
)
2539 parse_eol(char *volatile *var
)
2541 unsigned char *token
= (unsigned char *) strtok(NULL
, null_string
);
2549 while (*token
&& xisspace(*token
))
2557 *var
= xstrdup((char *) token
);
2560 #define dump_eol dump_string
2561 #define free_eol free_string
2564 dump_time_t(StoreEntry
* entry
, const char *name
, time_t var
)
2566 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int) var
);
2570 parse_time_t(time_t * var
)
2572 parseTimeLine(var
, T_SECOND_STR
);
2576 free_time_t(time_t * var
)
2583 dump_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
2585 storeAppendPrintf(entry
, "%s %d\n", name
, (int) var
);
2590 dump_b_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
2592 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
2597 dump_kb_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
2599 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_KBYTES_STR
);
2604 dump_b_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
2606 storeAppendPrintf(entry
, "%s %"PRId64
" %s\n", name
, var
, B_BYTES_STR
);
2610 dump_kb_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
2612 storeAppendPrintf(entry
, "%s %"PRId64
" %s\n", name
, var
, B_KBYTES_STR
);
2617 parse_size_t(size_t * var
)
2626 parse_b_size_t(size_t * var
)
2628 parseBytesLine(var
, B_BYTES_STR
);
2633 parse_kb_size_t(size_t * var
)
2635 parseBytesLine(var
, B_KBYTES_STR
);
2640 parse_b_int64_t(int64_t * var
)
2642 parseBytesLine64(var
, B_BYTES_STR
);
2646 parse_kb_int64_t(int64_t * var
)
2648 parseBytesLine64(var
, B_KBYTES_STR
);
2652 free_size_t(size_t * var
)
2658 free_b_int64_t(int64_t * var
)
2663 #define free_b_size_t free_size_t
2664 #define free_kb_size_t free_size_t
2665 #define free_mb_size_t free_size_t
2666 #define free_gb_size_t free_size_t
2667 #define free_kb_int64_t free_b_int64_t
2670 dump_ushort(StoreEntry
* entry
, const char *name
, u_short var
)
2672 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2676 free_ushort(u_short
* u
)
2682 parse_ushort(u_short
* var
)
2684 ConfigParser::ParseUShort(var
);
2688 ConfigParser::ParseUShort(u_short
*var
)
2694 ConfigParser::ParseBool(bool *var
)
2696 int i
= GetInteger();
2707 dump_wordlist(StoreEntry
* entry
, const char *name
, wordlist
* list
)
2709 while (list
!= NULL
) {
2710 storeAppendPrintf(entry
, "%s %s\n", name
, list
->key
);
2716 ConfigParser::ParseWordList(wordlist
** list
)
2718 parse_wordlist(list
);
2722 parse_wordlist(wordlist
** list
)
2725 char *t
= strtok(NULL
, "");
2727 while ((token
= strwordtok(NULL
, &t
)))
2728 wordlistAdd(list
, token
);
2731 #if 0 /* now unused */
2733 check_null_wordlist(wordlist
* w
)
2740 check_null_acl_access(acl_access
* a
)
2745 #define free_wordlist wordlistDestroy
2747 #define free_uri_whitespace free_int
2750 parse_uri_whitespace(int *var
)
2752 char *token
= strtok(NULL
, w_space
);
2757 if (!strcasecmp(token
, "strip"))
2758 *var
= URI_WHITESPACE_STRIP
;
2759 else if (!strcasecmp(token
, "deny"))
2760 *var
= URI_WHITESPACE_DENY
;
2761 else if (!strcasecmp(token
, "allow"))
2762 *var
= URI_WHITESPACE_ALLOW
;
2763 else if (!strcasecmp(token
, "encode"))
2764 *var
= URI_WHITESPACE_ENCODE
;
2765 else if (!strcasecmp(token
, "chop"))
2766 *var
= URI_WHITESPACE_CHOP
;
2772 dump_uri_whitespace(StoreEntry
* entry
, const char *name
, int var
)
2776 if (var
== URI_WHITESPACE_ALLOW
)
2778 else if (var
== URI_WHITESPACE_ENCODE
)
2780 else if (var
== URI_WHITESPACE_CHOP
)
2782 else if (var
== URI_WHITESPACE_DENY
)
2787 storeAppendPrintf(entry
, "%s %s\n", name
, s
);
2791 free_removalpolicy(RemovalPolicySettings
** settings
)
2796 free_string(&(*settings
)->type
);
2798 free_wordlist(&(*settings
)->args
);
2806 parse_removalpolicy(RemovalPolicySettings
** settings
)
2809 free_removalpolicy(settings
);
2811 *settings
= new RemovalPolicySettings
;
2813 parse_string(&(*settings
)->type
);
2815 parse_wordlist(&(*settings
)->args
);
2819 dump_removalpolicy(StoreEntry
* entry
, const char *name
, RemovalPolicySettings
* settings
)
2822 storeAppendPrintf(entry
, "%s %s", name
, settings
->type
);
2823 args
= settings
->args
;
2826 storeAppendPrintf(entry
, " %s", args
->key
);
2830 storeAppendPrintf(entry
, "\n");
2834 free_memcachemode(SquidConfig
* config
)
2840 parse_memcachemode(SquidConfig
* config
)
2842 char *token
= strtok(NULL
, w_space
);
2846 if (strcmp(token
, "always") == 0) {
2847 Config
.onoff
.memory_cache_first
= 1;
2848 Config
.onoff
.memory_cache_disk
= 1;
2849 } else if (strcmp(token
, "disk") == 0) {
2850 Config
.onoff
.memory_cache_first
= 0;
2851 Config
.onoff
.memory_cache_disk
= 1;
2852 } else if (strncmp(token
, "net", 3) == 0) {
2853 Config
.onoff
.memory_cache_first
= 1;
2854 Config
.onoff
.memory_cache_disk
= 0;
2855 } else if (strcmp(token
, "never") == 0) {
2856 Config
.onoff
.memory_cache_first
= 0;
2857 Config
.onoff
.memory_cache_disk
= 0;
2863 dump_memcachemode(StoreEntry
* entry
, const char *name
, SquidConfig
&config
)
2865 storeAppendPrintf(entry
, "%s ", name
);
2866 if (Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
2867 storeAppendPrintf(entry
, "always");
2868 else if (!Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
2869 storeAppendPrintf(entry
, "disk");
2870 else if (Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
2871 storeAppendPrintf(entry
, "network");
2872 else if (!Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
2873 storeAppendPrintf(entry
, "none");
2874 storeAppendPrintf(entry
, "\n");
2877 #include "cf_parser.h"
2880 parseNeighborType(const char *s
)
2882 if (!strcasecmp(s
, "parent"))
2885 if (!strcasecmp(s
, "neighbor"))
2886 return PEER_SIBLING
;
2888 if (!strcasecmp(s
, "neighbour"))
2889 return PEER_SIBLING
;
2891 if (!strcasecmp(s
, "sibling"))
2892 return PEER_SIBLING
;
2894 if (!strcasecmp(s
, "multicast"))
2895 return PEER_MULTICAST
;
2897 debugs(15, 0, "WARNING: Unknown neighbor type: " << s
);
2899 return PEER_SIBLING
;
2904 parse_IpAddress_list(IpAddress_list
** head
)
2910 while ((token
= strtok(NULL
, w_space
))) {
2911 if (GetHostWithPort(token
, &ipa
)) {
2914 head
= &(*head
)->next
;
2916 s
= static_cast<IpAddress_list
*>(xcalloc(1, sizeof(*s
)));
2926 dump_IpAddress_list(StoreEntry
* e
, const char *n
, const IpAddress_list
* s
)
2928 char ntoabuf
[MAX_IPSTRLEN
];
2931 storeAppendPrintf(e
, "%s %s\n",
2933 s
->s
.NtoA(ntoabuf
,MAX_IPSTRLEN
));
2939 free_IpAddress_list(IpAddress_list
** head
)
2941 if (*head
) delete *head
;
2945 #if CURRENTLY_UNUSED
2946 /* This code was previously used by http_port. Left as it really should
2947 * be used by icp_port and htcp_port
2950 check_null_IpAddress_list(const IpAddress_list
* s
)
2955 #endif /* CURRENTLY_UNUSED */
2956 #endif /* USE_WCCPv2 */
2958 CBDATA_CLASS_INIT(http_port_list
);
2961 parse_http_port_specification(http_port_list
* s
, char *token
)
2964 unsigned short port
= 0;
2968 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
2969 s
->name
= xstrdup(token
);
2970 s
->connection_auth_disabled
= false;
2973 if (*token
== '[') {
2976 t
= strchr(host
, ']');
2978 debugs(3, 0, "http(s)_port: missing ']' on IPv6 address: " << token
);
2983 debugs(3, 0, "http(s)_port: missing Port in: " << token
);
2986 port
= xatos(t
+ 1);
2989 if ((t
= strchr(token
, ':'))) {
2994 port
= xatos(t
+ 1);
2996 } else if ((port
= strtol(token
, &junk
, 10)), !*junk
) {
2998 debugs(3, 3, "http(s)_port: found Listen on Port: " << port
);
3000 debugs(3, 0, "http(s)_port: missing Port: " << token
);
3005 debugs(3, 0, "http(s)_port: Port cannot be 0: " << token
);
3009 extern void update_port(unsigned short* port
);
3015 debugs(3, 3, "http(s)_port: found Listen on wildcard address: *:" << s
->s
.GetPort() );
3016 } else if ( s
->s
= host
) { /* check/parse numeric IPA */
3018 debugs(3, 3, "http(s)_port: Listen on Host/IP: " << host
<< " --> " << s
->s
);
3019 } else if ( s
->s
.GetHostByName(host
) ) { /* check/parse for FQDN */
3020 /* dont use ipcache */
3021 s
->defaultsite
= xstrdup(host
);
3023 debugs(3, 3, "http(s)_port: found Listen as Host " << s
->defaultsite
<< " on IP: " << s
->s
);
3025 debugs(3, 0, "http(s)_port: failed to resolve Host/IP: " << host
);
3031 parse_http_port_option(http_port_list
* s
, char *token
)
3033 if (strncmp(token
, "defaultsite=", 12) == 0) {
3034 safe_free(s
->defaultsite
);
3035 s
->defaultsite
= xstrdup(token
+ 12);
3037 } else if (strncmp(token
, "name=", 5) == 0) {
3039 s
->name
= xstrdup(token
+ 5);
3040 } else if (strcmp(token
, "vhost") == 0) {
3043 } else if (strcmp(token
, "vport") == 0) {
3046 } else if (strncmp(token
, "vport=", 6) == 0) {
3047 s
->vport
= xatos(token
+ 6);
3049 } else if (strncmp(token
, "protocol=", 9) == 0) {
3050 s
->protocol
= xstrdup(token
+ 9);
3052 } else if (strcmp(token
, "accel") == 0) {
3054 } else if (strcmp(token
, "allow-direct") == 0) {
3055 s
->allow_direct
= 1;
3056 } else if (strcmp(token
, "ignore-cc") == 0) {
3058 #if !HTTP_VIOLATIONS
3060 debugs(3, DBG_CRITICAL
, "FATAL: ignore-cc is only valid in accelerator mode");
3064 } else if (strcmp(token
, "no-connection-auth") == 0) {
3065 s
->connection_auth_disabled
= true;
3066 } else if (strcmp(token
, "connection-auth=off") == 0) {
3067 s
->connection_auth_disabled
= true;
3068 } else if (strcmp(token
, "connection-auth") == 0) {
3069 s
->connection_auth_disabled
= false;
3070 } else if (strcmp(token
, "connection-auth=on") == 0) {
3071 s
->connection_auth_disabled
= false;
3072 } else if (strncmp(token
, "disable-pmtu-discovery=", 23) == 0) {
3073 if (!strcasecmp(token
+ 23, "off"))
3074 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3075 else if (!strcasecmp(token
+ 23, "transparent"))
3076 s
->disable_pmtu_discovery
= DISABLE_PMTU_TRANSPARENT
;
3077 else if (!strcasecmp(token
+ 23, "always"))
3078 s
->disable_pmtu_discovery
= DISABLE_PMTU_ALWAYS
;
3082 } else if (strcmp(token
, "transparent") == 0 || strcmp(token
, "intercept") == 0) {
3084 IpInterceptor
.StartInterception();
3085 /* Log information regarding the port modes under interception. */
3086 debugs(3, DBG_IMPORTANT
, "Starting Authentication on port " << s
->s
);
3087 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (interception enabled)");
3090 /* INET6: until transparent REDIRECT works on IPv6 SOCKET, force wildcard to IPv4 */
3091 debugs(3, DBG_IMPORTANT
, "Disabling IPv6 on port " << s
->s
<< " (interception enabled)");
3092 if ( !s
->s
.SetIPv4() ) {
3093 debugs(3, DBG_CRITICAL
, "http(s)_port: IPv6 addresses cannot be transparent (protocol does not provide NAT)" << s
->s
);
3097 } else if (strcmp(token
, "tproxy") == 0) {
3098 if (s
->intercepted
|| s
->accel
) {
3099 debugs(3,DBG_CRITICAL
, "http(s)_port: TPROXY option requires its own interception port. It cannot be shared.");
3102 s
->spoof_client_ip
= 1;
3103 IpInterceptor
.StartTransparency();
3104 /* Log information regarding the port modes under transparency. */
3105 debugs(3, DBG_IMPORTANT
, "Starting IP Spoofing on port " << s
->s
);
3106 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (IP spoofing enabled)");
3108 if (!IpInterceptor
.ProbeForTproxy(s
->s
)) {
3109 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: TPROXY support in the system does not work.");
3113 } else if (strcmp(token
, "ipv4") == 0) {
3115 if ( !s
->s
.SetIPv4() ) {
3116 debugs(3, 0, "http(s)_port: IPv6 addresses cannot be used a IPv4-Only." << s
->s
);
3120 } else if (strcmp(token
, "tcpkeepalive") == 0) {
3121 s
->tcp_keepalive
.enabled
= 1;
3122 } else if (strncmp(token
, "tcpkeepalive=", 13) == 0) {
3123 char *t
= token
+ 13;
3124 s
->tcp_keepalive
.enabled
= 1;
3125 s
->tcp_keepalive
.idle
= atoi(t
);
3129 s
->tcp_keepalive
.interval
= atoi(t
);
3134 s
->tcp_keepalive
.timeout
= atoi(t
);
3138 } else if (strncmp(token
, "cert=", 5) == 0) {
3140 s
->cert
= xstrdup(token
+ 5);
3141 } else if (strncmp(token
, "key=", 4) == 0) {
3143 s
->key
= xstrdup(token
+ 4);
3144 } else if (strncmp(token
, "version=", 8) == 0) {
3145 s
->version
= xatoi(token
+ 8);
3147 if (s
->version
< 1 || s
->version
> 4)
3149 } else if (strncmp(token
, "options=", 8) == 0) {
3150 safe_free(s
->options
);
3151 s
->options
= xstrdup(token
+ 8);
3152 } else if (strncmp(token
, "cipher=", 7) == 0) {
3153 safe_free(s
->cipher
);
3154 s
->cipher
= xstrdup(token
+ 7);
3155 } else if (strncmp(token
, "clientca=", 9) == 0) {
3156 safe_free(s
->clientca
);
3157 s
->clientca
= xstrdup(token
+ 9);
3158 } else if (strncmp(token
, "cafile=", 7) == 0) {
3159 safe_free(s
->cafile
);
3160 s
->cafile
= xstrdup(token
+ 7);
3161 } else if (strncmp(token
, "capath=", 7) == 0) {
3162 safe_free(s
->capath
);
3163 s
->capath
= xstrdup(token
+ 7);
3164 } else if (strncmp(token
, "crlfile=", 8) == 0) {
3165 safe_free(s
->crlfile
);
3166 s
->crlfile
= xstrdup(token
+ 8);
3167 } else if (strncmp(token
, "dhparams=", 9) == 0) {
3168 safe_free(s
->dhfile
);
3169 s
->dhfile
= xstrdup(token
+ 9);
3170 } else if (strncmp(token
, "sslflags=", 9) == 0) {
3171 safe_free(s
->sslflags
);
3172 s
->sslflags
= xstrdup(token
+ 9);
3173 } else if (strncmp(token
, "sslcontext=", 11) == 0) {
3174 safe_free(s
->sslcontext
);
3175 s
->sslcontext
= xstrdup(token
+ 11);
3176 } else if (strcmp(token
, "sslBump") == 0) {
3177 s
->sslBump
= 1; // accelerated when bumped, otherwise not
3183 if ( s
->spoof_client_ip
&& (s
->intercepted
|| s
->accel
) ) {
3184 debugs(3,DBG_CRITICAL
, "http(s)_port: TPROXY option requires its own interception port. It cannot be shared.");
3189 static http_port_list
*
3190 create_http_port(char *portspec
)
3192 http_port_list
*s
= new http_port_list("http");
3193 parse_http_port_specification(s
, portspec
);
3198 add_http_port(char *portspec
)
3200 http_port_list
*s
= create_http_port(portspec
);
3201 // we may need to merge better of the above returns a list with clones
3202 assert(s
->next
== NULL
);
3203 s
->next
= Config
.Sockaddr
.http
;
3204 Config
.Sockaddr
.http
= s
;
3207 #if IPV6_SPECIAL_SPLITSTACK
3209 clone_http_port_list(http_port_list
*a
)
3211 http_port_list
*b
= new http_port_list(a
->protocol
);
3215 b
->name
= xstrdup(a
->name
);
3217 b
->defaultsite
= xstrdup(a
->defaultsite
);
3219 b
->intercepted
= a
->intercepted
;
3220 b
->spoof_client_ip
= a
->spoof_client_ip
;
3221 b
->accel
= a
->accel
;
3222 b
->allow_direct
= a
->allow_direct
;
3223 b
->vhost
= a
->vhost
;
3224 b
->sslBump
= a
->sslBump
;
3225 b
->vport
= a
->vport
;
3226 b
->connection_auth_disabled
= a
->connection_auth_disabled
;
3227 b
->disable_pmtu_discovery
= a
->disable_pmtu_discovery
;
3229 memcpy( &(b
->tcp_keepalive
), &(a
->tcp_keepalive
), sizeof(a
->tcp_keepalive
));
3232 // AYJ: 2009-07-18: for now SSL does not clone. Configure separate ports with IPs and SSL settings
3235 // XXX: temporary hack to ease move of SSL options to http_port
3236 http_port_list
&http
;
3250 SSL_CTX
*sslContext
;
3260 parse_http_port_list(http_port_list
** head
)
3262 char *token
= strtok(NULL
, w_space
);
3269 http_port_list
*s
= create_http_port(token
);
3271 /* parse options ... */
3272 while ((token
= strtok(NULL
, w_space
))) {
3273 parse_http_port_option(s
, token
);
3276 #if IPV6_SPECIAL_SPLITSTACK
3277 if (s
->s
.IsAnyAddr()) {
3278 // clone the port options from *s to *(s->next)
3279 s
->next
= clone_http_port_list(s
);
3280 s
->next
->s
.SetIPv4();
3281 debugs(3, 3, "http(s)_port: clone wildcard address for split-stack: " << s
->s
<< " and " << s
->next
->s
);
3286 head
= &(*head
)->next
;
3292 dump_generic_http_port(StoreEntry
* e
, const char *n
, const http_port_list
* s
)
3294 char buf
[MAX_IPSTRLEN
];
3296 storeAppendPrintf(e
, "%s %s",
3298 s
->s
.ToURL(buf
,MAX_IPSTRLEN
));
3301 storeAppendPrintf(e
, " defaultsite=%s", s
->defaultsite
);
3304 storeAppendPrintf(e
, " intercept");
3307 storeAppendPrintf(e
, " vhost");
3310 storeAppendPrintf(e
, " vport");
3312 if (s
->connection_auth_disabled
)
3313 storeAppendPrintf(e
, " connection-auth=off");
3315 storeAppendPrintf(e
, " connection-auth=on");
3317 if (s
->disable_pmtu_discovery
!= DISABLE_PMTU_OFF
) {
3320 if (s
->disable_pmtu_discovery
== DISABLE_PMTU_ALWAYS
)
3323 pmtu
= "transparent";
3325 storeAppendPrintf(e
, " disable-pmtu-discovery=%s", pmtu
);
3328 if (s
->tcp_keepalive
.enabled
) {
3329 if (s
->tcp_keepalive
.idle
|| s
->tcp_keepalive
.interval
|| s
->tcp_keepalive
.timeout
) {
3330 storeAppendPrintf(e
, " tcpkeepalive=%d,%d,%d", s
->tcp_keepalive
.idle
, s
->tcp_keepalive
.interval
, s
->tcp_keepalive
.timeout
);
3332 storeAppendPrintf(e
, " tcpkeepalive");
3338 storeAppendPrintf(e
, " cert=%s", s
->cert
);
3341 storeAppendPrintf(e
, " key=%s", s
->key
);
3344 storeAppendPrintf(e
, " version=%d", s
->version
);
3347 storeAppendPrintf(e
, " options=%s", s
->options
);
3350 storeAppendPrintf(e
, " cipher=%s", s
->cipher
);
3353 storeAppendPrintf(e
, " cafile=%s", s
->cafile
);
3356 storeAppendPrintf(e
, " capath=%s", s
->capath
);
3359 storeAppendPrintf(e
, " crlfile=%s", s
->crlfile
);
3362 storeAppendPrintf(e
, " dhparams=%s", s
->dhfile
);
3365 storeAppendPrintf(e
, " sslflags=%s", s
->sslflags
);
3368 storeAppendPrintf(e
, " sslcontext=%s", s
->sslcontext
);
3371 storeAppendPrintf(e
, " sslBump");
3376 dump_http_port_list(StoreEntry
* e
, const char *n
, const http_port_list
* s
)
3379 dump_generic_http_port(e
, n
, s
);
3380 storeAppendPrintf(e
, "\n");
3386 free_http_port_list(http_port_list
** head
)
3390 while ((s
= *head
) != NULL
) {
3398 // TODO: merge better with parse_http_port_list
3400 parse_https_port_list(https_port_list
** head
)
3405 token
= strtok(NULL
, w_space
);
3410 s
= new https_port_list
;
3411 parse_http_port_specification(&s
->http
, token
);
3413 /* parse options ... */
3414 while ((token
= strtok(NULL
, w_space
))) {
3415 parse_http_port_option(s
, token
);
3419 http_port_list
** headTmp
= &(*head
)->http
.next
;
3420 head
= (https_port_list
**)headTmp
;
3427 dump_https_port_list(StoreEntry
* e
, const char *n
, const https_port_list
* s
)
3429 dump_http_port_list(e
, n
, s
);
3433 free_https_port_list(https_port_list
** head
)
3435 free_http_port_list((http_port_list
**)head
);
3440 check_null_https_port_list(const https_port_list
* s
)
3447 #endif /* USE_SSL */
3450 configFreeMemory(void)
3456 requirePathnameExists(const char *name
, const char *path
)
3460 char pathbuf
[BUFSIZ
];
3461 assert(path
!= NULL
);
3463 if (Config
.chroot_dir
&& (geteuid() == 0)) {
3464 snprintf(pathbuf
, BUFSIZ
, "%s/%s", Config
.chroot_dir
, path
);
3468 if (stat(path
, &sb
) < 0) {
3469 if (opt_send_signal
== -1 || opt_send_signal
== SIGHUP
)
3470 fatalf("%s %s: %s", name
, path
, xstrerror());
3472 fprintf(stderr
, "WARNING: %s %s: %s\n", name
, path
, xstrerror());
3479 return ConfigParser::strtokFile();
3482 #include "AccessLogEntry.h"
3483 /* TODO: split out parsing somehow ...*/
3485 parse_logformat(logformat
** logformat_definitions
)
3490 if ((name
= strtok(NULL
, w_space
)) == NULL
)
3493 if ((def
= strtok(NULL
, "\r\n")) == NULL
) {
3498 debugs(3, 2, "Logformat for '" << name
<< "' is '" << def
<< "'");
3500 nlf
= (logformat
*)xcalloc(1, sizeof(logformat
));
3502 nlf
->name
= xstrdup(name
);
3504 if (!accessLogParseLogFormat(&nlf
->format
, def
)) {
3509 nlf
->next
= *logformat_definitions
;
3511 *logformat_definitions
= nlf
;
3515 parse_access_log(customlog
** logs
)
3517 const char *filename
, *logdef_name
;
3521 cl
= (customlog
*)xcalloc(1, sizeof(*cl
));
3523 if ((filename
= strtok(NULL
, w_space
)) == NULL
) {
3528 if (strcmp(filename
, "none") == 0) {
3529 cl
->type
= CLF_NONE
;
3533 if ((logdef_name
= strtok(NULL
, w_space
)) == NULL
)
3534 logdef_name
= "auto";
3536 debugs(3, 9, "Log definition name '" << logdef_name
<< "' file '" << filename
<< "'");
3538 cl
->filename
= xstrdup(filename
);
3540 /* look for the definition pointer corresponding to this name */
3541 lf
= Config
.Log
.logformats
;
3543 while (lf
!= NULL
) {
3544 debugs(3, 9, "Comparing against '" << lf
->name
<< "'");
3546 if (strcmp(lf
->name
, logdef_name
) == 0)
3553 cl
->type
= CLF_CUSTOM
;
3555 } else if (strcmp(logdef_name
, "auto") == 0) {
3556 cl
->type
= CLF_AUTO
;
3557 } else if (strcmp(logdef_name
, "squid") == 0) {
3558 cl
->type
= CLF_SQUID
;
3559 } else if (strcmp(logdef_name
, "common") == 0) {
3560 cl
->type
= CLF_COMMON
;
3562 } else if (strcmp(logdef_name
, "icap_squid") == 0) {
3563 cl
->type
= CLF_ICAP_SQUID
;
3566 debugs(3, 0, "Log format '" << logdef_name
<< "' is not defined");
3572 aclParseAclList(LegacyParser
, &cl
->aclList
);
3575 logs
= &(*logs
)->next
;
3581 check_null_access_log(customlog
*customlog_definitions
)
3583 return customlog_definitions
== NULL
;
3587 dump_logformat(StoreEntry
* entry
, const char *name
, logformat
* definitions
)
3589 accessLogDumpLogFormat(entry
, name
, definitions
);
3593 dump_access_log(StoreEntry
* entry
, const char *name
, customlog
* logs
)
3597 for (log
= logs
; log
; log
= log
->next
) {
3598 storeAppendPrintf(entry
, "%s ", name
);
3600 switch (log
->type
) {
3603 storeAppendPrintf(entry
, "%s %s", log
->filename
, log
->logFormat
->name
);
3607 storeAppendPrintf(entry
, "none");
3611 storeAppendPrintf(entry
, "%s squid", log
->filename
);
3615 storeAppendPrintf(entry
, "%s squid", log
->filename
);
3618 case CLF_ICAP_SQUID
:
3619 storeAppendPrintf(entry
, "%s icap_squid", log
->filename
);
3625 storeAppendPrintf(entry
, "%s auto", log
->filename
);
3627 storeAppendPrintf(entry
, "%s", log
->filename
);
3636 dump_acl_list(entry
, log
->aclList
);
3638 storeAppendPrintf(entry
, "\n");
3643 free_logformat(logformat
** definitions
)
3645 while (*definitions
) {
3646 logformat
*format
= *definitions
;
3647 *definitions
= format
->next
;
3648 safe_free(format
->name
);
3649 accessLogFreeLogFormat(&format
->format
);
3655 free_access_log(customlog
** definitions
)
3657 while (*definitions
) {
3658 customlog
*log
= *definitions
;
3659 *definitions
= log
->next
;
3661 log
->logFormat
= NULL
;
3662 log
->type
= CLF_UNKNOWN
;
3665 aclDestroyAclList(&log
->aclList
);
3667 safe_free(log
->filename
);
3676 parse_adaptation_service_set_type()
3678 Adaptation::Config::ParseServiceSet();
3682 parse_adaptation_service_chain_type()
3684 Adaptation::Config::ParseServiceChain();
3688 parse_adaptation_access_type()
3690 Adaptation::Config::ParseAccess(LegacyParser
);
3693 #endif /* USE_ADAPTATION */
3699 parse_icap_service_type(Adaptation::Icap::Config
* cfg
)
3701 cfg
->parseService();
3705 free_icap_service_type(Adaptation::Icap::Config
* cfg
)
3711 dump_icap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
3713 cfg
.dumpService(entry
, name
);
3717 parse_icap_class_type()
3719 debugs(93, 0, "WARNING: 'icap_class' is depricated. " <<
3720 "Use 'adaptation_service_set' instead");
3721 Adaptation::Config::ParseServiceSet();
3725 parse_icap_access_type()
3727 debugs(93, 0, "WARNING: 'icap_access' is depricated. " <<
3728 "Use 'adaptation_access' instead");
3729 Adaptation::Config::ParseAccess(LegacyParser
);
3738 parse_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
3740 cfg
->parseService();
3744 free_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
3750 dump_ecap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Ecap::Config
&cfg
)
3752 cfg
.dumpService(entry
, name
);
3755 #endif /* USE_ECAP */