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.
36 #include "ProtoPort.h"
37 #include "HttpRequestMethod.h"
38 #include "auth/Config.h"
39 #include "auth/Scheme.h"
40 #include "CacheManager.h"
43 #include "ConfigParser.h"
45 #include "acl/Gadgets.h"
46 #include "StoreFileSystem.h"
50 #include "ip/IpIntercept.h"
60 #include "esi/Parser.h"
64 #include "adaptation/Config.h"
66 static void parse_adaptation_service_set_type();
67 static void parse_adaptation_access_type();
72 #include "adaptation/icap/Config.h"
74 static void parse_icap_service_type(Adaptation::Icap::Config
*);
75 static void dump_icap_service_type(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
76 static void free_icap_service_type(Adaptation::Icap::Config
*);
77 static void parse_icap_class_type();
78 static void parse_icap_access_type();
83 #include "adaptation/ecap/Config.h"
84 static void parse_ecap_service_type(Adaptation::Ecap::Config
*);
85 static void dump_ecap_service_type(StoreEntry
*, const char *, const Adaptation::Ecap::Config
&);
86 static void free_ecap_service_type(Adaptation::Ecap::Config
*);
91 static const char *const T_SECOND_STR
= "second";
92 static const char *const T_MINUTE_STR
= "minute";
93 static const char *const T_HOUR_STR
= "hour";
94 static const char *const T_DAY_STR
= "day";
95 static const char *const T_WEEK_STR
= "week";
96 static const char *const T_FORTNIGHT_STR
= "fortnight";
97 static const char *const T_MONTH_STR
= "month";
98 static const char *const T_YEAR_STR
= "year";
99 static const char *const T_DECADE_STR
= "decade";
101 static const char *const B_BYTES_STR
= "bytes";
102 static const char *const B_KBYTES_STR
= "KB";
103 static const char *const B_MBYTES_STR
= "MB";
104 static const char *const B_GBYTES_STR
= "GB";
106 static const char *const list_sep
= ", \t\n\r";
108 static void parse_logformat(logformat
** logformat_definitions
);
109 static void parse_access_log(customlog
** customlog_definitions
);
110 static int check_null_access_log(customlog
*customlog_definitions
);
112 static void dump_logformat(StoreEntry
* entry
, const char *name
, logformat
* definitions
);
113 static void dump_access_log(StoreEntry
* entry
, const char *name
, customlog
* definitions
);
114 static void free_logformat(logformat
** definitions
);
115 static void free_access_log(customlog
** definitions
);
117 static void update_maxobjsize(void);
118 static void configDoConfigure(void);
119 static void parse_refreshpattern(refresh_t
**);
120 static int parseTimeUnits(const char *unit
);
121 static void parseTimeLine(time_t * tptr
, const char *units
);
122 static void parse_ushort(u_short
* var
);
123 static void parse_string(char **);
124 static void default_all(void);
125 static void defaults_if_none(void);
126 static int parse_line(char *);
127 static void parseBytesLine(size_t * bptr
, const char *units
);
128 static size_t parseBytesUnits(const char *unit
);
129 static void free_all(void);
130 void requirePathnameExists(const char *name
, const char *path
);
131 static OBJH dump_config
;
133 static void dump_http_header_access(StoreEntry
* entry
, const char *name
, header_mangler header
[]);
134 static void parse_http_header_access(header_mangler header
[]);
135 static void free_http_header_access(header_mangler header
[]);
136 static void dump_http_header_replace(StoreEntry
* entry
, const char *name
, header_mangler header
[]);
137 static void parse_http_header_replace(header_mangler
* header
);
138 static void free_http_header_replace(header_mangler
* header
);
140 static void parse_denyinfo(acl_deny_info_list
** var
);
141 static void dump_denyinfo(StoreEntry
* entry
, const char *name
, acl_deny_info_list
* var
);
142 static void free_denyinfo(acl_deny_info_list
** var
);
145 static void parse_IpAddress_list(IpAddress_list
**);
146 static void dump_IpAddress_list(StoreEntry
*, const char *, const IpAddress_list
*);
147 static void free_IpAddress_list(IpAddress_list
**);
149 static int check_null_IpAddress_list(const IpAddress_list
*);
150 #endif /* CURRENTLY_UNUSED */
151 #endif /* USE_WCCPv2 */
153 static void parse_http_port_list(http_port_list
**);
154 static void dump_http_port_list(StoreEntry
*, const char *, const http_port_list
*);
155 static void free_http_port_list(http_port_list
**);
158 static void parse_https_port_list(https_port_list
**);
159 static void dump_https_port_list(StoreEntry
*, const char *, const https_port_list
*);
160 static void free_https_port_list(https_port_list
**);
162 static int check_null_https_port_list(const https_port_list
*);
166 static void parse_b_size_t(size_t * var
);
167 static void parse_b_int64_t(int64_t * var
);
169 static int parseOneConfigFile(const char *file_name
, unsigned int depth
);
172 * LegacyParser is a parser for legacy code that uses the global
173 * approach. This is static so that it is only exposed to cache_cf.
174 * Other modules needing access to a ConfigParser should have it
175 * provided to them in their parserFOO methods.
177 static ConfigParser LegacyParser
= ConfigParser();
182 LegacyParser
.destruct();
186 update_maxobjsize(void)
191 for (i
= 0; i
< Config
.cacheSwap
.n_configured
; i
++) {
192 assert (Config
.cacheSwap
.swapDirs
[i
].getRaw());
194 if (dynamic_cast<SwapDir
*>(Config
.cacheSwap
.swapDirs
[i
].getRaw())->
196 ms
= dynamic_cast<SwapDir
*>(Config
.cacheSwap
.swapDirs
[i
].getRaw())->max_objsize
;
198 store_maxobjsize
= ms
;
202 SetConfigFilename(char const *file_name
, bool is_pipe
)
204 cfg_filename
= file_name
;
209 cfg_filename
= file_name
+ 1;
210 else if ((token
= strrchr(cfg_filename
, '/')))
211 cfg_filename
= token
+ 1;
215 skip_ws(const char* s
)
224 parseManyConfigFiles(char* files
, int depth
)
227 char* saveptr
= NULL
;
232 memset(&globbuf
, 0, sizeof(globbuf
));
233 for (path
= strwordtok(files
, &saveptr
); path
; path
= strwordtok(NULL
, &saveptr
)) {
234 if (glob(path
, globbuf
.gl_pathc
? GLOB_APPEND
: 0, NULL
, &globbuf
) != 0) {
235 fatalf("Unable to find configuration file: %s: %s",
239 for (i
= 0; i
< (int)globbuf
.gl_pathc
; i
++) {
240 error_count
+= parseOneConfigFile(globbuf
.gl_pathv
[i
], depth
);
244 char* file
= strwordtok(files
, &saveptr
);
245 while (file
!= NULL
) {
246 error_count
+= parseOneConfigFile(file
, depth
);
247 file
= strwordtok(NULL
, &saveptr
);
249 #endif /* HAVE_GLOB */
254 parseOneConfigFile(const char *file_name
, unsigned int depth
)
257 const char *orig_cfg_filename
= cfg_filename
;
258 const int orig_config_lineno
= config_lineno
;
260 char *tmp_line
= NULL
;
261 int tmp_line_len
= 0;
265 debugs(3, 1, "Processing Configuration File: " << file_name
<< " (depth " << depth
<< ")");
267 fatalf("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name
);
271 if (file_name
[0] == '!' || file_name
[0] == '|') {
272 fp
= popen(file_name
+ 1, "r");
275 fp
= fopen(file_name
, "r");
279 fatalf("Unable to open configuration file: %s: %s", file_name
, xstrerror());
283 setmode(fileno(fp
), O_TEXT
);
287 SetConfigFilename(file_name
, bool(is_pipe
));
289 memset(config_input_line
, '\0', BUFSIZ
);
293 while (fgets(config_input_line
, BUFSIZ
, fp
)) {
296 if ((token
= strchr(config_input_line
, '\n')))
299 if ((token
= strchr(config_input_line
, '\r')))
302 if (strncmp(config_input_line
, "#line ", 6) == 0) {
303 static char new_file_name
[1024];
305 static char new_lineno
;
306 token
= config_input_line
+ 6;
307 new_lineno
= strtol(token
, &file
, 0) - 1;
310 continue; /* Not a valid #line directive, may be a comment */
312 while (*file
&& xisspace((unsigned char) *file
))
317 continue; /* Not a valid #line directive, may be a comment */
319 xstrncpy(new_file_name
, file
+ 1, sizeof(new_file_name
));
321 if ((token
= strchr(new_file_name
, '"')))
324 cfg_filename
= new_file_name
;
327 config_lineno
= new_lineno
;
330 if (config_input_line
[0] == '#')
333 if (config_input_line
[0] == '\0')
336 const char* append
= tmp_line_len
? skip_ws(config_input_line
) : config_input_line
;
338 size_t append_len
= strlen(append
);
340 tmp_line
= (char*)xrealloc(tmp_line
, tmp_line_len
+ append_len
+ 1);
342 strcpy(tmp_line
+ tmp_line_len
, append
);
344 tmp_line_len
+= append_len
;
346 if (tmp_line
[tmp_line_len
-1] == '\\') {
347 debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line
<< "'");
348 tmp_line
[--tmp_line_len
] = '\0';
352 debugs(3, 5, "Processing: '" << tmp_line
<< "'");
354 /* Handle includes here */
355 if (tmp_line_len
>= 9 && strncmp(tmp_line
, "include", 7) == 0 && xisspace(tmp_line
[7])) {
356 err_count
+= parseManyConfigFiles(tmp_line
+ 8, depth
+ 1);
357 } else if (!parse_line(tmp_line
)) {
358 debugs(3, 0, HERE
<< cfg_filename
<< ":" << config_lineno
<< " unrecognized: '" << tmp_line
<< "'");
368 int ret
= pclose(fp
);
371 fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name
, ret
);
376 cfg_filename
= orig_cfg_filename
;
377 config_lineno
= orig_config_lineno
;
383 parseConfigFile(const char *file_name
)
386 CacheManager
*manager
=CacheManager::GetInstance();
392 err_count
= parseOneConfigFile(file_name
, 0);
397 * We must call configDoConfigure() before leave_suid() because
398 * configDoConfigure() is where we turn username strings into
403 if (!Config
.chroot_dir
) {
405 setUmask(Config
.umask
);
406 _db_init(Debug::cache_log
, Debug::debugOptions
);
410 if (opt_send_signal
== -1) {
411 manager
->registerAction("config",
412 "Current Squid Configuration",
422 configDoConfigure(void)
424 memset(&Config2
, '\0', sizeof(SquidConfig2
));
425 /* init memory as early as possible */
429 #if SIZEOF_OFF_T <= 4
430 if (Config
.Store
.maxObjectSize
> 0x7FFF0000) {
431 debugs(3, 0, "WARNING: This Squid binary can not handle files larger than 2GB. Limiting maximum_object_size to just below 2GB");
432 Config
.Store
.maxObjectSize
= 0x7FFF0000;
435 if (0 == Store::Root().maxSize())
436 /* people might want a zero-sized cache on purpose */
438 else if (Store::Root().maxSize() < (Config
.memMaxSize
>> 10))
439 /* This is bogus. folk with NULL caches will want this */
440 debugs(3, 0, "WARNING cache_mem is larger than total disk cache space!");
442 if (Config
.Announce
.period
> 0) {
443 Config
.onoff
.announce
= 1;
444 } else if (Config
.Announce
.period
< 1) {
445 Config
.Announce
.period
= 86400 * 365; /* one year */
446 Config
.onoff
.announce
= 0;
449 if (Config
.onoff
.httpd_suppress_version_string
)
450 visible_appname_string
= (char *)appname_string
;
452 visible_appname_string
= (char const *)APP_FULLNAME
;
456 if (Config
.dnsChildren
< 1)
457 fatal("No dnsservers allocated");
461 if (Config
.Program
.redirect
) {
462 if (Config
.redirectChildren
< 1) {
463 Config
.redirectChildren
= 0;
464 wordlistDestroy(&Config
.Program
.redirect
);
468 if (Config
.appendDomain
)
469 if (*Config
.appendDomain
!= '.')
470 fatal("append_domain must begin with a '.'");
472 if (Config
.errHtmlText
== NULL
)
473 Config
.errHtmlText
= xstrdup(null_string
);
477 snprintf(ThisCache
, sizeof(ThisCache
), "%s (%s)",
479 visible_appname_string
);
482 * the extra space is for loop detection in client_side.c -- we search
483 * for substrings in the Via header.
485 snprintf(ThisCache2
, sizeof(ThisCache
), " %s (%s)",
487 visible_appname_string
);
489 if (!Config
.udpMaxHitObjsz
|| Config
.udpMaxHitObjsz
> SQUID_UDP_SO_SNDBUF
)
490 Config
.udpMaxHitObjsz
= SQUID_UDP_SO_SNDBUF
;
492 if (Config
.appendDomain
)
493 Config
.appendDomainLen
= strlen(Config
.appendDomain
);
495 Config
.appendDomainLen
= 0;
497 if (Config
.retry
.maxtries
> 10)
498 fatal("maximum_single_addr_tries cannot be larger than 10");
500 if (Config
.retry
.maxtries
< 1) {
501 debugs(3, 0, "WARNING: resetting 'maximum_single_addr_tries to 1");
502 Config
.retry
.maxtries
= 1;
505 requirePathnameExists("MIME Config Table", Config
.mimeTablePathname
);
508 requirePathnameExists("cache_dns_program", Config
.Program
.dnsserver
);
512 requirePathnameExists("unlinkd_program", Config
.Program
.unlinkd
);
515 if (Config
.Program
.redirect
)
516 requirePathnameExists("redirect_program", Config
.Program
.redirect
->key
);
518 requirePathnameExists("Icon Directory", Config
.icons
.directory
);
520 if (Config
.errorDirectory
)
521 requirePathnameExists("Error Directory", Config
.errorDirectory
);
528 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
529 if (!R
->flags
.override_expire
)
532 debugs(22, 1, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP");
537 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
538 if (!R
->flags
.override_lastmod
)
541 debugs(22, 1, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP");
546 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
547 if (!R
->flags
.reload_into_ims
)
550 debugs(22, 1, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP");
555 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
556 if (!R
->flags
.ignore_reload
)
559 debugs(22, 1, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP");
564 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
565 if (!R
->flags
.ignore_no_cache
)
568 debugs(22, 1, "WARNING: use of 'ignore-no-cache' in 'refresh_pattern' violates HTTP");
573 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
574 if (!R
->flags
.ignore_no_store
)
577 debugs(22, 1, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP");
582 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
583 if (!R
->flags
.ignore_must_revalidate
)
585 debugs(22, 1, "WARNING: use of 'ignore-must-revalidate' in 'refresh_pattern' violates HTTP");
589 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
590 if (!R
->flags
.ignore_private
)
593 debugs(22, 1, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP");
598 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
599 if (!R
->flags
.ignore_auth
)
602 debugs(22, 1, "WARNING: use of 'ignore-auth' in 'refresh_pattern' violates HTTP");
610 Config
.onoff
.via
= 1;
613 if (!Config
.onoff
.via
)
614 debugs(22, 1, "WARNING: HTTP requires the use of Via");
618 if (aclPurgeMethodInUse(Config
.accessList
.http
))
619 Config2
.onoff
.enable_purge
= 1;
621 Config2
.onoff
.mangle_request_headers
= httpReqHdrManglersConfigured();
623 if (geteuid() == 0) {
624 if (NULL
!= Config
.effectiveUser
) {
626 struct passwd
*pwd
= getpwnam(Config
.effectiveUser
);
630 * Andres Kroonmaa <andre@online.ee>:
631 * Some getpwnam() implementations (Solaris?) require
632 * an available FD < 256 for opening a FILE* to the
635 * This should be safe at startup, but might still fail
636 * during reconfigure.
638 fatalf("getpwnam failed to find userid for effective user '%s'",
639 Config
.effectiveUser
);
643 Config2
.effectiveUserID
= pwd
->pw_uid
;
645 Config2
.effectiveGroupID
= pwd
->pw_gid
;
649 if (pwd
->pw_dir
&& *pwd
->pw_dir
) {
651 char *env_str
= (char *)xcalloc((len
= strlen(pwd
->pw_dir
) + 6), 1);
652 snprintf(env_str
, len
, "HOME=%s", pwd
->pw_dir
);
660 Config2
.effectiveUserID
= geteuid();
661 Config2
.effectiveGroupID
= getegid();
664 if (NULL
!= Config
.effectiveGroup
) {
666 struct group
*grp
= getgrnam(Config
.effectiveGroup
);
669 fatalf("getgrnam failed to find groupid for effective group '%s'",
670 Config
.effectiveGroup
);
674 Config2
.effectiveGroupID
= grp
->gr_gid
;
677 HttpRequestMethod::Configure(Config
);
680 debugs(3, 1, "Initializing https proxy context");
682 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
);
688 for (p
= Config
.peers
; p
!= NULL
; p
= p
->next
) {
690 debugs(3, 1, "Initializing cache_peer " << p
->name
<< " SSL context");
691 p
->sslContext
= sslCreateClientContext(p
->sslcert
, p
->sslkey
, p
->sslversion
, p
->sslcipher
, p
->ssloptions
, p
->sslflags
, p
->sslcafile
, p
->sslcapath
, p
->sslcrlfile
);
700 for (s
= Config
.Sockaddr
.http
; s
!= NULL
; s
= (http_port_list
*) s
->next
) {
701 if (!s
->cert
&& !s
->key
)
704 debugs(3, 1, "Initializing http_port " << s
->http
.s
<< " SSL context");
706 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
);
714 for (s
= Config
.Sockaddr
.https
; s
!= NULL
; s
= (https_port_list
*) s
->http
.next
) {
715 debugs(3, 1, "Initializing https_port " << s
->http
.s
<< " SSL context");
717 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
);
724 /* Parse a time specification from the config file. Store the
725 * result in 'tptr', after converting it to 'units' */
727 parseTimeLine(time_t * tptr
, const char *units
)
734 if ((u
= parseTimeUnits(units
)) == 0)
737 if ((token
= strtok(NULL
, w_space
)) == NULL
)
742 m
= u
; /* default to 'units' if none specified */
746 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
747 debugs(3, 0, "WARNING: No units on '" <<
748 config_input_line
<< "', assuming " <<
750 else if ((m
= parseTimeUnits(token
)) == 0)
753 *tptr
= static_cast<time_t> (m
* d
/ u
);
757 parseTimeUnits(const char *unit
)
759 if (!strncasecmp(unit
, T_SECOND_STR
, strlen(T_SECOND_STR
)))
762 if (!strncasecmp(unit
, T_MINUTE_STR
, strlen(T_MINUTE_STR
)))
765 if (!strncasecmp(unit
, T_HOUR_STR
, strlen(T_HOUR_STR
)))
768 if (!strncasecmp(unit
, T_DAY_STR
, strlen(T_DAY_STR
)))
771 if (!strncasecmp(unit
, T_WEEK_STR
, strlen(T_WEEK_STR
)))
774 if (!strncasecmp(unit
, T_FORTNIGHT_STR
, strlen(T_FORTNIGHT_STR
)))
777 if (!strncasecmp(unit
, T_MONTH_STR
, strlen(T_MONTH_STR
)))
780 if (!strncasecmp(unit
, T_YEAR_STR
, strlen(T_YEAR_STR
)))
781 return static_cast<int>(86400 * 365.2522);
783 if (!strncasecmp(unit
, T_DECADE_STR
, strlen(T_DECADE_STR
)))
784 return static_cast<int>(86400 * 365.2522 * 10);
786 debugs(3, 1, "parseTimeUnits: unknown time unit '" << unit
<< "'");
792 parseBytesLine64(int64_t * bptr
, const char *units
)
799 if ((u
= parseBytesUnits(units
)) == 0) {
804 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
809 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
816 m
= u
; /* default to 'units' if none specified */
820 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
821 debugs(3, 0, "WARNING: No units on '" <<
822 config_input_line
<< "', assuming " <<
824 else if ((m
= parseBytesUnits(token
)) == 0) {
829 *bptr
= static_cast<int64_t>(m
* d
/ u
);
831 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
837 parseBytesLine(size_t * bptr
, const char *units
)
844 if ((u
= parseBytesUnits(units
)) == 0) {
849 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
854 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
855 *bptr
= static_cast<size_t>(-1);
861 m
= u
; /* default to 'units' if none specified */
865 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
866 debugs(3, 0, "WARNING: No units on '" <<
867 config_input_line
<< "', assuming " <<
869 else if ((m
= parseBytesUnits(token
)) == 0) {
874 *bptr
= static_cast<size_t>(m
* d
/ u
);
876 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
881 parseBytesUnits(const char *unit
)
883 if (!strncasecmp(unit
, B_BYTES_STR
, strlen(B_BYTES_STR
)))
886 if (!strncasecmp(unit
, B_KBYTES_STR
, strlen(B_KBYTES_STR
)))
889 if (!strncasecmp(unit
, B_MBYTES_STR
, strlen(B_MBYTES_STR
)))
892 if (!strncasecmp(unit
, B_GBYTES_STR
, strlen(B_GBYTES_STR
)))
895 debugs(3, DBG_CRITICAL
, "WARNING: Unknown bytes unit '" << unit
<< "'");
900 /*****************************************************************************
902 *****************************************************************************/
905 dump_acl(StoreEntry
* entry
, const char *name
, ACL
* ae
)
911 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
);
912 storeAppendPrintf(entry
, "%s %s %s ",
919 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
<< " " << v
->key
);
920 storeAppendPrintf(entry
, "%s ", v
->key
);
924 storeAppendPrintf(entry
, "\n");
933 ACL::ParseAclLine(LegacyParser
, ae
);
943 dump_acl_list(StoreEntry
* entry
, ACLList
* head
)
947 for (l
= head
; l
; l
= l
->next
) {
948 storeAppendPrintf(entry
, " %s%s",
949 l
->op
? null_string
: "!",
955 dump_acl_access(StoreEntry
* entry
, const char *name
, acl_access
* head
)
959 for (l
= head
; l
; l
= l
->next
) {
960 storeAppendPrintf(entry
, "%s %s",
962 l
->allow
? "Allow" : "Deny");
963 dump_acl_list(entry
, l
->aclList
);
964 storeAppendPrintf(entry
, "\n");
969 parse_acl_access(acl_access
** head
)
971 aclParseAccessLine(LegacyParser
, head
);
975 free_acl_access(acl_access
** head
)
977 aclDestroyAccessList(head
);
981 dump_address(StoreEntry
* entry
, const char *name
, IpAddress
&addr
)
983 char buf
[MAX_IPSTRLEN
];
984 storeAppendPrintf(entry
, "%s %s\n", name
, addr
.NtoA(buf
,MAX_IPSTRLEN
) );
988 parse_address(IpAddress
*addr
)
990 char *token
= strtok(NULL
, w_space
);
997 if (!strcmp(token
,"any_addr")) {
1000 } else if ( (!strcmp(token
,"no_addr")) || (!strcmp(token
,"full_mask")) ) {
1008 free_address(IpAddress
*addr
)
1013 CBDATA_TYPE(acl_address
);
1016 dump_acl_address(StoreEntry
* entry
, const char *name
, acl_address
* head
)
1018 char buf
[MAX_IPSTRLEN
];
1021 for (l
= head
; l
; l
= l
->next
) {
1022 if (!l
->addr
.IsAnyAddr())
1023 storeAppendPrintf(entry
, "%s %s", name
, l
->addr
.NtoA(buf
,MAX_IPSTRLEN
));
1025 storeAppendPrintf(entry
, "%s autoselect", name
);
1027 dump_acl_list(entry
, l
->aclList
);
1029 storeAppendPrintf(entry
, "\n");
1034 freed_acl_address(void *data
)
1036 acl_address
*l
= static_cast<acl_address
*>(data
);
1037 aclDestroyAclList(&l
->aclList
);
1041 parse_acl_address(acl_address
** head
)
1044 acl_address
**tail
= head
; /* sane name below */
1045 CBDATA_INIT_TYPE_FREECB(acl_address
, freed_acl_address
);
1046 l
= cbdataAlloc(acl_address
);
1047 parse_address(&l
->addr
);
1048 aclParseAclList(LegacyParser
, &l
->aclList
);
1051 tail
= &(*tail
)->next
;
1057 free_acl_address(acl_address
** head
)
1060 acl_address
*l
= *head
;
1066 CBDATA_TYPE(acl_tos
);
1069 dump_acl_tos(StoreEntry
* entry
, const char *name
, acl_tos
* head
)
1073 for (l
= head
; l
; l
= l
->next
) {
1075 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->tos
);
1077 storeAppendPrintf(entry
, "%s none", name
);
1079 dump_acl_list(entry
, l
->aclList
);
1081 storeAppendPrintf(entry
, "\n");
1086 freed_acl_tos(void *data
)
1088 acl_tos
*l
= static_cast<acl_tos
*>(data
);
1089 aclDestroyAclList(&l
->aclList
);
1093 parse_acl_tos(acl_tos
** head
)
1096 acl_tos
**tail
= head
; /* sane name below */
1099 char *token
= strtok(NULL
, w_space
);
1106 if (sscanf(token
, "0x%x%c", &tos
, &junk
) != 1) {
1111 if (tos
< 0 || tos
> 255) {
1116 CBDATA_INIT_TYPE_FREECB(acl_tos
, freed_acl_tos
);
1118 l
= cbdataAlloc(acl_tos
);
1122 aclParseAclList(LegacyParser
, &l
->aclList
);
1125 tail
= &(*tail
)->next
;
1131 free_acl_tos(acl_tos
** head
)
1141 CBDATA_TYPE(acl_size_t
);
1144 dump_acl_b_size_t(StoreEntry
* entry
, const char *name
, acl_size_t
* head
)
1148 for (l
= head
; l
; l
= l
->next
) {
1150 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) l
->size
, B_BYTES_STR
);
1152 storeAppendPrintf(entry
, "%s none", name
);
1154 dump_acl_list(entry
, l
->aclList
);
1156 storeAppendPrintf(entry
, "\n");
1161 freed_acl_b_size_t(void *data
)
1163 acl_size_t
*l
= static_cast<acl_size_t
*>(data
);
1164 aclDestroyAclList(&l
->aclList
);
1168 parse_acl_b_size_t(acl_size_t
** head
)
1171 acl_size_t
**tail
= head
; /* sane name below */
1173 CBDATA_INIT_TYPE_FREECB(acl_size_t
, freed_acl_b_size_t
);
1175 l
= cbdataAlloc(acl_size_t
);
1177 parse_b_int64_t(&l
->size
);
1179 aclParseAclList(LegacyParser
, &l
->aclList
);
1182 tail
= &(*tail
)->next
;
1188 free_acl_b_size_t(acl_size_t
** head
)
1191 acl_size_t
*l
= *head
;
1200 #include "DelayPools.h"
1201 #include "DelayConfig.h"
1202 /* do nothing - free_delay_pool_count is the magic free function.
1203 * this is why delay_pool_count isn't just marked TYPE: ushort
1205 #define free_delay_pool_class(X)
1206 #define free_delay_pool_access(X)
1207 #define free_delay_pool_rates(X)
1208 #define dump_delay_pool_class(X, Y, Z)
1209 #define dump_delay_pool_access(X, Y, Z)
1210 #define dump_delay_pool_rates(X, Y, Z)
1213 free_delay_pool_count(DelayConfig
* cfg
)
1215 cfg
->freePoolCount();
1219 dump_delay_pool_count(StoreEntry
* entry
, const char *name
, DelayConfig
&cfg
)
1221 cfg
.dumpPoolCount (entry
, name
);
1225 parse_delay_pool_count(DelayConfig
* cfg
)
1227 cfg
->parsePoolCount();
1231 parse_delay_pool_class(DelayConfig
* cfg
)
1233 cfg
->parsePoolClass();
1237 parse_delay_pool_rates(DelayConfig
* cfg
)
1239 cfg
->parsePoolRates();
1243 parse_delay_pool_access(DelayConfig
* cfg
)
1245 cfg
->parsePoolAccess(LegacyParser
);
1252 dump_http_header_access(StoreEntry
* entry
, const char *name
, header_mangler header
[])
1256 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1257 if (header
[i
].access_list
!= NULL
) {
1258 storeAppendPrintf(entry
, "%s ", name
);
1259 dump_acl_access(entry
, httpHeaderNameById(i
),
1260 header
[i
].access_list
);
1266 parse_http_header_access(header_mangler header
[])
1271 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1272 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1273 debugs(3, 0, "parse_http_header_access: missing header name.");
1277 /* Now lookup index of header. */
1278 id
= httpHeaderIdByNameDef(t
, strlen(t
));
1280 if (strcmp(t
, "All") == 0)
1282 else if (strcmp(t
, "Other") == 0)
1284 else if (id
== -1) {
1285 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1286 debugs(3, 0, "parse_http_header_access: unknown header name '" << t
<< "'");
1290 if (id
!= HDR_ENUM_END
) {
1291 parse_acl_access(&header
[id
].access_list
);
1293 char *next_string
= t
+ strlen(t
) - 1;
1295 *(next_string
+ 1) = ' ';
1297 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1298 char *new_string
= xstrdup(next_string
);
1299 strtok(new_string
, w_space
);
1300 parse_acl_access(&header
[i
].access_list
);
1301 safe_free(new_string
);
1307 free_http_header_access(header_mangler header
[])
1311 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1312 free_acl_access(&header
[i
].access_list
);
1317 dump_http_header_replace(StoreEntry
* entry
, const char *name
, header_mangler
1322 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1323 if (NULL
== header
[i
].replacement
)
1326 storeAppendPrintf(entry
, "%s %s %s\n", name
, httpHeaderNameById(i
),
1327 header
[i
].replacement
);
1332 parse_http_header_replace(header_mangler header
[])
1337 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1338 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1339 debugs(3, 0, "parse_http_header_replace: missing header name.");
1343 /* Now lookup index of header. */
1344 id
= httpHeaderIdByNameDef(t
, strlen(t
));
1346 if (strcmp(t
, "All") == 0)
1348 else if (strcmp(t
, "Other") == 0)
1350 else if (id
== -1) {
1351 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1352 debugs(3, 0, "parse_http_header_replace: unknown header name " << t
<< ".");
1357 if (id
!= HDR_ENUM_END
) {
1358 if (header
[id
].replacement
!= NULL
)
1359 safe_free(header
[id
].replacement
);
1361 header
[id
].replacement
= xstrdup(t
+ strlen(t
) + 1);
1363 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1364 if (header
[i
].replacement
!= NULL
)
1365 safe_free(header
[i
].replacement
);
1367 header
[i
].replacement
= xstrdup(t
+ strlen(t
) + 1);
1373 free_http_header_replace(header_mangler header
[])
1377 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1378 if (header
[i
].replacement
!= NULL
)
1379 safe_free(header
[i
].replacement
);
1386 dump_cachedir(StoreEntry
* entry
, const char *name
, SquidConfig::_cacheSwap swap
)
1392 for (i
= 0; i
< swap
.n_configured
; i
++) {
1393 s
= dynamic_cast<SwapDir
*>(swap
.swapDirs
[i
].getRaw());
1395 storeAppendPrintf(entry
, "%s %s %s", name
, s
->type(), s
->path
);
1397 storeAppendPrintf(entry
, "\n");
1402 check_null_string(char *s
)
1408 parse_authparam(authConfig
* config
)
1413 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1416 if ((param_str
= strtok(NULL
, w_space
)) == NULL
)
1419 /* find a configuration for the scheme */
1420 AuthConfig
*scheme
= AuthConfig::Find (type_str
);
1422 if (scheme
== NULL
) {
1423 /* Create a configuration */
1424 AuthScheme
*theScheme
;
1426 if ((theScheme
= AuthScheme::Find(type_str
)) == NULL
) {
1427 debugs(3, 0, "Parsing Config File: Unknown authentication scheme '" << type_str
<< "'.");
1431 config
->push_back(theScheme
->createConfig());
1432 scheme
= config
->back();
1436 scheme
->parse(scheme
, config
->size(), param_str
);
1440 free_authparam(authConfig
* cfg
)
1443 /* DON'T FREE THESE FOR RECONFIGURE */
1448 while (cfg
->size()) {
1449 scheme
= cfg
->pop_back();
1455 dump_authparam(StoreEntry
* entry
, const char *name
, authConfig cfg
)
1457 for (authConfig::iterator i
= cfg
.begin(); i
!= cfg
.end(); ++i
)
1458 (*i
)->dump(entry
, name
, (*i
));
1461 /* TODO: just return the object, the # is irrelevant */
1463 find_fstype(char *type
)
1465 for (size_t i
= 0; i
< StoreFileSystem::FileSystems().size(); ++i
)
1466 if (strcasecmp(type
, StoreFileSystem::FileSystems().items
[i
]->type()) == 0)
1473 parse_cachedir(SquidConfig::_cacheSwap
* swap
)
1477 RefCount
<SwapDir
> sd
;
1481 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1484 if ((path_str
= strtok(NULL
, w_space
)) == NULL
)
1487 fs
= find_fstype(type_str
);
1492 /* reconfigure existing dir */
1494 for (i
= 0; i
< swap
->n_configured
; i
++) {
1495 assert (swap
->swapDirs
[i
].getRaw());
1497 if ((strcasecmp(path_str
, dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw())->path
)) == 0) {
1498 /* this is specific to on-fs Stores. The right
1499 * way to handle this is probably to have a mapping
1500 * from paths to stores, and have on-fs stores
1501 * register with that, and lookip in that in their
1502 * own setup logic. RBC 20041225. TODO.
1505 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw());
1507 if (sd
->type() != StoreFileSystem::FileSystems().items
[fs
]->type()) {
1508 debugs(3, 0, "ERROR: Can't change type of existing cache_dir " <<
1509 sd
->type() << " " << sd
->path
<< " to " << type_str
<< ". Restart required");
1513 sd
->reconfigure (i
, path_str
);
1515 update_maxobjsize();
1522 if (swap
->n_configured
> 63) {
1523 /* 7 bits, signed */
1524 debugs(3, DBG_CRITICAL
, "WARNING: There is a fixed maximum of 63 cache_dir entries Squid can handle.");
1525 debugs(3, DBG_CRITICAL
, "WARNING: '" << path_str
<< "' is one to many.");
1530 allocate_new_swapdir(swap
);
1532 swap
->swapDirs
[swap
->n_configured
] = StoreFileSystem::FileSystems().items
[fs
]->createSwapDir();
1534 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[swap
->n_configured
].getRaw());
1536 /* parse the FS parameters and options */
1537 sd
->parse(swap
->n_configured
, path_str
);
1539 ++swap
->n_configured
;
1541 /* Update the max object size */
1542 update_maxobjsize();
1546 peer_type_str(const peer_t type
)
1548 const char * result
;
1560 case PEER_MULTICAST
:
1561 result
= "multicast";
1573 dump_peer(StoreEntry
* entry
, const char *name
, peer
* p
)
1577 LOCAL_ARRAY(char, xname
, 128);
1580 storeAppendPrintf(entry
, "%s %s %s %d %d",
1586 dump_peer_options(entry
, p
);
1588 for (d
= p
->peer_domain
; d
; d
= d
->next
) {
1589 storeAppendPrintf(entry
, "cache_peer_domain %s %s%s\n",
1591 d
->do_ping
? null_string
: "!",
1596 snprintf(xname
, 128, "cache_peer_access %s", p
->name
);
1597 dump_acl_access(entry
, xname
, p
->access
);
1600 for (t
= p
->typelist
; t
; t
= t
->next
) {
1601 storeAppendPrintf(entry
, "neighbor_type_domain %s %s %s\n",
1603 peer_type_str(t
->type
),
1612 \param proto 'tcp' or 'udp' for protocol
1613 \returns Port the named service is supposed to be listening on.
1616 GetService(const char *proto
)
1618 struct servent
*port
= NULL
;
1619 /** Parses a port number or service name from the squid.conf */
1620 char *token
= strtok(NULL
, w_space
);
1621 if (token
== NULL
) {
1623 return 0; /* NEVER REACHED */
1625 /** Returns either the service port number from /etc/services */
1626 port
= getservbyname(token
, proto
);
1628 return ntohs((u_short
)port
->s_port
);
1630 /** Or a numeric translation of the config text. */
1631 return xatos(token
);
1635 \returns Port the named TCP service is supposed to be listening on.
1636 \copydoc GetService(const char *proto)
1641 return GetService("tcp");
1645 \returns Port the named UDP service is supposed to be listening on.
1646 \copydoc GetService(const char *proto)
1651 return GetService("udp");
1655 parse_peer(peer
** head
)
1659 CBDATA_INIT_TYPE_FREECB(peer
, peerDestroy
);
1660 p
= cbdataAlloc(peer
);
1661 p
->http_port
= CACHE_HTTP_PORT
;
1662 p
->icp
.port
= CACHE_ICP_PORT
;
1665 p
->stats
.logged_state
= PEER_ALIVE
;
1667 if ((token
= strtok(NULL
, w_space
)) == NULL
)
1670 p
->host
= xstrdup(token
);
1672 p
->name
= xstrdup(token
);
1674 if ((token
= strtok(NULL
, w_space
)) == NULL
)
1677 p
->type
= parseNeighborType(token
);
1679 if (p
->type
== PEER_MULTICAST
) {
1680 p
->options
.no_digest
= 1;
1681 p
->options
.no_netdb_exchange
= 1;
1684 p
->http_port
= GetTcpService();
1689 p
->icp
.port
= GetUdpService();
1690 p
->connection_auth
= 2; /* auto */
1692 while ((token
= strtok(NULL
, w_space
))) {
1693 if (!strcasecmp(token
, "proxy-only")) {
1694 p
->options
.proxy_only
= 1;
1695 } else if (!strcasecmp(token
, "no-query")) {
1696 p
->options
.no_query
= 1;
1697 } else if (!strcasecmp(token
, "background-ping")) {
1698 p
->options
.background_ping
= 1;
1699 } else if (!strcasecmp(token
, "no-digest")) {
1700 p
->options
.no_digest
= 1;
1701 } else if (!strcasecmp(token
, "multicast-responder")) {
1702 p
->options
.mcast_responder
= 1;
1703 } else if (!strncasecmp(token
, "weight=", 7)) {
1704 p
->weight
= xatoi(token
+ 7);
1705 } else if (!strncasecmp(token
, "basetime=", 9)) {
1706 p
->basetime
= xatoi(token
+ 9);
1707 } else if (!strcasecmp(token
, "closest-only")) {
1708 p
->options
.closest_only
= 1;
1709 } else if (!strncasecmp(token
, "ttl=", 4)) {
1710 p
->mcast
.ttl
= xatoi(token
+ 4);
1712 if (p
->mcast
.ttl
< 0)
1715 if (p
->mcast
.ttl
> 128)
1717 } else if (!strcasecmp(token
, "default")) {
1718 p
->options
.default_parent
= 1;
1719 } else if (!strcasecmp(token
, "round-robin")) {
1720 p
->options
.roundrobin
= 1;
1721 } else if (!strcasecmp(token
, "weighted-round-robin")) {
1722 p
->options
.weighted_roundrobin
= 1;
1725 } else if (!strcasecmp(token
, "htcp")) {
1726 p
->options
.htcp
= 1;
1727 } else if (!strcasecmp(token
, "htcp-oldsquid")) {
1728 p
->options
.htcp
= 1;
1729 p
->options
.htcp_oldsquid
= 1;
1730 } else if (!strcasecmp(token
, "htcp-no-clr")) {
1731 if (p
->options
.htcp_only_clr
)
1732 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
1733 p
->options
.htcp
= 1;
1734 p
->options
.htcp_no_clr
= 1;
1735 } else if (!strcasecmp(token
, "htcp-no-purge-clr")) {
1736 p
->options
.htcp
= 1;
1737 p
->options
.htcp_no_purge_clr
= 1;
1738 } else if (!strcasecmp(token
, "htcp-only-clr")) {
1739 if (p
->options
.htcp_no_clr
)
1740 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
1741 p
->options
.htcp
= 1;
1742 p
->options
.htcp_only_clr
= 1;
1743 } else if (!strcasecmp(token
, "htcp-forward-clr")) {
1744 p
->options
.htcp
= 1;
1745 p
->options
.htcp_forward_clr
= 1;
1748 } else if (!strcasecmp(token
, "no-netdb-exchange")) {
1749 p
->options
.no_netdb_exchange
= 1;
1751 } else if (!strcasecmp(token
, "carp")) {
1752 if (p
->type
!= PEER_PARENT
)
1753 fatalf("parse_peer: non-parent carp peer %s/%d\n", p
->host
, p
->http_port
);
1755 p
->options
.carp
= 1;
1757 } else if (!strcasecmp(token
, "userhash")) {
1758 if (p
->type
!= PEER_PARENT
)
1759 fatalf("parse_peer: non-parent userhash peer %s/%d\n", p
->host
, p
->http_port
);
1761 p
->options
.userhash
= 1;
1763 } else if (!strcasecmp(token
, "sourcehash")) {
1764 if (p
->type
!= PEER_PARENT
)
1765 fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p
->host
, p
->http_port
);
1767 p
->options
.sourcehash
= 1;
1771 } else if (!strcasecmp(token
, "no-delay")) {
1772 p
->options
.no_delay
= 1;
1775 } else if (!strncasecmp(token
, "login=", 6)) {
1776 p
->login
= xstrdup(token
+ 6);
1777 rfc1738_unescape(p
->login
);
1778 } else if (!strncasecmp(token
, "connect-timeout=", 16)) {
1779 p
->connect_timeout
= xatoi(token
+ 16);
1780 #if USE_CACHE_DIGESTS
1782 } else if (!strncasecmp(token
, "digest-url=", 11)) {
1783 p
->digest_url
= xstrdup(token
+ 11);
1786 } else if (!strcasecmp(token
, "allow-miss")) {
1787 p
->options
.allow_miss
= 1;
1788 } else if (!strncasecmp(token
, "max-conn=", 9)) {
1789 p
->max_conn
= xatoi(token
+ 9);
1790 } else if (!strcasecmp(token
, "originserver")) {
1791 p
->options
.originserver
= 1;
1792 } else if (!strncasecmp(token
, "name=", 5)) {
1796 p
->name
= xstrdup(token
+ 5);
1797 } else if (!strncasecmp(token
, "forceddomain=", 13)) {
1798 safe_free(p
->domain
);
1801 p
->domain
= xstrdup(token
+ 13);
1805 } else if (strcmp(token
, "ssl") == 0) {
1807 } else if (strncmp(token
, "sslcert=", 8) == 0) {
1808 safe_free(p
->sslcert
);
1809 p
->sslcert
= xstrdup(token
+ 8);
1810 } else if (strncmp(token
, "sslkey=", 7) == 0) {
1811 safe_free(p
->sslkey
);
1812 p
->sslkey
= xstrdup(token
+ 7);
1813 } else if (strncmp(token
, "sslversion=", 11) == 0) {
1814 p
->sslversion
= atoi(token
+ 11);
1815 } else if (strncmp(token
, "ssloptions=", 11) == 0) {
1816 safe_free(p
->ssloptions
);
1817 p
->ssloptions
= xstrdup(token
+ 11);
1818 } else if (strncmp(token
, "sslcipher=", 10) == 0) {
1819 safe_free(p
->sslcipher
);
1820 p
->sslcipher
= xstrdup(token
+ 10);
1821 } else if (strncmp(token
, "sslcafile=", 10) == 0) {
1822 safe_free(p
->sslcafile
);
1823 p
->sslcafile
= xstrdup(token
+ 10);
1824 } else if (strncmp(token
, "sslcapath=", 10) == 0) {
1825 safe_free(p
->sslcapath
);
1826 p
->sslcapath
= xstrdup(token
+ 10);
1827 } else if (strncmp(token
, "sslcrlfile=", 11) == 0) {
1828 safe_free(p
->sslcrlfile
);
1829 p
->sslcapath
= xstrdup(token
+ 10);
1830 } else if (strncmp(token
, "sslflags=", 9) == 0) {
1831 safe_free(p
->sslflags
);
1832 p
->sslflags
= xstrdup(token
+ 9);
1833 } else if (strncmp(token
, "ssldomain=", 10) == 0) {
1834 safe_free(p
->ssldomain
);
1835 p
->ssldomain
= xstrdup(token
+ 10);
1838 } else if (strcmp(token
, "front-end-https") == 0) {
1839 p
->front_end_https
= 1;
1840 } else if (strcmp(token
, "front-end-https=on") == 0) {
1841 p
->front_end_https
= 1;
1842 } else if (strcmp(token
, "front-end-https=auto") == 0) {
1843 p
->front_end_https
= 2;
1844 } else if (strcmp(token
, "connection-auth=off") == 0) {
1845 p
->connection_auth
= 0;
1846 } else if (strcmp(token
, "connection-auth") == 0) {
1847 p
->connection_auth
= 1;
1848 } else if (strcmp(token
, "connection-auth=on") == 0) {
1849 p
->connection_auth
= 1;
1850 } else if (strcmp(token
, "connection-auth=auto") == 0) {
1851 p
->connection_auth
= 2;
1853 debugs(3, 0, "parse_peer: token='" << token
<< "'");
1858 if (peerFindByName(p
->name
))
1859 fatalf("ERROR: cache_peer %s specified twice\n", p
->name
);
1864 p
->icp
.version
= ICP_VERSION_CURRENT
;
1868 #if USE_CACHE_DIGESTS
1870 if (!p
->options
.no_digest
) {
1871 /* XXX This looks odd.. who has the original pointer
1874 PeerDigest
*pd
= peerDigestCreate(p
);
1875 p
->digest
= cbdataReference(pd
);
1880 p
->index
= ++Config
.npeers
;
1882 while (*head
!= NULL
)
1883 head
= &(*head
)->next
;
1891 free_peer(peer
** P
)
1895 while ((p
= *P
) != NULL
) {
1897 #if USE_CACHE_DIGESTS
1899 cbdataReferenceDone(p
->digest
);
1909 dump_cachemgrpasswd(StoreEntry
* entry
, const char *name
, cachemgr_passwd
* list
)
1913 while (list
!= NULL
) {
1914 if (strcmp(list
->passwd
, "none") && strcmp(list
->passwd
, "disable"))
1915 storeAppendPrintf(entry
, "%s XXXXXXXXXX", name
);
1917 storeAppendPrintf(entry
, "%s %s", name
, list
->passwd
);
1919 for (w
= list
->actions
; w
!= NULL
; w
= w
->next
) {
1920 storeAppendPrintf(entry
, " %s", w
->key
);
1923 storeAppendPrintf(entry
, "\n");
1929 parse_cachemgrpasswd(cachemgr_passwd
** head
)
1931 char *passwd
= NULL
;
1932 wordlist
*actions
= NULL
;
1934 cachemgr_passwd
**P
;
1935 parse_string(&passwd
);
1936 parse_wordlist(&actions
);
1937 p
= static_cast<cachemgr_passwd
*>(xcalloc(1, sizeof(cachemgr_passwd
)));
1939 p
->actions
= actions
;
1941 for (P
= head
; *P
; P
= &(*P
)->next
) {
1943 * See if any of the actions from this line already have a
1944 * password from previous lines. The password checking
1945 * routines in cache_manager.c take the the password from
1946 * the first cachemgr_passwd struct that contains the
1947 * requested action. Thus, we should warn users who might
1948 * think they can have two passwords for the same action.
1953 for (w
= (*P
)->actions
; w
; w
= w
->next
) {
1954 for (u
= actions
; u
; u
= u
->next
) {
1955 if (strcmp(w
->key
, u
->key
))
1958 debugs(0, 0, "WARNING: action '" << u
->key
<< "' (line " << config_lineno
<< ") already has a password");
1967 free_cachemgrpasswd(cachemgr_passwd
** head
)
1971 while ((p
= *head
) != NULL
) {
1974 wordlistDestroy(&p
->actions
);
1980 dump_denyinfo(StoreEntry
* entry
, const char *name
, acl_deny_info_list
* var
)
1984 while (var
!= NULL
) {
1985 storeAppendPrintf(entry
, "%s %s", name
, var
->err_page_name
);
1987 for (a
= var
->acl_list
; a
!= NULL
; a
= a
->next
)
1988 storeAppendPrintf(entry
, " %s", a
->name
);
1990 storeAppendPrintf(entry
, "\n");
1997 parse_denyinfo(acl_deny_info_list
** var
)
1999 aclParseDenyInfoLine(var
);
2003 free_denyinfo(acl_deny_info_list
** list
)
2005 acl_deny_info_list
*a
= NULL
;
2006 acl_deny_info_list
*a_next
= NULL
;
2007 acl_name_list
*l
= NULL
;
2008 acl_name_list
*l_next
= NULL
;
2010 for (a
= *list
; a
; a
= a_next
) {
2011 for (l
= a
->acl_list
; l
; l
= l_next
) {
2013 memFree(l
, MEM_ACL_NAME_LIST
);
2018 memFree(a
, MEM_ACL_DENY_INFO_LIST
);
2026 parse_peer_access(void)
2031 if (!(host
= strtok(NULL
, w_space
)))
2034 if ((p
= peerFindByName(host
)) == NULL
) {
2035 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2039 aclParseAccessLine(LegacyParser
, &p
->access
);
2043 parse_hostdomain(void)
2046 char *domain
= NULL
;
2048 if (!(host
= strtok(NULL
, w_space
)))
2051 while ((domain
= strtok(NULL
, list_sep
))) {
2052 domain_ping
*l
= NULL
;
2053 domain_ping
**L
= NULL
;
2056 if ((p
= peerFindByName(host
)) == NULL
) {
2057 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2061 l
= static_cast<domain_ping
*>(xcalloc(1, sizeof(domain_ping
)));
2064 if (*domain
== '!') { /* check for !.edu */
2069 l
->domain
= xstrdup(domain
);
2071 for (L
= &(p
->peer_domain
); *L
; L
= &((*L
)->next
));
2077 parse_hostdomaintype(void)
2081 char *domain
= NULL
;
2083 if (!(host
= strtok(NULL
, w_space
)))
2086 if (!(type
= strtok(NULL
, w_space
)))
2089 while ((domain
= strtok(NULL
, list_sep
))) {
2090 domain_type
*l
= NULL
;
2091 domain_type
**L
= NULL
;
2094 if ((p
= peerFindByName(host
)) == NULL
) {
2095 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2099 l
= static_cast<domain_type
*>(xcalloc(1, sizeof(domain_type
)));
2100 l
->type
= parseNeighborType(type
);
2101 l
->domain
= xstrdup(domain
);
2103 for (L
= &(p
->typelist
); *L
; L
= &((*L
)->next
));
2109 dump_int(StoreEntry
* entry
, const char *name
, int var
)
2111 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2129 dump_onoff(StoreEntry
* entry
, const char *name
, int var
)
2131 storeAppendPrintf(entry
, "%s %s\n", name
, var
? "on" : "off");
2135 parse_onoff(int *var
)
2137 char *token
= strtok(NULL
, w_space
);
2142 if (!strcasecmp(token
, "on") || !strcasecmp(token
, "enable"))
2148 #define free_onoff free_int
2151 dump_tristate(StoreEntry
* entry
, const char *name
, int var
)
2162 storeAppendPrintf(entry
, "%s %s\n", name
, state
);
2166 parse_tristate(int *var
)
2168 char *token
= strtok(NULL
, w_space
);
2173 if (!strcasecmp(token
, "on") || !strcasecmp(token
, "enable"))
2175 else if (!strcasecmp(token
, "warn"))
2181 #define free_tristate free_int
2184 dump_refreshpattern(StoreEntry
* entry
, const char *name
, refresh_t
* head
)
2186 while (head
!= NULL
) {
2187 storeAppendPrintf(entry
, "%s%s %s %d %d%% %d\n",
2189 head
->flags
.icase
? " -i" : null_string
,
2191 (int) head
->min
/ 60,
2192 (int) (100.0 * head
->pct
+ 0.5),
2193 (int) head
->max
/ 60);
2195 if (head
->flags
.refresh_ims
)
2196 storeAppendPrintf(entry
, " refresh-ims");
2200 if (head
->flags
.override_expire
)
2201 storeAppendPrintf(entry
, " override-expire");
2203 if (head
->flags
.override_lastmod
)
2204 storeAppendPrintf(entry
, " override-lastmod");
2206 if (head
->flags
.reload_into_ims
)
2207 storeAppendPrintf(entry
, " reload-into-ims");
2209 if (head
->flags
.ignore_reload
)
2210 storeAppendPrintf(entry
, " ignore-reload");
2212 if (head
->flags
.ignore_no_cache
)
2213 storeAppendPrintf(entry
, " ignore-no-cache");
2215 if (head
->flags
.ignore_no_store
)
2216 storeAppendPrintf(entry
, " ignore-no-store");
2218 if (head
->flags
.ignore_must_revalidate
)
2219 storeAppendPrintf(entry
, " ignore-must-revalidate");
2221 if (head
->flags
.ignore_private
)
2222 storeAppendPrintf(entry
, " ignore-private");
2224 if (head
->flags
.ignore_auth
)
2225 storeAppendPrintf(entry
, " ignore-auth");
2229 storeAppendPrintf(entry
, "\n");
2236 parse_refreshpattern(refresh_t
** head
)
2243 int refresh_ims
= 0;
2246 int override_expire
= 0;
2247 int override_lastmod
= 0;
2248 int reload_into_ims
= 0;
2249 int ignore_reload
= 0;
2250 int ignore_no_cache
= 0;
2251 int ignore_no_store
= 0;
2252 int ignore_must_revalidate
= 0;
2253 int ignore_private
= 0;
2254 int ignore_auth
= 0;
2261 int flags
= REG_EXTENDED
| REG_NOSUB
;
2263 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
2268 if (strcmp(token
, "-i") == 0) {
2270 token
= strtok(NULL
, w_space
);
2271 } else if (strcmp(token
, "+i") == 0) {
2272 flags
&= ~REG_ICASE
;
2273 token
= strtok(NULL
, w_space
);
2276 if (token
== NULL
) {
2281 pattern
= xstrdup(token
);
2283 i
= GetInteger(); /* token: min */
2285 min
= (time_t) (i
* 60); /* convert minutes to seconds */
2287 i
= GetInteger(); /* token: pct */
2289 pct
= (double) i
/ 100.0;
2291 i
= GetInteger(); /* token: max */
2293 max
= (time_t) (i
* 60); /* convert minutes to seconds */
2296 while ((token
= strtok(NULL
, w_space
)) != NULL
) {
2297 if (!strcmp(token
, "refresh-ims")) {
2301 } else if (!strcmp(token
, "override-expire"))
2302 override_expire
= 1;
2303 else if (!strcmp(token
, "override-lastmod"))
2304 override_lastmod
= 1;
2305 else if (!strcmp(token
, "ignore-no-cache"))
2306 ignore_no_cache
= 1;
2307 else if (!strcmp(token
, "ignore-no-store"))
2308 ignore_no_store
= 1;
2309 else if (!strcmp(token
, "ignore-must-revalidate"))
2310 ignore_must_revalidate
= 1;
2311 else if (!strcmp(token
, "ignore-private"))
2313 else if (!strcmp(token
, "ignore-auth"))
2315 else if (!strcmp(token
, "reload-into-ims")) {
2316 reload_into_ims
= 1;
2317 refresh_nocache_hack
= 1;
2318 /* tell client_side.c that this is used */
2319 } else if (!strcmp(token
, "ignore-reload")) {
2321 refresh_nocache_hack
= 1;
2322 /* tell client_side.c that this is used */
2326 debugs(22, 0, "redreshAddToList: Unknown option '" << pattern
<< "': " << token
);
2329 if ((errcode
= regcomp(&comp
, pattern
, flags
)) != 0) {
2331 regerror(errcode
, &comp
, errbuf
, sizeof errbuf
);
2332 debugs(22, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
2333 debugs(22, 0, "refreshAddToList: Invalid regular expression '" << pattern
<< "': " << errbuf
);
2337 pct
= pct
< 0.0 ? 0.0 : pct
;
2338 max
= max
< 0 ? 0 : max
;
2339 t
= static_cast<refresh_t
*>(xcalloc(1, sizeof(refresh_t
)));
2340 t
->pattern
= (char *) xstrdup(pattern
);
2341 t
->compiled_pattern
= comp
;
2346 if (flags
& REG_ICASE
)
2350 t
->flags
.refresh_ims
= 1;
2354 if (override_expire
)
2355 t
->flags
.override_expire
= 1;
2357 if (override_lastmod
)
2358 t
->flags
.override_lastmod
= 1;
2360 if (reload_into_ims
)
2361 t
->flags
.reload_into_ims
= 1;
2364 t
->flags
.ignore_reload
= 1;
2366 if (ignore_no_cache
)
2367 t
->flags
.ignore_no_cache
= 1;
2369 if (ignore_no_store
)
2370 t
->flags
.ignore_no_store
= 1;
2372 if (ignore_must_revalidate
)
2373 t
->flags
.ignore_must_revalidate
= 1;
2376 t
->flags
.ignore_private
= 1;
2379 t
->flags
.ignore_auth
= 1;
2386 head
= &(*head
)->next
;
2394 free_refreshpattern(refresh_t
** head
)
2398 while ((t
= *head
) != NULL
) {
2400 safe_free(t
->pattern
);
2401 regfree(&t
->compiled_pattern
);
2406 refresh_nocache_hack
= 0;
2412 dump_string(StoreEntry
* entry
, const char *name
, char *var
)
2415 storeAppendPrintf(entry
, "%s %s\n", name
, var
);
2419 parse_string(char **var
)
2421 char *token
= strtok(NULL
, w_space
);
2427 *var
= xstrdup(token
);
2431 ConfigParser::ParseString(char **var
)
2437 ConfigParser::ParseString(String
*var
)
2439 char *token
= strtok(NULL
, w_space
);
2448 free_string(char **var
)
2454 parse_eol(char *volatile *var
)
2456 unsigned char *token
= (unsigned char *) strtok(NULL
, null_string
);
2464 while (*token
&& xisspace(*token
))
2472 *var
= xstrdup((char *) token
);
2475 #define dump_eol dump_string
2476 #define free_eol free_string
2479 dump_time_t(StoreEntry
* entry
, const char *name
, time_t var
)
2481 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int) var
);
2485 parse_time_t(time_t * var
)
2487 parseTimeLine(var
, T_SECOND_STR
);
2491 free_time_t(time_t * var
)
2497 dump_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
2499 storeAppendPrintf(entry
, "%s %d\n", name
, (int) var
);
2503 dump_b_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
2505 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
2510 dump_kb_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
2512 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_KBYTES_STR
);
2517 dump_b_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
2519 storeAppendPrintf(entry
, "%s %"PRId64
" %s\n", name
, var
, B_BYTES_STR
);
2523 dump_kb_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
2525 storeAppendPrintf(entry
, "%s %"PRId64
" %s\n", name
, var
, B_KBYTES_STR
);
2529 parse_size_t(size_t * var
)
2537 parse_b_size_t(size_t * var
)
2539 parseBytesLine(var
, B_BYTES_STR
);
2544 parse_kb_size_t(size_t * var
)
2546 parseBytesLine(var
, B_KBYTES_STR
);
2551 parse_b_int64_t(int64_t * var
)
2553 parseBytesLine64(var
, B_BYTES_STR
);
2557 parse_kb_int64_t(int64_t * var
)
2559 parseBytesLine64(var
, B_KBYTES_STR
);
2563 free_size_t(size_t * var
)
2569 free_b_int64_t(int64_t * var
)
2574 #define free_b_size_t free_size_t
2575 #define free_kb_size_t free_size_t
2576 #define free_mb_size_t free_size_t
2577 #define free_gb_size_t free_size_t
2578 #define free_kb_int64_t free_b_int64_t
2581 dump_ushort(StoreEntry
* entry
, const char *name
, u_short var
)
2583 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2587 free_ushort(u_short
* u
)
2593 parse_ushort(u_short
* var
)
2595 ConfigParser::ParseUShort(var
);
2599 ConfigParser::ParseUShort(u_short
*var
)
2605 ConfigParser::ParseBool(bool *var
)
2607 int i
= GetInteger();
2618 dump_wordlist(StoreEntry
* entry
, const char *name
, wordlist
* list
)
2620 while (list
!= NULL
) {
2621 storeAppendPrintf(entry
, "%s %s\n", name
, list
->key
);
2627 ConfigParser::ParseWordList(wordlist
** list
)
2629 parse_wordlist(list
);
2633 parse_wordlist(wordlist
** list
)
2636 char *t
= strtok(NULL
, "");
2638 while ((token
= strwordtok(NULL
, &t
)))
2639 wordlistAdd(list
, token
);
2642 #if 0 /* now unused */
2644 check_null_wordlist(wordlist
* w
)
2651 check_null_acl_access(acl_access
* a
)
2656 #define free_wordlist wordlistDestroy
2658 #define free_uri_whitespace free_int
2661 parse_uri_whitespace(int *var
)
2663 char *token
= strtok(NULL
, w_space
);
2668 if (!strcasecmp(token
, "strip"))
2669 *var
= URI_WHITESPACE_STRIP
;
2670 else if (!strcasecmp(token
, "deny"))
2671 *var
= URI_WHITESPACE_DENY
;
2672 else if (!strcasecmp(token
, "allow"))
2673 *var
= URI_WHITESPACE_ALLOW
;
2674 else if (!strcasecmp(token
, "encode"))
2675 *var
= URI_WHITESPACE_ENCODE
;
2676 else if (!strcasecmp(token
, "chop"))
2677 *var
= URI_WHITESPACE_CHOP
;
2683 dump_uri_whitespace(StoreEntry
* entry
, const char *name
, int var
)
2687 if (var
== URI_WHITESPACE_ALLOW
)
2689 else if (var
== URI_WHITESPACE_ENCODE
)
2691 else if (var
== URI_WHITESPACE_CHOP
)
2693 else if (var
== URI_WHITESPACE_DENY
)
2698 storeAppendPrintf(entry
, "%s %s\n", name
, s
);
2702 free_removalpolicy(RemovalPolicySettings
** settings
)
2707 free_string(&(*settings
)->type
);
2709 free_wordlist(&(*settings
)->args
);
2717 parse_removalpolicy(RemovalPolicySettings
** settings
)
2720 free_removalpolicy(settings
);
2722 *settings
= new RemovalPolicySettings
;
2724 parse_string(&(*settings
)->type
);
2726 parse_wordlist(&(*settings
)->args
);
2730 dump_removalpolicy(StoreEntry
* entry
, const char *name
, RemovalPolicySettings
* settings
)
2733 storeAppendPrintf(entry
, "%s %s", name
, settings
->type
);
2734 args
= settings
->args
;
2737 storeAppendPrintf(entry
, " %s", args
->key
);
2741 storeAppendPrintf(entry
, "\n");
2744 #include "cf_parser.h"
2747 parseNeighborType(const char *s
)
2749 if (!strcasecmp(s
, "parent"))
2752 if (!strcasecmp(s
, "neighbor"))
2753 return PEER_SIBLING
;
2755 if (!strcasecmp(s
, "neighbour"))
2756 return PEER_SIBLING
;
2758 if (!strcasecmp(s
, "sibling"))
2759 return PEER_SIBLING
;
2761 if (!strcasecmp(s
, "multicast"))
2762 return PEER_MULTICAST
;
2764 debugs(15, 0, "WARNING: Unknown neighbor type: " << s
);
2766 return PEER_SIBLING
;
2771 parse_IpAddress_list_token(IpAddress_list
** head
, char *token
)
2778 unsigned short port
;
2785 if (*token
== '[') {
2788 t
= strchr(host
, ']');
2794 port
= xatos(t
+ 1);
2797 if ((t
= strchr(token
, ':'))) {
2801 port
= xatos(t
+ 1);
2805 } else if ((port
= strtol(token
, &tmp
, 10)), !*tmp
) {
2814 else if ( ipa
.GetHostByName(host
) ) /* dont use ipcache. Accept either FQDN or IPA. */
2819 /* port MUST be set after the IPA lookup/conversion is perofrmed. */
2823 head
= &(*head
)->next
;
2825 s
= static_cast<IpAddress_list
*>(xcalloc(1, sizeof(*s
)));
2832 parse_IpAddress_list(IpAddress_list
** head
)
2836 while ((token
= strtok(NULL
, w_space
))) {
2837 parse_IpAddress_list_token(head
, token
);
2842 dump_IpAddress_list(StoreEntry
* e
, const char *n
, const IpAddress_list
* s
)
2844 char ntoabuf
[MAX_IPSTRLEN
];
2847 storeAppendPrintf(e
, "%s %s\n",
2849 s
->s
.NtoA(ntoabuf
,MAX_IPSTRLEN
));
2855 free_IpAddress_list(IpAddress_list
** head
)
2857 if (*head
) delete *head
;
2861 #if CURRENTLY_UNUSED
2862 /* This code was previously used by http_port. Left as it really should
2863 * be used by icp_port and htcp_port
2866 check_null_IpAddress_list(const IpAddress_list
* s
)
2871 #endif /* CURRENTLY_UNUSED */
2872 #endif /* USE_WCCPv2 */
2874 CBDATA_CLASS_INIT(http_port_list
);
2877 parse_http_port_specification(http_port_list
* s
, char *token
)
2880 unsigned short port
= 0;
2884 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
2885 s
->name
= xstrdup(token
);
2886 s
->connection_auth_disabled
= false;
2889 if (*token
== '[') {
2892 t
= strchr(host
, ']');
2894 debugs(3, 0, "http(s)_port: missing ']' on IPv6 address: " << token
);
2899 debugs(3, 0, "http(s)_port: missing Port in: " << token
);
2902 port
= xatos(t
+ 1);
2905 if ((t
= strchr(token
, ':'))) {
2910 port
= xatos(t
+ 1);
2912 } else if ((port
= strtol(token
, &junk
, 10)), !*junk
) {
2914 debugs(3, 3, "http(s)_port: found Listen on Port: " << port
);
2916 debugs(3, 0, "http(s)_port: missing Port: " << token
);
2921 debugs(3, 0, "http(s)_port: Port cannot be 0: " << token
);
2928 debugs(3, 3, "http(s)_port: found Listen on wildcard address: " << s
->s
);
2929 } else if ( s
->s
= host
) { /* check/parse numeric IPA */
2931 debugs(3, 3, "http(s)_port: Listen on Host/IP: " << host
<< " --> " << s
->s
);
2932 } else if ( s
->s
.GetHostByName(host
) ) { /* check/parse for FQDN */
2933 /* dont use ipcache */
2934 s
->defaultsite
= xstrdup(host
);
2936 debugs(3, 3, "http(s)_port: found Listen as Host " << s
->defaultsite
<< " on IP: " << s
->s
);
2938 debugs(3, 0, "http(s)_port: failed to resolve Host/IP: " << host
);
2944 parse_http_port_option(http_port_list
* s
, char *token
)
2946 if (strncmp(token
, "defaultsite=", 12) == 0) {
2947 safe_free(s
->defaultsite
);
2948 s
->defaultsite
= xstrdup(token
+ 12);
2950 } else if (strncmp(token
, "name=", 5) == 0) {
2952 s
->name
= xstrdup(token
+ 5);
2953 } else if (strcmp(token
, "vhost") == 0) {
2956 } else if (strcmp(token
, "vport") == 0) {
2959 } else if (strncmp(token
, "vport=", 6) == 0) {
2960 s
->vport
= xatos(token
+ 6);
2962 } else if (strncmp(token
, "protocol=", 9) == 0) {
2963 s
->protocol
= xstrdup(token
+ 9);
2965 } else if (strcmp(token
, "accel") == 0) {
2967 } else if (strcmp(token
, "no-connection-auth") == 0) {
2968 s
->connection_auth_disabled
= true;
2969 } else if (strcmp(token
, "connection-auth=off") == 0) {
2970 s
->connection_auth_disabled
= true;
2971 } else if (strcmp(token
, "connection-auth") == 0) {
2972 s
->connection_auth_disabled
= false;
2973 } else if (strcmp(token
, "connection-auth=on") == 0) {
2974 s
->connection_auth_disabled
= false;
2975 } else if (strncmp(token
, "disable-pmtu-discovery=", 23) == 0) {
2976 if (!strcasecmp(token
+ 23, "off"))
2977 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
2978 else if (!strcasecmp(token
+ 23, "transparent"))
2979 s
->disable_pmtu_discovery
= DISABLE_PMTU_TRANSPARENT
;
2980 else if (!strcasecmp(token
+ 23, "always"))
2981 s
->disable_pmtu_discovery
= DISABLE_PMTU_ALWAYS
;
2985 } else if (strcmp(token
, "transparent") == 0 || strcmp(token
, "intercept") == 0) {
2987 IpInterceptor
.StartInterception();
2988 /* Log information regarding the port modes under interception. */
2989 debugs(3, DBG_IMPORTANT
, "Starting Authentication on port " << s
->s
);
2990 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (interception enabled)");
2993 /* INET6: until transparent REDIRECT works on IPv6 SOCKET, force wildcard to IPv4 */
2994 debugs(3, DBG_IMPORTANT
, "Disabling IPv6 on port " << s
->s
<< " (interception enabled)");
2995 if ( !s
->s
.SetIPv4() ) {
2996 debugs(3, DBG_CRITICAL
, "http(s)_port: IPv6 addresses cannot be transparent (protocol does not provide NAT)" << s
->s
);
3000 } else if (strcmp(token
, "tproxy") == 0) {
3001 if (s
->intercepted
|| s
->accel
) {
3002 debugs(3,DBG_CRITICAL
, "http(s)_port: TPROXY option requires its own interception port. It cannot be shared.");
3005 s
->spoof_client_ip
= 1;
3006 IpInterceptor
.StartTransparency();
3007 /* Log information regarding the port modes under transparency. */
3008 debugs(3, DBG_IMPORTANT
, "Starting IP Spoofing on port " << s
->s
);
3009 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (Ip spoofing enabled)");
3012 /* INET6: until target TPROXY is known to work on IPv6 SOCKET, force wildcard to IPv4 */
3013 debugs(3, DBG_IMPORTANT
, "Disabling IPv6 on port " << s
->s
<< " (interception enabled)");
3014 if ( s
->s
.IsIPv6() && !s
->s
.SetIPv4() ) {
3015 debugs(3, DBG_CRITICAL
, "http(s)_port: IPv6 addresses cannot be transparent (protocol does not provide NAT)" << s
->s
);
3020 } else if (strcmp(token
, "ipv4") == 0) {
3022 if ( !s
->s
.SetIPv4() ) {
3023 debugs(3, 0, "http(s)_port: IPv6 addresses cannot be used a IPv4-Only." << s
->s
);
3027 } else if (strcmp(token
, "tcpkeepalive") == 0) {
3028 s
->tcp_keepalive
.enabled
= 1;
3029 } else if (strncmp(token
, "tcpkeepalive=", 13) == 0) {
3030 char *t
= token
+ 13;
3031 s
->tcp_keepalive
.enabled
= 1;
3032 s
->tcp_keepalive
.idle
= atoi(t
);
3036 s
->tcp_keepalive
.interval
= atoi(t
);
3041 s
->tcp_keepalive
.timeout
= atoi(t
);
3045 } else if (strncmp(token
, "cert=", 5) == 0) {
3047 s
->cert
= xstrdup(token
+ 5);
3048 } else if (strncmp(token
, "key=", 4) == 0) {
3050 s
->key
= xstrdup(token
+ 4);
3051 } else if (strncmp(token
, "version=", 8) == 0) {
3052 s
->version
= xatoi(token
+ 8);
3054 if (s
->version
< 1 || s
->version
> 4)
3056 } else if (strncmp(token
, "options=", 8) == 0) {
3057 safe_free(s
->options
);
3058 s
->options
= xstrdup(token
+ 8);
3059 } else if (strncmp(token
, "cipher=", 7) == 0) {
3060 safe_free(s
->cipher
);
3061 s
->cipher
= xstrdup(token
+ 7);
3062 } else if (strncmp(token
, "clientca=", 9) == 0) {
3063 safe_free(s
->clientca
);
3064 s
->clientca
= xstrdup(token
+ 9);
3065 } else if (strncmp(token
, "cafile=", 7) == 0) {
3066 safe_free(s
->cafile
);
3067 s
->cafile
= xstrdup(token
+ 7);
3068 } else if (strncmp(token
, "capath=", 7) == 0) {
3069 safe_free(s
->capath
);
3070 s
->capath
= xstrdup(token
+ 7);
3071 } else if (strncmp(token
, "crlfile=", 8) == 0) {
3072 safe_free(s
->crlfile
);
3073 s
->crlfile
= xstrdup(token
+ 8);
3074 } else if (strncmp(token
, "dhparams=", 9) == 0) {
3075 safe_free(s
->dhfile
);
3076 s
->dhfile
= xstrdup(token
+ 9);
3077 } else if (strncmp(token
, "sslflags=", 9) == 0) {
3078 safe_free(s
->sslflags
);
3079 s
->sslflags
= xstrdup(token
+ 9);
3080 } else if (strncmp(token
, "sslcontext=", 11) == 0) {
3081 safe_free(s
->sslcontext
);
3082 s
->sslcontext
= xstrdup(token
+ 11);
3083 } else if (strcmp(token
, "sslBump") == 0) {
3084 s
->sslBump
= 1; // accelerated when bumped, otherwise not
3090 if ( s
->spoof_client_ip
&& (s
->intercepted
|| s
->accel
) ) {
3091 debugs(3,DBG_CRITICAL
, "http(s)_port: TPROXY option requires its own interception port. It cannot be shared.");
3096 static http_port_list
*
3097 create_http_port(char *portspec
)
3099 http_port_list
*s
= new http_port_list("http");
3100 parse_http_port_specification(s
, portspec
);
3105 add_http_port(char *portspec
)
3107 http_port_list
*s
= create_http_port(portspec
);
3108 s
->next
= Config
.Sockaddr
.http
;
3109 Config
.Sockaddr
.http
= s
;
3113 parse_http_port_list(http_port_list
** head
)
3115 char *token
= strtok(NULL
, w_space
);
3122 http_port_list
*s
= create_http_port(token
);
3124 /* parse options ... */
3125 while ((token
= strtok(NULL
, w_space
))) {
3126 parse_http_port_option(s
, token
);
3130 head
= &(*head
)->next
;
3136 dump_generic_http_port(StoreEntry
* e
, const char *n
, const http_port_list
* s
)
3138 char buf
[MAX_IPSTRLEN
];
3140 storeAppendPrintf(e
, "%s %s",
3142 s
->s
.ToURL(buf
,MAX_IPSTRLEN
));
3145 storeAppendPrintf(e
, " defaultsite=%s", s
->defaultsite
);
3148 storeAppendPrintf(e
, " intercept");
3151 storeAppendPrintf(e
, " vhost");
3154 storeAppendPrintf(e
, " vport");
3156 if (s
->connection_auth_disabled
)
3157 storeAppendPrintf(e
, " connection-auth=off");
3159 storeAppendPrintf(e
, " connection-auth=on");
3161 if (s
->disable_pmtu_discovery
!= DISABLE_PMTU_OFF
) {
3164 if (s
->disable_pmtu_discovery
== DISABLE_PMTU_ALWAYS
)
3167 pmtu
= "transparent";
3169 storeAppendPrintf(e
, " disable-pmtu-discovery=%s", pmtu
);
3172 if (s
->tcp_keepalive
.enabled
) {
3173 if (s
->tcp_keepalive
.idle
|| s
->tcp_keepalive
.interval
|| s
->tcp_keepalive
.timeout
) {
3174 storeAppendPrintf(e
, " tcp_keepalive=%d,%d,%d", s
->tcp_keepalive
.idle
, s
->tcp_keepalive
.interval
, s
->tcp_keepalive
.timeout
);
3176 storeAppendPrintf(e
, " tcp_keepalive");
3182 storeAppendPrintf(e
, " cert=%s", s
->cert
);
3185 storeAppendPrintf(e
, " key=%s", s
->key
);
3188 storeAppendPrintf(e
, " version=%d", s
->version
);
3191 storeAppendPrintf(e
, " options=%s", s
->options
);
3194 storeAppendPrintf(e
, " cipher=%s", s
->cipher
);
3197 storeAppendPrintf(e
, " cafile=%s", s
->cafile
);
3200 storeAppendPrintf(e
, " capath=%s", s
->capath
);
3203 storeAppendPrintf(e
, " crlfile=%s", s
->crlfile
);
3206 storeAppendPrintf(e
, " dhparams=%s", s
->dhfile
);
3209 storeAppendPrintf(e
, " sslflags=%s", s
->sslflags
);
3212 storeAppendPrintf(e
, " sslcontext=%s", s
->sslcontext
);
3215 storeAppendPrintf(e
, " sslBump");
3220 dump_http_port_list(StoreEntry
* e
, const char *n
, const http_port_list
* s
)
3223 dump_generic_http_port(e
, n
, s
);
3224 storeAppendPrintf(e
, "\n");
3230 free_http_port_list(http_port_list
** head
)
3234 while ((s
= *head
) != NULL
) {
3242 // TODO: merge better with parse_http_port_list
3244 parse_https_port_list(https_port_list
** head
)
3249 token
= strtok(NULL
, w_space
);
3254 s
= new https_port_list
;
3255 parse_http_port_specification(&s
->http
, token
);
3257 /* parse options ... */
3258 while ((token
= strtok(NULL
, w_space
))) {
3259 parse_http_port_option(s
, token
);
3263 http_port_list
** headTmp
= &(*head
)->http
.next
;
3264 head
= (https_port_list
**)headTmp
;
3271 dump_https_port_list(StoreEntry
* e
, const char *n
, const https_port_list
* s
)
3273 dump_http_port_list(e
, n
, s
);
3277 free_https_port_list(https_port_list
** head
)
3279 free_http_port_list((http_port_list
**)head
);
3284 check_null_https_port_list(const https_port_list
* s
)
3291 #endif /* USE_SSL */
3294 configFreeMemory(void)
3300 requirePathnameExists(const char *name
, const char *path
)
3304 char pathbuf
[BUFSIZ
];
3305 assert(path
!= NULL
);
3307 if (Config
.chroot_dir
&& (geteuid() == 0)) {
3308 snprintf(pathbuf
, BUFSIZ
, "%s/%s", Config
.chroot_dir
, path
);
3312 if (stat(path
, &sb
) < 0) {
3313 if (opt_send_signal
== -1 || opt_send_signal
== SIGHUP
)
3314 fatalf("%s %s: %s", name
, path
, xstrerror());
3316 fprintf(stderr
, "WARNING: %s %s: %s\n", name
, path
, xstrerror());
3323 return ConfigParser::strtokFile();
3326 #include "AccessLogEntry.h"
3327 /* TODO: split out parsing somehow ...*/
3329 parse_logformat(logformat
** logformat_definitions
)
3334 if ((name
= strtok(NULL
, w_space
)) == NULL
)
3337 if ((def
= strtok(NULL
, "\r\n")) == NULL
) {
3342 debugs(3, 2, "Logformat for '" << name
<< "' is '" << def
<< "'");
3344 nlf
= (logformat
*)xcalloc(1, sizeof(logformat
));
3346 nlf
->name
= xstrdup(name
);
3348 if (!accessLogParseLogFormat(&nlf
->format
, def
)) {
3353 nlf
->next
= *logformat_definitions
;
3355 *logformat_definitions
= nlf
;
3359 parse_access_log(customlog
** logs
)
3361 const char *filename
, *logdef_name
;
3365 cl
= (customlog
*)xcalloc(1, sizeof(*cl
));
3367 if ((filename
= strtok(NULL
, w_space
)) == NULL
) {
3372 if (strcmp(filename
, "none") == 0) {
3373 cl
->type
= CLF_NONE
;
3377 if ((logdef_name
= strtok(NULL
, w_space
)) == NULL
)
3378 logdef_name
= "auto";
3380 debugs(3, 9, "Log definition name '" << logdef_name
<< "' file '" << filename
<< "'");
3382 cl
->filename
= xstrdup(filename
);
3384 /* look for the definition pointer corresponding to this name */
3385 lf
= Config
.Log
.logformats
;
3387 while (lf
!= NULL
) {
3388 debugs(3, 9, "Comparing against '" << lf
->name
<< "'");
3390 if (strcmp(lf
->name
, logdef_name
) == 0)
3397 cl
->type
= CLF_CUSTOM
;
3399 } else if (strcmp(logdef_name
, "auto") == 0) {
3400 cl
->type
= CLF_AUTO
;
3401 } else if (strcmp(logdef_name
, "squid") == 0) {
3402 cl
->type
= CLF_SQUID
;
3403 } else if (strcmp(logdef_name
, "common") == 0) {
3404 cl
->type
= CLF_COMMON
;
3406 debugs(3, 0, "Log format '" << logdef_name
<< "' is not defined");
3412 aclParseAclList(LegacyParser
, &cl
->aclList
);
3415 logs
= &(*logs
)->next
;
3421 check_null_access_log(customlog
*customlog_definitions
)
3423 return customlog_definitions
== NULL
;
3427 dump_logformat(StoreEntry
* entry
, const char *name
, logformat
* definitions
)
3429 accessLogDumpLogFormat(entry
, name
, definitions
);
3433 dump_access_log(StoreEntry
* entry
, const char *name
, customlog
* logs
)
3437 for (log
= logs
; log
; log
= log
->next
) {
3438 storeAppendPrintf(entry
, "%s ", name
);
3440 switch (log
->type
) {
3443 storeAppendPrintf(entry
, "%s %s", log
->filename
, log
->logFormat
->name
);
3447 storeAppendPrintf(entry
, "none");
3451 storeAppendPrintf(entry
, "%s squid", log
->filename
);
3455 storeAppendPrintf(entry
, "%s squid", log
->filename
);
3461 storeAppendPrintf(entry
, "%s auto", log
->filename
);
3463 storeAppendPrintf(entry
, "%s", log
->filename
);
3472 dump_acl_list(entry
, log
->aclList
);
3474 storeAppendPrintf(entry
, "\n");
3479 free_logformat(logformat
** definitions
)
3481 while (*definitions
) {
3482 logformat
*format
= *definitions
;
3483 *definitions
= format
->next
;
3484 safe_free(format
->name
);
3485 accessLogFreeLogFormat(&format
->format
);
3491 free_access_log(customlog
** definitions
)
3493 while (*definitions
) {
3494 customlog
*log
= *definitions
;
3495 *definitions
= log
->next
;
3497 log
->logFormat
= NULL
;
3498 log
->type
= CLF_UNKNOWN
;
3501 aclDestroyAclList(&log
->aclList
);
3503 safe_free(log
->filename
);
3512 parse_adaptation_service_set_type()
3514 Adaptation::Config::ParseServiceSet();
3518 parse_adaptation_access_type()
3520 Adaptation::Config::ParseAccess(LegacyParser
);
3523 #endif /* USE_ADAPTATION */
3529 parse_icap_service_type(Adaptation::Icap::Config
* cfg
)
3531 cfg
->parseService();
3535 free_icap_service_type(Adaptation::Icap::Config
* cfg
)
3541 dump_icap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
3543 cfg
.dumpService(entry
, name
);
3547 parse_icap_class_type()
3549 debugs(93, 0, "WARNING: 'icap_class' is depricated. " <<
3550 "Use 'adaptation_service_set' instead");
3551 Adaptation::Config::ParseServiceSet();
3555 parse_icap_access_type()
3557 debugs(93, 0, "WARNING: 'icap_access' is depricated. " <<
3558 "Use 'adaptation_access' instead");
3559 Adaptation::Config::ParseAccess(LegacyParser
);
3568 parse_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
3570 cfg
->parseService();
3574 free_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
3580 dump_ecap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Ecap::Config
&cfg
)
3582 cfg
.dumpService(entry
, name
);
3585 #endif /* USE_ECAP */