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 "ident/Config.h"
51 #include "ip/IpIntercept.h"
61 #include "esi/Parser.h"
65 #include "adaptation/Config.h"
67 static void parse_adaptation_service_set_type();
68 static void parse_adaptation_access_type();
73 #include "adaptation/icap/Config.h"
75 static void parse_icap_service_type(Adaptation::Icap::Config
*);
76 static void dump_icap_service_type(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
77 static void free_icap_service_type(Adaptation::Icap::Config
*);
78 static void parse_icap_class_type();
79 static void parse_icap_access_type();
84 #include "adaptation/ecap/Config.h"
85 static void parse_ecap_service_type(Adaptation::Ecap::Config
*);
86 static void dump_ecap_service_type(StoreEntry
*, const char *, const Adaptation::Ecap::Config
&);
87 static void free_ecap_service_type(Adaptation::Ecap::Config
*);
92 static const char *const T_SECOND_STR
= "second";
93 static const char *const T_MINUTE_STR
= "minute";
94 static const char *const T_HOUR_STR
= "hour";
95 static const char *const T_DAY_STR
= "day";
96 static const char *const T_WEEK_STR
= "week";
97 static const char *const T_FORTNIGHT_STR
= "fortnight";
98 static const char *const T_MONTH_STR
= "month";
99 static const char *const T_YEAR_STR
= "year";
100 static const char *const T_DECADE_STR
= "decade";
102 static const char *const B_BYTES_STR
= "bytes";
103 static const char *const B_KBYTES_STR
= "KB";
104 static const char *const B_MBYTES_STR
= "MB";
105 static const char *const B_GBYTES_STR
= "GB";
107 static const char *const list_sep
= ", \t\n\r";
109 static void parse_logformat(logformat
** logformat_definitions
);
110 static void parse_access_log(customlog
** customlog_definitions
);
111 static int check_null_access_log(customlog
*customlog_definitions
);
113 static void dump_logformat(StoreEntry
* entry
, const char *name
, logformat
* definitions
);
114 static void dump_access_log(StoreEntry
* entry
, const char *name
, customlog
* definitions
);
115 static void free_logformat(logformat
** definitions
);
116 static void free_access_log(customlog
** definitions
);
118 static void update_maxobjsize(void);
119 static void configDoConfigure(void);
120 static void parse_refreshpattern(refresh_t
**);
121 static int parseTimeUnits(const char *unit
);
122 static void parseTimeLine(time_t * tptr
, const char *units
);
123 static void parse_ushort(u_short
* var
);
124 static void parse_string(char **);
125 static void default_all(void);
126 static void defaults_if_none(void);
127 static int parse_line(char *);
128 static void parseBytesLine(size_t * bptr
, const char *units
);
129 static size_t parseBytesUnits(const char *unit
);
130 static void free_all(void);
131 void requirePathnameExists(const char *name
, const char *path
);
132 static OBJH dump_config
;
134 static void dump_http_header_access(StoreEntry
* entry
, const char *name
, header_mangler header
[]);
135 static void parse_http_header_access(header_mangler header
[]);
136 static void free_http_header_access(header_mangler header
[]);
137 static void dump_http_header_replace(StoreEntry
* entry
, const char *name
, header_mangler header
[]);
138 static void parse_http_header_replace(header_mangler
* header
);
139 static void free_http_header_replace(header_mangler
* header
);
141 static void parse_denyinfo(acl_deny_info_list
** var
);
142 static void dump_denyinfo(StoreEntry
* entry
, const char *name
, acl_deny_info_list
* var
);
143 static void free_denyinfo(acl_deny_info_list
** var
);
146 static void parse_IpAddress_list(IpAddress_list
**);
147 static void dump_IpAddress_list(StoreEntry
*, const char *, const IpAddress_list
*);
148 static void free_IpAddress_list(IpAddress_list
**);
150 static int check_null_IpAddress_list(const IpAddress_list
*);
151 #endif /* CURRENTLY_UNUSED */
152 #endif /* USE_WCCPv2 */
154 static void parse_http_port_list(http_port_list
**);
155 static void dump_http_port_list(StoreEntry
*, const char *, const http_port_list
*);
156 static void free_http_port_list(http_port_list
**);
159 static void parse_https_port_list(https_port_list
**);
160 static void dump_https_port_list(StoreEntry
*, const char *, const https_port_list
*);
161 static void free_https_port_list(https_port_list
**);
163 static int check_null_https_port_list(const https_port_list
*);
167 static void parse_b_size_t(size_t * var
);
168 static void parse_b_int64_t(int64_t * var
);
170 static int parseOneConfigFile(const char *file_name
, unsigned int depth
);
173 * LegacyParser is a parser for legacy code that uses the global
174 * approach. This is static so that it is only exposed to cache_cf.
175 * Other modules needing access to a ConfigParser should have it
176 * provided to them in their parserFOO methods.
178 static ConfigParser LegacyParser
= ConfigParser();
183 LegacyParser
.destruct();
187 update_maxobjsize(void)
192 for (i
= 0; i
< Config
.cacheSwap
.n_configured
; i
++) {
193 assert (Config
.cacheSwap
.swapDirs
[i
].getRaw());
195 if (dynamic_cast<SwapDir
*>(Config
.cacheSwap
.swapDirs
[i
].getRaw())->
197 ms
= dynamic_cast<SwapDir
*>(Config
.cacheSwap
.swapDirs
[i
].getRaw())->max_objsize
;
199 store_maxobjsize
= ms
;
203 SetConfigFilename(char const *file_name
, bool is_pipe
)
205 cfg_filename
= file_name
;
210 cfg_filename
= file_name
+ 1;
211 else if ((token
= strrchr(cfg_filename
, '/')))
212 cfg_filename
= token
+ 1;
216 skip_ws(const char* s
)
225 parseManyConfigFiles(char* files
, int depth
)
228 char* saveptr
= NULL
;
233 memset(&globbuf
, 0, sizeof(globbuf
));
234 for (path
= strwordtok(files
, &saveptr
); path
; path
= strwordtok(NULL
, &saveptr
)) {
235 if (glob(path
, globbuf
.gl_pathc
? GLOB_APPEND
: 0, NULL
, &globbuf
) != 0) {
236 fatalf("Unable to find configuration file: %s: %s",
240 for (i
= 0; i
< (int)globbuf
.gl_pathc
; i
++) {
241 error_count
+= parseOneConfigFile(globbuf
.gl_pathv
[i
], depth
);
245 char* file
= strwordtok(files
, &saveptr
);
246 while (file
!= NULL
) {
247 error_count
+= parseOneConfigFile(file
, depth
);
248 file
= strwordtok(NULL
, &saveptr
);
250 #endif /* HAVE_GLOB */
255 parseOneConfigFile(const char *file_name
, unsigned int depth
)
258 const char *orig_cfg_filename
= cfg_filename
;
259 const int orig_config_lineno
= config_lineno
;
261 char *tmp_line
= NULL
;
262 int tmp_line_len
= 0;
266 debugs(3, 1, "Processing Configuration File: " << file_name
<< " (depth " << depth
<< ")");
268 fatalf("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name
);
272 if (file_name
[0] == '!' || file_name
[0] == '|') {
273 fp
= popen(file_name
+ 1, "r");
276 fp
= fopen(file_name
, "r");
280 fatalf("Unable to open configuration file: %s: %s", file_name
, xstrerror());
284 setmode(fileno(fp
), O_TEXT
);
288 SetConfigFilename(file_name
, bool(is_pipe
));
290 memset(config_input_line
, '\0', BUFSIZ
);
294 while (fgets(config_input_line
, BUFSIZ
, fp
)) {
297 if ((token
= strchr(config_input_line
, '\n')))
300 if ((token
= strchr(config_input_line
, '\r')))
303 if (strncmp(config_input_line
, "#line ", 6) == 0) {
304 static char new_file_name
[1024];
306 static char new_lineno
;
307 token
= config_input_line
+ 6;
308 new_lineno
= strtol(token
, &file
, 0) - 1;
311 continue; /* Not a valid #line directive, may be a comment */
313 while (*file
&& xisspace((unsigned char) *file
))
318 continue; /* Not a valid #line directive, may be a comment */
320 xstrncpy(new_file_name
, file
+ 1, sizeof(new_file_name
));
322 if ((token
= strchr(new_file_name
, '"')))
325 cfg_filename
= new_file_name
;
328 config_lineno
= new_lineno
;
331 if (config_input_line
[0] == '#')
334 if (config_input_line
[0] == '\0')
337 const char* append
= tmp_line_len
? skip_ws(config_input_line
) : config_input_line
;
339 size_t append_len
= strlen(append
);
341 tmp_line
= (char*)xrealloc(tmp_line
, tmp_line_len
+ append_len
+ 1);
343 strcpy(tmp_line
+ tmp_line_len
, append
);
345 tmp_line_len
+= append_len
;
347 if (tmp_line
[tmp_line_len
-1] == '\\') {
348 debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line
<< "'");
349 tmp_line
[--tmp_line_len
] = '\0';
353 debugs(3, 5, "Processing: '" << tmp_line
<< "'");
355 /* Handle includes here */
356 if (tmp_line_len
>= 9 && strncmp(tmp_line
, "include", 7) == 0 && xisspace(tmp_line
[7])) {
357 err_count
+= parseManyConfigFiles(tmp_line
+ 8, depth
+ 1);
358 } else if (!parse_line(tmp_line
)) {
359 debugs(3, 0, HERE
<< cfg_filename
<< ":" << config_lineno
<< " unrecognized: '" << tmp_line
<< "'");
369 int ret
= pclose(fp
);
372 fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name
, ret
);
377 cfg_filename
= orig_cfg_filename
;
378 config_lineno
= orig_config_lineno
;
384 parseConfigFile(const char *file_name
)
387 CacheManager
*manager
=CacheManager::GetInstance();
393 err_count
= parseOneConfigFile(file_name
, 0);
398 * We must call configDoConfigure() before leave_suid() because
399 * configDoConfigure() is where we turn username strings into
404 if (!Config
.chroot_dir
) {
406 setUmask(Config
.umask
);
407 _db_init(Debug::cache_log
, Debug::debugOptions
);
411 if (opt_send_signal
== -1) {
412 manager
->registerAction("config",
413 "Current Squid Configuration",
423 configDoConfigure(void)
425 memset(&Config2
, '\0', sizeof(SquidConfig2
));
426 /* init memory as early as possible */
430 if (Debug::rotateNumber
< 0) {
431 Debug::rotateNumber
= Config
.Log
.rotateNumber
;
434 #if SIZEOF_OFF_T <= 4
435 if (Config
.Store
.maxObjectSize
> 0x7FFF0000) {
436 debugs(3, 0, "WARNING: This Squid binary can not handle files larger than 2GB. Limiting maximum_object_size to just below 2GB");
437 Config
.Store
.maxObjectSize
= 0x7FFF0000;
440 if (0 == Store::Root().maxSize())
441 /* people might want a zero-sized cache on purpose */
443 else if (Store::Root().maxSize() < (Config
.memMaxSize
>> 10))
444 /* This is bogus. folk with NULL caches will want this */
445 debugs(3, 0, "WARNING cache_mem is larger than total disk cache space!");
447 if (Config
.Announce
.period
> 0) {
448 Config
.onoff
.announce
= 1;
449 } else if (Config
.Announce
.period
< 1) {
450 Config
.Announce
.period
= 86400 * 365; /* one year */
451 Config
.onoff
.announce
= 0;
454 if (Config
.onoff
.httpd_suppress_version_string
)
455 visible_appname_string
= (char *)appname_string
;
457 visible_appname_string
= (char const *)APP_FULLNAME
;
461 if (Config
.dnsChildren
< 1)
462 fatal("No dnsservers allocated");
466 if (Config
.Program
.redirect
) {
467 if (Config
.redirectChildren
< 1) {
468 Config
.redirectChildren
= 0;
469 wordlistDestroy(&Config
.Program
.redirect
);
473 if (Config
.appendDomain
)
474 if (*Config
.appendDomain
!= '.')
475 fatal("append_domain must begin with a '.'");
477 if (Config
.errHtmlText
== NULL
)
478 Config
.errHtmlText
= xstrdup(null_string
);
482 snprintf(ThisCache
, sizeof(ThisCache
), "%s (%s)",
484 visible_appname_string
);
487 * the extra space is for loop detection in client_side.c -- we search
488 * for substrings in the Via header.
490 snprintf(ThisCache2
, sizeof(ThisCache
), " %s (%s)",
492 visible_appname_string
);
494 if (!Config
.udpMaxHitObjsz
|| Config
.udpMaxHitObjsz
> SQUID_UDP_SO_SNDBUF
)
495 Config
.udpMaxHitObjsz
= SQUID_UDP_SO_SNDBUF
;
497 if (Config
.appendDomain
)
498 Config
.appendDomainLen
= strlen(Config
.appendDomain
);
500 Config
.appendDomainLen
= 0;
502 if (Config
.retry
.maxtries
> 10)
503 fatal("maximum_single_addr_tries cannot be larger than 10");
505 if (Config
.retry
.maxtries
< 1) {
506 debugs(3, 0, "WARNING: resetting 'maximum_single_addr_tries to 1");
507 Config
.retry
.maxtries
= 1;
510 requirePathnameExists("MIME Config Table", Config
.mimeTablePathname
);
513 requirePathnameExists("cache_dns_program", Config
.Program
.dnsserver
);
517 requirePathnameExists("unlinkd_program", Config
.Program
.unlinkd
);
520 if (Config
.Program
.redirect
)
521 requirePathnameExists("redirect_program", Config
.Program
.redirect
->key
);
523 requirePathnameExists("Icon Directory", Config
.icons
.directory
);
525 if (Config
.errorDirectory
)
526 requirePathnameExists("Error Directory", Config
.errorDirectory
);
533 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
534 if (!R
->flags
.override_expire
)
537 debugs(22, 1, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP");
542 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
543 if (!R
->flags
.override_lastmod
)
546 debugs(22, 1, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP");
551 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
552 if (!R
->flags
.reload_into_ims
)
555 debugs(22, 1, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP");
560 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
561 if (!R
->flags
.ignore_reload
)
564 debugs(22, 1, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP");
569 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
570 if (!R
->flags
.ignore_no_cache
)
573 debugs(22, 1, "WARNING: use of 'ignore-no-cache' in 'refresh_pattern' violates HTTP");
578 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
579 if (!R
->flags
.ignore_no_store
)
582 debugs(22, 1, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP");
587 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
588 if (!R
->flags
.ignore_must_revalidate
)
590 debugs(22, 1, "WARNING: use of 'ignore-must-revalidate' in 'refresh_pattern' violates HTTP");
594 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
595 if (!R
->flags
.ignore_private
)
598 debugs(22, 1, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP");
603 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
604 if (!R
->flags
.ignore_auth
)
607 debugs(22, 1, "WARNING: use of 'ignore-auth' in 'refresh_pattern' violates HTTP");
615 Config
.onoff
.via
= 1;
618 if (!Config
.onoff
.via
)
619 debugs(22, 1, "WARNING: HTTP requires the use of Via");
623 // we have reconfigured and in the process disabled any need for PURGE.
625 if(Config2
.onoff
.enable_purge
== 2)
626 Config2
.onoff
.enable_purge
= 0;
628 Config2
.onoff
.mangle_request_headers
= httpReqHdrManglersConfigured();
630 if (geteuid() == 0) {
631 if (NULL
!= Config
.effectiveUser
) {
633 struct passwd
*pwd
= getpwnam(Config
.effectiveUser
);
637 * Andres Kroonmaa <andre@online.ee>:
638 * Some getpwnam() implementations (Solaris?) require
639 * an available FD < 256 for opening a FILE* to the
642 * This should be safe at startup, but might still fail
643 * during reconfigure.
645 fatalf("getpwnam failed to find userid for effective user '%s'",
646 Config
.effectiveUser
);
650 Config2
.effectiveUserID
= pwd
->pw_uid
;
652 Config2
.effectiveGroupID
= pwd
->pw_gid
;
656 if (pwd
->pw_dir
&& *pwd
->pw_dir
) {
658 char *env_str
= (char *)xcalloc((len
= strlen(pwd
->pw_dir
) + 6), 1);
659 snprintf(env_str
, len
, "HOME=%s", pwd
->pw_dir
);
667 Config2
.effectiveUserID
= geteuid();
668 Config2
.effectiveGroupID
= getegid();
671 if (NULL
!= Config
.effectiveGroup
) {
673 struct group
*grp
= getgrnam(Config
.effectiveGroup
);
676 fatalf("getgrnam failed to find groupid for effective group '%s'",
677 Config
.effectiveGroup
);
681 Config2
.effectiveGroupID
= grp
->gr_gid
;
684 HttpRequestMethod::Configure(Config
);
687 debugs(3, 1, "Initializing https proxy context");
689 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
);
695 for (p
= Config
.peers
; p
!= NULL
; p
= p
->next
) {
697 debugs(3, 1, "Initializing cache_peer " << p
->name
<< " SSL context");
698 p
->sslContext
= sslCreateClientContext(p
->sslcert
, p
->sslkey
, p
->sslversion
, p
->sslcipher
, p
->ssloptions
, p
->sslflags
, p
->sslcafile
, p
->sslcapath
, p
->sslcrlfile
);
707 for (s
= Config
.Sockaddr
.http
; s
!= NULL
; s
= (http_port_list
*) s
->next
) {
708 if (!s
->cert
&& !s
->key
)
711 debugs(3, 1, "Initializing http_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
);
721 for (s
= Config
.Sockaddr
.https
; s
!= NULL
; s
= (https_port_list
*) s
->http
.next
) {
722 debugs(3, 1, "Initializing https_port " << s
->http
.s
<< " SSL context");
724 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
);
731 /* Parse a time specification from the config file. Store the
732 * result in 'tptr', after converting it to 'units' */
734 parseTimeLine(time_t * tptr
, const char *units
)
741 if ((u
= parseTimeUnits(units
)) == 0)
744 if ((token
= strtok(NULL
, w_space
)) == NULL
)
749 m
= u
; /* default to 'units' if none specified */
753 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
754 debugs(3, 0, "WARNING: No units on '" <<
755 config_input_line
<< "', assuming " <<
757 else if ((m
= parseTimeUnits(token
)) == 0)
760 *tptr
= static_cast<time_t> (m
* d
/ u
);
764 parseTimeUnits(const char *unit
)
766 if (!strncasecmp(unit
, T_SECOND_STR
, strlen(T_SECOND_STR
)))
769 if (!strncasecmp(unit
, T_MINUTE_STR
, strlen(T_MINUTE_STR
)))
772 if (!strncasecmp(unit
, T_HOUR_STR
, strlen(T_HOUR_STR
)))
775 if (!strncasecmp(unit
, T_DAY_STR
, strlen(T_DAY_STR
)))
778 if (!strncasecmp(unit
, T_WEEK_STR
, strlen(T_WEEK_STR
)))
781 if (!strncasecmp(unit
, T_FORTNIGHT_STR
, strlen(T_FORTNIGHT_STR
)))
784 if (!strncasecmp(unit
, T_MONTH_STR
, strlen(T_MONTH_STR
)))
787 if (!strncasecmp(unit
, T_YEAR_STR
, strlen(T_YEAR_STR
)))
788 return static_cast<int>(86400 * 365.2522);
790 if (!strncasecmp(unit
, T_DECADE_STR
, strlen(T_DECADE_STR
)))
791 return static_cast<int>(86400 * 365.2522 * 10);
793 debugs(3, 1, "parseTimeUnits: unknown time unit '" << unit
<< "'");
799 parseBytesLine64(int64_t * bptr
, const char *units
)
806 if ((u
= parseBytesUnits(units
)) == 0) {
811 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
816 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
823 m
= u
; /* default to 'units' if none specified */
827 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
828 debugs(3, 0, "WARNING: No units on '" <<
829 config_input_line
<< "', assuming " <<
831 else if ((m
= parseBytesUnits(token
)) == 0) {
836 *bptr
= static_cast<int64_t>(m
* d
/ u
);
838 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
844 parseBytesLine(size_t * bptr
, const char *units
)
851 if ((u
= parseBytesUnits(units
)) == 0) {
856 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
861 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
862 *bptr
= static_cast<size_t>(-1);
868 m
= u
; /* default to 'units' if none specified */
872 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
873 debugs(3, 0, "WARNING: No units on '" <<
874 config_input_line
<< "', assuming " <<
876 else if ((m
= parseBytesUnits(token
)) == 0) {
881 *bptr
= static_cast<size_t>(m
* d
/ u
);
883 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
888 parseBytesUnits(const char *unit
)
890 if (!strncasecmp(unit
, B_BYTES_STR
, strlen(B_BYTES_STR
)))
893 if (!strncasecmp(unit
, B_KBYTES_STR
, strlen(B_KBYTES_STR
)))
896 if (!strncasecmp(unit
, B_MBYTES_STR
, strlen(B_MBYTES_STR
)))
899 if (!strncasecmp(unit
, B_GBYTES_STR
, strlen(B_GBYTES_STR
)))
902 debugs(3, DBG_CRITICAL
, "WARNING: Unknown bytes unit '" << unit
<< "'");
907 /*****************************************************************************
909 *****************************************************************************/
912 dump_acl(StoreEntry
* entry
, const char *name
, ACL
* ae
)
918 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
);
919 storeAppendPrintf(entry
, "%s %s %s ",
926 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
<< " " << v
->key
);
927 storeAppendPrintf(entry
, "%s ", v
->key
);
931 storeAppendPrintf(entry
, "\n");
940 ACL::ParseAclLine(LegacyParser
, ae
);
950 dump_acl_list(StoreEntry
* entry
, ACLList
* head
)
954 for (l
= head
; l
; l
= l
->next
) {
955 storeAppendPrintf(entry
, " %s%s",
956 l
->op
? null_string
: "!",
962 dump_acl_access(StoreEntry
* entry
, const char *name
, acl_access
* head
)
966 for (l
= head
; l
; l
= l
->next
) {
967 storeAppendPrintf(entry
, "%s %s",
969 l
->allow
? "Allow" : "Deny");
970 dump_acl_list(entry
, l
->aclList
);
971 storeAppendPrintf(entry
, "\n");
976 parse_acl_access(acl_access
** head
)
978 aclParseAccessLine(LegacyParser
, head
);
982 free_acl_access(acl_access
** head
)
984 aclDestroyAccessList(head
);
988 dump_address(StoreEntry
* entry
, const char *name
, IpAddress
&addr
)
990 char buf
[MAX_IPSTRLEN
];
991 storeAppendPrintf(entry
, "%s %s\n", name
, addr
.NtoA(buf
,MAX_IPSTRLEN
) );
995 parse_address(IpAddress
*addr
)
997 char *token
= strtok(NULL
, w_space
);
1004 if (!strcmp(token
,"any_addr")) {
1007 } else if ( (!strcmp(token
,"no_addr")) || (!strcmp(token
,"full_mask")) ) {
1015 free_address(IpAddress
*addr
)
1020 CBDATA_TYPE(acl_address
);
1023 dump_acl_address(StoreEntry
* entry
, const char *name
, acl_address
* head
)
1025 char buf
[MAX_IPSTRLEN
];
1028 for (l
= head
; l
; l
= l
->next
) {
1029 if (!l
->addr
.IsAnyAddr())
1030 storeAppendPrintf(entry
, "%s %s", name
, l
->addr
.NtoA(buf
,MAX_IPSTRLEN
));
1032 storeAppendPrintf(entry
, "%s autoselect", name
);
1034 dump_acl_list(entry
, l
->aclList
);
1036 storeAppendPrintf(entry
, "\n");
1041 freed_acl_address(void *data
)
1043 acl_address
*l
= static_cast<acl_address
*>(data
);
1044 aclDestroyAclList(&l
->aclList
);
1048 parse_acl_address(acl_address
** head
)
1051 acl_address
**tail
= head
; /* sane name below */
1052 CBDATA_INIT_TYPE_FREECB(acl_address
, freed_acl_address
);
1053 l
= cbdataAlloc(acl_address
);
1054 parse_address(&l
->addr
);
1055 aclParseAclList(LegacyParser
, &l
->aclList
);
1058 tail
= &(*tail
)->next
;
1064 free_acl_address(acl_address
** head
)
1067 acl_address
*l
= *head
;
1073 CBDATA_TYPE(acl_tos
);
1076 dump_acl_tos(StoreEntry
* entry
, const char *name
, acl_tos
* head
)
1080 for (l
= head
; l
; l
= l
->next
) {
1082 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->tos
);
1084 storeAppendPrintf(entry
, "%s none", name
);
1086 dump_acl_list(entry
, l
->aclList
);
1088 storeAppendPrintf(entry
, "\n");
1093 freed_acl_tos(void *data
)
1095 acl_tos
*l
= static_cast<acl_tos
*>(data
);
1096 aclDestroyAclList(&l
->aclList
);
1100 parse_acl_tos(acl_tos
** head
)
1103 acl_tos
**tail
= head
; /* sane name below */
1106 char *token
= strtok(NULL
, w_space
);
1113 if (sscanf(token
, "0x%x%c", &tos
, &junk
) != 1) {
1118 if (tos
< 0 || tos
> 255) {
1123 CBDATA_INIT_TYPE_FREECB(acl_tos
, freed_acl_tos
);
1125 l
= cbdataAlloc(acl_tos
);
1129 aclParseAclList(LegacyParser
, &l
->aclList
);
1132 tail
= &(*tail
)->next
;
1138 free_acl_tos(acl_tos
** head
)
1148 CBDATA_TYPE(acl_size_t
);
1151 dump_acl_b_size_t(StoreEntry
* entry
, const char *name
, acl_size_t
* head
)
1155 for (l
= head
; l
; l
= l
->next
) {
1157 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) l
->size
, B_BYTES_STR
);
1159 storeAppendPrintf(entry
, "%s none", name
);
1161 dump_acl_list(entry
, l
->aclList
);
1163 storeAppendPrintf(entry
, "\n");
1168 freed_acl_b_size_t(void *data
)
1170 acl_size_t
*l
= static_cast<acl_size_t
*>(data
);
1171 aclDestroyAclList(&l
->aclList
);
1175 parse_acl_b_size_t(acl_size_t
** head
)
1178 acl_size_t
**tail
= head
; /* sane name below */
1180 CBDATA_INIT_TYPE_FREECB(acl_size_t
, freed_acl_b_size_t
);
1182 l
= cbdataAlloc(acl_size_t
);
1184 parse_b_int64_t(&l
->size
);
1186 aclParseAclList(LegacyParser
, &l
->aclList
);
1189 tail
= &(*tail
)->next
;
1195 free_acl_b_size_t(acl_size_t
** head
)
1198 acl_size_t
*l
= *head
;
1207 #include "DelayPools.h"
1208 #include "DelayConfig.h"
1209 /* do nothing - free_delay_pool_count is the magic free function.
1210 * this is why delay_pool_count isn't just marked TYPE: ushort
1212 #define free_delay_pool_class(X)
1213 #define free_delay_pool_access(X)
1214 #define free_delay_pool_rates(X)
1215 #define dump_delay_pool_class(X, Y, Z)
1216 #define dump_delay_pool_access(X, Y, Z)
1217 #define dump_delay_pool_rates(X, Y, Z)
1220 free_delay_pool_count(DelayConfig
* cfg
)
1222 cfg
->freePoolCount();
1226 dump_delay_pool_count(StoreEntry
* entry
, const char *name
, DelayConfig
&cfg
)
1228 cfg
.dumpPoolCount (entry
, name
);
1232 parse_delay_pool_count(DelayConfig
* cfg
)
1234 cfg
->parsePoolCount();
1238 parse_delay_pool_class(DelayConfig
* cfg
)
1240 cfg
->parsePoolClass();
1244 parse_delay_pool_rates(DelayConfig
* cfg
)
1246 cfg
->parsePoolRates();
1250 parse_delay_pool_access(DelayConfig
* cfg
)
1252 cfg
->parsePoolAccess(LegacyParser
);
1259 dump_http_header_access(StoreEntry
* entry
, const char *name
, header_mangler header
[])
1263 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1264 if (header
[i
].access_list
!= NULL
) {
1265 storeAppendPrintf(entry
, "%s ", name
);
1266 dump_acl_access(entry
, httpHeaderNameById(i
),
1267 header
[i
].access_list
);
1273 parse_http_header_access(header_mangler header
[])
1278 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1279 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1280 debugs(3, 0, "parse_http_header_access: missing header name.");
1284 /* Now lookup index of header. */
1285 id
= httpHeaderIdByNameDef(t
, strlen(t
));
1287 if (strcmp(t
, "All") == 0)
1289 else if (strcmp(t
, "Other") == 0)
1291 else if (id
== -1) {
1292 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1293 debugs(3, 0, "parse_http_header_access: unknown header name '" << t
<< "'");
1297 if (id
!= HDR_ENUM_END
) {
1298 parse_acl_access(&header
[id
].access_list
);
1300 char *next_string
= t
+ strlen(t
) - 1;
1302 *(next_string
+ 1) = ' ';
1304 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1305 char *new_string
= xstrdup(next_string
);
1306 strtok(new_string
, w_space
);
1307 parse_acl_access(&header
[i
].access_list
);
1308 safe_free(new_string
);
1314 free_http_header_access(header_mangler header
[])
1318 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1319 free_acl_access(&header
[i
].access_list
);
1324 dump_http_header_replace(StoreEntry
* entry
, const char *name
, header_mangler
1329 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1330 if (NULL
== header
[i
].replacement
)
1333 storeAppendPrintf(entry
, "%s %s %s\n", name
, httpHeaderNameById(i
),
1334 header
[i
].replacement
);
1339 parse_http_header_replace(header_mangler header
[])
1344 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1345 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1346 debugs(3, 0, "parse_http_header_replace: missing header name.");
1350 /* Now lookup index of header. */
1351 id
= httpHeaderIdByNameDef(t
, strlen(t
));
1353 if (strcmp(t
, "All") == 0)
1355 else if (strcmp(t
, "Other") == 0)
1357 else if (id
== -1) {
1358 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1359 debugs(3, 0, "parse_http_header_replace: unknown header name " << t
<< ".");
1364 if (id
!= HDR_ENUM_END
) {
1365 if (header
[id
].replacement
!= NULL
)
1366 safe_free(header
[id
].replacement
);
1368 header
[id
].replacement
= xstrdup(t
+ strlen(t
) + 1);
1370 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1371 if (header
[i
].replacement
!= NULL
)
1372 safe_free(header
[i
].replacement
);
1374 header
[i
].replacement
= xstrdup(t
+ strlen(t
) + 1);
1380 free_http_header_replace(header_mangler header
[])
1384 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1385 if (header
[i
].replacement
!= NULL
)
1386 safe_free(header
[i
].replacement
);
1393 dump_cachedir(StoreEntry
* entry
, const char *name
, SquidConfig::_cacheSwap swap
)
1399 for (i
= 0; i
< swap
.n_configured
; i
++) {
1400 s
= dynamic_cast<SwapDir
*>(swap
.swapDirs
[i
].getRaw());
1402 storeAppendPrintf(entry
, "%s %s %s", name
, s
->type(), s
->path
);
1404 storeAppendPrintf(entry
, "\n");
1409 check_null_string(char *s
)
1415 parse_authparam(authConfig
* config
)
1420 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1423 if ((param_str
= strtok(NULL
, w_space
)) == NULL
)
1426 /* find a configuration for the scheme */
1427 AuthConfig
*scheme
= AuthConfig::Find (type_str
);
1429 if (scheme
== NULL
) {
1430 /* Create a configuration */
1431 AuthScheme
*theScheme
;
1433 if ((theScheme
= AuthScheme::Find(type_str
)) == NULL
) {
1434 debugs(3, 0, "Parsing Config File: Unknown authentication scheme '" << type_str
<< "'.");
1438 config
->push_back(theScheme
->createConfig());
1439 scheme
= config
->back();
1443 scheme
->parse(scheme
, config
->size(), param_str
);
1447 free_authparam(authConfig
* cfg
)
1450 /* DON'T FREE THESE FOR RECONFIGURE */
1455 while (cfg
->size()) {
1456 scheme
= cfg
->pop_back();
1462 dump_authparam(StoreEntry
* entry
, const char *name
, authConfig cfg
)
1464 for (authConfig::iterator i
= cfg
.begin(); i
!= cfg
.end(); ++i
)
1465 (*i
)->dump(entry
, name
, (*i
));
1468 /* TODO: just return the object, the # is irrelevant */
1470 find_fstype(char *type
)
1472 for (size_t i
= 0; i
< StoreFileSystem::FileSystems().size(); ++i
)
1473 if (strcasecmp(type
, StoreFileSystem::FileSystems().items
[i
]->type()) == 0)
1480 parse_cachedir(SquidConfig::_cacheSwap
* swap
)
1484 RefCount
<SwapDir
> sd
;
1488 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1491 if ((path_str
= strtok(NULL
, w_space
)) == NULL
)
1494 fs
= find_fstype(type_str
);
1499 /* reconfigure existing dir */
1501 for (i
= 0; i
< swap
->n_configured
; i
++) {
1502 assert (swap
->swapDirs
[i
].getRaw());
1504 if ((strcasecmp(path_str
, dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw())->path
)) == 0) {
1505 /* this is specific to on-fs Stores. The right
1506 * way to handle this is probably to have a mapping
1507 * from paths to stores, and have on-fs stores
1508 * register with that, and lookip in that in their
1509 * own setup logic. RBC 20041225. TODO.
1512 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw());
1514 if (sd
->type() != StoreFileSystem::FileSystems().items
[fs
]->type()) {
1515 debugs(3, 0, "ERROR: Can't change type of existing cache_dir " <<
1516 sd
->type() << " " << sd
->path
<< " to " << type_str
<< ". Restart required");
1520 sd
->reconfigure (i
, path_str
);
1522 update_maxobjsize();
1529 if (swap
->n_configured
> 63) {
1530 /* 7 bits, signed */
1531 debugs(3, DBG_CRITICAL
, "WARNING: There is a fixed maximum of 63 cache_dir entries Squid can handle.");
1532 debugs(3, DBG_CRITICAL
, "WARNING: '" << path_str
<< "' is one to many.");
1537 allocate_new_swapdir(swap
);
1539 swap
->swapDirs
[swap
->n_configured
] = StoreFileSystem::FileSystems().items
[fs
]->createSwapDir();
1541 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[swap
->n_configured
].getRaw());
1543 /* parse the FS parameters and options */
1544 sd
->parse(swap
->n_configured
, path_str
);
1546 ++swap
->n_configured
;
1548 /* Update the max object size */
1549 update_maxobjsize();
1553 peer_type_str(const peer_t type
)
1555 const char * result
;
1567 case PEER_MULTICAST
:
1568 result
= "multicast";
1580 dump_peer(StoreEntry
* entry
, const char *name
, peer
* p
)
1584 LOCAL_ARRAY(char, xname
, 128);
1587 storeAppendPrintf(entry
, "%s %s %s %d %d",
1593 dump_peer_options(entry
, p
);
1595 for (d
= p
->peer_domain
; d
; d
= d
->next
) {
1596 storeAppendPrintf(entry
, "cache_peer_domain %s %s%s\n",
1598 d
->do_ping
? null_string
: "!",
1603 snprintf(xname
, 128, "cache_peer_access %s", p
->name
);
1604 dump_acl_access(entry
, xname
, p
->access
);
1607 for (t
= p
->typelist
; t
; t
= t
->next
) {
1608 storeAppendPrintf(entry
, "neighbor_type_domain %s %s %s\n",
1610 peer_type_str(t
->type
),
1619 * utility function to prevent getservbyname() being called with a numeric value
1620 * on Windows at least it returns garage results.
1623 isUnsignedNumeric(const char *str
, size_t len
)
1625 if (len
< 1) return false;
1627 for (; len
>0 && *str
; str
++, len
--) {
1628 if (! isdigit(*str
))
1635 \param proto 'tcp' or 'udp' for protocol
1636 \returns Port the named service is supposed to be listening on.
1639 GetService(const char *proto
)
1641 struct servent
*port
= NULL
;
1642 /** Parses a port number or service name from the squid.conf */
1643 char *token
= strtok(NULL
, w_space
);
1644 if (token
== NULL
) {
1646 return 0; /* NEVER REACHED */
1648 /** Returns either the service port number from /etc/services */
1649 if( !isUnsignedNumeric(token
, strlen(token
)) )
1650 port
= getservbyname(token
, proto
);
1652 return ntohs((u_short
)port
->s_port
);
1654 /** Or a numeric translation of the config text. */
1655 return xatos(token
);
1659 \returns Port the named TCP service is supposed to be listening on.
1660 \copydoc GetService(const char *proto)
1665 return GetService("tcp");
1669 \returns Port the named UDP service is supposed to be listening on.
1670 \copydoc GetService(const char *proto)
1675 return GetService("udp");
1679 parse_peer(peer
** head
)
1683 CBDATA_INIT_TYPE_FREECB(peer
, peerDestroy
);
1684 p
= cbdataAlloc(peer
);
1685 p
->http_port
= CACHE_HTTP_PORT
;
1686 p
->icp
.port
= CACHE_ICP_PORT
;
1689 p
->stats
.logged_state
= PEER_ALIVE
;
1691 if ((token
= strtok(NULL
, w_space
)) == NULL
)
1694 p
->host
= xstrdup(token
);
1696 p
->name
= xstrdup(token
);
1698 if ((token
= strtok(NULL
, w_space
)) == NULL
)
1701 p
->type
= parseNeighborType(token
);
1703 if (p
->type
== PEER_MULTICAST
) {
1704 p
->options
.no_digest
= 1;
1705 p
->options
.no_netdb_exchange
= 1;
1708 p
->http_port
= GetTcpService();
1713 p
->icp
.port
= GetUdpService();
1714 p
->connection_auth
= 2; /* auto */
1716 while ((token
= strtok(NULL
, w_space
))) {
1717 if (!strcasecmp(token
, "proxy-only")) {
1718 p
->options
.proxy_only
= 1;
1719 } else if (!strcasecmp(token
, "no-query")) {
1720 p
->options
.no_query
= 1;
1721 } else if (!strcasecmp(token
, "background-ping")) {
1722 p
->options
.background_ping
= 1;
1723 } else if (!strcasecmp(token
, "no-digest")) {
1724 p
->options
.no_digest
= 1;
1725 } else if (!strcasecmp(token
, "multicast-responder")) {
1726 p
->options
.mcast_responder
= 1;
1727 } else if (!strncasecmp(token
, "weight=", 7)) {
1728 p
->weight
= xatoi(token
+ 7);
1729 } else if (!strncasecmp(token
, "basetime=", 9)) {
1730 p
->basetime
= xatoi(token
+ 9);
1731 } else if (!strcasecmp(token
, "closest-only")) {
1732 p
->options
.closest_only
= 1;
1733 } else if (!strncasecmp(token
, "ttl=", 4)) {
1734 p
->mcast
.ttl
= xatoi(token
+ 4);
1736 if (p
->mcast
.ttl
< 0)
1739 if (p
->mcast
.ttl
> 128)
1741 } else if (!strcasecmp(token
, "default")) {
1742 p
->options
.default_parent
= 1;
1743 } else if (!strcasecmp(token
, "round-robin")) {
1744 p
->options
.roundrobin
= 1;
1745 } else if (!strcasecmp(token
, "weighted-round-robin")) {
1746 p
->options
.weighted_roundrobin
= 1;
1749 } else if (!strcasecmp(token
, "htcp")) {
1750 p
->options
.htcp
= 1;
1751 } else if (!strcasecmp(token
, "htcp-oldsquid")) {
1752 p
->options
.htcp
= 1;
1753 p
->options
.htcp_oldsquid
= 1;
1754 } else if (!strcasecmp(token
, "htcp-no-clr")) {
1755 if (p
->options
.htcp_only_clr
)
1756 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
1757 p
->options
.htcp
= 1;
1758 p
->options
.htcp_no_clr
= 1;
1759 } else if (!strcasecmp(token
, "htcp-no-purge-clr")) {
1760 p
->options
.htcp
= 1;
1761 p
->options
.htcp_no_purge_clr
= 1;
1762 } else if (!strcasecmp(token
, "htcp-only-clr")) {
1763 if (p
->options
.htcp_no_clr
)
1764 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
1765 p
->options
.htcp
= 1;
1766 p
->options
.htcp_only_clr
= 1;
1767 } else if (!strcasecmp(token
, "htcp-forward-clr")) {
1768 p
->options
.htcp
= 1;
1769 p
->options
.htcp_forward_clr
= 1;
1772 } else if (!strcasecmp(token
, "no-netdb-exchange")) {
1773 p
->options
.no_netdb_exchange
= 1;
1775 } else if (!strcasecmp(token
, "carp")) {
1776 if (p
->type
!= PEER_PARENT
)
1777 fatalf("parse_peer: non-parent carp peer %s/%d\n", p
->host
, p
->http_port
);
1779 p
->options
.carp
= 1;
1781 } else if (!strcasecmp(token
, "userhash")) {
1782 if (p
->type
!= PEER_PARENT
)
1783 fatalf("parse_peer: non-parent userhash peer %s/%d\n", p
->host
, p
->http_port
);
1785 p
->options
.userhash
= 1;
1787 } else if (!strcasecmp(token
, "sourcehash")) {
1788 if (p
->type
!= PEER_PARENT
)
1789 fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p
->host
, p
->http_port
);
1791 p
->options
.sourcehash
= 1;
1795 } else if (!strcasecmp(token
, "no-delay")) {
1796 p
->options
.no_delay
= 1;
1799 } else if (!strncasecmp(token
, "login=", 6)) {
1800 p
->login
= xstrdup(token
+ 6);
1801 rfc1738_unescape(p
->login
);
1802 } else if (!strncasecmp(token
, "connect-timeout=", 16)) {
1803 p
->connect_timeout
= xatoi(token
+ 16);
1804 } else if (!strncasecmp(token
, "connect-fail-limit=", 19)) {
1805 p
->connect_fail_limit
= xatoi(token
+ 19);
1806 #if USE_CACHE_DIGESTS
1807 } else if (!strncasecmp(token
, "digest-url=", 11)) {
1808 p
->digest_url
= xstrdup(token
+ 11);
1811 } else if (!strcasecmp(token
, "allow-miss")) {
1812 p
->options
.allow_miss
= 1;
1813 } else if (!strncasecmp(token
, "max-conn=", 9)) {
1814 p
->max_conn
= xatoi(token
+ 9);
1815 } else if (!strcasecmp(token
, "originserver")) {
1816 p
->options
.originserver
= 1;
1817 } else if (!strncasecmp(token
, "name=", 5)) {
1821 p
->name
= xstrdup(token
+ 5);
1822 } else if (!strncasecmp(token
, "forceddomain=", 13)) {
1823 safe_free(p
->domain
);
1826 p
->domain
= xstrdup(token
+ 13);
1830 } else if (strcmp(token
, "ssl") == 0) {
1832 } else if (strncmp(token
, "sslcert=", 8) == 0) {
1833 safe_free(p
->sslcert
);
1834 p
->sslcert
= xstrdup(token
+ 8);
1835 } else if (strncmp(token
, "sslkey=", 7) == 0) {
1836 safe_free(p
->sslkey
);
1837 p
->sslkey
= xstrdup(token
+ 7);
1838 } else if (strncmp(token
, "sslversion=", 11) == 0) {
1839 p
->sslversion
= atoi(token
+ 11);
1840 } else if (strncmp(token
, "ssloptions=", 11) == 0) {
1841 safe_free(p
->ssloptions
);
1842 p
->ssloptions
= xstrdup(token
+ 11);
1843 } else if (strncmp(token
, "sslcipher=", 10) == 0) {
1844 safe_free(p
->sslcipher
);
1845 p
->sslcipher
= xstrdup(token
+ 10);
1846 } else if (strncmp(token
, "sslcafile=", 10) == 0) {
1847 safe_free(p
->sslcafile
);
1848 p
->sslcafile
= xstrdup(token
+ 10);
1849 } else if (strncmp(token
, "sslcapath=", 10) == 0) {
1850 safe_free(p
->sslcapath
);
1851 p
->sslcapath
= xstrdup(token
+ 10);
1852 } else if (strncmp(token
, "sslcrlfile=", 11) == 0) {
1853 safe_free(p
->sslcrlfile
);
1854 p
->sslcapath
= xstrdup(token
+ 10);
1855 } else if (strncmp(token
, "sslflags=", 9) == 0) {
1856 safe_free(p
->sslflags
);
1857 p
->sslflags
= xstrdup(token
+ 9);
1858 } else if (strncmp(token
, "ssldomain=", 10) == 0) {
1859 safe_free(p
->ssldomain
);
1860 p
->ssldomain
= xstrdup(token
+ 10);
1863 } else if (strcmp(token
, "front-end-https") == 0) {
1864 p
->front_end_https
= 1;
1865 } else if (strcmp(token
, "front-end-https=on") == 0) {
1866 p
->front_end_https
= 1;
1867 } else if (strcmp(token
, "front-end-https=auto") == 0) {
1868 p
->front_end_https
= 2;
1869 } else if (strcmp(token
, "connection-auth=off") == 0) {
1870 p
->connection_auth
= 0;
1871 } else if (strcmp(token
, "connection-auth") == 0) {
1872 p
->connection_auth
= 1;
1873 } else if (strcmp(token
, "connection-auth=on") == 0) {
1874 p
->connection_auth
= 1;
1875 } else if (strcmp(token
, "connection-auth=auto") == 0) {
1876 p
->connection_auth
= 2;
1878 debugs(3, 0, "parse_peer: token='" << token
<< "'");
1883 if (peerFindByName(p
->name
))
1884 fatalf("ERROR: cache_peer %s specified twice\n", p
->name
);
1889 if (p
->connect_fail_limit
< 1)
1890 p
->connect_fail_limit
= 1;
1892 p
->icp
.version
= ICP_VERSION_CURRENT
;
1896 #if USE_CACHE_DIGESTS
1898 if (!p
->options
.no_digest
) {
1899 /* XXX This looks odd.. who has the original pointer
1902 PeerDigest
*pd
= peerDigestCreate(p
);
1903 p
->digest
= cbdataReference(pd
);
1908 p
->index
= ++Config
.npeers
;
1910 while (*head
!= NULL
)
1911 head
= &(*head
)->next
;
1919 free_peer(peer
** P
)
1923 while ((p
= *P
) != NULL
) {
1925 #if USE_CACHE_DIGESTS
1927 cbdataReferenceDone(p
->digest
);
1937 dump_cachemgrpasswd(StoreEntry
* entry
, const char *name
, cachemgr_passwd
* list
)
1941 while (list
!= NULL
) {
1942 if (strcmp(list
->passwd
, "none") && strcmp(list
->passwd
, "disable"))
1943 storeAppendPrintf(entry
, "%s XXXXXXXXXX", name
);
1945 storeAppendPrintf(entry
, "%s %s", name
, list
->passwd
);
1947 for (w
= list
->actions
; w
!= NULL
; w
= w
->next
) {
1948 storeAppendPrintf(entry
, " %s", w
->key
);
1951 storeAppendPrintf(entry
, "\n");
1957 parse_cachemgrpasswd(cachemgr_passwd
** head
)
1959 char *passwd
= NULL
;
1960 wordlist
*actions
= NULL
;
1962 cachemgr_passwd
**P
;
1963 parse_string(&passwd
);
1964 parse_wordlist(&actions
);
1965 p
= static_cast<cachemgr_passwd
*>(xcalloc(1, sizeof(cachemgr_passwd
)));
1967 p
->actions
= actions
;
1969 for (P
= head
; *P
; P
= &(*P
)->next
) {
1971 * See if any of the actions from this line already have a
1972 * password from previous lines. The password checking
1973 * routines in cache_manager.c take the the password from
1974 * the first cachemgr_passwd struct that contains the
1975 * requested action. Thus, we should warn users who might
1976 * think they can have two passwords for the same action.
1981 for (w
= (*P
)->actions
; w
; w
= w
->next
) {
1982 for (u
= actions
; u
; u
= u
->next
) {
1983 if (strcmp(w
->key
, u
->key
))
1986 debugs(0, 0, "WARNING: action '" << u
->key
<< "' (line " << config_lineno
<< ") already has a password");
1995 free_cachemgrpasswd(cachemgr_passwd
** head
)
1999 while ((p
= *head
) != NULL
) {
2002 wordlistDestroy(&p
->actions
);
2008 dump_denyinfo(StoreEntry
* entry
, const char *name
, acl_deny_info_list
* var
)
2012 while (var
!= NULL
) {
2013 storeAppendPrintf(entry
, "%s %s", name
, var
->err_page_name
);
2015 for (a
= var
->acl_list
; a
!= NULL
; a
= a
->next
)
2016 storeAppendPrintf(entry
, " %s", a
->name
);
2018 storeAppendPrintf(entry
, "\n");
2025 parse_denyinfo(acl_deny_info_list
** var
)
2027 aclParseDenyInfoLine(var
);
2031 free_denyinfo(acl_deny_info_list
** list
)
2033 acl_deny_info_list
*a
= NULL
;
2034 acl_deny_info_list
*a_next
= NULL
;
2035 acl_name_list
*l
= NULL
;
2036 acl_name_list
*l_next
= NULL
;
2038 for (a
= *list
; a
; a
= a_next
) {
2039 for (l
= a
->acl_list
; l
; l
= l_next
) {
2041 memFree(l
, MEM_ACL_NAME_LIST
);
2046 memFree(a
, MEM_ACL_DENY_INFO_LIST
);
2054 parse_peer_access(void)
2059 if (!(host
= strtok(NULL
, w_space
)))
2062 if ((p
= peerFindByName(host
)) == NULL
) {
2063 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2067 aclParseAccessLine(LegacyParser
, &p
->access
);
2071 parse_hostdomain(void)
2074 char *domain
= NULL
;
2076 if (!(host
= strtok(NULL
, w_space
)))
2079 while ((domain
= strtok(NULL
, list_sep
))) {
2080 domain_ping
*l
= NULL
;
2081 domain_ping
**L
= NULL
;
2084 if ((p
= peerFindByName(host
)) == NULL
) {
2085 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2089 l
= static_cast<domain_ping
*>(xcalloc(1, sizeof(domain_ping
)));
2092 if (*domain
== '!') { /* check for !.edu */
2097 l
->domain
= xstrdup(domain
);
2099 for (L
= &(p
->peer_domain
); *L
; L
= &((*L
)->next
));
2105 parse_hostdomaintype(void)
2109 char *domain
= NULL
;
2111 if (!(host
= strtok(NULL
, w_space
)))
2114 if (!(type
= strtok(NULL
, w_space
)))
2117 while ((domain
= strtok(NULL
, list_sep
))) {
2118 domain_type
*l
= NULL
;
2119 domain_type
**L
= NULL
;
2122 if ((p
= peerFindByName(host
)) == NULL
) {
2123 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2127 l
= static_cast<domain_type
*>(xcalloc(1, sizeof(domain_type
)));
2128 l
->type
= parseNeighborType(type
);
2129 l
->domain
= xstrdup(domain
);
2131 for (L
= &(p
->typelist
); *L
; L
= &((*L
)->next
));
2137 dump_int(StoreEntry
* entry
, const char *name
, int var
)
2139 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2157 dump_onoff(StoreEntry
* entry
, const char *name
, int var
)
2159 storeAppendPrintf(entry
, "%s %s\n", name
, var
? "on" : "off");
2163 parse_onoff(int *var
)
2165 char *token
= strtok(NULL
, w_space
);
2170 if (!strcasecmp(token
, "on") || !strcasecmp(token
, "enable"))
2176 #define free_onoff free_int
2179 dump_tristate(StoreEntry
* entry
, const char *name
, int var
)
2190 storeAppendPrintf(entry
, "%s %s\n", name
, state
);
2194 parse_tristate(int *var
)
2196 char *token
= strtok(NULL
, w_space
);
2201 if (!strcasecmp(token
, "on") || !strcasecmp(token
, "enable"))
2203 else if (!strcasecmp(token
, "warn"))
2209 #define free_tristate free_int
2212 dump_refreshpattern(StoreEntry
* entry
, const char *name
, refresh_t
* head
)
2214 while (head
!= NULL
) {
2215 storeAppendPrintf(entry
, "%s%s %s %d %d%% %d\n",
2217 head
->flags
.icase
? " -i" : null_string
,
2219 (int) head
->min
/ 60,
2220 (int) (100.0 * head
->pct
+ 0.5),
2221 (int) head
->max
/ 60);
2223 if (head
->flags
.refresh_ims
)
2224 storeAppendPrintf(entry
, " refresh-ims");
2228 if (head
->flags
.override_expire
)
2229 storeAppendPrintf(entry
, " override-expire");
2231 if (head
->flags
.override_lastmod
)
2232 storeAppendPrintf(entry
, " override-lastmod");
2234 if (head
->flags
.reload_into_ims
)
2235 storeAppendPrintf(entry
, " reload-into-ims");
2237 if (head
->flags
.ignore_reload
)
2238 storeAppendPrintf(entry
, " ignore-reload");
2240 if (head
->flags
.ignore_no_cache
)
2241 storeAppendPrintf(entry
, " ignore-no-cache");
2243 if (head
->flags
.ignore_no_store
)
2244 storeAppendPrintf(entry
, " ignore-no-store");
2246 if (head
->flags
.ignore_must_revalidate
)
2247 storeAppendPrintf(entry
, " ignore-must-revalidate");
2249 if (head
->flags
.ignore_private
)
2250 storeAppendPrintf(entry
, " ignore-private");
2252 if (head
->flags
.ignore_auth
)
2253 storeAppendPrintf(entry
, " ignore-auth");
2257 storeAppendPrintf(entry
, "\n");
2264 parse_refreshpattern(refresh_t
** head
)
2271 int refresh_ims
= 0;
2274 int override_expire
= 0;
2275 int override_lastmod
= 0;
2276 int reload_into_ims
= 0;
2277 int ignore_reload
= 0;
2278 int ignore_no_cache
= 0;
2279 int ignore_no_store
= 0;
2280 int ignore_must_revalidate
= 0;
2281 int ignore_private
= 0;
2282 int ignore_auth
= 0;
2289 int flags
= REG_EXTENDED
| REG_NOSUB
;
2291 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
2296 if (strcmp(token
, "-i") == 0) {
2298 token
= strtok(NULL
, w_space
);
2299 } else if (strcmp(token
, "+i") == 0) {
2300 flags
&= ~REG_ICASE
;
2301 token
= strtok(NULL
, w_space
);
2304 if (token
== NULL
) {
2309 pattern
= xstrdup(token
);
2311 i
= GetInteger(); /* token: min */
2313 min
= (time_t) (i
* 60); /* convert minutes to seconds */
2315 i
= GetInteger(); /* token: pct */
2317 pct
= (double) i
/ 100.0;
2319 i
= GetInteger(); /* token: max */
2321 max
= (time_t) (i
* 60); /* convert minutes to seconds */
2324 while ((token
= strtok(NULL
, w_space
)) != NULL
) {
2325 if (!strcmp(token
, "refresh-ims")) {
2329 } else if (!strcmp(token
, "override-expire"))
2330 override_expire
= 1;
2331 else if (!strcmp(token
, "override-lastmod"))
2332 override_lastmod
= 1;
2333 else if (!strcmp(token
, "ignore-no-cache"))
2334 ignore_no_cache
= 1;
2335 else if (!strcmp(token
, "ignore-no-store"))
2336 ignore_no_store
= 1;
2337 else if (!strcmp(token
, "ignore-must-revalidate"))
2338 ignore_must_revalidate
= 1;
2339 else if (!strcmp(token
, "ignore-private"))
2341 else if (!strcmp(token
, "ignore-auth"))
2343 else if (!strcmp(token
, "reload-into-ims")) {
2344 reload_into_ims
= 1;
2345 refresh_nocache_hack
= 1;
2346 /* tell client_side.c that this is used */
2347 } else if (!strcmp(token
, "ignore-reload")) {
2349 refresh_nocache_hack
= 1;
2350 /* tell client_side.c that this is used */
2354 debugs(22, 0, "redreshAddToList: Unknown option '" << pattern
<< "': " << token
);
2357 if ((errcode
= regcomp(&comp
, pattern
, flags
)) != 0) {
2359 regerror(errcode
, &comp
, errbuf
, sizeof errbuf
);
2360 debugs(22, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
2361 debugs(22, 0, "refreshAddToList: Invalid regular expression '" << pattern
<< "': " << errbuf
);
2365 pct
= pct
< 0.0 ? 0.0 : pct
;
2366 max
= max
< 0 ? 0 : max
;
2367 t
= static_cast<refresh_t
*>(xcalloc(1, sizeof(refresh_t
)));
2368 t
->pattern
= (char *) xstrdup(pattern
);
2369 t
->compiled_pattern
= comp
;
2374 if (flags
& REG_ICASE
)
2378 t
->flags
.refresh_ims
= 1;
2382 if (override_expire
)
2383 t
->flags
.override_expire
= 1;
2385 if (override_lastmod
)
2386 t
->flags
.override_lastmod
= 1;
2388 if (reload_into_ims
)
2389 t
->flags
.reload_into_ims
= 1;
2392 t
->flags
.ignore_reload
= 1;
2394 if (ignore_no_cache
)
2395 t
->flags
.ignore_no_cache
= 1;
2397 if (ignore_no_store
)
2398 t
->flags
.ignore_no_store
= 1;
2400 if (ignore_must_revalidate
)
2401 t
->flags
.ignore_must_revalidate
= 1;
2404 t
->flags
.ignore_private
= 1;
2407 t
->flags
.ignore_auth
= 1;
2414 head
= &(*head
)->next
;
2422 free_refreshpattern(refresh_t
** head
)
2426 while ((t
= *head
) != NULL
) {
2428 safe_free(t
->pattern
);
2429 regfree(&t
->compiled_pattern
);
2434 refresh_nocache_hack
= 0;
2440 dump_string(StoreEntry
* entry
, const char *name
, char *var
)
2443 storeAppendPrintf(entry
, "%s %s\n", name
, var
);
2447 parse_string(char **var
)
2449 char *token
= strtok(NULL
, w_space
);
2455 *var
= xstrdup(token
);
2459 ConfigParser::ParseString(char **var
)
2465 ConfigParser::ParseString(String
*var
)
2467 char *token
= strtok(NULL
, w_space
);
2476 free_string(char **var
)
2482 parse_eol(char *volatile *var
)
2484 unsigned char *token
= (unsigned char *) strtok(NULL
, null_string
);
2492 while (*token
&& xisspace(*token
))
2500 *var
= xstrdup((char *) token
);
2503 #define dump_eol dump_string
2504 #define free_eol free_string
2507 dump_time_t(StoreEntry
* entry
, const char *name
, time_t var
)
2509 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int) var
);
2513 parse_time_t(time_t * var
)
2515 parseTimeLine(var
, T_SECOND_STR
);
2519 free_time_t(time_t * var
)
2525 dump_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
2527 storeAppendPrintf(entry
, "%s %d\n", name
, (int) var
);
2531 dump_b_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
2533 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
2538 dump_kb_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
2540 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_KBYTES_STR
);
2545 dump_b_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
2547 storeAppendPrintf(entry
, "%s %"PRId64
" %s\n", name
, var
, B_BYTES_STR
);
2551 dump_kb_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
2553 storeAppendPrintf(entry
, "%s %"PRId64
" %s\n", name
, var
, B_KBYTES_STR
);
2557 parse_size_t(size_t * var
)
2565 parse_b_size_t(size_t * var
)
2567 parseBytesLine(var
, B_BYTES_STR
);
2572 parse_kb_size_t(size_t * var
)
2574 parseBytesLine(var
, B_KBYTES_STR
);
2579 parse_b_int64_t(int64_t * var
)
2581 parseBytesLine64(var
, B_BYTES_STR
);
2585 parse_kb_int64_t(int64_t * var
)
2587 parseBytesLine64(var
, B_KBYTES_STR
);
2591 free_size_t(size_t * var
)
2597 free_b_int64_t(int64_t * var
)
2602 #define free_b_size_t free_size_t
2603 #define free_kb_size_t free_size_t
2604 #define free_mb_size_t free_size_t
2605 #define free_gb_size_t free_size_t
2606 #define free_kb_int64_t free_b_int64_t
2609 dump_ushort(StoreEntry
* entry
, const char *name
, u_short var
)
2611 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2615 free_ushort(u_short
* u
)
2621 parse_ushort(u_short
* var
)
2623 ConfigParser::ParseUShort(var
);
2627 ConfigParser::ParseUShort(u_short
*var
)
2633 ConfigParser::ParseBool(bool *var
)
2635 int i
= GetInteger();
2646 dump_wordlist(StoreEntry
* entry
, const char *name
, wordlist
* list
)
2648 while (list
!= NULL
) {
2649 storeAppendPrintf(entry
, "%s %s\n", name
, list
->key
);
2655 ConfigParser::ParseWordList(wordlist
** list
)
2657 parse_wordlist(list
);
2661 parse_wordlist(wordlist
** list
)
2664 char *t
= strtok(NULL
, "");
2666 while ((token
= strwordtok(NULL
, &t
)))
2667 wordlistAdd(list
, token
);
2670 #if 0 /* now unused */
2672 check_null_wordlist(wordlist
* w
)
2679 check_null_acl_access(acl_access
* a
)
2684 #define free_wordlist wordlistDestroy
2686 #define free_uri_whitespace free_int
2689 parse_uri_whitespace(int *var
)
2691 char *token
= strtok(NULL
, w_space
);
2696 if (!strcasecmp(token
, "strip"))
2697 *var
= URI_WHITESPACE_STRIP
;
2698 else if (!strcasecmp(token
, "deny"))
2699 *var
= URI_WHITESPACE_DENY
;
2700 else if (!strcasecmp(token
, "allow"))
2701 *var
= URI_WHITESPACE_ALLOW
;
2702 else if (!strcasecmp(token
, "encode"))
2703 *var
= URI_WHITESPACE_ENCODE
;
2704 else if (!strcasecmp(token
, "chop"))
2705 *var
= URI_WHITESPACE_CHOP
;
2711 dump_uri_whitespace(StoreEntry
* entry
, const char *name
, int var
)
2715 if (var
== URI_WHITESPACE_ALLOW
)
2717 else if (var
== URI_WHITESPACE_ENCODE
)
2719 else if (var
== URI_WHITESPACE_CHOP
)
2721 else if (var
== URI_WHITESPACE_DENY
)
2726 storeAppendPrintf(entry
, "%s %s\n", name
, s
);
2730 free_removalpolicy(RemovalPolicySettings
** settings
)
2735 free_string(&(*settings
)->type
);
2737 free_wordlist(&(*settings
)->args
);
2745 parse_removalpolicy(RemovalPolicySettings
** settings
)
2748 free_removalpolicy(settings
);
2750 *settings
= new RemovalPolicySettings
;
2752 parse_string(&(*settings
)->type
);
2754 parse_wordlist(&(*settings
)->args
);
2758 dump_removalpolicy(StoreEntry
* entry
, const char *name
, RemovalPolicySettings
* settings
)
2761 storeAppendPrintf(entry
, "%s %s", name
, settings
->type
);
2762 args
= settings
->args
;
2765 storeAppendPrintf(entry
, " %s", args
->key
);
2769 storeAppendPrintf(entry
, "\n");
2772 #include "cf_parser.h"
2775 parseNeighborType(const char *s
)
2777 if (!strcasecmp(s
, "parent"))
2780 if (!strcasecmp(s
, "neighbor"))
2781 return PEER_SIBLING
;
2783 if (!strcasecmp(s
, "neighbour"))
2784 return PEER_SIBLING
;
2786 if (!strcasecmp(s
, "sibling"))
2787 return PEER_SIBLING
;
2789 if (!strcasecmp(s
, "multicast"))
2790 return PEER_MULTICAST
;
2792 debugs(15, 0, "WARNING: Unknown neighbor type: " << s
);
2794 return PEER_SIBLING
;
2799 parse_IpAddress_list_token(IpAddress_list
** head
, char *token
)
2806 unsigned short port
;
2813 if (*token
== '[') {
2816 t
= strchr(host
, ']');
2822 port
= xatos(t
+ 1);
2825 if ((t
= strchr(token
, ':'))) {
2829 port
= xatos(t
+ 1);
2833 } else if ((port
= strtol(token
, &tmp
, 10)), !*tmp
) {
2842 else if ( ipa
.GetHostByName(host
) ) /* dont use ipcache. Accept either FQDN or IPA. */
2847 /* port MUST be set after the IPA lookup/conversion is perofrmed. */
2851 head
= &(*head
)->next
;
2853 s
= static_cast<IpAddress_list
*>(xcalloc(1, sizeof(*s
)));
2860 parse_IpAddress_list(IpAddress_list
** head
)
2864 while ((token
= strtok(NULL
, w_space
))) {
2865 parse_IpAddress_list_token(head
, token
);
2870 dump_IpAddress_list(StoreEntry
* e
, const char *n
, const IpAddress_list
* s
)
2872 char ntoabuf
[MAX_IPSTRLEN
];
2875 storeAppendPrintf(e
, "%s %s\n",
2877 s
->s
.NtoA(ntoabuf
,MAX_IPSTRLEN
));
2883 free_IpAddress_list(IpAddress_list
** head
)
2885 if (*head
) delete *head
;
2889 #if CURRENTLY_UNUSED
2890 /* This code was previously used by http_port. Left as it really should
2891 * be used by icp_port and htcp_port
2894 check_null_IpAddress_list(const IpAddress_list
* s
)
2899 #endif /* CURRENTLY_UNUSED */
2900 #endif /* USE_WCCPv2 */
2902 CBDATA_CLASS_INIT(http_port_list
);
2905 parse_http_port_specification(http_port_list
* s
, char *token
)
2908 unsigned short port
= 0;
2912 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
2913 s
->name
= xstrdup(token
);
2914 s
->connection_auth_disabled
= false;
2917 if (*token
== '[') {
2920 t
= strchr(host
, ']');
2922 debugs(3, 0, "http(s)_port: missing ']' on IPv6 address: " << token
);
2927 debugs(3, 0, "http(s)_port: missing Port in: " << token
);
2930 port
= xatos(t
+ 1);
2933 if ((t
= strchr(token
, ':'))) {
2938 port
= xatos(t
+ 1);
2940 } else if ((port
= strtol(token
, &junk
, 10)), !*junk
) {
2942 debugs(3, 3, "http(s)_port: found Listen on Port: " << port
);
2944 debugs(3, 0, "http(s)_port: missing Port: " << token
);
2949 debugs(3, 0, "http(s)_port: Port cannot be 0: " << token
);
2956 debugs(3, 3, "http(s)_port: found Listen on wildcard address: " << s
->s
);
2957 } else if ( s
->s
= host
) { /* check/parse numeric IPA */
2959 debugs(3, 3, "http(s)_port: Listen on Host/IP: " << host
<< " --> " << s
->s
);
2960 } else if ( s
->s
.GetHostByName(host
) ) { /* check/parse for FQDN */
2961 /* dont use ipcache */
2962 s
->defaultsite
= xstrdup(host
);
2964 debugs(3, 3, "http(s)_port: found Listen as Host " << s
->defaultsite
<< " on IP: " << s
->s
);
2966 debugs(3, 0, "http(s)_port: failed to resolve Host/IP: " << host
);
2972 parse_http_port_option(http_port_list
* s
, char *token
)
2974 if (strncmp(token
, "defaultsite=", 12) == 0) {
2975 safe_free(s
->defaultsite
);
2976 s
->defaultsite
= xstrdup(token
+ 12);
2978 } else if (strncmp(token
, "name=", 5) == 0) {
2980 s
->name
= xstrdup(token
+ 5);
2981 } else if (strcmp(token
, "vhost") == 0) {
2984 } else if (strcmp(token
, "vport") == 0) {
2987 } else if (strncmp(token
, "vport=", 6) == 0) {
2988 s
->vport
= xatos(token
+ 6);
2990 } else if (strncmp(token
, "protocol=", 9) == 0) {
2991 s
->protocol
= xstrdup(token
+ 9);
2993 } else if (strcmp(token
, "accel") == 0) {
2995 } else if (strcmp(token
, "allow-direct") == 0) {
2996 s
->allow_direct
= 1;
2997 } else if (strcmp(token
, "no-connection-auth") == 0) {
2998 s
->connection_auth_disabled
= true;
2999 } else if (strcmp(token
, "connection-auth=off") == 0) {
3000 s
->connection_auth_disabled
= true;
3001 } else if (strcmp(token
, "connection-auth") == 0) {
3002 s
->connection_auth_disabled
= false;
3003 } else if (strcmp(token
, "connection-auth=on") == 0) {
3004 s
->connection_auth_disabled
= false;
3005 } else if (strncmp(token
, "disable-pmtu-discovery=", 23) == 0) {
3006 if (!strcasecmp(token
+ 23, "off"))
3007 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3008 else if (!strcasecmp(token
+ 23, "transparent"))
3009 s
->disable_pmtu_discovery
= DISABLE_PMTU_TRANSPARENT
;
3010 else if (!strcasecmp(token
+ 23, "always"))
3011 s
->disable_pmtu_discovery
= DISABLE_PMTU_ALWAYS
;
3015 } else if (strcmp(token
, "transparent") == 0 || strcmp(token
, "intercept") == 0) {
3017 IpInterceptor
.StartInterception();
3018 /* Log information regarding the port modes under interception. */
3019 debugs(3, DBG_IMPORTANT
, "Starting Authentication on port " << s
->s
);
3020 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (interception enabled)");
3023 /* INET6: until transparent REDIRECT works on IPv6 SOCKET, force wildcard to IPv4 */
3024 debugs(3, DBG_IMPORTANT
, "Disabling IPv6 on port " << s
->s
<< " (interception enabled)");
3025 if ( !s
->s
.SetIPv4() ) {
3026 debugs(3, DBG_CRITICAL
, "http(s)_port: IPv6 addresses cannot be transparent (protocol does not provide NAT)" << s
->s
);
3030 } else if (strcmp(token
, "tproxy") == 0) {
3031 if (s
->intercepted
|| s
->accel
) {
3032 debugs(3,DBG_CRITICAL
, "http(s)_port: TPROXY option requires its own interception port. It cannot be shared.");
3035 s
->spoof_client_ip
= 1;
3036 IpInterceptor
.StartTransparency();
3037 /* Log information regarding the port modes under transparency. */
3038 debugs(3, DBG_IMPORTANT
, "Starting IP Spoofing on port " << s
->s
);
3039 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (Ip spoofing enabled)");
3042 /* INET6: until target TPROXY is known to work on IPv6 SOCKET, force wildcard to IPv4 */
3043 debugs(3, DBG_IMPORTANT
, "Disabling IPv6 on port " << s
->s
<< " (interception enabled)");
3044 if ( s
->s
.IsIPv6() && !s
->s
.SetIPv4() ) {
3045 debugs(3, DBG_CRITICAL
, "http(s)_port: IPv6 addresses cannot be transparent (protocol does not provide NAT)" << s
->s
);
3050 } else if (strcmp(token
, "ipv4") == 0) {
3052 if ( !s
->s
.SetIPv4() ) {
3053 debugs(3, 0, "http(s)_port: IPv6 addresses cannot be used a IPv4-Only." << s
->s
);
3057 } else if (strcmp(token
, "tcpkeepalive") == 0) {
3058 s
->tcp_keepalive
.enabled
= 1;
3059 } else if (strncmp(token
, "tcpkeepalive=", 13) == 0) {
3060 char *t
= token
+ 13;
3061 s
->tcp_keepalive
.enabled
= 1;
3062 s
->tcp_keepalive
.idle
= atoi(t
);
3066 s
->tcp_keepalive
.interval
= atoi(t
);
3071 s
->tcp_keepalive
.timeout
= atoi(t
);
3075 } else if (strncmp(token
, "cert=", 5) == 0) {
3077 s
->cert
= xstrdup(token
+ 5);
3078 } else if (strncmp(token
, "key=", 4) == 0) {
3080 s
->key
= xstrdup(token
+ 4);
3081 } else if (strncmp(token
, "version=", 8) == 0) {
3082 s
->version
= xatoi(token
+ 8);
3084 if (s
->version
< 1 || s
->version
> 4)
3086 } else if (strncmp(token
, "options=", 8) == 0) {
3087 safe_free(s
->options
);
3088 s
->options
= xstrdup(token
+ 8);
3089 } else if (strncmp(token
, "cipher=", 7) == 0) {
3090 safe_free(s
->cipher
);
3091 s
->cipher
= xstrdup(token
+ 7);
3092 } else if (strncmp(token
, "clientca=", 9) == 0) {
3093 safe_free(s
->clientca
);
3094 s
->clientca
= xstrdup(token
+ 9);
3095 } else if (strncmp(token
, "cafile=", 7) == 0) {
3096 safe_free(s
->cafile
);
3097 s
->cafile
= xstrdup(token
+ 7);
3098 } else if (strncmp(token
, "capath=", 7) == 0) {
3099 safe_free(s
->capath
);
3100 s
->capath
= xstrdup(token
+ 7);
3101 } else if (strncmp(token
, "crlfile=", 8) == 0) {
3102 safe_free(s
->crlfile
);
3103 s
->crlfile
= xstrdup(token
+ 8);
3104 } else if (strncmp(token
, "dhparams=", 9) == 0) {
3105 safe_free(s
->dhfile
);
3106 s
->dhfile
= xstrdup(token
+ 9);
3107 } else if (strncmp(token
, "sslflags=", 9) == 0) {
3108 safe_free(s
->sslflags
);
3109 s
->sslflags
= xstrdup(token
+ 9);
3110 } else if (strncmp(token
, "sslcontext=", 11) == 0) {
3111 safe_free(s
->sslcontext
);
3112 s
->sslcontext
= xstrdup(token
+ 11);
3113 } else if (strcmp(token
, "sslBump") == 0) {
3114 s
->sslBump
= 1; // accelerated when bumped, otherwise not
3120 if ( s
->spoof_client_ip
&& (s
->intercepted
|| s
->accel
) ) {
3121 debugs(3,DBG_CRITICAL
, "http(s)_port: TPROXY option requires its own interception port. It cannot be shared.");
3126 static http_port_list
*
3127 create_http_port(char *portspec
)
3129 http_port_list
*s
= new http_port_list("http");
3130 parse_http_port_specification(s
, portspec
);
3135 add_http_port(char *portspec
)
3137 http_port_list
*s
= create_http_port(portspec
);
3138 s
->next
= Config
.Sockaddr
.http
;
3139 Config
.Sockaddr
.http
= s
;
3143 parse_http_port_list(http_port_list
** head
)
3145 char *token
= strtok(NULL
, w_space
);
3152 http_port_list
*s
= create_http_port(token
);
3154 /* parse options ... */
3155 while ((token
= strtok(NULL
, w_space
))) {
3156 parse_http_port_option(s
, token
);
3160 head
= &(*head
)->next
;
3166 dump_generic_http_port(StoreEntry
* e
, const char *n
, const http_port_list
* s
)
3168 char buf
[MAX_IPSTRLEN
];
3170 storeAppendPrintf(e
, "%s %s",
3172 s
->s
.ToURL(buf
,MAX_IPSTRLEN
));
3175 storeAppendPrintf(e
, " defaultsite=%s", s
->defaultsite
);
3178 storeAppendPrintf(e
, " intercept");
3181 storeAppendPrintf(e
, " vhost");
3184 storeAppendPrintf(e
, " vport");
3186 if (s
->connection_auth_disabled
)
3187 storeAppendPrintf(e
, " connection-auth=off");
3189 storeAppendPrintf(e
, " connection-auth=on");
3191 if (s
->disable_pmtu_discovery
!= DISABLE_PMTU_OFF
) {
3194 if (s
->disable_pmtu_discovery
== DISABLE_PMTU_ALWAYS
)
3197 pmtu
= "transparent";
3199 storeAppendPrintf(e
, " disable-pmtu-discovery=%s", pmtu
);
3202 if (s
->tcp_keepalive
.enabled
) {
3203 if (s
->tcp_keepalive
.idle
|| s
->tcp_keepalive
.interval
|| s
->tcp_keepalive
.timeout
) {
3204 storeAppendPrintf(e
, " tcpkeepalive=%d,%d,%d", s
->tcp_keepalive
.idle
, s
->tcp_keepalive
.interval
, s
->tcp_keepalive
.timeout
);
3206 storeAppendPrintf(e
, " tcpkeepalive");
3212 storeAppendPrintf(e
, " cert=%s", s
->cert
);
3215 storeAppendPrintf(e
, " key=%s", s
->key
);
3218 storeAppendPrintf(e
, " version=%d", s
->version
);
3221 storeAppendPrintf(e
, " options=%s", s
->options
);
3224 storeAppendPrintf(e
, " cipher=%s", s
->cipher
);
3227 storeAppendPrintf(e
, " cafile=%s", s
->cafile
);
3230 storeAppendPrintf(e
, " capath=%s", s
->capath
);
3233 storeAppendPrintf(e
, " crlfile=%s", s
->crlfile
);
3236 storeAppendPrintf(e
, " dhparams=%s", s
->dhfile
);
3239 storeAppendPrintf(e
, " sslflags=%s", s
->sslflags
);
3242 storeAppendPrintf(e
, " sslcontext=%s", s
->sslcontext
);
3245 storeAppendPrintf(e
, " sslBump");
3250 dump_http_port_list(StoreEntry
* e
, const char *n
, const http_port_list
* s
)
3253 dump_generic_http_port(e
, n
, s
);
3254 storeAppendPrintf(e
, "\n");
3260 free_http_port_list(http_port_list
** head
)
3264 while ((s
= *head
) != NULL
) {
3272 // TODO: merge better with parse_http_port_list
3274 parse_https_port_list(https_port_list
** head
)
3279 token
= strtok(NULL
, w_space
);
3284 s
= new https_port_list
;
3285 parse_http_port_specification(&s
->http
, token
);
3287 /* parse options ... */
3288 while ((token
= strtok(NULL
, w_space
))) {
3289 parse_http_port_option(s
, token
);
3293 http_port_list
** headTmp
= &(*head
)->http
.next
;
3294 head
= (https_port_list
**)headTmp
;
3301 dump_https_port_list(StoreEntry
* e
, const char *n
, const https_port_list
* s
)
3303 dump_http_port_list(e
, n
, s
);
3307 free_https_port_list(https_port_list
** head
)
3309 free_http_port_list((http_port_list
**)head
);
3314 check_null_https_port_list(const https_port_list
* s
)
3321 #endif /* USE_SSL */
3324 configFreeMemory(void)
3330 requirePathnameExists(const char *name
, const char *path
)
3334 char pathbuf
[BUFSIZ
];
3335 assert(path
!= NULL
);
3337 if (Config
.chroot_dir
&& (geteuid() == 0)) {
3338 snprintf(pathbuf
, BUFSIZ
, "%s/%s", Config
.chroot_dir
, path
);
3342 if (stat(path
, &sb
) < 0) {
3343 if (opt_send_signal
== -1 || opt_send_signal
== SIGHUP
)
3344 fatalf("%s %s: %s", name
, path
, xstrerror());
3346 fprintf(stderr
, "WARNING: %s %s: %s\n", name
, path
, xstrerror());
3353 return ConfigParser::strtokFile();
3356 #include "AccessLogEntry.h"
3357 /* TODO: split out parsing somehow ...*/
3359 parse_logformat(logformat
** logformat_definitions
)
3364 if ((name
= strtok(NULL
, w_space
)) == NULL
)
3367 if ((def
= strtok(NULL
, "\r\n")) == NULL
) {
3372 debugs(3, 2, "Logformat for '" << name
<< "' is '" << def
<< "'");
3374 nlf
= (logformat
*)xcalloc(1, sizeof(logformat
));
3376 nlf
->name
= xstrdup(name
);
3378 if (!accessLogParseLogFormat(&nlf
->format
, def
)) {
3383 nlf
->next
= *logformat_definitions
;
3385 *logformat_definitions
= nlf
;
3389 parse_access_log(customlog
** logs
)
3391 const char *filename
, *logdef_name
;
3395 cl
= (customlog
*)xcalloc(1, sizeof(*cl
));
3397 if ((filename
= strtok(NULL
, w_space
)) == NULL
) {
3402 if (strcmp(filename
, "none") == 0) {
3403 cl
->type
= CLF_NONE
;
3407 if ((logdef_name
= strtok(NULL
, w_space
)) == NULL
)
3408 logdef_name
= "auto";
3410 debugs(3, 9, "Log definition name '" << logdef_name
<< "' file '" << filename
<< "'");
3412 cl
->filename
= xstrdup(filename
);
3414 /* look for the definition pointer corresponding to this name */
3415 lf
= Config
.Log
.logformats
;
3417 while (lf
!= NULL
) {
3418 debugs(3, 9, "Comparing against '" << lf
->name
<< "'");
3420 if (strcmp(lf
->name
, logdef_name
) == 0)
3427 cl
->type
= CLF_CUSTOM
;
3429 } else if (strcmp(logdef_name
, "auto") == 0) {
3430 cl
->type
= CLF_AUTO
;
3431 } else if (strcmp(logdef_name
, "squid") == 0) {
3432 cl
->type
= CLF_SQUID
;
3433 } else if (strcmp(logdef_name
, "common") == 0) {
3434 cl
->type
= CLF_COMMON
;
3436 debugs(3, 0, "Log format '" << logdef_name
<< "' is not defined");
3442 aclParseAclList(LegacyParser
, &cl
->aclList
);
3445 logs
= &(*logs
)->next
;
3451 check_null_access_log(customlog
*customlog_definitions
)
3453 return customlog_definitions
== NULL
;
3457 dump_logformat(StoreEntry
* entry
, const char *name
, logformat
* definitions
)
3459 accessLogDumpLogFormat(entry
, name
, definitions
);
3463 dump_access_log(StoreEntry
* entry
, const char *name
, customlog
* logs
)
3467 for (log
= logs
; log
; log
= log
->next
) {
3468 storeAppendPrintf(entry
, "%s ", name
);
3470 switch (log
->type
) {
3473 storeAppendPrintf(entry
, "%s %s", log
->filename
, log
->logFormat
->name
);
3477 storeAppendPrintf(entry
, "none");
3481 storeAppendPrintf(entry
, "%s squid", log
->filename
);
3485 storeAppendPrintf(entry
, "%s squid", log
->filename
);
3491 storeAppendPrintf(entry
, "%s auto", log
->filename
);
3493 storeAppendPrintf(entry
, "%s", log
->filename
);
3502 dump_acl_list(entry
, log
->aclList
);
3504 storeAppendPrintf(entry
, "\n");
3509 free_logformat(logformat
** definitions
)
3511 while (*definitions
) {
3512 logformat
*format
= *definitions
;
3513 *definitions
= format
->next
;
3514 safe_free(format
->name
);
3515 accessLogFreeLogFormat(&format
->format
);
3521 free_access_log(customlog
** definitions
)
3523 while (*definitions
) {
3524 customlog
*log
= *definitions
;
3525 *definitions
= log
->next
;
3527 log
->logFormat
= NULL
;
3528 log
->type
= CLF_UNKNOWN
;
3531 aclDestroyAclList(&log
->aclList
);
3533 safe_free(log
->filename
);
3542 parse_adaptation_service_set_type()
3544 Adaptation::Config::ParseServiceSet();
3548 parse_adaptation_access_type()
3550 Adaptation::Config::ParseAccess(LegacyParser
);
3553 #endif /* USE_ADAPTATION */
3559 parse_icap_service_type(Adaptation::Icap::Config
* cfg
)
3561 cfg
->parseService();
3565 free_icap_service_type(Adaptation::Icap::Config
* cfg
)
3571 dump_icap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
3573 cfg
.dumpService(entry
, name
);
3577 parse_icap_class_type()
3579 debugs(93, 0, "WARNING: 'icap_class' is depricated. " <<
3580 "Use 'adaptation_service_set' instead");
3581 Adaptation::Config::ParseServiceSet();
3585 parse_icap_access_type()
3587 debugs(93, 0, "WARNING: 'icap_access' is depricated. " <<
3588 "Use 'adaptation_access' instead");
3589 Adaptation::Config::ParseAccess(LegacyParser
);
3598 parse_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
3600 cfg
->parseService();
3604 free_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
3610 dump_ecap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Ecap::Config
&cfg
)
3612 cfg
.dumpService(entry
, name
);
3615 #endif /* USE_ECAP */