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(Config
.Log
.log
, Config
.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 safe_free(debug_options
)
498 debug_options
= xstrdup(Config
.debugOptions
);
500 if (Config
.retry
.maxtries
> 10)
501 fatal("maximum_single_addr_tries cannot be larger than 10");
503 if (Config
.retry
.maxtries
< 1) {
504 debugs(3, 0, "WARNING: resetting 'maximum_single_addr_tries to 1");
505 Config
.retry
.maxtries
= 1;
508 requirePathnameExists("MIME Config Table", Config
.mimeTablePathname
);
511 requirePathnameExists("cache_dns_program", Config
.Program
.dnsserver
);
515 requirePathnameExists("unlinkd_program", Config
.Program
.unlinkd
);
518 if (Config
.Program
.redirect
)
519 requirePathnameExists("redirect_program", Config
.Program
.redirect
->key
);
521 requirePathnameExists("Icon Directory", Config
.icons
.directory
);
523 if (Config
.errorDirectory
)
524 requirePathnameExists("Error Directory", Config
.errorDirectory
);
531 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
532 if (!R
->flags
.override_expire
)
535 debugs(22, 1, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP");
540 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
541 if (!R
->flags
.override_lastmod
)
544 debugs(22, 1, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP");
549 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
550 if (!R
->flags
.reload_into_ims
)
553 debugs(22, 1, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP");
558 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
559 if (!R
->flags
.ignore_reload
)
562 debugs(22, 1, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP");
567 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
568 if (!R
->flags
.ignore_no_cache
)
571 debugs(22, 1, "WARNING: use of 'ignore-no-cache' in 'refresh_pattern' violates HTTP");
576 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
577 if (!R
->flags
.ignore_no_store
)
580 debugs(22, 1, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP");
585 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
586 if (!R
->flags
.ignore_private
)
589 debugs(22, 1, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP");
594 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
595 if (!R
->flags
.ignore_auth
)
598 debugs(22, 1, "WARNING: use of 'ignore-auth' in 'refresh_pattern' violates HTTP");
606 Config
.onoff
.via
= 1;
609 if (!Config
.onoff
.via
)
610 debugs(22, 1, "WARNING: HTTP requires the use of Via");
614 if (aclPurgeMethodInUse(Config
.accessList
.http
))
615 Config2
.onoff
.enable_purge
= 1;
617 Config2
.onoff
.mangle_request_headers
= httpReqHdrManglersConfigured();
619 if (geteuid() == 0) {
620 if (NULL
!= Config
.effectiveUser
) {
622 struct passwd
*pwd
= getpwnam(Config
.effectiveUser
);
626 * Andres Kroonmaa <andre@online.ee>:
627 * Some getpwnam() implementations (Solaris?) require
628 * an available FD < 256 for opening a FILE* to the
631 * This should be safe at startup, but might still fail
632 * during reconfigure.
634 fatalf("getpwnam failed to find userid for effective user '%s'",
635 Config
.effectiveUser
);
639 Config2
.effectiveUserID
= pwd
->pw_uid
;
641 Config2
.effectiveGroupID
= pwd
->pw_gid
;
645 if (pwd
->pw_dir
&& *pwd
->pw_dir
) {
647 char *env_str
= (char *)xcalloc((len
= strlen(pwd
->pw_dir
) + 6), 1);
648 snprintf(env_str
, len
, "HOME=%s", pwd
->pw_dir
);
656 Config2
.effectiveUserID
= geteuid();
657 Config2
.effectiveGroupID
= getegid();
660 if (NULL
!= Config
.effectiveGroup
) {
662 struct group
*grp
= getgrnam(Config
.effectiveGroup
);
665 fatalf("getgrnam failed to find groupid for effective group '%s'",
666 Config
.effectiveGroup
);
670 Config2
.effectiveGroupID
= grp
->gr_gid
;
673 HttpRequestMethod::Configure(Config
);
676 debugs(3, 1, "Initializing https proxy context");
678 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
);
684 for (p
= Config
.peers
; p
!= NULL
; p
= p
->next
) {
686 debugs(3, 1, "Initializing cache_peer " << p
->name
<< " SSL context");
687 p
->sslContext
= sslCreateClientContext(p
->sslcert
, p
->sslkey
, p
->sslversion
, p
->sslcipher
, p
->ssloptions
, p
->sslflags
, p
->sslcafile
, p
->sslcapath
, p
->sslcrlfile
);
696 for (s
= Config
.Sockaddr
.http
; s
!= NULL
; s
= (http_port_list
*) s
->next
) {
697 if (!s
->cert
&& !s
->key
)
700 debugs(3, 1, "Initializing http_port " << s
->http
.s
<< " SSL context");
702 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
);
710 for (s
= Config
.Sockaddr
.https
; s
!= NULL
; s
= (https_port_list
*) s
->http
.next
) {
711 debugs(3, 1, "Initializing https_port " << s
->http
.s
<< " SSL context");
713 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
);
720 /* Parse a time specification from the config file. Store the
721 * result in 'tptr', after converting it to 'units' */
723 parseTimeLine(time_t * tptr
, const char *units
)
730 if ((u
= parseTimeUnits(units
)) == 0)
733 if ((token
= strtok(NULL
, w_space
)) == NULL
)
738 m
= u
; /* default to 'units' if none specified */
742 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
743 debugs(3, 0, "WARNING: No units on '" <<
744 config_input_line
<< "', assuming " <<
746 else if ((m
= parseTimeUnits(token
)) == 0)
749 *tptr
= static_cast<time_t> (m
* d
/ u
);
753 parseTimeUnits(const char *unit
)
755 if (!strncasecmp(unit
, T_SECOND_STR
, strlen(T_SECOND_STR
)))
758 if (!strncasecmp(unit
, T_MINUTE_STR
, strlen(T_MINUTE_STR
)))
761 if (!strncasecmp(unit
, T_HOUR_STR
, strlen(T_HOUR_STR
)))
764 if (!strncasecmp(unit
, T_DAY_STR
, strlen(T_DAY_STR
)))
767 if (!strncasecmp(unit
, T_WEEK_STR
, strlen(T_WEEK_STR
)))
770 if (!strncasecmp(unit
, T_FORTNIGHT_STR
, strlen(T_FORTNIGHT_STR
)))
773 if (!strncasecmp(unit
, T_MONTH_STR
, strlen(T_MONTH_STR
)))
776 if (!strncasecmp(unit
, T_YEAR_STR
, strlen(T_YEAR_STR
)))
777 return static_cast<int>(86400 * 365.2522);
779 if (!strncasecmp(unit
, T_DECADE_STR
, strlen(T_DECADE_STR
)))
780 return static_cast<int>(86400 * 365.2522 * 10);
782 debugs(3, 1, "parseTimeUnits: unknown time unit '" << unit
<< "'");
788 parseBytesLine64(int64_t * bptr
, const char *units
)
795 if ((u
= parseBytesUnits(units
)) == 0) {
800 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
805 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
812 m
= u
; /* default to 'units' if none specified */
816 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
817 debugs(3, 0, "WARNING: No units on '" <<
818 config_input_line
<< "', assuming " <<
820 else if ((m
= parseBytesUnits(token
)) == 0) {
825 *bptr
= static_cast<int64_t>(m
* d
/ u
);
827 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
833 parseBytesLine(size_t * bptr
, const char *units
)
840 if ((u
= parseBytesUnits(units
)) == 0) {
845 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
850 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
851 *bptr
= static_cast<size_t>(-1);
857 m
= u
; /* default to 'units' if none specified */
861 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
862 debugs(3, 0, "WARNING: No units on '" <<
863 config_input_line
<< "', assuming " <<
865 else if ((m
= parseBytesUnits(token
)) == 0) {
870 *bptr
= static_cast<size_t>(m
* d
/ u
);
872 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
877 parseBytesUnits(const char *unit
)
879 if (!strncasecmp(unit
, B_BYTES_STR
, strlen(B_BYTES_STR
)))
882 if (!strncasecmp(unit
, B_KBYTES_STR
, strlen(B_KBYTES_STR
)))
885 if (!strncasecmp(unit
, B_MBYTES_STR
, strlen(B_MBYTES_STR
)))
888 if (!strncasecmp(unit
, B_GBYTES_STR
, strlen(B_GBYTES_STR
)))
891 debugs(3, DBG_CRITICAL
, "WARNING: Unknown bytes unit '" << unit
<< "'");
896 /*****************************************************************************
898 *****************************************************************************/
901 dump_acl(StoreEntry
* entry
, const char *name
, ACL
* ae
)
907 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
);
908 storeAppendPrintf(entry
, "%s %s %s ",
915 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
<< " " << v
->key
);
916 storeAppendPrintf(entry
, "%s ", v
->key
);
920 storeAppendPrintf(entry
, "\n");
929 ACL::ParseAclLine(LegacyParser
, ae
);
939 dump_acl_list(StoreEntry
* entry
, ACLList
* head
)
943 for (l
= head
; l
; l
= l
->next
) {
944 storeAppendPrintf(entry
, " %s%s",
945 l
->op
? null_string
: "!",
951 dump_acl_access(StoreEntry
* entry
, const char *name
, acl_access
* head
)
955 for (l
= head
; l
; l
= l
->next
) {
956 storeAppendPrintf(entry
, "%s %s",
958 l
->allow
? "Allow" : "Deny");
959 dump_acl_list(entry
, l
->aclList
);
960 storeAppendPrintf(entry
, "\n");
965 parse_acl_access(acl_access
** head
)
967 aclParseAccessLine(LegacyParser
, head
);
971 free_acl_access(acl_access
** head
)
973 aclDestroyAccessList(head
);
977 dump_address(StoreEntry
* entry
, const char *name
, IpAddress
&addr
)
979 char buf
[MAX_IPSTRLEN
];
980 storeAppendPrintf(entry
, "%s %s\n", name
, addr
.NtoA(buf
,MAX_IPSTRLEN
) );
984 parse_address(IpAddress
*addr
)
986 char *token
= strtok(NULL
, w_space
);
993 if (!strcmp(token
,"any_addr")) {
996 } else if ( (!strcmp(token
,"no_addr")) || (!strcmp(token
,"full_mask")) ) {
1004 free_address(IpAddress
*addr
)
1009 CBDATA_TYPE(acl_address
);
1012 dump_acl_address(StoreEntry
* entry
, const char *name
, acl_address
* head
)
1014 char buf
[MAX_IPSTRLEN
];
1017 for (l
= head
; l
; l
= l
->next
) {
1018 if (!l
->addr
.IsAnyAddr())
1019 storeAppendPrintf(entry
, "%s %s", name
, l
->addr
.NtoA(buf
,MAX_IPSTRLEN
));
1021 storeAppendPrintf(entry
, "%s autoselect", name
);
1023 dump_acl_list(entry
, l
->aclList
);
1025 storeAppendPrintf(entry
, "\n");
1030 freed_acl_address(void *data
)
1032 acl_address
*l
= static_cast<acl_address
*>(data
);
1033 aclDestroyAclList(&l
->aclList
);
1037 parse_acl_address(acl_address
** head
)
1040 acl_address
**tail
= head
; /* sane name below */
1041 CBDATA_INIT_TYPE_FREECB(acl_address
, freed_acl_address
);
1042 l
= cbdataAlloc(acl_address
);
1043 parse_address(&l
->addr
);
1044 aclParseAclList(LegacyParser
, &l
->aclList
);
1047 tail
= &(*tail
)->next
;
1053 free_acl_address(acl_address
** head
)
1056 acl_address
*l
= *head
;
1062 CBDATA_TYPE(acl_tos
);
1065 dump_acl_tos(StoreEntry
* entry
, const char *name
, acl_tos
* head
)
1069 for (l
= head
; l
; l
= l
->next
) {
1071 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->tos
);
1073 storeAppendPrintf(entry
, "%s none", name
);
1075 dump_acl_list(entry
, l
->aclList
);
1077 storeAppendPrintf(entry
, "\n");
1082 freed_acl_tos(void *data
)
1084 acl_tos
*l
= static_cast<acl_tos
*>(data
);
1085 aclDestroyAclList(&l
->aclList
);
1089 parse_acl_tos(acl_tos
** head
)
1092 acl_tos
**tail
= head
; /* sane name below */
1095 char *token
= strtok(NULL
, w_space
);
1102 if (sscanf(token
, "0x%x%c", &tos
, &junk
) != 1) {
1107 if (tos
< 0 || tos
> 255) {
1112 CBDATA_INIT_TYPE_FREECB(acl_tos
, freed_acl_tos
);
1114 l
= cbdataAlloc(acl_tos
);
1118 aclParseAclList(LegacyParser
, &l
->aclList
);
1121 tail
= &(*tail
)->next
;
1127 free_acl_tos(acl_tos
** head
)
1137 CBDATA_TYPE(acl_size_t
);
1140 dump_acl_b_size_t(StoreEntry
* entry
, const char *name
, acl_size_t
* head
)
1144 for (l
= head
; l
; l
= l
->next
) {
1146 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) l
->size
, B_BYTES_STR
);
1148 storeAppendPrintf(entry
, "%s none", name
);
1150 dump_acl_list(entry
, l
->aclList
);
1152 storeAppendPrintf(entry
, "\n");
1157 freed_acl_b_size_t(void *data
)
1159 acl_size_t
*l
= static_cast<acl_size_t
*>(data
);
1160 aclDestroyAclList(&l
->aclList
);
1164 parse_acl_b_size_t(acl_size_t
** head
)
1167 acl_size_t
**tail
= head
; /* sane name below */
1169 CBDATA_INIT_TYPE_FREECB(acl_size_t
, freed_acl_b_size_t
);
1171 l
= cbdataAlloc(acl_size_t
);
1173 parse_b_int64_t(&l
->size
);
1175 aclParseAclList(LegacyParser
, &l
->aclList
);
1178 tail
= &(*tail
)->next
;
1184 free_acl_b_size_t(acl_size_t
** head
)
1187 acl_size_t
*l
= *head
;
1196 #include "DelayPools.h"
1197 #include "DelayConfig.h"
1198 /* do nothing - free_delay_pool_count is the magic free function.
1199 * this is why delay_pool_count isn't just marked TYPE: ushort
1201 #define free_delay_pool_class(X)
1202 #define free_delay_pool_access(X)
1203 #define free_delay_pool_rates(X)
1204 #define dump_delay_pool_class(X, Y, Z)
1205 #define dump_delay_pool_access(X, Y, Z)
1206 #define dump_delay_pool_rates(X, Y, Z)
1209 free_delay_pool_count(DelayConfig
* cfg
)
1211 cfg
->freePoolCount();
1215 dump_delay_pool_count(StoreEntry
* entry
, const char *name
, DelayConfig
&cfg
)
1217 cfg
.dumpPoolCount (entry
, name
);
1221 parse_delay_pool_count(DelayConfig
* cfg
)
1223 cfg
->parsePoolCount();
1227 parse_delay_pool_class(DelayConfig
* cfg
)
1229 cfg
->parsePoolClass();
1233 parse_delay_pool_rates(DelayConfig
* cfg
)
1235 cfg
->parsePoolRates();
1239 parse_delay_pool_access(DelayConfig
* cfg
)
1241 cfg
->parsePoolAccess(LegacyParser
);
1248 dump_http_header_access(StoreEntry
* entry
, const char *name
, header_mangler header
[])
1252 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1253 if (header
[i
].access_list
!= NULL
) {
1254 storeAppendPrintf(entry
, "%s ", name
);
1255 dump_acl_access(entry
, httpHeaderNameById(i
),
1256 header
[i
].access_list
);
1262 parse_http_header_access(header_mangler header
[])
1267 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1268 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1269 debugs(3, 0, "parse_http_header_access: missing header name.");
1273 /* Now lookup index of header. */
1274 id
= httpHeaderIdByNameDef(t
, strlen(t
));
1276 if (strcmp(t
, "All") == 0)
1278 else if (strcmp(t
, "Other") == 0)
1280 else if (id
== -1) {
1281 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1282 debugs(3, 0, "parse_http_header_access: unknown header name '" << t
<< "'");
1286 if (id
!= HDR_ENUM_END
) {
1287 parse_acl_access(&header
[id
].access_list
);
1289 char *next_string
= t
+ strlen(t
) - 1;
1291 *(next_string
+ 1) = ' ';
1293 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1294 char *new_string
= xstrdup(next_string
);
1295 strtok(new_string
, w_space
);
1296 parse_acl_access(&header
[i
].access_list
);
1297 safe_free(new_string
);
1303 free_http_header_access(header_mangler header
[])
1307 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1308 free_acl_access(&header
[i
].access_list
);
1313 dump_http_header_replace(StoreEntry
* entry
, const char *name
, header_mangler
1318 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1319 if (NULL
== header
[i
].replacement
)
1322 storeAppendPrintf(entry
, "%s %s %s\n", name
, httpHeaderNameById(i
),
1323 header
[i
].replacement
);
1328 parse_http_header_replace(header_mangler header
[])
1333 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1334 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1335 debugs(3, 0, "parse_http_header_replace: missing header name.");
1339 /* Now lookup index of header. */
1340 id
= httpHeaderIdByNameDef(t
, strlen(t
));
1342 if (strcmp(t
, "All") == 0)
1344 else if (strcmp(t
, "Other") == 0)
1346 else if (id
== -1) {
1347 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1348 debugs(3, 0, "parse_http_header_replace: unknown header name " << t
<< ".");
1353 if (id
!= HDR_ENUM_END
) {
1354 if (header
[id
].replacement
!= NULL
)
1355 safe_free(header
[id
].replacement
);
1357 header
[id
].replacement
= xstrdup(t
+ strlen(t
) + 1);
1359 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1360 if (header
[i
].replacement
!= NULL
)
1361 safe_free(header
[i
].replacement
);
1363 header
[i
].replacement
= xstrdup(t
+ strlen(t
) + 1);
1369 free_http_header_replace(header_mangler header
[])
1373 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1374 if (header
[i
].replacement
!= NULL
)
1375 safe_free(header
[i
].replacement
);
1382 dump_cachedir(StoreEntry
* entry
, const char *name
, SquidConfig::_cacheSwap swap
)
1388 for (i
= 0; i
< swap
.n_configured
; i
++) {
1389 s
= dynamic_cast<SwapDir
*>(swap
.swapDirs
[i
].getRaw());
1391 storeAppendPrintf(entry
, "%s %s %s", name
, s
->type(), s
->path
);
1393 storeAppendPrintf(entry
, "\n");
1398 check_null_string(char *s
)
1404 parse_authparam(authConfig
* config
)
1409 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1412 if ((param_str
= strtok(NULL
, w_space
)) == NULL
)
1415 /* find a configuration for the scheme */
1416 AuthConfig
*scheme
= AuthConfig::Find (type_str
);
1418 if (scheme
== NULL
) {
1419 /* Create a configuration */
1420 AuthScheme
*theScheme
;
1422 if ((theScheme
= AuthScheme::Find(type_str
)) == NULL
) {
1423 debugs(3, 0, "Parsing Config File: Unknown authentication scheme '" << type_str
<< "'.");
1427 config
->push_back(theScheme
->createConfig());
1428 scheme
= config
->back();
1432 scheme
->parse(scheme
, config
->size(), param_str
);
1436 free_authparam(authConfig
* cfg
)
1439 /* DON'T FREE THESE FOR RECONFIGURE */
1444 while (cfg
->size()) {
1445 scheme
= cfg
->pop_back();
1451 dump_authparam(StoreEntry
* entry
, const char *name
, authConfig cfg
)
1453 for (authConfig::iterator i
= cfg
.begin(); i
!= cfg
.end(); ++i
)
1454 (*i
)->dump(entry
, name
, (*i
));
1457 /* TODO: just return the object, the # is irrelevant */
1459 find_fstype(char *type
)
1461 for (size_t i
= 0; i
< StoreFileSystem::FileSystems().size(); ++i
)
1462 if (strcasecmp(type
, StoreFileSystem::FileSystems().items
[i
]->type()) == 0)
1469 parse_cachedir(SquidConfig::_cacheSwap
* swap
)
1473 RefCount
<SwapDir
> sd
;
1477 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1480 if ((path_str
= strtok(NULL
, w_space
)) == NULL
)
1483 fs
= find_fstype(type_str
);
1488 /* reconfigure existing dir */
1490 for (i
= 0; i
< swap
->n_configured
; i
++) {
1491 assert (swap
->swapDirs
[i
].getRaw());
1493 if ((strcasecmp(path_str
, dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw())->path
)) == 0) {
1494 /* this is specific to on-fs Stores. The right
1495 * way to handle this is probably to have a mapping
1496 * from paths to stores, and have on-fs stores
1497 * register with that, and lookip in that in their
1498 * own setup logic. RBC 20041225. TODO.
1501 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw());
1503 if (sd
->type() != StoreFileSystem::FileSystems().items
[fs
]->type()) {
1504 debugs(3, 0, "ERROR: Can't change type of existing cache_dir " <<
1505 sd
->type() << " " << sd
->path
<< " to " << type_str
<< ". Restart required");
1509 sd
->reconfigure (i
, path_str
);
1511 update_maxobjsize();
1518 if (swap
->n_configured
> 63) {
1519 /* 7 bits, signed */
1520 debugs(3, DBG_CRITICAL
, "WARNING: There is a fixed maximum of 63 cache_dir entries Squid can handle.");
1521 debugs(3, DBG_CRITICAL
, "WARNING: '" << path_str
<< "' is one to many.");
1526 allocate_new_swapdir(swap
);
1528 swap
->swapDirs
[swap
->n_configured
] = StoreFileSystem::FileSystems().items
[fs
]->createSwapDir();
1530 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[swap
->n_configured
].getRaw());
1532 /* parse the FS parameters and options */
1533 sd
->parse(swap
->n_configured
, path_str
);
1535 ++swap
->n_configured
;
1537 /* Update the max object size */
1538 update_maxobjsize();
1542 peer_type_str(const peer_t type
)
1544 const char * result
;
1556 case PEER_MULTICAST
:
1557 result
= "multicast";
1569 dump_peer(StoreEntry
* entry
, const char *name
, peer
* p
)
1573 LOCAL_ARRAY(char, xname
, 128);
1576 storeAppendPrintf(entry
, "%s %s %s %d %d",
1582 dump_peer_options(entry
, p
);
1584 for (d
= p
->peer_domain
; d
; d
= d
->next
) {
1585 storeAppendPrintf(entry
, "cache_peer_domain %s %s%s\n",
1587 d
->do_ping
? null_string
: "!",
1592 snprintf(xname
, 128, "cache_peer_access %s", p
->name
);
1593 dump_acl_access(entry
, xname
, p
->access
);
1596 for (t
= p
->typelist
; t
; t
= t
->next
) {
1597 storeAppendPrintf(entry
, "neighbor_type_domain %s %s %s\n",
1599 peer_type_str(t
->type
),
1608 \param proto 'tcp' or 'udp' for protocol
1609 \returns Port the named service is supposed to be listening on.
1612 GetService(const char *proto
)
1614 struct servent
*port
= NULL
;
1615 /** Parses a port number or service name from the squid.conf */
1616 char *token
= strtok(NULL
, w_space
);
1617 if (token
== NULL
) {
1619 return 0; /* NEVER REACHED */
1621 /** Returns either the service port number from /etc/services */
1622 port
= getservbyname(token
, proto
);
1624 return ntohs((u_short
)port
->s_port
);
1626 /** Or a numeric translation of the config text. */
1627 return xatos(token
);
1631 \returns Port the named TCP service is supposed to be listening on.
1632 \copydoc GetService(const char *proto)
1637 return GetService("tcp");
1641 \returns Port the named UDP service is supposed to be listening on.
1642 \copydoc GetService(const char *proto)
1647 return GetService("udp");
1651 parse_peer(peer
** head
)
1655 CBDATA_INIT_TYPE_FREECB(peer
, peerDestroy
);
1656 p
= cbdataAlloc(peer
);
1657 p
->http_port
= CACHE_HTTP_PORT
;
1658 p
->icp
.port
= CACHE_ICP_PORT
;
1661 p
->stats
.logged_state
= PEER_ALIVE
;
1663 if ((token
= strtok(NULL
, w_space
)) == NULL
)
1666 p
->host
= xstrdup(token
);
1668 p
->name
= xstrdup(token
);
1670 if ((token
= strtok(NULL
, w_space
)) == NULL
)
1673 p
->type
= parseNeighborType(token
);
1675 if (p
->type
== PEER_MULTICAST
) {
1676 p
->options
.no_digest
= 1;
1677 p
->options
.no_netdb_exchange
= 1;
1680 p
->http_port
= GetTcpService();
1685 p
->icp
.port
= GetUdpService();
1686 p
->connection_auth
= 2; /* auto */
1688 while ((token
= strtok(NULL
, w_space
))) {
1689 if (!strcasecmp(token
, "proxy-only")) {
1690 p
->options
.proxy_only
= 1;
1691 } else if (!strcasecmp(token
, "no-query")) {
1692 p
->options
.no_query
= 1;
1693 } else if (!strcasecmp(token
, "background-ping")) {
1694 p
->options
.background_ping
= 1;
1695 } else if (!strcasecmp(token
, "no-digest")) {
1696 p
->options
.no_digest
= 1;
1697 } else if (!strcasecmp(token
, "multicast-responder")) {
1698 p
->options
.mcast_responder
= 1;
1699 } else if (!strncasecmp(token
, "weight=", 7)) {
1700 p
->weight
= xatoi(token
+ 7);
1701 } else if (!strncasecmp(token
, "basetime=", 9)) {
1702 p
->basetime
= xatoi(token
+ 9);
1703 } else if (!strcasecmp(token
, "closest-only")) {
1704 p
->options
.closest_only
= 1;
1705 } else if (!strncasecmp(token
, "ttl=", 4)) {
1706 p
->mcast
.ttl
= xatoi(token
+ 4);
1708 if (p
->mcast
.ttl
< 0)
1711 if (p
->mcast
.ttl
> 128)
1713 } else if (!strcasecmp(token
, "default")) {
1714 p
->options
.default_parent
= 1;
1715 } else if (!strcasecmp(token
, "round-robin")) {
1716 p
->options
.roundrobin
= 1;
1717 } else if (!strcasecmp(token
, "weighted-round-robin")) {
1718 p
->options
.weighted_roundrobin
= 1;
1721 } else if (!strcasecmp(token
, "htcp")) {
1722 p
->options
.htcp
= 1;
1723 } else if (!strcasecmp(token
, "htcp-oldsquid")) {
1724 p
->options
.htcp
= 1;
1725 p
->options
.htcp_oldsquid
= 1;
1726 } else if (!strcasecmp(token
, "htcp-no-clr")) {
1727 if (p
->options
.htcp_only_clr
)
1728 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
1729 p
->options
.htcp
= 1;
1730 p
->options
.htcp_no_clr
= 1;
1731 } else if (!strcasecmp(token
, "htcp-no-purge-clr")) {
1732 p
->options
.htcp
= 1;
1733 p
->options
.htcp_no_purge_clr
= 1;
1734 } else if (!strcasecmp(token
, "htcp-only-clr")) {
1735 if (p
->options
.htcp_no_clr
)
1736 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
1737 p
->options
.htcp
= 1;
1738 p
->options
.htcp_only_clr
= 1;
1739 } else if (!strcasecmp(token
, "htcp-forward-clr")) {
1740 p
->options
.htcp
= 1;
1741 p
->options
.htcp_forward_clr
= 1;
1744 } else if (!strcasecmp(token
, "no-netdb-exchange")) {
1745 p
->options
.no_netdb_exchange
= 1;
1747 } else if (!strcasecmp(token
, "carp")) {
1748 if (p
->type
!= PEER_PARENT
)
1749 fatalf("parse_peer: non-parent carp peer %s/%d\n", p
->host
, p
->http_port
);
1751 p
->options
.carp
= 1;
1753 } else if (!strcasecmp(token
, "userhash")) {
1754 if (p
->type
!= PEER_PARENT
)
1755 fatalf("parse_peer: non-parent userhash peer %s/%d\n", p
->host
, p
->http_port
);
1757 p
->options
.userhash
= 1;
1759 } else if (!strcasecmp(token
, "sourcehash")) {
1760 if (p
->type
!= PEER_PARENT
)
1761 fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p
->host
, p
->http_port
);
1763 p
->options
.sourcehash
= 1;
1767 } else if (!strcasecmp(token
, "no-delay")) {
1768 p
->options
.no_delay
= 1;
1771 } else if (!strncasecmp(token
, "login=", 6)) {
1772 p
->login
= xstrdup(token
+ 6);
1773 rfc1738_unescape(p
->login
);
1774 } else if (!strncasecmp(token
, "connect-timeout=", 16)) {
1775 p
->connect_timeout
= xatoi(token
+ 16);
1776 #if USE_CACHE_DIGESTS
1778 } else if (!strncasecmp(token
, "digest-url=", 11)) {
1779 p
->digest_url
= xstrdup(token
+ 11);
1782 } else if (!strcasecmp(token
, "allow-miss")) {
1783 p
->options
.allow_miss
= 1;
1784 } else if (!strncasecmp(token
, "max-conn=", 9)) {
1785 p
->max_conn
= xatoi(token
+ 9);
1786 } else if (!strcasecmp(token
, "originserver")) {
1787 p
->options
.originserver
= 1;
1788 } else if (!strncasecmp(token
, "name=", 5)) {
1792 p
->name
= xstrdup(token
+ 5);
1793 } else if (!strncasecmp(token
, "forceddomain=", 13)) {
1794 safe_free(p
->domain
);
1797 p
->domain
= xstrdup(token
+ 13);
1801 } else if (strcmp(token
, "ssl") == 0) {
1803 } else if (strncmp(token
, "sslcert=", 8) == 0) {
1804 safe_free(p
->sslcert
);
1805 p
->sslcert
= xstrdup(token
+ 8);
1806 } else if (strncmp(token
, "sslkey=", 7) == 0) {
1807 safe_free(p
->sslkey
);
1808 p
->sslkey
= xstrdup(token
+ 7);
1809 } else if (strncmp(token
, "sslversion=", 11) == 0) {
1810 p
->sslversion
= atoi(token
+ 11);
1811 } else if (strncmp(token
, "ssloptions=", 11) == 0) {
1812 safe_free(p
->ssloptions
);
1813 p
->ssloptions
= xstrdup(token
+ 11);
1814 } else if (strncmp(token
, "sslcipher=", 10) == 0) {
1815 safe_free(p
->sslcipher
);
1816 p
->sslcipher
= xstrdup(token
+ 10);
1817 } else if (strncmp(token
, "sslcafile=", 10) == 0) {
1818 safe_free(p
->sslcafile
);
1819 p
->sslcafile
= xstrdup(token
+ 10);
1820 } else if (strncmp(token
, "sslcapath=", 10) == 0) {
1821 safe_free(p
->sslcapath
);
1822 p
->sslcapath
= xstrdup(token
+ 10);
1823 } else if (strncmp(token
, "sslcrlfile=", 11) == 0) {
1824 safe_free(p
->sslcrlfile
);
1825 p
->sslcapath
= xstrdup(token
+ 10);
1826 } else if (strncmp(token
, "sslflags=", 9) == 0) {
1827 safe_free(p
->sslflags
);
1828 p
->sslflags
= xstrdup(token
+ 9);
1829 } else if (strncmp(token
, "ssldomain=", 10) == 0) {
1830 safe_free(p
->ssldomain
);
1831 p
->ssldomain
= xstrdup(token
+ 10);
1834 } else if (strcmp(token
, "front-end-https") == 0) {
1835 p
->front_end_https
= 1;
1836 } else if (strcmp(token
, "front-end-https=on") == 0) {
1837 p
->front_end_https
= 1;
1838 } else if (strcmp(token
, "front-end-https=auto") == 0) {
1839 p
->front_end_https
= 2;
1840 } else if (strcmp(token
, "connection-auth=off") == 0) {
1841 p
->connection_auth
= 0;
1842 } else if (strcmp(token
, "connection-auth") == 0) {
1843 p
->connection_auth
= 1;
1844 } else if (strcmp(token
, "connection-auth=on") == 0) {
1845 p
->connection_auth
= 1;
1846 } else if (strcmp(token
, "connection-auth=auto") == 0) {
1847 p
->connection_auth
= 2;
1849 debugs(3, 0, "parse_peer: token='" << token
<< "'");
1854 if (peerFindByName(p
->name
))
1855 fatalf("ERROR: cache_peer %s specified twice\n", p
->name
);
1860 p
->icp
.version
= ICP_VERSION_CURRENT
;
1864 #if USE_CACHE_DIGESTS
1866 if (!p
->options
.no_digest
) {
1867 /* XXX This looks odd.. who has the original pointer
1870 PeerDigest
*pd
= peerDigestCreate(p
);
1871 p
->digest
= cbdataReference(pd
);
1876 p
->index
= ++Config
.npeers
;
1878 while (*head
!= NULL
)
1879 head
= &(*head
)->next
;
1887 free_peer(peer
** P
)
1891 while ((p
= *P
) != NULL
) {
1893 #if USE_CACHE_DIGESTS
1895 cbdataReferenceDone(p
->digest
);
1905 dump_cachemgrpasswd(StoreEntry
* entry
, const char *name
, cachemgr_passwd
* list
)
1909 while (list
!= NULL
) {
1910 if (strcmp(list
->passwd
, "none") && strcmp(list
->passwd
, "disable"))
1911 storeAppendPrintf(entry
, "%s XXXXXXXXXX", name
);
1913 storeAppendPrintf(entry
, "%s %s", name
, list
->passwd
);
1915 for (w
= list
->actions
; w
!= NULL
; w
= w
->next
) {
1916 storeAppendPrintf(entry
, " %s", w
->key
);
1919 storeAppendPrintf(entry
, "\n");
1925 parse_cachemgrpasswd(cachemgr_passwd
** head
)
1927 char *passwd
= NULL
;
1928 wordlist
*actions
= NULL
;
1930 cachemgr_passwd
**P
;
1931 parse_string(&passwd
);
1932 parse_wordlist(&actions
);
1933 p
= static_cast<cachemgr_passwd
*>(xcalloc(1, sizeof(cachemgr_passwd
)));
1935 p
->actions
= actions
;
1937 for (P
= head
; *P
; P
= &(*P
)->next
) {
1939 * See if any of the actions from this line already have a
1940 * password from previous lines. The password checking
1941 * routines in cache_manager.c take the the password from
1942 * the first cachemgr_passwd struct that contains the
1943 * requested action. Thus, we should warn users who might
1944 * think they can have two passwords for the same action.
1949 for (w
= (*P
)->actions
; w
; w
= w
->next
) {
1950 for (u
= actions
; u
; u
= u
->next
) {
1951 if (strcmp(w
->key
, u
->key
))
1954 debugs(0, 0, "WARNING: action '" << u
->key
<< "' (line " << config_lineno
<< ") already has a password");
1963 free_cachemgrpasswd(cachemgr_passwd
** head
)
1967 while ((p
= *head
) != NULL
) {
1970 wordlistDestroy(&p
->actions
);
1976 dump_denyinfo(StoreEntry
* entry
, const char *name
, acl_deny_info_list
* var
)
1980 while (var
!= NULL
) {
1981 storeAppendPrintf(entry
, "%s %s", name
, var
->err_page_name
);
1983 for (a
= var
->acl_list
; a
!= NULL
; a
= a
->next
)
1984 storeAppendPrintf(entry
, " %s", a
->name
);
1986 storeAppendPrintf(entry
, "\n");
1993 parse_denyinfo(acl_deny_info_list
** var
)
1995 aclParseDenyInfoLine(var
);
1999 free_denyinfo(acl_deny_info_list
** list
)
2001 acl_deny_info_list
*a
= NULL
;
2002 acl_deny_info_list
*a_next
= NULL
;
2003 acl_name_list
*l
= NULL
;
2004 acl_name_list
*l_next
= NULL
;
2006 for (a
= *list
; a
; a
= a_next
) {
2007 for (l
= a
->acl_list
; l
; l
= l_next
) {
2009 memFree(l
, MEM_ACL_NAME_LIST
);
2014 memFree(a
, MEM_ACL_DENY_INFO_LIST
);
2022 parse_peer_access(void)
2027 if (!(host
= strtok(NULL
, w_space
)))
2030 if ((p
= peerFindByName(host
)) == NULL
) {
2031 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2035 aclParseAccessLine(LegacyParser
, &p
->access
);
2039 parse_hostdomain(void)
2042 char *domain
= NULL
;
2044 if (!(host
= strtok(NULL
, w_space
)))
2047 while ((domain
= strtok(NULL
, list_sep
))) {
2048 domain_ping
*l
= NULL
;
2049 domain_ping
**L
= NULL
;
2052 if ((p
= peerFindByName(host
)) == NULL
) {
2053 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2057 l
= static_cast<domain_ping
*>(xcalloc(1, sizeof(domain_ping
)));
2060 if (*domain
== '!') { /* check for !.edu */
2065 l
->domain
= xstrdup(domain
);
2067 for (L
= &(p
->peer_domain
); *L
; L
= &((*L
)->next
));
2073 parse_hostdomaintype(void)
2077 char *domain
= NULL
;
2079 if (!(host
= strtok(NULL
, w_space
)))
2082 if (!(type
= strtok(NULL
, w_space
)))
2085 while ((domain
= strtok(NULL
, list_sep
))) {
2086 domain_type
*l
= NULL
;
2087 domain_type
**L
= NULL
;
2090 if ((p
= peerFindByName(host
)) == NULL
) {
2091 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2095 l
= static_cast<domain_type
*>(xcalloc(1, sizeof(domain_type
)));
2096 l
->type
= parseNeighborType(type
);
2097 l
->domain
= xstrdup(domain
);
2099 for (L
= &(p
->typelist
); *L
; L
= &((*L
)->next
));
2105 dump_int(StoreEntry
* entry
, const char *name
, int var
)
2107 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2125 dump_onoff(StoreEntry
* entry
, const char *name
, int var
)
2127 storeAppendPrintf(entry
, "%s %s\n", name
, var
? "on" : "off");
2131 parse_onoff(int *var
)
2133 char *token
= strtok(NULL
, w_space
);
2138 if (!strcasecmp(token
, "on") || !strcasecmp(token
, "enable"))
2144 #define free_onoff free_int
2147 dump_tristate(StoreEntry
* entry
, const char *name
, int var
)
2158 storeAppendPrintf(entry
, "%s %s\n", name
, state
);
2162 parse_tristate(int *var
)
2164 char *token
= strtok(NULL
, w_space
);
2169 if (!strcasecmp(token
, "on") || !strcasecmp(token
, "enable"))
2171 else if (!strcasecmp(token
, "warn"))
2177 #define free_tristate free_int
2180 dump_refreshpattern(StoreEntry
* entry
, const char *name
, refresh_t
* head
)
2182 while (head
!= NULL
) {
2183 storeAppendPrintf(entry
, "%s%s %s %d %d%% %d\n",
2185 head
->flags
.icase
? " -i" : null_string
,
2187 (int) head
->min
/ 60,
2188 (int) (100.0 * head
->pct
+ 0.5),
2189 (int) head
->max
/ 60);
2191 if (head
->flags
.refresh_ims
)
2192 storeAppendPrintf(entry
, " refresh-ims");
2196 if (head
->flags
.override_expire
)
2197 storeAppendPrintf(entry
, " override-expire");
2199 if (head
->flags
.override_lastmod
)
2200 storeAppendPrintf(entry
, " override-lastmod");
2202 if (head
->flags
.reload_into_ims
)
2203 storeAppendPrintf(entry
, " reload-into-ims");
2205 if (head
->flags
.ignore_reload
)
2206 storeAppendPrintf(entry
, " ignore-reload");
2208 if (head
->flags
.ignore_no_cache
)
2209 storeAppendPrintf(entry
, " ignore-no-cache");
2211 if (head
->flags
.ignore_no_store
)
2212 storeAppendPrintf(entry
, " ignore-no-store");
2214 if (head
->flags
.ignore_private
)
2215 storeAppendPrintf(entry
, " ignore-private");
2217 if (head
->flags
.ignore_auth
)
2218 storeAppendPrintf(entry
, " ignore-auth");
2222 storeAppendPrintf(entry
, "\n");
2229 parse_refreshpattern(refresh_t
** head
)
2236 int refresh_ims
= 0;
2239 int override_expire
= 0;
2240 int override_lastmod
= 0;
2241 int reload_into_ims
= 0;
2242 int ignore_reload
= 0;
2243 int ignore_no_cache
= 0;
2244 int ignore_no_store
= 0;
2245 int ignore_private
= 0;
2246 int ignore_auth
= 0;
2253 int flags
= REG_EXTENDED
| REG_NOSUB
;
2255 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
2260 if (strcmp(token
, "-i") == 0) {
2262 token
= strtok(NULL
, w_space
);
2263 } else if (strcmp(token
, "+i") == 0) {
2264 flags
&= ~REG_ICASE
;
2265 token
= strtok(NULL
, w_space
);
2268 if (token
== NULL
) {
2273 pattern
= xstrdup(token
);
2275 i
= GetInteger(); /* token: min */
2277 min
= (time_t) (i
* 60); /* convert minutes to seconds */
2279 i
= GetInteger(); /* token: pct */
2281 pct
= (double) i
/ 100.0;
2283 i
= GetInteger(); /* token: max */
2285 max
= (time_t) (i
* 60); /* convert minutes to seconds */
2288 while ((token
= strtok(NULL
, w_space
)) != NULL
) {
2289 if (!strcmp(token
, "refresh-ims")) {
2293 } else if (!strcmp(token
, "override-expire"))
2294 override_expire
= 1;
2295 else if (!strcmp(token
, "override-lastmod"))
2296 override_lastmod
= 1;
2297 else if (!strcmp(token
, "ignore-no-cache"))
2298 ignore_no_cache
= 1;
2299 else if (!strcmp(token
, "ignore-no-store"))
2300 ignore_no_store
= 1;
2301 else if (!strcmp(token
, "ignore-private"))
2303 else if (!strcmp(token
, "ignore-auth"))
2305 else if (!strcmp(token
, "reload-into-ims")) {
2306 reload_into_ims
= 1;
2307 refresh_nocache_hack
= 1;
2308 /* tell client_side.c that this is used */
2309 } else if (!strcmp(token
, "ignore-reload")) {
2311 refresh_nocache_hack
= 1;
2312 /* tell client_side.c that this is used */
2316 debugs(22, 0, "redreshAddToList: Unknown option '" << pattern
<< "': " << token
);
2319 if ((errcode
= regcomp(&comp
, pattern
, flags
)) != 0) {
2321 regerror(errcode
, &comp
, errbuf
, sizeof errbuf
);
2322 debugs(22, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
2323 debugs(22, 0, "refreshAddToList: Invalid regular expression '" << pattern
<< "': " << errbuf
);
2327 pct
= pct
< 0.0 ? 0.0 : pct
;
2328 max
= max
< 0 ? 0 : max
;
2329 t
= static_cast<refresh_t
*>(xcalloc(1, sizeof(refresh_t
)));
2330 t
->pattern
= (char *) xstrdup(pattern
);
2331 t
->compiled_pattern
= comp
;
2336 if (flags
& REG_ICASE
)
2340 t
->flags
.refresh_ims
= 1;
2344 if (override_expire
)
2345 t
->flags
.override_expire
= 1;
2347 if (override_lastmod
)
2348 t
->flags
.override_lastmod
= 1;
2350 if (reload_into_ims
)
2351 t
->flags
.reload_into_ims
= 1;
2354 t
->flags
.ignore_reload
= 1;
2356 if (ignore_no_cache
)
2357 t
->flags
.ignore_no_cache
= 1;
2359 if (ignore_no_store
)
2360 t
->flags
.ignore_no_store
= 1;
2363 t
->flags
.ignore_private
= 1;
2366 t
->flags
.ignore_auth
= 1;
2373 head
= &(*head
)->next
;
2381 free_refreshpattern(refresh_t
** head
)
2385 while ((t
= *head
) != NULL
) {
2387 safe_free(t
->pattern
);
2388 regfree(&t
->compiled_pattern
);
2393 refresh_nocache_hack
= 0;
2399 dump_string(StoreEntry
* entry
, const char *name
, char *var
)
2402 storeAppendPrintf(entry
, "%s %s\n", name
, var
);
2406 parse_string(char **var
)
2408 char *token
= strtok(NULL
, w_space
);
2414 *var
= xstrdup(token
);
2418 ConfigParser::ParseString(char **var
)
2424 ConfigParser::ParseString(String
*var
)
2426 char *token
= strtok(NULL
, w_space
);
2435 free_string(char **var
)
2441 parse_eol(char *volatile *var
)
2443 unsigned char *token
= (unsigned char *) strtok(NULL
, null_string
);
2451 while (*token
&& xisspace(*token
))
2459 *var
= xstrdup((char *) token
);
2462 #define dump_eol dump_string
2463 #define free_eol free_string
2466 dump_time_t(StoreEntry
* entry
, const char *name
, time_t var
)
2468 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int) var
);
2472 parse_time_t(time_t * var
)
2474 parseTimeLine(var
, T_SECOND_STR
);
2478 free_time_t(time_t * var
)
2484 dump_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
2486 storeAppendPrintf(entry
, "%s %d\n", name
, (int) var
);
2490 dump_b_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
2492 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
2497 dump_kb_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
2499 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_KBYTES_STR
);
2504 dump_b_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
2506 storeAppendPrintf(entry
, "%s %"PRId64
" %s\n", name
, var
, B_BYTES_STR
);
2510 dump_kb_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
2512 storeAppendPrintf(entry
, "%s %"PRId64
" %s\n", name
, var
, B_KBYTES_STR
);
2516 parse_size_t(size_t * var
)
2524 parse_b_size_t(size_t * var
)
2526 parseBytesLine(var
, B_BYTES_STR
);
2531 parse_kb_size_t(size_t * var
)
2533 parseBytesLine(var
, B_KBYTES_STR
);
2538 parse_b_int64_t(int64_t * var
)
2540 parseBytesLine64(var
, B_BYTES_STR
);
2544 parse_kb_int64_t(int64_t * var
)
2546 parseBytesLine64(var
, B_KBYTES_STR
);
2550 free_size_t(size_t * var
)
2556 free_b_int64_t(int64_t * var
)
2561 #define free_b_size_t free_size_t
2562 #define free_kb_size_t free_size_t
2563 #define free_mb_size_t free_size_t
2564 #define free_gb_size_t free_size_t
2565 #define free_kb_int64_t free_b_int64_t
2568 dump_ushort(StoreEntry
* entry
, const char *name
, u_short var
)
2570 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2574 free_ushort(u_short
* u
)
2580 parse_ushort(u_short
* var
)
2582 ConfigParser::ParseUShort(var
);
2586 ConfigParser::ParseUShort(u_short
*var
)
2592 ConfigParser::ParseBool(bool *var
)
2594 int i
= GetInteger();
2605 dump_wordlist(StoreEntry
* entry
, const char *name
, wordlist
* list
)
2607 while (list
!= NULL
) {
2608 storeAppendPrintf(entry
, "%s %s\n", name
, list
->key
);
2614 ConfigParser::ParseWordList(wordlist
** list
)
2616 parse_wordlist(list
);
2620 parse_wordlist(wordlist
** list
)
2623 char *t
= strtok(NULL
, "");
2625 while ((token
= strwordtok(NULL
, &t
)))
2626 wordlistAdd(list
, token
);
2629 #if 0 /* now unused */
2631 check_null_wordlist(wordlist
* w
)
2638 check_null_acl_access(acl_access
* a
)
2643 #define free_wordlist wordlistDestroy
2645 #define free_uri_whitespace free_int
2648 parse_uri_whitespace(int *var
)
2650 char *token
= strtok(NULL
, w_space
);
2655 if (!strcasecmp(token
, "strip"))
2656 *var
= URI_WHITESPACE_STRIP
;
2657 else if (!strcasecmp(token
, "deny"))
2658 *var
= URI_WHITESPACE_DENY
;
2659 else if (!strcasecmp(token
, "allow"))
2660 *var
= URI_WHITESPACE_ALLOW
;
2661 else if (!strcasecmp(token
, "encode"))
2662 *var
= URI_WHITESPACE_ENCODE
;
2663 else if (!strcasecmp(token
, "chop"))
2664 *var
= URI_WHITESPACE_CHOP
;
2670 dump_uri_whitespace(StoreEntry
* entry
, const char *name
, int var
)
2674 if (var
== URI_WHITESPACE_ALLOW
)
2676 else if (var
== URI_WHITESPACE_ENCODE
)
2678 else if (var
== URI_WHITESPACE_CHOP
)
2680 else if (var
== URI_WHITESPACE_DENY
)
2685 storeAppendPrintf(entry
, "%s %s\n", name
, s
);
2689 free_removalpolicy(RemovalPolicySettings
** settings
)
2694 free_string(&(*settings
)->type
);
2696 free_wordlist(&(*settings
)->args
);
2704 parse_removalpolicy(RemovalPolicySettings
** settings
)
2707 free_removalpolicy(settings
);
2709 *settings
= new RemovalPolicySettings
;
2711 parse_string(&(*settings
)->type
);
2713 parse_wordlist(&(*settings
)->args
);
2717 dump_removalpolicy(StoreEntry
* entry
, const char *name
, RemovalPolicySettings
* settings
)
2720 storeAppendPrintf(entry
, "%s %s", name
, settings
->type
);
2721 args
= settings
->args
;
2724 storeAppendPrintf(entry
, " %s", args
->key
);
2728 storeAppendPrintf(entry
, "\n");
2731 #include "cf_parser.h"
2734 parseNeighborType(const char *s
)
2736 if (!strcasecmp(s
, "parent"))
2739 if (!strcasecmp(s
, "neighbor"))
2740 return PEER_SIBLING
;
2742 if (!strcasecmp(s
, "neighbour"))
2743 return PEER_SIBLING
;
2745 if (!strcasecmp(s
, "sibling"))
2746 return PEER_SIBLING
;
2748 if (!strcasecmp(s
, "multicast"))
2749 return PEER_MULTICAST
;
2751 debugs(15, 0, "WARNING: Unknown neighbor type: " << s
);
2753 return PEER_SIBLING
;
2758 parse_IpAddress_list_token(IpAddress_list
** head
, char *token
)
2765 unsigned short port
;
2772 if (*token
== '[') {
2775 t
= strchr(host
, ']');
2781 port
= xatos(t
+ 1);
2784 if ((t
= strchr(token
, ':'))) {
2788 port
= xatos(t
+ 1);
2792 } else if ((port
= strtol(token
, &tmp
, 10)), !*tmp
) {
2801 else if ( ipa
.GetHostByName(host
) ) /* dont use ipcache. Accept either FQDN or IPA. */
2806 /* port MUST be set after the IPA lookup/conversion is perofrmed. */
2810 head
= &(*head
)->next
;
2812 s
= static_cast<IpAddress_list
*>(xcalloc(1, sizeof(*s
)));
2819 parse_IpAddress_list(IpAddress_list
** head
)
2823 while ((token
= strtok(NULL
, w_space
))) {
2824 parse_IpAddress_list_token(head
, token
);
2829 dump_IpAddress_list(StoreEntry
* e
, const char *n
, const IpAddress_list
* s
)
2831 char ntoabuf
[MAX_IPSTRLEN
];
2834 storeAppendPrintf(e
, "%s %s\n",
2836 s
->s
.NtoA(ntoabuf
,MAX_IPSTRLEN
));
2842 free_IpAddress_list(IpAddress_list
** head
)
2844 if (*head
) delete *head
;
2848 #if CURRENTLY_UNUSED
2849 /* This code was previously used by http_port. Left as it really should
2850 * be used by icp_port and htcp_port
2853 check_null_IpAddress_list(const IpAddress_list
* s
)
2858 #endif /* CURRENTLY_UNUSED */
2859 #endif /* USE_WCCPv2 */
2861 CBDATA_CLASS_INIT(http_port_list
);
2864 parse_http_port_specification(http_port_list
* s
, char *token
)
2867 unsigned short port
= 0;
2871 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
2872 s
->name
= xstrdup(token
);
2873 s
->connection_auth_disabled
= false;
2876 if (*token
== '[') {
2879 t
= strchr(host
, ']');
2881 debugs(3, 0, "http(s)_port: missing ']' on IPv6 address: " << token
);
2886 debugs(3, 0, "http(s)_port: missing Port in: " << token
);
2889 port
= xatos(t
+ 1);
2892 if ((t
= strchr(token
, ':'))) {
2897 port
= xatos(t
+ 1);
2899 } else if ((port
= strtol(token
, &junk
, 10)), !*junk
) {
2901 debugs(3, 3, "http(s)_port: found Listen on Port: " << port
);
2903 debugs(3, 0, "http(s)_port: missing Port: " << token
);
2908 debugs(3, 0, "http(s)_port: Port cannot be 0: " << token
);
2915 debugs(3, 3, "http(s)_port: found Listen on wildcard address: " << s
->s
);
2916 } else if ( s
->s
= host
) { /* check/parse numeric IPA */
2918 debugs(3, 3, "http(s)_port: Listen on Host/IP: " << host
<< " --> " << s
->s
);
2919 } else if ( s
->s
.GetHostByName(host
) ) { /* check/parse for FQDN */
2920 /* dont use ipcache */
2921 s
->defaultsite
= xstrdup(host
);
2923 debugs(3, 3, "http(s)_port: found Listen as Host " << s
->defaultsite
<< " on IP: " << s
->s
);
2925 debugs(3, 0, "http(s)_port: failed to resolve Host/IP: " << host
);
2931 parse_http_port_option(http_port_list
* s
, char *token
)
2933 if (strncmp(token
, "defaultsite=", 12) == 0) {
2934 safe_free(s
->defaultsite
);
2935 s
->defaultsite
= xstrdup(token
+ 12);
2937 } else if (strncmp(token
, "name=", 5) == 0) {
2939 s
->name
= xstrdup(token
+ 5);
2940 } else if (strcmp(token
, "vhost") == 0) {
2943 } else if (strcmp(token
, "vport") == 0) {
2946 } else if (strncmp(token
, "vport=", 6) == 0) {
2947 s
->vport
= xatos(token
+ 6);
2949 } else if (strncmp(token
, "protocol=", 9) == 0) {
2950 s
->protocol
= xstrdup(token
+ 9);
2952 } else if (strcmp(token
, "accel") == 0) {
2954 } else if (strcmp(token
, "no-connection-auth") == 0) {
2955 s
->connection_auth_disabled
= true;
2956 } else if (strcmp(token
, "connection-auth=off") == 0) {
2957 s
->connection_auth_disabled
= true;
2958 } else if (strcmp(token
, "connection-auth") == 0) {
2959 s
->connection_auth_disabled
= false;
2960 } else if (strcmp(token
, "connection-auth=on") == 0) {
2961 s
->connection_auth_disabled
= false;
2962 } else if (strncmp(token
, "disable-pmtu-discovery=", 23) == 0) {
2963 if (!strcasecmp(token
+ 23, "off"))
2964 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
2965 else if (!strcasecmp(token
+ 23, "transparent"))
2966 s
->disable_pmtu_discovery
= DISABLE_PMTU_TRANSPARENT
;
2967 else if (!strcasecmp(token
+ 23, "always"))
2968 s
->disable_pmtu_discovery
= DISABLE_PMTU_ALWAYS
;
2972 } else if (strcmp(token
, "transparent") == 0 || strcmp(token
, "intercept") == 0) {
2974 IpInterceptor
.StartInterception();
2975 /* Log information regarding the port modes under interception. */
2976 debugs(3, DBG_IMPORTANT
, "Starting Authentication on port " << s
->s
);
2977 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (interception enabled)");
2980 /* INET6: until transparent REDIRECT works on IPv6 SOCKET, force wildcard to IPv4 */
2981 debugs(3, DBG_IMPORTANT
, "Disabling IPv6 on port " << s
->s
<< " (interception enabled)");
2982 if ( !s
->s
.SetIPv4() ) {
2983 debugs(3, DBG_CRITICAL
, "http(s)_port: IPv6 addresses cannot be transparent (protocol does not provide NAT)" << s
->s
);
2987 } else if (strcmp(token
, "tproxy") == 0) {
2988 if (s
->intercepted
|| s
->accel
) {
2989 debugs(3,DBG_CRITICAL
, "http(s)_port: TPROXY option requires its own interception port. It cannot be shared.");
2992 s
->spoof_client_ip
= 1;
2993 IpInterceptor
.StartTransparency();
2994 /* Log information regarding the port modes under transparency. */
2995 debugs(3, DBG_IMPORTANT
, "Starting IP Spoofing on port " << s
->s
);
2996 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (Ip spoofing enabled)");
2999 /* INET6: until target TPROXY is known to work on IPv6 SOCKET, force wildcard to IPv4 */
3000 debugs(3, DBG_IMPORTANT
, "Disabling IPv6 on port " << s
->s
<< " (interception enabled)");
3001 if ( s
->s
.IsIPv6() && !s
->s
.SetIPv4() ) {
3002 debugs(3, DBG_CRITICAL
, "http(s)_port: IPv6 addresses cannot be transparent (protocol does not provide NAT)" << s
->s
);
3007 } else if (strcmp(token
, "ipv4") == 0) {
3009 if ( !s
->s
.SetIPv4() ) {
3010 debugs(3, 0, "http(s)_port: IPv6 addresses cannot be used a IPv4-Only." << s
->s
);
3014 } else if (strcmp(token
, "tcpkeepalive") == 0) {
3015 s
->tcp_keepalive
.enabled
= 1;
3016 } else if (strncmp(token
, "tcpkeepalive=", 13) == 0) {
3017 char *t
= token
+ 13;
3018 s
->tcp_keepalive
.enabled
= 1;
3019 s
->tcp_keepalive
.idle
= atoi(t
);
3023 s
->tcp_keepalive
.interval
= atoi(t
);
3028 s
->tcp_keepalive
.timeout
= atoi(t
);
3032 } else if (strncmp(token
, "cert=", 5) == 0) {
3034 s
->cert
= xstrdup(token
+ 5);
3035 } else if (strncmp(token
, "key=", 4) == 0) {
3037 s
->key
= xstrdup(token
+ 4);
3038 } else if (strncmp(token
, "version=", 8) == 0) {
3039 s
->version
= xatoi(token
+ 8);
3041 if (s
->version
< 1 || s
->version
> 4)
3043 } else if (strncmp(token
, "options=", 8) == 0) {
3044 safe_free(s
->options
);
3045 s
->options
= xstrdup(token
+ 8);
3046 } else if (strncmp(token
, "cipher=", 7) == 0) {
3047 safe_free(s
->cipher
);
3048 s
->cipher
= xstrdup(token
+ 7);
3049 } else if (strncmp(token
, "clientca=", 9) == 0) {
3050 safe_free(s
->clientca
);
3051 s
->clientca
= xstrdup(token
+ 9);
3052 } else if (strncmp(token
, "cafile=", 7) == 0) {
3053 safe_free(s
->cafile
);
3054 s
->cafile
= xstrdup(token
+ 7);
3055 } else if (strncmp(token
, "capath=", 7) == 0) {
3056 safe_free(s
->capath
);
3057 s
->capath
= xstrdup(token
+ 7);
3058 } else if (strncmp(token
, "crlfile=", 8) == 0) {
3059 safe_free(s
->crlfile
);
3060 s
->crlfile
= xstrdup(token
+ 8);
3061 } else if (strncmp(token
, "dhparams=", 9) == 0) {
3062 safe_free(s
->dhfile
);
3063 s
->dhfile
= xstrdup(token
+ 9);
3064 } else if (strncmp(token
, "sslflags=", 9) == 0) {
3065 safe_free(s
->sslflags
);
3066 s
->sslflags
= xstrdup(token
+ 9);
3067 } else if (strncmp(token
, "sslcontext=", 11) == 0) {
3068 safe_free(s
->sslcontext
);
3069 s
->sslcontext
= xstrdup(token
+ 11);
3070 } else if (strcmp(token
, "sslBump") == 0) {
3071 s
->sslBump
= 1; // accelerated when bumped, otherwise not
3077 if ( s
->spoof_client_ip
&& (s
->intercepted
|| s
->accel
) ) {
3078 debugs(3,DBG_CRITICAL
, "http(s)_port: TPROXY option requires its own interception port. It cannot be shared.");
3083 static http_port_list
*
3084 create_http_port(char *portspec
)
3086 http_port_list
*s
= new http_port_list("http");
3087 parse_http_port_specification(s
, portspec
);
3092 add_http_port(char *portspec
)
3094 http_port_list
*s
= create_http_port(portspec
);
3095 s
->next
= Config
.Sockaddr
.http
;
3096 Config
.Sockaddr
.http
= s
;
3100 parse_http_port_list(http_port_list
** head
)
3102 char *token
= strtok(NULL
, w_space
);
3109 http_port_list
*s
= create_http_port(token
);
3111 /* parse options ... */
3112 while ((token
= strtok(NULL
, w_space
))) {
3113 parse_http_port_option(s
, token
);
3117 head
= &(*head
)->next
;
3123 dump_generic_http_port(StoreEntry
* e
, const char *n
, const http_port_list
* s
)
3125 char buf
[MAX_IPSTRLEN
];
3127 storeAppendPrintf(e
, "%s %s",
3129 s
->s
.ToURL(buf
,MAX_IPSTRLEN
));
3132 storeAppendPrintf(e
, " defaultsite=%s", s
->defaultsite
);
3135 storeAppendPrintf(e
, " intercept");
3138 storeAppendPrintf(e
, " vhost");
3141 storeAppendPrintf(e
, " vport");
3143 if (s
->connection_auth_disabled
)
3144 storeAppendPrintf(e
, " connection-auth=off");
3146 storeAppendPrintf(e
, " connection-auth=on");
3148 if (s
->disable_pmtu_discovery
!= DISABLE_PMTU_OFF
) {
3151 if (s
->disable_pmtu_discovery
== DISABLE_PMTU_ALWAYS
)
3154 pmtu
= "transparent";
3156 storeAppendPrintf(e
, " disable-pmtu-discovery=%s", pmtu
);
3159 if (s
->tcp_keepalive
.enabled
) {
3160 if (s
->tcp_keepalive
.idle
|| s
->tcp_keepalive
.interval
|| s
->tcp_keepalive
.timeout
) {
3161 storeAppendPrintf(e
, " tcp_keepalive=%d,%d,%d", s
->tcp_keepalive
.idle
, s
->tcp_keepalive
.interval
, s
->tcp_keepalive
.timeout
);
3163 storeAppendPrintf(e
, " tcp_keepalive");
3169 storeAppendPrintf(e
, " cert=%s", s
->cert
);
3172 storeAppendPrintf(e
, " key=%s", s
->key
);
3175 storeAppendPrintf(e
, " version=%d", s
->version
);
3178 storeAppendPrintf(e
, " options=%s", s
->options
);
3181 storeAppendPrintf(e
, " cipher=%s", s
->cipher
);
3184 storeAppendPrintf(e
, " cafile=%s", s
->cafile
);
3187 storeAppendPrintf(e
, " capath=%s", s
->capath
);
3190 storeAppendPrintf(e
, " crlfile=%s", s
->crlfile
);
3193 storeAppendPrintf(e
, " dhparams=%s", s
->dhfile
);
3196 storeAppendPrintf(e
, " sslflags=%s", s
->sslflags
);
3199 storeAppendPrintf(e
, " sslcontext=%s", s
->sslcontext
);
3202 storeAppendPrintf(e
, " sslBump");
3207 dump_http_port_list(StoreEntry
* e
, const char *n
, const http_port_list
* s
)
3210 dump_generic_http_port(e
, n
, s
);
3211 storeAppendPrintf(e
, "\n");
3217 free_http_port_list(http_port_list
** head
)
3221 while ((s
= *head
) != NULL
) {
3229 // TODO: merge better with parse_http_port_list
3231 parse_https_port_list(https_port_list
** head
)
3236 token
= strtok(NULL
, w_space
);
3241 s
= new https_port_list
;
3242 parse_http_port_specification(&s
->http
, token
);
3244 /* parse options ... */
3245 while ((token
= strtok(NULL
, w_space
))) {
3246 parse_http_port_option(s
, token
);
3250 http_port_list
** headTmp
= &(*head
)->http
.next
;
3251 head
= (https_port_list
**)headTmp
;
3258 dump_https_port_list(StoreEntry
* e
, const char *n
, const https_port_list
* s
)
3260 dump_http_port_list(e
, n
, s
);
3264 free_https_port_list(https_port_list
** head
)
3266 free_http_port_list((http_port_list
**)head
);
3271 check_null_https_port_list(const https_port_list
* s
)
3278 #endif /* USE_SSL */
3281 configFreeMemory(void)
3287 requirePathnameExists(const char *name
, const char *path
)
3291 char pathbuf
[BUFSIZ
];
3292 assert(path
!= NULL
);
3294 if (Config
.chroot_dir
&& (geteuid() == 0)) {
3295 snprintf(pathbuf
, BUFSIZ
, "%s/%s", Config
.chroot_dir
, path
);
3299 if (stat(path
, &sb
) < 0) {
3300 if (opt_send_signal
== -1 || opt_send_signal
== SIGHUP
)
3301 fatalf("%s %s: %s", name
, path
, xstrerror());
3303 fprintf(stderr
, "WARNING: %s %s: %s\n", name
, path
, xstrerror());
3310 return ConfigParser::strtokFile();
3313 #include "AccessLogEntry.h"
3314 /* TODO: split out parsing somehow ...*/
3316 parse_logformat(logformat
** logformat_definitions
)
3321 if ((name
= strtok(NULL
, w_space
)) == NULL
)
3324 if ((def
= strtok(NULL
, "\r\n")) == NULL
) {
3329 debugs(3, 2, "Logformat for '" << name
<< "' is '" << def
<< "'");
3331 nlf
= (logformat
*)xcalloc(1, sizeof(logformat
));
3333 nlf
->name
= xstrdup(name
);
3335 if (!accessLogParseLogFormat(&nlf
->format
, def
)) {
3340 nlf
->next
= *logformat_definitions
;
3342 *logformat_definitions
= nlf
;
3346 parse_access_log(customlog
** logs
)
3348 const char *filename
, *logdef_name
;
3352 cl
= (customlog
*)xcalloc(1, sizeof(*cl
));
3354 if ((filename
= strtok(NULL
, w_space
)) == NULL
) {
3359 if (strcmp(filename
, "none") == 0) {
3360 cl
->type
= CLF_NONE
;
3364 if ((logdef_name
= strtok(NULL
, w_space
)) == NULL
)
3365 logdef_name
= "auto";
3367 debugs(3, 9, "Log definition name '" << logdef_name
<< "' file '" << filename
<< "'");
3369 cl
->filename
= xstrdup(filename
);
3371 /* look for the definition pointer corresponding to this name */
3372 lf
= Config
.Log
.logformats
;
3374 while (lf
!= NULL
) {
3375 debugs(3, 9, "Comparing against '" << lf
->name
<< "'");
3377 if (strcmp(lf
->name
, logdef_name
) == 0)
3384 cl
->type
= CLF_CUSTOM
;
3386 } else if (strcmp(logdef_name
, "auto") == 0) {
3387 cl
->type
= CLF_AUTO
;
3388 } else if (strcmp(logdef_name
, "squid") == 0) {
3389 cl
->type
= CLF_SQUID
;
3390 } else if (strcmp(logdef_name
, "common") == 0) {
3391 cl
->type
= CLF_COMMON
;
3393 debugs(3, 0, "Log format '" << logdef_name
<< "' is not defined");
3399 aclParseAclList(LegacyParser
, &cl
->aclList
);
3402 logs
= &(*logs
)->next
;
3408 check_null_access_log(customlog
*customlog_definitions
)
3410 return customlog_definitions
== NULL
;
3414 dump_logformat(StoreEntry
* entry
, const char *name
, logformat
* definitions
)
3416 accessLogDumpLogFormat(entry
, name
, definitions
);
3420 dump_access_log(StoreEntry
* entry
, const char *name
, customlog
* logs
)
3424 for (log
= logs
; log
; log
= log
->next
) {
3425 storeAppendPrintf(entry
, "%s ", name
);
3427 switch (log
->type
) {
3430 storeAppendPrintf(entry
, "%s %s", log
->filename
, log
->logFormat
->name
);
3434 storeAppendPrintf(entry
, "none");
3438 storeAppendPrintf(entry
, "%s squid", log
->filename
);
3442 storeAppendPrintf(entry
, "%s squid", log
->filename
);
3448 storeAppendPrintf(entry
, "%s auto", log
->filename
);
3450 storeAppendPrintf(entry
, "%s", log
->filename
);
3459 dump_acl_list(entry
, log
->aclList
);
3461 storeAppendPrintf(entry
, "\n");
3466 free_logformat(logformat
** definitions
)
3468 while (*definitions
) {
3469 logformat
*format
= *definitions
;
3470 *definitions
= format
->next
;
3471 safe_free(format
->name
);
3472 accessLogFreeLogFormat(&format
->format
);
3478 free_access_log(customlog
** definitions
)
3480 while (*definitions
) {
3481 customlog
*log
= *definitions
;
3482 *definitions
= log
->next
;
3484 log
->logFormat
= NULL
;
3485 log
->type
= CLF_UNKNOWN
;
3488 aclDestroyAclList(&log
->aclList
);
3490 safe_free(log
->filename
);
3499 parse_adaptation_service_set_type()
3501 Adaptation::Config::ParseServiceSet();
3505 parse_adaptation_access_type()
3507 Adaptation::Config::ParseAccess(LegacyParser
);
3510 #endif /* USE_ADAPTATION */
3516 parse_icap_service_type(Adaptation::Icap::Config
* cfg
)
3518 cfg
->parseService();
3522 free_icap_service_type(Adaptation::Icap::Config
* cfg
)
3528 dump_icap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
3530 cfg
.dumpService(entry
, name
);
3534 parse_icap_class_type()
3536 debugs(93, 0, "WARNING: 'icap_class' is depricated. " <<
3537 "Use 'adaptation_service_set' instead");
3538 Adaptation::Config::ParseServiceSet();
3542 parse_icap_access_type()
3544 debugs(93, 0, "WARNING: 'icap_access' is depricated. " <<
3545 "Use 'adaptation_access' instead");
3546 Adaptation::Config::ParseAccess(LegacyParser
);
3555 parse_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
3557 cfg
->parseService();
3561 free_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
3567 dump_ecap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Ecap::Config
&cfg
)
3569 cfg
.dumpService(entry
, name
);
3572 #endif /* USE_ECAP */