4 * DEBUG: section 03 Configuration File Parsing
5 * AUTHOR: Harvest Derived
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
10 * Squid is the result of efforts by numerous individuals from
11 * the Internet community; see the CONTRIBUTORS file for full
12 * details. Many organizations have provided support for Squid's
13 * development; see the SPONSORS file for full details. Squid is
14 * Copyrighted (C) 2001 by the Regents of the University of
15 * California; see the COPYRIGHT file for full details. Squid
16 * incorporates software developed and/or copyrighted by other
17 * sources; see the CREDITS file for full details.
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
38 #include "acl/Gadgets.h"
39 #include "acl/MethodData.h"
41 #include "adaptation/Config.h"
44 #include "adaptation/icap/Config.h"
47 #include "adaptation/ecap/Config.h"
49 #include "auth/Config.h"
50 #include "auth/Scheme.h"
51 #include "CacheManager.h"
52 #include "ConfigParser.h"
53 #include "eui/Config.h"
55 #include "esi/Parser.h"
57 #include "HttpRequestMethod.h"
58 #include "ident/Config.h"
59 #include "ip/Intercept.h"
60 #include "ip/QosConfig.h"
62 #include "log/Config.h"
65 #include "ProtoPort.h"
71 #include "StoreFileSystem.h"
81 static void parse_adaptation_service_set_type();
82 static void parse_adaptation_service_chain_type();
83 static void parse_adaptation_access_type();
87 static void parse_icap_service_type(Adaptation::Icap::Config
*);
88 static void dump_icap_service_type(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
89 static void free_icap_service_type(Adaptation::Icap::Config
*);
90 static void parse_icap_class_type();
91 static void parse_icap_access_type();
93 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*);
94 static void dump_icap_service_failure_limit(StoreEntry
*, const char *, const Adaptation::Icap::Config
&);
95 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*);
99 static void parse_ecap_service_type(Adaptation::Ecap::Config
*);
100 static void dump_ecap_service_type(StoreEntry
*, const char *, const Adaptation::Ecap::Config
&);
101 static void free_ecap_service_type(Adaptation::Ecap::Config
*);
106 static const char *const T_SECOND_STR
= "second";
107 static const char *const T_MINUTE_STR
= "minute";
108 static const char *const T_HOUR_STR
= "hour";
109 static const char *const T_DAY_STR
= "day";
110 static const char *const T_WEEK_STR
= "week";
111 static const char *const T_FORTNIGHT_STR
= "fortnight";
112 static const char *const T_MONTH_STR
= "month";
113 static const char *const T_YEAR_STR
= "year";
114 static const char *const T_DECADE_STR
= "decade";
116 static const char *const B_BYTES_STR
= "bytes";
117 static const char *const B_KBYTES_STR
= "KB";
118 static const char *const B_MBYTES_STR
= "MB";
119 static const char *const B_GBYTES_STR
= "GB";
121 static const char *const list_sep
= ", \t\n\r";
123 static void parse_logformat(logformat
** logformat_definitions
);
124 static void parse_access_log(customlog
** customlog_definitions
);
125 static int check_null_access_log(customlog
*customlog_definitions
);
127 static void dump_logformat(StoreEntry
* entry
, const char *name
, logformat
* definitions
);
128 static void dump_access_log(StoreEntry
* entry
, const char *name
, customlog
* definitions
);
129 static void free_logformat(logformat
** definitions
);
130 static void free_access_log(customlog
** definitions
);
132 static void update_maxobjsize(void);
133 static void configDoConfigure(void);
134 static void parse_refreshpattern(refresh_t
**);
135 static int parseTimeUnits(const char *unit
);
136 static void parseTimeLine(time_t * tptr
, const char *units
);
137 static void parse_ushort(u_short
* var
);
138 static void parse_string(char **);
139 static void default_all(void);
140 static void defaults_if_none(void);
141 static int parse_line(char *);
142 static void parseBytesLine(size_t * bptr
, const char *units
);
143 static size_t parseBytesUnits(const char *unit
);
144 static void free_all(void);
145 void requirePathnameExists(const char *name
, const char *path
);
146 static OBJH dump_config
;
147 #if USE_HTTP_VIOLATIONS
148 static void dump_http_header_access(StoreEntry
* entry
, const char *name
, header_mangler header
[]);
149 static void parse_http_header_access(header_mangler header
[]);
150 static void free_http_header_access(header_mangler header
[]);
151 static void dump_http_header_replace(StoreEntry
* entry
, const char *name
, header_mangler header
[]);
152 static void parse_http_header_replace(header_mangler
* header
);
153 static void free_http_header_replace(header_mangler
* header
);
155 static void parse_denyinfo(acl_deny_info_list
** var
);
156 static void dump_denyinfo(StoreEntry
* entry
, const char *name
, acl_deny_info_list
* var
);
157 static void free_denyinfo(acl_deny_info_list
** var
);
160 static void parse_IpAddress_list(Ip::Address_list
**);
161 static void dump_IpAddress_list(StoreEntry
*, const char *, const Ip::Address_list
*);
162 static void free_IpAddress_list(Ip::Address_list
**);
164 static int check_null_IpAddress_list(const Ip::Address_list
*);
165 #endif /* CURRENTLY_UNUSED */
166 #endif /* USE_WCCPv2 */
168 static void parse_http_port_list(http_port_list
**);
169 static void dump_http_port_list(StoreEntry
*, const char *, const http_port_list
*);
170 static void free_http_port_list(http_port_list
**);
173 static void parse_https_port_list(https_port_list
**);
174 static void dump_https_port_list(StoreEntry
*, const char *, const https_port_list
*);
175 static void free_https_port_list(https_port_list
**);
177 static int check_null_https_port_list(const https_port_list
*);
181 static void parse_b_size_t(size_t * var
);
182 static void parse_b_int64_t(int64_t * var
);
184 static int parseOneConfigFile(const char *file_name
, unsigned int depth
);
187 * LegacyParser is a parser for legacy code that uses the global
188 * approach. This is static so that it is only exposed to cache_cf.
189 * Other modules needing access to a ConfigParser should have it
190 * provided to them in their parserFOO methods.
192 static ConfigParser LegacyParser
= ConfigParser();
197 LegacyParser
.destruct();
201 update_maxobjsize(void)
206 for (i
= 0; i
< Config
.cacheSwap
.n_configured
; i
++) {
207 assert (Config
.cacheSwap
.swapDirs
[i
].getRaw());
209 if (dynamic_cast<SwapDir
*>(Config
.cacheSwap
.swapDirs
[i
].getRaw())->
211 ms
= dynamic_cast<SwapDir
*>(Config
.cacheSwap
.swapDirs
[i
].getRaw())->max_objsize
;
213 store_maxobjsize
= ms
;
217 SetConfigFilename(char const *file_name
, bool is_pipe
)
219 cfg_filename
= file_name
;
224 cfg_filename
= file_name
+ 1;
225 else if ((token
= strrchr(cfg_filename
, '/')))
226 cfg_filename
= token
+ 1;
230 skip_ws(const char* s
)
239 parseManyConfigFiles(char* files
, int depth
)
242 char* saveptr
= NULL
;
247 memset(&globbuf
, 0, sizeof(globbuf
));
248 for (path
= strwordtok(files
, &saveptr
); path
; path
= strwordtok(NULL
, &saveptr
)) {
249 if (glob(path
, globbuf
.gl_pathc
? GLOB_APPEND
: 0, NULL
, &globbuf
) != 0) {
250 fatalf("Unable to find configuration file: %s: %s",
254 for (i
= 0; i
< (int)globbuf
.gl_pathc
; i
++) {
255 error_count
+= parseOneConfigFile(globbuf
.gl_pathv
[i
], depth
);
259 char* file
= strwordtok(files
, &saveptr
);
260 while (file
!= NULL
) {
261 error_count
+= parseOneConfigFile(file
, depth
);
262 file
= strwordtok(NULL
, &saveptr
);
264 #endif /* HAVE_GLOB */
269 ReplaceSubstr(char*& str
, int& len
, unsigned substrIdx
, unsigned substrLen
, const char* newSubstr
)
272 assert(newSubstr
!= NULL
);
274 unsigned newSubstrLen
= strlen(newSubstr
);
275 if (newSubstrLen
> substrLen
)
276 str
= (char*)realloc(str
, len
- substrLen
+ newSubstrLen
+ 1);
278 // move tail part including zero
279 memmove(str
+ substrIdx
+ newSubstrLen
, str
+ substrIdx
+ substrLen
, len
- substrIdx
- substrLen
+ 1);
280 // copy new substring in place
281 memcpy(str
+ substrIdx
, newSubstr
, newSubstrLen
);
287 SubstituteMacro(char*& line
, int& len
, const char* macroName
, const char* substStr
)
289 assert(line
!= NULL
);
290 assert(macroName
!= NULL
);
291 assert(substStr
!= NULL
);
292 unsigned macroNameLen
= strlen(macroName
);
293 while (const char* macroPos
= strstr(line
, macroName
)) // we would replace all occurrences
294 ReplaceSubstr(line
, len
, macroPos
- line
, macroNameLen
, substStr
);
298 ProcessMacros(char*& line
, int& len
)
300 SubstituteMacro(line
, len
, "${process_name}", TheKidName
);
301 SubstituteMacro(line
, len
, "${process_number}", xitoa(KidIdentifier
));
305 trim_trailing_ws(char* str
)
308 unsigned i
= strlen(str
);
309 while ((i
> 0) && xisspace(str
[i
- 1]))
315 FindStatement(const char* line
, const char* statement
)
317 assert(line
!= NULL
);
318 assert(statement
!= NULL
);
320 const char* str
= skip_ws(line
);
321 unsigned len
= strlen(statement
);
322 if (strncmp(str
, statement
, len
) == 0) {
326 else if (xisspace(*str
))
334 StrToInt(const char* str
, long& number
)
339 number
= strtol(str
, &end
, 0);
341 return (end
!= str
) && (*end
== '\0'); // returns true if string contains nothing except number
345 EvalBoolExpr(const char* expr
)
347 assert(expr
!= NULL
);
348 if (strcmp(expr
, "true") == 0) {
350 } else if (strcmp(expr
, "false") == 0) {
352 } else if (const char* equation
= strchr(expr
, '=')) {
353 const char* rvalue
= skip_ws(equation
+ 1);
354 char* lvalue
= (char*)xmalloc(equation
- expr
+ 1);
355 xstrncpy(lvalue
, expr
, equation
- expr
+ 1);
356 trim_trailing_ws(lvalue
);
359 if (!StrToInt(lvalue
, number1
))
360 fatalf("String is not a integer number: '%s'\n", lvalue
);
362 if (!StrToInt(rvalue
, number2
))
363 fatalf("String is not a integer number: '%s'\n", rvalue
);
366 return number1
== number2
;
368 fatalf("Unable to evaluate expression '%s'\n", expr
);
369 return false; // this place cannot be reached
373 parseOneConfigFile(const char *file_name
, unsigned int depth
)
376 const char *orig_cfg_filename
= cfg_filename
;
377 const int orig_config_lineno
= config_lineno
;
379 char *tmp_line
= NULL
;
380 int tmp_line_len
= 0;
384 debugs(3, 1, "Processing Configuration File: " << file_name
<< " (depth " << depth
<< ")");
386 fatalf("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name
);
390 if (file_name
[0] == '!' || file_name
[0] == '|') {
391 fp
= popen(file_name
+ 1, "r");
394 fp
= fopen(file_name
, "r");
398 fatalf("Unable to open configuration file: %s: %s", file_name
, xstrerror());
402 setmode(fileno(fp
), O_TEXT
);
406 SetConfigFilename(file_name
, bool(is_pipe
));
408 memset(config_input_line
, '\0', BUFSIZ
);
412 Vector
<bool> if_states
;
413 while (fgets(config_input_line
, BUFSIZ
, fp
)) {
416 if ((token
= strchr(config_input_line
, '\n')))
419 if ((token
= strchr(config_input_line
, '\r')))
422 if (strncmp(config_input_line
, "#line ", 6) == 0) {
423 static char new_file_name
[1024];
425 static char new_lineno
;
426 token
= config_input_line
+ 6;
427 new_lineno
= strtol(token
, &file
, 0) - 1;
430 continue; /* Not a valid #line directive, may be a comment */
432 while (*file
&& xisspace((unsigned char) *file
))
437 continue; /* Not a valid #line directive, may be a comment */
439 xstrncpy(new_file_name
, file
+ 1, sizeof(new_file_name
));
441 if ((token
= strchr(new_file_name
, '"')))
444 cfg_filename
= new_file_name
;
447 config_lineno
= new_lineno
;
450 if (config_input_line
[0] == '#')
453 if (config_input_line
[0] == '\0')
456 const char* append
= tmp_line_len
? skip_ws(config_input_line
) : config_input_line
;
458 size_t append_len
= strlen(append
);
460 tmp_line
= (char*)xrealloc(tmp_line
, tmp_line_len
+ append_len
+ 1);
462 strcpy(tmp_line
+ tmp_line_len
, append
);
464 tmp_line_len
+= append_len
;
466 if (tmp_line
[tmp_line_len
-1] == '\\') {
467 debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line
<< "'");
468 tmp_line
[--tmp_line_len
] = '\0';
472 trim_trailing_ws(tmp_line
);
473 ProcessMacros(tmp_line
, tmp_line_len
);
474 debugs(3, 5, "Processing: '" << tmp_line
<< "'");
476 if (const char* expr
= FindStatement(tmp_line
, "if")) {
477 if_states
.push_back(EvalBoolExpr(expr
)); // store last if-statement meaning
478 } else if (FindStatement(tmp_line
, "endif")) {
479 if (!if_states
.empty())
480 if_states
.pop_back(); // remove last if-statement meaning
482 fatalf("'endif' without 'if'\n");
483 } else if (FindStatement(tmp_line
, "else")) {
484 if (!if_states
.empty())
485 if_states
.back() = !if_states
.back();
487 fatalf("'else' without 'if'\n");
488 } else if (if_states
.empty() || if_states
.back()) { // test last if-statement meaning if present
489 /* Handle includes here */
490 if (tmp_line_len
>= 9 && strncmp(tmp_line
, "include", 7) == 0 && xisspace(tmp_line
[7])) {
491 err_count
+= parseManyConfigFiles(tmp_line
+ 8, depth
+ 1);
492 } else if (!parse_line(tmp_line
)) {
493 debugs(3, 0, HERE
<< cfg_filename
<< ":" << config_lineno
<< " unrecognized: '" << tmp_line
<< "'");
502 if (!if_states
.empty())
503 fatalf("if-statement without 'endif'\n");
506 int ret
= pclose(fp
);
509 fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name
, ret
);
514 cfg_filename
= orig_cfg_filename
;
515 config_lineno
= orig_config_lineno
;
521 parseConfigFile(const char *file_name
)
524 CacheManager
*manager
=CacheManager::GetInstance();
530 ACLMethodData::ThePurgeCount
= 0;
533 err_count
= parseOneConfigFile(file_name
, 0);
538 * We must call configDoConfigure() before leave_suid() because
539 * configDoConfigure() is where we turn username strings into
544 if (!Config
.chroot_dir
) {
546 setUmask(Config
.umask
);
547 _db_init(Debug::cache_log
, Debug::debugOptions
);
551 if (opt_send_signal
== -1) {
552 manager
->registerAction("config",
553 "Current Squid Configuration",
563 configDoConfigure(void)
565 memset(&Config2
, '\0', sizeof(SquidConfig2
));
566 /* init memory as early as possible */
570 if (Config
.cacheSwap
.swapDirs
== NULL
) {
571 /* Memory-only cache probably in effect. */
572 /* turn off the cache rebuild delays... */
573 StoreController::store_dirs_rebuilding
= 0;
576 if (Debug::rotateNumber
< 0) {
577 Debug::rotateNumber
= Config
.Log
.rotateNumber
;
580 #if SIZEOF_OFF_T <= 4
581 if (Config
.Store
.maxObjectSize
> 0x7FFF0000) {
582 debugs(3, 0, "WARNING: This Squid binary can not handle files larger than 2GB. Limiting maximum_object_size to just below 2GB");
583 Config
.Store
.maxObjectSize
= 0x7FFF0000;
586 if (0 == Store::Root().maxSize())
587 /* people might want a zero-sized cache on purpose */
589 else if (Store::Root().maxSize() < (Config
.memMaxSize
>> 10))
590 /* This is bogus. folk with NULL caches will want this */
591 debugs(3, 0, "WARNING cache_mem is larger than total disk cache space!");
593 if (Config
.Announce
.period
> 0) {
594 Config
.onoff
.announce
= 1;
595 } else if (Config
.Announce
.period
< 1) {
596 Config
.Announce
.period
= 86400 * 365; /* one year */
597 Config
.onoff
.announce
= 0;
600 if (Config
.onoff
.httpd_suppress_version_string
)
601 visible_appname_string
= (char *)appname_string
;
603 visible_appname_string
= (char const *)APP_FULLNAME
;
607 if (Config
.dnsChildren
.n_max
< 1)
608 fatal("No dnsservers allocated");
612 if (Config
.Program
.redirect
) {
613 if (Config
.redirectChildren
.n_max
< 1) {
614 Config
.redirectChildren
.n_max
= 0;
615 wordlistDestroy(&Config
.Program
.redirect
);
619 if (Config
.appendDomain
)
620 if (*Config
.appendDomain
!= '.')
621 fatal("append_domain must begin with a '.'");
623 if (Config
.errHtmlText
== NULL
)
624 Config
.errHtmlText
= xstrdup(null_string
);
628 snprintf(ThisCache
, sizeof(ThisCache
), "%s (%s)",
630 visible_appname_string
);
633 * the extra space is for loop detection in client_side.c -- we search
634 * for substrings in the Via header.
636 snprintf(ThisCache2
, sizeof(ThisCache
), " %s (%s)",
638 visible_appname_string
);
640 /* Use visible_hostname as default surrogate_id */
641 if (!Config
.Accel
.surrogate_id
) {
642 const char *t
= getMyHostname();
643 Config
.Accel
.surrogate_id
= xstrdup( (t
?t
:"unset-id") );
646 if (!Config
.udpMaxHitObjsz
|| Config
.udpMaxHitObjsz
> SQUID_UDP_SO_SNDBUF
)
647 Config
.udpMaxHitObjsz
= SQUID_UDP_SO_SNDBUF
;
649 if (Config
.appendDomain
)
650 Config
.appendDomainLen
= strlen(Config
.appendDomain
);
652 Config
.appendDomainLen
= 0;
654 if (Config
.retry
.maxtries
> 10)
655 fatal("maximum_single_addr_tries cannot be larger than 10");
657 if (Config
.retry
.maxtries
< 1) {
658 debugs(3, 0, "WARNING: resetting 'maximum_single_addr_tries to 1");
659 Config
.retry
.maxtries
= 1;
662 requirePathnameExists("MIME Config Table", Config
.mimeTablePathname
);
665 requirePathnameExists("cache_dns_program", Config
.Program
.dnsserver
);
669 requirePathnameExists("unlinkd_program", Config
.Program
.unlinkd
);
671 requirePathnameExists("logfile_daemon", Log::TheConfig
.logfile_daemon
);
672 if (Config
.Program
.redirect
)
673 requirePathnameExists("redirect_program", Config
.Program
.redirect
->key
);
675 requirePathnameExists("Icon Directory", Config
.icons
.directory
);
677 if (Config
.errorDirectory
)
678 requirePathnameExists("Error Directory", Config
.errorDirectory
);
680 #if USE_HTTP_VIOLATIONS
685 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
686 if (!R
->flags
.override_expire
)
689 debugs(22, 1, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP");
694 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
695 if (!R
->flags
.override_lastmod
)
698 debugs(22, 1, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP");
703 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
704 if (!R
->flags
.reload_into_ims
)
707 debugs(22, 1, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP");
712 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
713 if (!R
->flags
.ignore_reload
)
716 debugs(22, 1, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP");
721 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
722 if (!R
->flags
.ignore_no_cache
)
725 debugs(22, 1, "WARNING: use of 'ignore-no-cache' in 'refresh_pattern' violates HTTP");
730 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
731 if (!R
->flags
.ignore_no_store
)
734 debugs(22, 1, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP");
739 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
740 if (!R
->flags
.ignore_must_revalidate
)
742 debugs(22, 1, "WARNING: use of 'ignore-must-revalidate' in 'refresh_pattern' violates HTTP");
746 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
747 if (!R
->flags
.ignore_private
)
750 debugs(22, 1, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP");
755 for (R
= Config
.Refresh
; R
; R
= R
->next
) {
756 if (!R
->flags
.ignore_auth
)
759 debugs(22, 1, "WARNING: use of 'ignore-auth' in 'refresh_pattern' violates HTTP");
766 #if !USE_HTTP_VIOLATIONS
767 Config
.onoff
.via
= 1;
770 if (!Config
.onoff
.via
)
771 debugs(22, 1, "WARNING: HTTP requires the use of Via");
775 // we enable runtime PURGE checks if there is at least one PURGE method ACL
776 // TODO: replace with a dedicated "purge" ACL option?
777 Config2
.onoff
.enable_purge
= (ACLMethodData::ThePurgeCount
> 0);
779 Config2
.onoff
.mangle_request_headers
= httpReqHdrManglersConfigured();
781 if (geteuid() == 0) {
782 if (NULL
!= Config
.effectiveUser
) {
784 struct passwd
*pwd
= getpwnam(Config
.effectiveUser
);
788 * Andres Kroonmaa <andre@online.ee>:
789 * Some getpwnam() implementations (Solaris?) require
790 * an available FD < 256 for opening a FILE* to the
793 * This should be safe at startup, but might still fail
794 * during reconfigure.
796 fatalf("getpwnam failed to find userid for effective user '%s'",
797 Config
.effectiveUser
);
801 Config2
.effectiveUserID
= pwd
->pw_uid
;
803 Config2
.effectiveGroupID
= pwd
->pw_gid
;
807 if (pwd
->pw_dir
&& *pwd
->pw_dir
) {
809 char *env_str
= (char *)xcalloc((len
= strlen(pwd
->pw_dir
) + 6), 1);
810 snprintf(env_str
, len
, "HOME=%s", pwd
->pw_dir
);
818 Config2
.effectiveUserID
= geteuid();
819 Config2
.effectiveGroupID
= getegid();
822 if (NULL
!= Config
.effectiveGroup
) {
824 struct group
*grp
= getgrnam(Config
.effectiveGroup
);
827 fatalf("getgrnam failed to find groupid for effective group '%s'",
828 Config
.effectiveGroup
);
832 Config2
.effectiveGroupID
= grp
->gr_gid
;
835 HttpRequestMethod::Configure(Config
);
838 debugs(3, 1, "Initializing https proxy context");
840 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
);
846 for (p
= Config
.peers
; p
!= NULL
; p
= p
->next
) {
848 debugs(3, 1, "Initializing cache_peer " << p
->name
<< " SSL context");
849 p
->sslContext
= sslCreateClientContext(p
->sslcert
, p
->sslkey
, p
->sslversion
, p
->sslcipher
, p
->ssloptions
, p
->sslflags
, p
->sslcafile
, p
->sslcapath
, p
->sslcrlfile
);
858 for (s
= Config
.Sockaddr
.http
; s
!= NULL
; s
= (http_port_list
*) s
->next
) {
859 if (!s
->cert
&& !s
->key
)
862 debugs(3, 1, "Initializing http_port " << s
->http
.s
<< " SSL context");
864 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
);
872 for (s
= Config
.Sockaddr
.https
; s
!= NULL
; s
= (https_port_list
*) s
->http
.next
) {
873 debugs(3, 1, "Initializing https_port " << s
->http
.s
<< " SSL context");
875 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
);
882 /* Parse a time specification from the config file. Store the
883 * result in 'tptr', after converting it to 'units' */
885 parseTimeLine(time_t * tptr
, const char *units
)
892 if ((u
= parseTimeUnits(units
)) == 0)
895 if ((token
= strtok(NULL
, w_space
)) == NULL
)
900 m
= u
; /* default to 'units' if none specified */
904 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
905 debugs(3, 0, "WARNING: No units on '" <<
906 config_input_line
<< "', assuming " <<
908 else if ((m
= parseTimeUnits(token
)) == 0)
911 *tptr
= static_cast<time_t> (m
* d
/ u
);
915 parseTimeUnits(const char *unit
)
917 if (!strncasecmp(unit
, T_SECOND_STR
, strlen(T_SECOND_STR
)))
920 if (!strncasecmp(unit
, T_MINUTE_STR
, strlen(T_MINUTE_STR
)))
923 if (!strncasecmp(unit
, T_HOUR_STR
, strlen(T_HOUR_STR
)))
926 if (!strncasecmp(unit
, T_DAY_STR
, strlen(T_DAY_STR
)))
929 if (!strncasecmp(unit
, T_WEEK_STR
, strlen(T_WEEK_STR
)))
932 if (!strncasecmp(unit
, T_FORTNIGHT_STR
, strlen(T_FORTNIGHT_STR
)))
935 if (!strncasecmp(unit
, T_MONTH_STR
, strlen(T_MONTH_STR
)))
938 if (!strncasecmp(unit
, T_YEAR_STR
, strlen(T_YEAR_STR
)))
939 return static_cast<int>(86400 * 365.2522);
941 if (!strncasecmp(unit
, T_DECADE_STR
, strlen(T_DECADE_STR
)))
942 return static_cast<int>(86400 * 365.2522 * 10);
944 debugs(3, 1, "parseTimeUnits: unknown time unit '" << unit
<< "'");
950 parseBytesLine64(int64_t * bptr
, const char *units
)
957 if ((u
= parseBytesUnits(units
)) == 0) {
962 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
967 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
974 m
= u
; /* default to 'units' if none specified */
978 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
979 debugs(3, 0, "WARNING: No units on '" <<
980 config_input_line
<< "', assuming " <<
982 else if ((m
= parseBytesUnits(token
)) == 0) {
987 *bptr
= static_cast<int64_t>(m
* d
/ u
);
989 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
995 parseBytesLine(size_t * bptr
, const char *units
)
1002 if ((u
= parseBytesUnits(units
)) == 0) {
1007 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
1012 if (strcmp(token
, "none") == 0 || strcmp(token
, "-1") == 0) {
1013 *bptr
= static_cast<size_t>(-1);
1019 m
= u
; /* default to 'units' if none specified */
1023 else if ((token
= strtok(NULL
, w_space
)) == NULL
)
1024 debugs(3, 0, "WARNING: No units on '" <<
1025 config_input_line
<< "', assuming " <<
1026 d
<< " " << units
);
1027 else if ((m
= parseBytesUnits(token
)) == 0) {
1032 *bptr
= static_cast<size_t>(m
* d
/ u
);
1034 if (static_cast<double>(*bptr
) * 2 != m
* d
/ u
* 2)
1039 parseBytesUnits(const char *unit
)
1041 if (!strncasecmp(unit
, B_BYTES_STR
, strlen(B_BYTES_STR
)))
1044 if (!strncasecmp(unit
, B_KBYTES_STR
, strlen(B_KBYTES_STR
)))
1047 if (!strncasecmp(unit
, B_MBYTES_STR
, strlen(B_MBYTES_STR
)))
1050 if (!strncasecmp(unit
, B_GBYTES_STR
, strlen(B_GBYTES_STR
)))
1053 debugs(3, DBG_CRITICAL
, "WARNING: Unknown bytes unit '" << unit
<< "'");
1058 /*****************************************************************************
1060 *****************************************************************************/
1063 dump_acl(StoreEntry
* entry
, const char *name
, ACL
* ae
)
1068 while (ae
!= NULL
) {
1069 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
);
1070 storeAppendPrintf(entry
, "%s %s %s ",
1077 debugs(3, 3, "dump_acl: " << name
<< " " << ae
->name
<< " " << v
->key
);
1078 storeAppendPrintf(entry
, "%s ", v
->key
);
1082 storeAppendPrintf(entry
, "\n");
1083 wordlistDestroy(&w
);
1089 parse_acl(ACL
** ae
)
1091 ACL::ParseAclLine(LegacyParser
, ae
);
1101 dump_acl_list(StoreEntry
* entry
, ACLList
* head
)
1105 for (l
= head
; l
; l
= l
->next
) {
1106 storeAppendPrintf(entry
, " %s%s",
1107 l
->op
? null_string
: "!",
1113 dump_acl_access(StoreEntry
* entry
, const char *name
, acl_access
* head
)
1117 for (l
= head
; l
; l
= l
->next
) {
1118 storeAppendPrintf(entry
, "%s %s",
1120 l
->allow
? "Allow" : "Deny");
1121 dump_acl_list(entry
, l
->aclList
);
1122 storeAppendPrintf(entry
, "\n");
1127 parse_acl_access(acl_access
** head
)
1129 aclParseAccessLine(LegacyParser
, head
);
1133 free_acl_access(acl_access
** head
)
1135 aclDestroyAccessList(head
);
1139 dump_address(StoreEntry
* entry
, const char *name
, Ip::Address
&addr
)
1141 char buf
[MAX_IPSTRLEN
];
1142 storeAppendPrintf(entry
, "%s %s\n", name
, addr
.NtoA(buf
,MAX_IPSTRLEN
) );
1146 parse_address(Ip::Address
*addr
)
1148 char *token
= strtok(NULL
, w_space
);
1155 if (!strcmp(token
,"any_addr")) {
1158 } else if ( (!strcmp(token
,"no_addr")) || (!strcmp(token
,"full_mask")) ) {
1166 free_address(Ip::Address
*addr
)
1171 CBDATA_TYPE(acl_address
);
1174 dump_acl_address(StoreEntry
* entry
, const char *name
, acl_address
* head
)
1176 char buf
[MAX_IPSTRLEN
];
1179 for (l
= head
; l
; l
= l
->next
) {
1180 if (!l
->addr
.IsAnyAddr())
1181 storeAppendPrintf(entry
, "%s %s", name
, l
->addr
.NtoA(buf
,MAX_IPSTRLEN
));
1183 storeAppendPrintf(entry
, "%s autoselect", name
);
1185 dump_acl_list(entry
, l
->aclList
);
1187 storeAppendPrintf(entry
, "\n");
1192 freed_acl_address(void *data
)
1194 acl_address
*l
= static_cast<acl_address
*>(data
);
1195 aclDestroyAclList(&l
->aclList
);
1199 parse_acl_address(acl_address
** head
)
1202 acl_address
**tail
= head
; /* sane name below */
1203 CBDATA_INIT_TYPE_FREECB(acl_address
, freed_acl_address
);
1204 l
= cbdataAlloc(acl_address
);
1205 parse_address(&l
->addr
);
1206 aclParseAclList(LegacyParser
, &l
->aclList
);
1209 tail
= &(*tail
)->next
;
1215 free_acl_address(acl_address
** head
)
1218 acl_address
*l
= *head
;
1224 CBDATA_TYPE(acl_tos
);
1227 dump_acl_tos(StoreEntry
* entry
, const char *name
, acl_tos
* head
)
1231 for (l
= head
; l
; l
= l
->next
) {
1233 storeAppendPrintf(entry
, "%s 0x%02X", name
, l
->tos
);
1235 storeAppendPrintf(entry
, "%s none", name
);
1237 dump_acl_list(entry
, l
->aclList
);
1239 storeAppendPrintf(entry
, "\n");
1244 freed_acl_tos(void *data
)
1246 acl_tos
*l
= static_cast<acl_tos
*>(data
);
1247 aclDestroyAclList(&l
->aclList
);
1251 parse_acl_tos(acl_tos
** head
)
1254 acl_tos
**tail
= head
; /* sane name below */
1257 char *token
= strtok(NULL
, w_space
);
1264 if (sscanf(token
, "0x%x%c", &tos
, &junk
) != 1) {
1269 if (tos
< 0 || tos
> 255) {
1274 CBDATA_INIT_TYPE_FREECB(acl_tos
, freed_acl_tos
);
1276 l
= cbdataAlloc(acl_tos
);
1280 aclParseAclList(LegacyParser
, &l
->aclList
);
1283 tail
= &(*tail
)->next
;
1289 free_acl_tos(acl_tos
** head
)
1299 CBDATA_TYPE(acl_size_t
);
1302 dump_acl_b_size_t(StoreEntry
* entry
, const char *name
, acl_size_t
* head
)
1306 for (l
= head
; l
; l
= l
->next
) {
1308 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) l
->size
, B_BYTES_STR
);
1310 storeAppendPrintf(entry
, "%s none", name
);
1312 dump_acl_list(entry
, l
->aclList
);
1314 storeAppendPrintf(entry
, "\n");
1319 freed_acl_b_size_t(void *data
)
1321 acl_size_t
*l
= static_cast<acl_size_t
*>(data
);
1322 aclDestroyAclList(&l
->aclList
);
1326 parse_acl_b_size_t(acl_size_t
** head
)
1329 acl_size_t
**tail
= head
; /* sane name below */
1331 CBDATA_INIT_TYPE_FREECB(acl_size_t
, freed_acl_b_size_t
);
1333 l
= cbdataAlloc(acl_size_t
);
1335 parse_b_int64_t(&l
->size
);
1337 aclParseAclList(LegacyParser
, &l
->aclList
);
1340 tail
= &(*tail
)->next
;
1346 free_acl_b_size_t(acl_size_t
** head
)
1349 acl_size_t
*l
= *head
;
1358 #include "DelayPools.h"
1359 #include "DelayConfig.h"
1360 /* do nothing - free_delay_pool_count is the magic free function.
1361 * this is why delay_pool_count isn't just marked TYPE: ushort
1363 #define free_delay_pool_class(X)
1364 #define free_delay_pool_access(X)
1365 #define free_delay_pool_rates(X)
1366 #define dump_delay_pool_class(X, Y, Z)
1367 #define dump_delay_pool_access(X, Y, Z)
1368 #define dump_delay_pool_rates(X, Y, Z)
1371 free_delay_pool_count(DelayConfig
* cfg
)
1373 cfg
->freePoolCount();
1377 dump_delay_pool_count(StoreEntry
* entry
, const char *name
, DelayConfig
&cfg
)
1379 cfg
.dumpPoolCount (entry
, name
);
1383 parse_delay_pool_count(DelayConfig
* cfg
)
1385 cfg
->parsePoolCount();
1389 parse_delay_pool_class(DelayConfig
* cfg
)
1391 cfg
->parsePoolClass();
1395 parse_delay_pool_rates(DelayConfig
* cfg
)
1397 cfg
->parsePoolRates();
1401 parse_delay_pool_access(DelayConfig
* cfg
)
1403 cfg
->parsePoolAccess(LegacyParser
);
1408 #if USE_HTTP_VIOLATIONS
1410 dump_http_header_access(StoreEntry
* entry
, const char *name
, header_mangler header
[])
1414 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1415 if (header
[i
].access_list
!= NULL
) {
1416 storeAppendPrintf(entry
, "%s ", name
);
1417 dump_acl_access(entry
, httpHeaderNameById(i
),
1418 header
[i
].access_list
);
1424 parse_http_header_access(header_mangler header
[])
1429 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1430 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1431 debugs(3, 0, "parse_http_header_access: missing header name.");
1435 /* Now lookup index of header. */
1436 id
= httpHeaderIdByNameDef(t
, strlen(t
));
1438 if (strcmp(t
, "All") == 0)
1440 else if (strcmp(t
, "Other") == 0)
1442 else if (id
== -1) {
1443 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1444 debugs(3, 0, "parse_http_header_access: unknown header name '" << t
<< "'");
1448 if (id
!= HDR_ENUM_END
) {
1449 parse_acl_access(&header
[id
].access_list
);
1451 char *next_string
= t
+ strlen(t
) - 1;
1453 *(next_string
+ 1) = ' ';
1455 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1456 char *new_string
= xstrdup(next_string
);
1457 strtok(new_string
, w_space
);
1458 parse_acl_access(&header
[i
].access_list
);
1459 safe_free(new_string
);
1465 free_http_header_access(header_mangler header
[])
1469 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1470 free_acl_access(&header
[i
].access_list
);
1475 dump_http_header_replace(StoreEntry
* entry
, const char *name
, header_mangler
1480 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1481 if (NULL
== header
[i
].replacement
)
1484 storeAppendPrintf(entry
, "%s %s %s\n", name
, httpHeaderNameById(i
),
1485 header
[i
].replacement
);
1490 parse_http_header_replace(header_mangler header
[])
1495 if ((t
= strtok(NULL
, w_space
)) == NULL
) {
1496 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1497 debugs(3, 0, "parse_http_header_replace: missing header name.");
1501 /* Now lookup index of header. */
1502 id
= httpHeaderIdByNameDef(t
, strlen(t
));
1504 if (strcmp(t
, "All") == 0)
1506 else if (strcmp(t
, "Other") == 0)
1508 else if (id
== -1) {
1509 debugs(3, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
1510 debugs(3, 0, "parse_http_header_replace: unknown header name " << t
<< ".");
1515 if (id
!= HDR_ENUM_END
) {
1516 if (header
[id
].replacement
!= NULL
)
1517 safe_free(header
[id
].replacement
);
1519 header
[id
].replacement
= xstrdup(t
+ strlen(t
) + 1);
1521 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1522 if (header
[i
].replacement
!= NULL
)
1523 safe_free(header
[i
].replacement
);
1525 header
[i
].replacement
= xstrdup(t
+ strlen(t
) + 1);
1531 free_http_header_replace(header_mangler header
[])
1535 for (i
= 0; i
< HDR_ENUM_END
; i
++) {
1536 if (header
[i
].replacement
!= NULL
)
1537 safe_free(header
[i
].replacement
);
1544 dump_cachedir(StoreEntry
* entry
, const char *name
, SquidConfig::_cacheSwap swap
)
1550 for (i
= 0; i
< swap
.n_configured
; i
++) {
1551 s
= dynamic_cast<SwapDir
*>(swap
.swapDirs
[i
].getRaw());
1553 storeAppendPrintf(entry
, "%s %s %s", name
, s
->type(), s
->path
);
1555 storeAppendPrintf(entry
, "\n");
1560 check_null_string(char *s
)
1566 parse_authparam(Auth::authConfig
* config
)
1571 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1574 if ((param_str
= strtok(NULL
, w_space
)) == NULL
)
1577 /* find a configuration for the scheme in the currently parsed configs... */
1578 AuthConfig
*schemeCfg
= AuthConfig::Find(type_str
);
1580 if (schemeCfg
== NULL
) {
1581 /* Create a configuration based on the scheme info */
1582 AuthScheme::Pointer theScheme
= AuthScheme::Find(type_str
);
1584 if (theScheme
== NULL
) {
1585 debugs(3, DBG_CRITICAL
, "Parsing Config File: Unknown authentication scheme '" << type_str
<< "'.");
1589 config
->push_back(theScheme
->createConfig());
1590 schemeCfg
= AuthConfig::Find(type_str
);
1591 if (schemeCfg
== NULL
) {
1592 debugs(3, DBG_CRITICAL
, "Parsing Config File: Corruption configuring authentication scheme '" << type_str
<< "'.");
1597 schemeCfg
->parse(schemeCfg
, config
->size(), param_str
);
1601 free_authparam(Auth::authConfig
* cfg
)
1603 /* Wipe the Auth globals and Detach/Destruct component config + state. */
1606 /* remove our pointers to the probably-dead sub-configs */
1607 while (cfg
->size()) {
1611 /* on reconfigure initialize new auth schemes for the new config. */
1612 if (reconfiguring
) {
1618 dump_authparam(StoreEntry
* entry
, const char *name
, authConfig cfg
)
1620 for (authConfig::iterator i
= cfg
.begin(); i
!= cfg
.end(); ++i
)
1621 (*i
)->dump(entry
, name
, (*i
));
1624 /* TODO: just return the object, the # is irrelevant */
1626 find_fstype(char *type
)
1628 for (size_t i
= 0; i
< StoreFileSystem::FileSystems().size(); ++i
)
1629 if (strcasecmp(type
, StoreFileSystem::FileSystems().items
[i
]->type()) == 0)
1636 parse_cachedir(SquidConfig::_cacheSwap
* swap
)
1640 RefCount
<SwapDir
> sd
;
1644 if ((type_str
= strtok(NULL
, w_space
)) == NULL
)
1647 if ((path_str
= strtok(NULL
, w_space
)) == NULL
)
1650 fs
= find_fstype(type_str
);
1655 /* reconfigure existing dir */
1657 for (i
= 0; i
< swap
->n_configured
; i
++) {
1658 assert (swap
->swapDirs
[i
].getRaw());
1660 if ((strcasecmp(path_str
, dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw())->path
)) == 0) {
1661 /* this is specific to on-fs Stores. The right
1662 * way to handle this is probably to have a mapping
1663 * from paths to stores, and have on-fs stores
1664 * register with that, and lookip in that in their
1665 * own setup logic. RBC 20041225. TODO.
1668 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[i
].getRaw());
1670 if (sd
->type() != StoreFileSystem::FileSystems().items
[fs
]->type()) {
1671 debugs(3, 0, "ERROR: Can't change type of existing cache_dir " <<
1672 sd
->type() << " " << sd
->path
<< " to " << type_str
<< ". Restart required");
1676 sd
->reconfigure (i
, path_str
);
1678 update_maxobjsize();
1685 if (swap
->n_configured
> 63) {
1686 /* 7 bits, signed */
1687 debugs(3, DBG_CRITICAL
, "WARNING: There is a fixed maximum of 63 cache_dir entries Squid can handle.");
1688 debugs(3, DBG_CRITICAL
, "WARNING: '" << path_str
<< "' is one to many.");
1693 allocate_new_swapdir(swap
);
1695 swap
->swapDirs
[swap
->n_configured
] = StoreFileSystem::FileSystems().items
[fs
]->createSwapDir();
1697 sd
= dynamic_cast<SwapDir
*>(swap
->swapDirs
[swap
->n_configured
].getRaw());
1699 /* parse the FS parameters and options */
1700 sd
->parse(swap
->n_configured
, path_str
);
1702 ++swap
->n_configured
;
1704 /* Update the max object size */
1705 update_maxobjsize();
1709 peer_type_str(const peer_t type
)
1711 const char * result
;
1723 case PEER_MULTICAST
:
1724 result
= "multicast";
1736 dump_peer(StoreEntry
* entry
, const char *name
, peer
* p
)
1740 LOCAL_ARRAY(char, xname
, 128);
1743 storeAppendPrintf(entry
, "%s %s %s %d %d name=%s",
1750 dump_peer_options(entry
, p
);
1752 for (d
= p
->peer_domain
; d
; d
= d
->next
) {
1753 storeAppendPrintf(entry
, "cache_peer_domain %s %s%s\n",
1755 d
->do_ping
? null_string
: "!",
1760 snprintf(xname
, 128, "cache_peer_access %s", p
->name
);
1761 dump_acl_access(entry
, xname
, p
->access
);
1764 for (t
= p
->typelist
; t
; t
= t
->next
) {
1765 storeAppendPrintf(entry
, "neighbor_type_domain %s %s %s\n",
1767 peer_type_str(t
->type
),
1776 * utility function to prevent getservbyname() being called with a numeric value
1777 * on Windows at least it returns garage results.
1780 isUnsignedNumeric(const char *str
, size_t len
)
1782 if (len
< 1) return false;
1784 for (; len
>0 && *str
; str
++, len
--) {
1785 if (! isdigit(*str
))
1792 \param proto 'tcp' or 'udp' for protocol
1793 \returns Port the named service is supposed to be listening on.
1796 GetService(const char *proto
)
1798 struct servent
*port
= NULL
;
1799 /** Parses a port number or service name from the squid.conf */
1800 char *token
= strtok(NULL
, w_space
);
1801 if (token
== NULL
) {
1803 return 0; /* NEVER REACHED */
1805 /** Returns either the service port number from /etc/services */
1806 if ( !isUnsignedNumeric(token
, strlen(token
)) )
1807 port
= getservbyname(token
, proto
);
1809 return ntohs((u_short
)port
->s_port
);
1811 /** Or a numeric translation of the config text. */
1812 return xatos(token
);
1816 \returns Port the named TCP service is supposed to be listening on.
1817 \copydoc GetService(const char *proto)
1822 return GetService("tcp");
1826 \returns Port the named UDP service is supposed to be listening on.
1827 \copydoc GetService(const char *proto)
1832 return GetService("udp");
1836 parse_peer(peer
** head
)
1840 CBDATA_INIT_TYPE_FREECB(peer
, peerDestroy
);
1841 p
= cbdataAlloc(peer
);
1842 p
->http_port
= CACHE_HTTP_PORT
;
1843 p
->icp
.port
= CACHE_ICP_PORT
;
1846 p
->stats
.logged_state
= PEER_ALIVE
;
1848 if ((token
= strtok(NULL
, w_space
)) == NULL
)
1851 p
->host
= xstrdup(token
);
1853 p
->name
= xstrdup(token
);
1855 if ((token
= strtok(NULL
, w_space
)) == NULL
)
1858 p
->type
= parseNeighborType(token
);
1860 if (p
->type
== PEER_MULTICAST
) {
1861 p
->options
.no_digest
= 1;
1862 p
->options
.no_netdb_exchange
= 1;
1865 p
->http_port
= GetTcpService();
1870 p
->icp
.port
= GetUdpService();
1871 p
->connection_auth
= 2; /* auto */
1873 while ((token
= strtok(NULL
, w_space
))) {
1874 if (!strcasecmp(token
, "proxy-only")) {
1875 p
->options
.proxy_only
= 1;
1876 } else if (!strcasecmp(token
, "no-query")) {
1877 p
->options
.no_query
= 1;
1878 } else if (!strcasecmp(token
, "background-ping")) {
1879 p
->options
.background_ping
= 1;
1880 } else if (!strcasecmp(token
, "no-digest")) {
1881 p
->options
.no_digest
= 1;
1882 } else if (!strcasecmp(token
, "no-tproxy")) {
1883 p
->options
.no_tproxy
= 1;
1884 } else if (!strcasecmp(token
, "multicast-responder")) {
1885 p
->options
.mcast_responder
= 1;
1886 #if PEER_MULTICAST_SIBLINGS
1887 } else if (!strcasecmp(token
, "multicast-siblings")) {
1888 p
->options
.mcast_siblings
= 1;
1890 } else if (!strncasecmp(token
, "weight=", 7)) {
1891 p
->weight
= xatoi(token
+ 7);
1892 } else if (!strncasecmp(token
, "basetime=", 9)) {
1893 p
->basetime
= xatoi(token
+ 9);
1894 } else if (!strcasecmp(token
, "closest-only")) {
1895 p
->options
.closest_only
= 1;
1896 } else if (!strncasecmp(token
, "ttl=", 4)) {
1897 p
->mcast
.ttl
= xatoi(token
+ 4);
1899 if (p
->mcast
.ttl
< 0)
1902 if (p
->mcast
.ttl
> 128)
1904 } else if (!strcasecmp(token
, "default")) {
1905 p
->options
.default_parent
= 1;
1906 } else if (!strcasecmp(token
, "round-robin")) {
1907 p
->options
.roundrobin
= 1;
1908 } else if (!strcasecmp(token
, "weighted-round-robin")) {
1909 p
->options
.weighted_roundrobin
= 1;
1912 } else if (!strcasecmp(token
, "htcp")) {
1913 p
->options
.htcp
= 1;
1914 } else if (!strcasecmp(token
, "htcp-oldsquid")) {
1915 p
->options
.htcp
= 1;
1916 p
->options
.htcp_oldsquid
= 1;
1917 } else if (!strcasecmp(token
, "htcp-no-clr")) {
1918 if (p
->options
.htcp_only_clr
)
1919 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
1920 p
->options
.htcp
= 1;
1921 p
->options
.htcp_no_clr
= 1;
1922 } else if (!strcasecmp(token
, "htcp-no-purge-clr")) {
1923 p
->options
.htcp
= 1;
1924 p
->options
.htcp_no_purge_clr
= 1;
1925 } else if (!strcasecmp(token
, "htcp-only-clr")) {
1926 if (p
->options
.htcp_no_clr
)
1927 fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously");
1928 p
->options
.htcp
= 1;
1929 p
->options
.htcp_only_clr
= 1;
1930 } else if (!strcasecmp(token
, "htcp-forward-clr")) {
1931 p
->options
.htcp
= 1;
1932 p
->options
.htcp_forward_clr
= 1;
1935 } else if (!strcasecmp(token
, "no-netdb-exchange")) {
1936 p
->options
.no_netdb_exchange
= 1;
1938 } else if (!strcasecmp(token
, "carp")) {
1939 if (p
->type
!= PEER_PARENT
)
1940 fatalf("parse_peer: non-parent carp peer %s/%d\n", p
->host
, p
->http_port
);
1942 p
->options
.carp
= 1;
1944 } else if (!strcasecmp(token
, "userhash")) {
1945 if (p
->type
!= PEER_PARENT
)
1946 fatalf("parse_peer: non-parent userhash peer %s/%d\n", p
->host
, p
->http_port
);
1948 p
->options
.userhash
= 1;
1950 } else if (!strcasecmp(token
, "sourcehash")) {
1951 if (p
->type
!= PEER_PARENT
)
1952 fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p
->host
, p
->http_port
);
1954 p
->options
.sourcehash
= 1;
1958 } else if (!strcasecmp(token
, "no-delay")) {
1959 p
->options
.no_delay
= 1;
1962 } else if (!strncasecmp(token
, "login=", 6)) {
1963 p
->login
= xstrdup(token
+ 6);
1964 rfc1738_unescape(p
->login
);
1965 } else if (!strncasecmp(token
, "connect-timeout=", 16)) {
1966 p
->connect_timeout
= xatoi(token
+ 16);
1967 } else if (!strncasecmp(token
, "connect-fail-limit=", 19)) {
1968 p
->connect_fail_limit
= xatoi(token
+ 19);
1969 #if USE_CACHE_DIGESTS
1970 } else if (!strncasecmp(token
, "digest-url=", 11)) {
1971 p
->digest_url
= xstrdup(token
+ 11);
1974 } else if (!strcasecmp(token
, "allow-miss")) {
1975 p
->options
.allow_miss
= 1;
1976 } else if (!strncasecmp(token
, "max-conn=", 9)) {
1977 p
->max_conn
= xatoi(token
+ 9);
1978 } else if (!strcasecmp(token
, "originserver")) {
1979 p
->options
.originserver
= 1;
1980 } else if (!strncasecmp(token
, "name=", 5)) {
1984 p
->name
= xstrdup(token
+ 5);
1985 } else if (!strncasecmp(token
, "forceddomain=", 13)) {
1986 safe_free(p
->domain
);
1989 p
->domain
= xstrdup(token
+ 13);
1993 } else if (strcmp(token
, "ssl") == 0) {
1995 } else if (strncmp(token
, "sslcert=", 8) == 0) {
1996 safe_free(p
->sslcert
);
1997 p
->sslcert
= xstrdup(token
+ 8);
1998 } else if (strncmp(token
, "sslkey=", 7) == 0) {
1999 safe_free(p
->sslkey
);
2000 p
->sslkey
= xstrdup(token
+ 7);
2001 } else if (strncmp(token
, "sslversion=", 11) == 0) {
2002 p
->sslversion
= atoi(token
+ 11);
2003 } else if (strncmp(token
, "ssloptions=", 11) == 0) {
2004 safe_free(p
->ssloptions
);
2005 p
->ssloptions
= xstrdup(token
+ 11);
2006 } else if (strncmp(token
, "sslcipher=", 10) == 0) {
2007 safe_free(p
->sslcipher
);
2008 p
->sslcipher
= xstrdup(token
+ 10);
2009 } else if (strncmp(token
, "sslcafile=", 10) == 0) {
2010 safe_free(p
->sslcafile
);
2011 p
->sslcafile
= xstrdup(token
+ 10);
2012 } else if (strncmp(token
, "sslcapath=", 10) == 0) {
2013 safe_free(p
->sslcapath
);
2014 p
->sslcapath
= xstrdup(token
+ 10);
2015 } else if (strncmp(token
, "sslcrlfile=", 11) == 0) {
2016 safe_free(p
->sslcrlfile
);
2017 p
->sslcapath
= xstrdup(token
+ 10);
2018 } else if (strncmp(token
, "sslflags=", 9) == 0) {
2019 safe_free(p
->sslflags
);
2020 p
->sslflags
= xstrdup(token
+ 9);
2021 } else if (strncmp(token
, "ssldomain=", 10) == 0) {
2022 safe_free(p
->ssldomain
);
2023 p
->ssldomain
= xstrdup(token
+ 10);
2026 } else if (strcmp(token
, "front-end-https") == 0) {
2027 p
->front_end_https
= 1;
2028 } else if (strcmp(token
, "front-end-https=on") == 0) {
2029 p
->front_end_https
= 1;
2030 } else if (strcmp(token
, "front-end-https=auto") == 0) {
2031 p
->front_end_https
= 2;
2032 } else if (strcmp(token
, "connection-auth=off") == 0) {
2033 p
->connection_auth
= 0;
2034 } else if (strcmp(token
, "connection-auth") == 0) {
2035 p
->connection_auth
= 1;
2036 } else if (strcmp(token
, "connection-auth=on") == 0) {
2037 p
->connection_auth
= 1;
2038 } else if (strcmp(token
, "connection-auth=auto") == 0) {
2039 p
->connection_auth
= 2;
2041 debugs(3, 0, "parse_peer: token='" << token
<< "'");
2046 if (peerFindByName(p
->name
))
2047 fatalf("ERROR: cache_peer %s specified twice\n", p
->name
);
2052 if (p
->connect_fail_limit
< 1)
2053 p
->connect_fail_limit
= 10;
2055 p
->icp
.version
= ICP_VERSION_CURRENT
;
2059 #if USE_CACHE_DIGESTS
2061 if (!p
->options
.no_digest
) {
2062 /* XXX This looks odd.. who has the original pointer
2065 PeerDigest
*pd
= peerDigestCreate(p
);
2066 p
->digest
= cbdataReference(pd
);
2071 p
->index
= ++Config
.npeers
;
2073 while (*head
!= NULL
)
2074 head
= &(*head
)->next
;
2082 free_peer(peer
** P
)
2086 while ((p
= *P
) != NULL
) {
2088 #if USE_CACHE_DIGESTS
2090 cbdataReferenceDone(p
->digest
);
2100 dump_cachemgrpasswd(StoreEntry
* entry
, const char *name
, cachemgr_passwd
* list
)
2104 while (list
!= NULL
) {
2105 if (strcmp(list
->passwd
, "none") && strcmp(list
->passwd
, "disable"))
2106 storeAppendPrintf(entry
, "%s XXXXXXXXXX", name
);
2108 storeAppendPrintf(entry
, "%s %s", name
, list
->passwd
);
2110 for (w
= list
->actions
; w
!= NULL
; w
= w
->next
) {
2111 storeAppendPrintf(entry
, " %s", w
->key
);
2114 storeAppendPrintf(entry
, "\n");
2120 parse_cachemgrpasswd(cachemgr_passwd
** head
)
2122 char *passwd
= NULL
;
2123 wordlist
*actions
= NULL
;
2125 cachemgr_passwd
**P
;
2126 parse_string(&passwd
);
2127 parse_wordlist(&actions
);
2128 p
= static_cast<cachemgr_passwd
*>(xcalloc(1, sizeof(cachemgr_passwd
)));
2130 p
->actions
= actions
;
2132 for (P
= head
; *P
; P
= &(*P
)->next
) {
2134 * See if any of the actions from this line already have a
2135 * password from previous lines. The password checking
2136 * routines in cache_manager.c take the the password from
2137 * the first cachemgr_passwd struct that contains the
2138 * requested action. Thus, we should warn users who might
2139 * think they can have two passwords for the same action.
2144 for (w
= (*P
)->actions
; w
; w
= w
->next
) {
2145 for (u
= actions
; u
; u
= u
->next
) {
2146 if (strcmp(w
->key
, u
->key
))
2149 debugs(0, 0, "WARNING: action '" << u
->key
<< "' (line " << config_lineno
<< ") already has a password");
2158 free_cachemgrpasswd(cachemgr_passwd
** head
)
2162 while ((p
= *head
) != NULL
) {
2165 wordlistDestroy(&p
->actions
);
2171 dump_denyinfo(StoreEntry
* entry
, const char *name
, acl_deny_info_list
* var
)
2175 while (var
!= NULL
) {
2176 storeAppendPrintf(entry
, "%s %s", name
, var
->err_page_name
);
2178 for (a
= var
->acl_list
; a
!= NULL
; a
= a
->next
)
2179 storeAppendPrintf(entry
, " %s", a
->name
);
2181 storeAppendPrintf(entry
, "\n");
2188 parse_denyinfo(acl_deny_info_list
** var
)
2190 aclParseDenyInfoLine(var
);
2194 free_denyinfo(acl_deny_info_list
** list
)
2196 acl_deny_info_list
*a
= NULL
;
2197 acl_deny_info_list
*a_next
= NULL
;
2198 acl_name_list
*l
= NULL
;
2199 acl_name_list
*l_next
= NULL
;
2201 for (a
= *list
; a
; a
= a_next
) {
2202 for (l
= a
->acl_list
; l
; l
= l_next
) {
2204 memFree(l
, MEM_ACL_NAME_LIST
);
2209 memFree(a
, MEM_ACL_DENY_INFO_LIST
);
2217 parse_peer_access(void)
2222 if (!(host
= strtok(NULL
, w_space
)))
2225 if ((p
= peerFindByName(host
)) == NULL
) {
2226 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2230 aclParseAccessLine(LegacyParser
, &p
->access
);
2234 parse_hostdomain(void)
2237 char *domain
= NULL
;
2239 if (!(host
= strtok(NULL
, w_space
)))
2242 while ((domain
= strtok(NULL
, list_sep
))) {
2243 domain_ping
*l
= NULL
;
2244 domain_ping
**L
= NULL
;
2247 if ((p
= peerFindByName(host
)) == NULL
) {
2248 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2252 l
= static_cast<domain_ping
*>(xcalloc(1, sizeof(domain_ping
)));
2255 if (*domain
== '!') { /* check for !.edu */
2260 l
->domain
= xstrdup(domain
);
2262 for (L
= &(p
->peer_domain
); *L
; L
= &((*L
)->next
));
2268 parse_hostdomaintype(void)
2272 char *domain
= NULL
;
2274 if (!(host
= strtok(NULL
, w_space
)))
2277 if (!(type
= strtok(NULL
, w_space
)))
2280 while ((domain
= strtok(NULL
, list_sep
))) {
2281 domain_type
*l
= NULL
;
2282 domain_type
**L
= NULL
;
2285 if ((p
= peerFindByName(host
)) == NULL
) {
2286 debugs(15, 0, "" << cfg_filename
<< ", line " << config_lineno
<< ": No cache_peer '" << host
<< "'");
2290 l
= static_cast<domain_type
*>(xcalloc(1, sizeof(domain_type
)));
2291 l
->type
= parseNeighborType(type
);
2292 l
->domain
= xstrdup(domain
);
2294 for (L
= &(p
->typelist
); *L
; L
= &((*L
)->next
));
2300 dump_int(StoreEntry
* entry
, const char *name
, int var
)
2302 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2320 dump_onoff(StoreEntry
* entry
, const char *name
, int var
)
2322 storeAppendPrintf(entry
, "%s %s\n", name
, var
? "on" : "off");
2326 parse_onoff(int *var
)
2328 char *token
= strtok(NULL
, w_space
);
2333 if (!strcasecmp(token
, "on") || !strcasecmp(token
, "enable"))
2339 #define free_onoff free_int
2342 dump_tristate(StoreEntry
* entry
, const char *name
, int var
)
2353 storeAppendPrintf(entry
, "%s %s\n", name
, state
);
2357 parse_tristate(int *var
)
2359 char *token
= strtok(NULL
, w_space
);
2364 if (!strcasecmp(token
, "on") || !strcasecmp(token
, "enable"))
2366 else if (!strcasecmp(token
, "warn"))
2372 #define free_tristate free_int
2375 dump_refreshpattern(StoreEntry
* entry
, const char *name
, refresh_t
* head
)
2377 while (head
!= NULL
) {
2378 storeAppendPrintf(entry
, "%s%s %s %d %d%% %d",
2380 head
->flags
.icase
? " -i" : null_string
,
2382 (int) head
->min
/ 60,
2383 (int) (100.0 * head
->pct
+ 0.5),
2384 (int) head
->max
/ 60);
2386 if (head
->flags
.refresh_ims
)
2387 storeAppendPrintf(entry
, " refresh-ims");
2389 if (head
->flags
.store_stale
)
2390 storeAppendPrintf(entry
, " store-stale");
2392 #if USE_HTTP_VIOLATIONS
2394 if (head
->flags
.override_expire
)
2395 storeAppendPrintf(entry
, " override-expire");
2397 if (head
->flags
.override_lastmod
)
2398 storeAppendPrintf(entry
, " override-lastmod");
2400 if (head
->flags
.reload_into_ims
)
2401 storeAppendPrintf(entry
, " reload-into-ims");
2403 if (head
->flags
.ignore_reload
)
2404 storeAppendPrintf(entry
, " ignore-reload");
2406 if (head
->flags
.ignore_no_cache
)
2407 storeAppendPrintf(entry
, " ignore-no-cache");
2409 if (head
->flags
.ignore_no_store
)
2410 storeAppendPrintf(entry
, " ignore-no-store");
2412 if (head
->flags
.ignore_must_revalidate
)
2413 storeAppendPrintf(entry
, " ignore-must-revalidate");
2415 if (head
->flags
.ignore_private
)
2416 storeAppendPrintf(entry
, " ignore-private");
2418 if (head
->flags
.ignore_auth
)
2419 storeAppendPrintf(entry
, " ignore-auth");
2423 storeAppendPrintf(entry
, "\n");
2430 parse_refreshpattern(refresh_t
** head
)
2437 int refresh_ims
= 0;
2438 int store_stale
= 0;
2440 #if USE_HTTP_VIOLATIONS
2442 int override_expire
= 0;
2443 int override_lastmod
= 0;
2444 int reload_into_ims
= 0;
2445 int ignore_reload
= 0;
2446 int ignore_no_cache
= 0;
2447 int ignore_no_store
= 0;
2448 int ignore_must_revalidate
= 0;
2449 int ignore_private
= 0;
2450 int ignore_auth
= 0;
2457 int flags
= REG_EXTENDED
| REG_NOSUB
;
2459 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
2464 if (strcmp(token
, "-i") == 0) {
2466 token
= strtok(NULL
, w_space
);
2467 } else if (strcmp(token
, "+i") == 0) {
2468 flags
&= ~REG_ICASE
;
2469 token
= strtok(NULL
, w_space
);
2472 if (token
== NULL
) {
2477 pattern
= xstrdup(token
);
2479 i
= GetInteger(); /* token: min */
2481 /* catch negative and insanely huge values close to 32-bit wrap */
2483 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age negative. Cropped back to zero.");
2486 if (i
> 60*24*365) {
2487 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern minimum age too high. Cropped back to 1 year.");
2491 min
= (time_t) (i
* 60); /* convert minutes to seconds */
2493 i
= GetInteger(); /* token: pct */
2495 pct
= (double) i
/ 100.0;
2497 i
= GetInteger(); /* token: max */
2499 /* catch negative and insanely huge values close to 32-bit wrap */
2501 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age negative. Cropped back to zero.");
2504 if (i
> 60*24*365) {
2505 debugs(3, DBG_IMPORTANT
, "WARNING: refresh_pattern maximum age too high. Cropped back to 1 year.");
2509 max
= (time_t) (i
* 60); /* convert minutes to seconds */
2512 while ((token
= strtok(NULL
, w_space
)) != NULL
) {
2513 if (!strcmp(token
, "refresh-ims")) {
2515 } else if (!strcmp(token
, "store-stale")) {
2517 #if USE_HTTP_VIOLATIONS
2519 } else if (!strcmp(token
, "override-expire"))
2520 override_expire
= 1;
2521 else if (!strcmp(token
, "override-lastmod"))
2522 override_lastmod
= 1;
2523 else if (!strcmp(token
, "ignore-no-cache"))
2524 ignore_no_cache
= 1;
2525 else if (!strcmp(token
, "ignore-no-store"))
2526 ignore_no_store
= 1;
2527 else if (!strcmp(token
, "ignore-must-revalidate"))
2528 ignore_must_revalidate
= 1;
2529 else if (!strcmp(token
, "ignore-private"))
2531 else if (!strcmp(token
, "ignore-auth"))
2533 else if (!strcmp(token
, "reload-into-ims")) {
2534 reload_into_ims
= 1;
2535 refresh_nocache_hack
= 1;
2536 /* tell client_side.c that this is used */
2537 } else if (!strcmp(token
, "ignore-reload")) {
2539 refresh_nocache_hack
= 1;
2540 /* tell client_side.c that this is used */
2544 debugs(22, 0, "redreshAddToList: Unknown option '" << pattern
<< "': " << token
);
2547 if ((errcode
= regcomp(&comp
, pattern
, flags
)) != 0) {
2549 regerror(errcode
, &comp
, errbuf
, sizeof errbuf
);
2550 debugs(22, 0, "" << cfg_filename
<< " line " << config_lineno
<< ": " << config_input_line
);
2551 debugs(22, 0, "refreshAddToList: Invalid regular expression '" << pattern
<< "': " << errbuf
);
2555 pct
= pct
< 0.0 ? 0.0 : pct
;
2556 max
= max
< 0 ? 0 : max
;
2557 t
= static_cast<refresh_t
*>(xcalloc(1, sizeof(refresh_t
)));
2558 t
->pattern
= (char *) xstrdup(pattern
);
2559 t
->compiled_pattern
= comp
;
2564 if (flags
& REG_ICASE
)
2568 t
->flags
.refresh_ims
= 1;
2571 t
->flags
.store_stale
= 1;
2573 #if USE_HTTP_VIOLATIONS
2575 if (override_expire
)
2576 t
->flags
.override_expire
= 1;
2578 if (override_lastmod
)
2579 t
->flags
.override_lastmod
= 1;
2581 if (reload_into_ims
)
2582 t
->flags
.reload_into_ims
= 1;
2585 t
->flags
.ignore_reload
= 1;
2587 if (ignore_no_cache
)
2588 t
->flags
.ignore_no_cache
= 1;
2590 if (ignore_no_store
)
2591 t
->flags
.ignore_no_store
= 1;
2593 if (ignore_must_revalidate
)
2594 t
->flags
.ignore_must_revalidate
= 1;
2597 t
->flags
.ignore_private
= 1;
2600 t
->flags
.ignore_auth
= 1;
2607 head
= &(*head
)->next
;
2615 free_refreshpattern(refresh_t
** head
)
2619 while ((t
= *head
) != NULL
) {
2621 safe_free(t
->pattern
);
2622 regfree(&t
->compiled_pattern
);
2626 #if USE_HTTP_VIOLATIONS
2627 refresh_nocache_hack
= 0;
2633 dump_string(StoreEntry
* entry
, const char *name
, char *var
)
2636 storeAppendPrintf(entry
, "%s %s\n", name
, var
);
2640 parse_string(char **var
)
2642 char *token
= strtok(NULL
, w_space
);
2648 *var
= xstrdup(token
);
2652 ConfigParser::ParseString(char **var
)
2658 ConfigParser::ParseString(String
*var
)
2660 char *token
= strtok(NULL
, w_space
);
2669 free_string(char **var
)
2675 parse_eol(char *volatile *var
)
2677 unsigned char *token
= (unsigned char *) strtok(NULL
, null_string
);
2685 while (*token
&& xisspace(*token
))
2693 *var
= xstrdup((char *) token
);
2696 #define dump_eol dump_string
2697 #define free_eol free_string
2700 dump_time_t(StoreEntry
* entry
, const char *name
, time_t var
)
2702 storeAppendPrintf(entry
, "%s %d seconds\n", name
, (int) var
);
2706 parse_time_t(time_t * var
)
2708 parseTimeLine(var
, T_SECOND_STR
);
2712 free_time_t(time_t * var
)
2719 dump_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
2721 storeAppendPrintf(entry
, "%s %d\n", name
, (int) var
);
2726 dump_b_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
2728 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_BYTES_STR
);
2733 dump_kb_size_t(StoreEntry
* entry
, const char *name
, size_t var
)
2735 storeAppendPrintf(entry
, "%s %d %s\n", name
, (int) var
, B_KBYTES_STR
);
2740 dump_b_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
2742 storeAppendPrintf(entry
, "%s %"PRId64
" %s\n", name
, var
, B_BYTES_STR
);
2746 dump_kb_int64_t(StoreEntry
* entry
, const char *name
, int64_t var
)
2748 storeAppendPrintf(entry
, "%s %"PRId64
" %s\n", name
, var
, B_KBYTES_STR
);
2753 parse_size_t(size_t * var
)
2762 parse_b_size_t(size_t * var
)
2764 parseBytesLine(var
, B_BYTES_STR
);
2769 parse_kb_size_t(size_t * var
)
2771 parseBytesLine(var
, B_KBYTES_STR
);
2776 parse_b_int64_t(int64_t * var
)
2778 parseBytesLine64(var
, B_BYTES_STR
);
2782 parse_kb_int64_t(int64_t * var
)
2784 parseBytesLine64(var
, B_KBYTES_STR
);
2788 free_size_t(size_t * var
)
2794 free_b_int64_t(int64_t * var
)
2799 #define free_b_size_t free_size_t
2800 #define free_kb_size_t free_size_t
2801 #define free_mb_size_t free_size_t
2802 #define free_gb_size_t free_size_t
2803 #define free_kb_int64_t free_b_int64_t
2806 dump_ushort(StoreEntry
* entry
, const char *name
, u_short var
)
2808 storeAppendPrintf(entry
, "%s %d\n", name
, var
);
2812 free_ushort(u_short
* u
)
2818 parse_ushort(u_short
* var
)
2820 ConfigParser::ParseUShort(var
);
2824 ConfigParser::ParseUShort(u_short
*var
)
2830 ConfigParser::ParseBool(bool *var
)
2832 int i
= GetInteger();
2843 dump_wordlist(StoreEntry
* entry
, const char *name
, wordlist
* list
)
2845 while (list
!= NULL
) {
2846 storeAppendPrintf(entry
, "%s %s\n", name
, list
->key
);
2852 ConfigParser::ParseWordList(wordlist
** list
)
2854 parse_wordlist(list
);
2858 parse_wordlist(wordlist
** list
)
2861 char *t
= strtok(NULL
, "");
2863 while ((token
= strwordtok(NULL
, &t
)))
2864 wordlistAdd(list
, token
);
2867 #if 0 /* now unused */
2869 check_null_wordlist(wordlist
* w
)
2876 check_null_acl_access(acl_access
* a
)
2881 #define free_wordlist wordlistDestroy
2883 #define free_uri_whitespace free_int
2886 parse_uri_whitespace(int *var
)
2888 char *token
= strtok(NULL
, w_space
);
2893 if (!strcasecmp(token
, "strip"))
2894 *var
= URI_WHITESPACE_STRIP
;
2895 else if (!strcasecmp(token
, "deny"))
2896 *var
= URI_WHITESPACE_DENY
;
2897 else if (!strcasecmp(token
, "allow"))
2898 *var
= URI_WHITESPACE_ALLOW
;
2899 else if (!strcasecmp(token
, "encode"))
2900 *var
= URI_WHITESPACE_ENCODE
;
2901 else if (!strcasecmp(token
, "chop"))
2902 *var
= URI_WHITESPACE_CHOP
;
2908 dump_uri_whitespace(StoreEntry
* entry
, const char *name
, int var
)
2912 if (var
== URI_WHITESPACE_ALLOW
)
2914 else if (var
== URI_WHITESPACE_ENCODE
)
2916 else if (var
== URI_WHITESPACE_CHOP
)
2918 else if (var
== URI_WHITESPACE_DENY
)
2923 storeAppendPrintf(entry
, "%s %s\n", name
, s
);
2927 free_removalpolicy(RemovalPolicySettings
** settings
)
2932 free_string(&(*settings
)->type
);
2934 free_wordlist(&(*settings
)->args
);
2942 parse_removalpolicy(RemovalPolicySettings
** settings
)
2945 free_removalpolicy(settings
);
2947 *settings
= new RemovalPolicySettings
;
2949 parse_string(&(*settings
)->type
);
2951 parse_wordlist(&(*settings
)->args
);
2955 dump_removalpolicy(StoreEntry
* entry
, const char *name
, RemovalPolicySettings
* settings
)
2958 storeAppendPrintf(entry
, "%s %s", name
, settings
->type
);
2959 args
= settings
->args
;
2962 storeAppendPrintf(entry
, " %s", args
->key
);
2966 storeAppendPrintf(entry
, "\n");
2970 free_memcachemode(SquidConfig
* config
)
2976 parse_memcachemode(SquidConfig
* config
)
2978 char *token
= strtok(NULL
, w_space
);
2982 if (strcmp(token
, "always") == 0) {
2983 Config
.onoff
.memory_cache_first
= 1;
2984 Config
.onoff
.memory_cache_disk
= 1;
2985 } else if (strcmp(token
, "disk") == 0) {
2986 Config
.onoff
.memory_cache_first
= 0;
2987 Config
.onoff
.memory_cache_disk
= 1;
2988 } else if (strncmp(token
, "net", 3) == 0) {
2989 Config
.onoff
.memory_cache_first
= 1;
2990 Config
.onoff
.memory_cache_disk
= 0;
2991 } else if (strcmp(token
, "never") == 0) {
2992 Config
.onoff
.memory_cache_first
= 0;
2993 Config
.onoff
.memory_cache_disk
= 0;
2999 dump_memcachemode(StoreEntry
* entry
, const char *name
, SquidConfig
&config
)
3001 storeAppendPrintf(entry
, "%s ", name
);
3002 if (Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3003 storeAppendPrintf(entry
, "always");
3004 else if (!Config
.onoff
.memory_cache_first
&& Config
.onoff
.memory_cache_disk
)
3005 storeAppendPrintf(entry
, "disk");
3006 else if (Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3007 storeAppendPrintf(entry
, "network");
3008 else if (!Config
.onoff
.memory_cache_first
&& !Config
.onoff
.memory_cache_disk
)
3009 storeAppendPrintf(entry
, "none");
3010 storeAppendPrintf(entry
, "\n");
3013 #include "cf_parser.cci"
3016 parseNeighborType(const char *s
)
3018 if (!strcasecmp(s
, "parent"))
3021 if (!strcasecmp(s
, "neighbor"))
3022 return PEER_SIBLING
;
3024 if (!strcasecmp(s
, "neighbour"))
3025 return PEER_SIBLING
;
3027 if (!strcasecmp(s
, "sibling"))
3028 return PEER_SIBLING
;
3030 if (!strcasecmp(s
, "multicast"))
3031 return PEER_MULTICAST
;
3033 debugs(15, 0, "WARNING: Unknown neighbor type: " << s
);
3035 return PEER_SIBLING
;
3040 parse_IpAddress_list(Ip::Address_list
** head
)
3043 Ip::Address_list
*s
;
3046 while ((token
= strtok(NULL
, w_space
))) {
3047 if (GetHostWithPort(token
, &ipa
)) {
3050 head
= &(*head
)->next
;
3052 s
= static_cast<Ip::Address_list
*>(xcalloc(1, sizeof(*s
)));
3062 dump_IpAddress_list(StoreEntry
* e
, const char *n
, const Ip::Address_list
* s
)
3064 char ntoabuf
[MAX_IPSTRLEN
];
3067 storeAppendPrintf(e
, "%s %s\n",
3069 s
->s
.NtoA(ntoabuf
,MAX_IPSTRLEN
));
3075 free_IpAddress_list(Ip::Address_list
** head
)
3077 if (*head
) delete *head
;
3081 #if CURRENTLY_UNUSED
3082 /* This code was previously used by http_port. Left as it really should
3083 * be used by icp_port and htcp_port
3086 check_null_IpAddress_list(const Ip::Address_list
* s
)
3091 #endif /* CURRENTLY_UNUSED */
3092 #endif /* USE_WCCPv2 */
3094 CBDATA_CLASS_INIT(http_port_list
);
3097 parse_http_port_specification(http_port_list
* s
, char *token
)
3100 unsigned short port
= 0;
3104 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3105 s
->name
= xstrdup(token
);
3106 s
->connection_auth_disabled
= false;
3108 if (*token
== '[') {
3111 t
= strchr(host
, ']');
3113 debugs(3, 0, "http(s)_port: missing ']' on IPv6 address: " << token
);
3118 debugs(3, 0, "http(s)_port: missing Port in: " << token
);
3121 if (!Ip::EnableIpv6
) {
3122 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 is not available.");
3125 port
= xatos(t
+ 1);
3126 } else if ((t
= strchr(token
, ':'))) {
3131 port
= xatos(t
+ 1);
3133 } else if ((port
= strtol(token
, &junk
, 10)), !*junk
) {
3135 debugs(3, 3, "http(s)_port: found Listen on Port: " << port
);
3137 debugs(3, 0, "http(s)_port: missing Port: " << token
);
3142 debugs(3, 0, "http(s)_port: Port cannot be 0: " << token
);
3149 if (!Ip::EnableIpv6
)
3151 debugs(3, 3, "http(s)_port: found Listen on wildcard address: *:" << s
->s
.GetPort() );
3152 } else if ( s
->s
= host
) { /* check/parse numeric IPA */
3154 if (!Ip::EnableIpv6
)
3156 debugs(3, 3, "http(s)_port: Listen on Host/IP: " << host
<< " --> " << s
->s
);
3157 } else if ( s
->s
.GetHostByName(host
) ) { /* check/parse for FQDN */
3158 /* dont use ipcache */
3159 s
->defaultsite
= xstrdup(host
);
3161 if (!Ip::EnableIpv6
)
3163 debugs(3, 3, "http(s)_port: found Listen as Host " << s
->defaultsite
<< " on IP: " << s
->s
);
3165 debugs(3, 0, "http(s)_port: failed to resolve Host/IP: " << host
);
3171 parse_http_port_option(http_port_list
* s
, char *token
)
3175 if (strcmp(token
, "accel") == 0) {
3176 if (s
->intercepted
|| s
->spoof_client_ip
) {
3177 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: Accelerator mode requires its own port. It cannot be shared with other modes.");
3181 } else if (strcmp(token
, "transparent") == 0 || strcmp(token
, "intercept") == 0) {
3182 if (s
->accel
|| s
->spoof_client_ip
) {
3183 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: Intercept mode requires its own interception port. It cannot be shared with other modes.");
3187 Ip::Interceptor
.StartInterception();
3188 /* Log information regarding the port modes under interception. */
3189 debugs(3, DBG_IMPORTANT
, "Starting Authentication on port " << s
->s
);
3190 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (interception enabled)");
3192 /* INET6: until transparent REDIRECT works on IPv6 SOCKET, force wildcard to IPv4 */
3194 debugs(3, DBG_IMPORTANT
, "Disabling IPv6 on port " << s
->s
<< " (interception enabled)");
3195 if ( !s
->s
.SetIPv4() ) {
3196 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 addresses cannot be transparent (protocol does not provide NAT)" << s
->s
);
3199 } else if (strcmp(token
, "tproxy") == 0) {
3200 if (s
->intercepted
|| s
->accel
) {
3201 debugs(3,DBG_CRITICAL
, "FATAL: http(s)_port: TPROXY option requires its own interception port. It cannot be shared with other modes.");
3204 s
->spoof_client_ip
= 1;
3205 Ip::Interceptor
.StartTransparency();
3206 /* Log information regarding the port modes under transparency. */
3207 debugs(3, DBG_IMPORTANT
, "Starting IP Spoofing on port " << s
->s
);
3208 debugs(3, DBG_IMPORTANT
, "Disabling Authentication on port " << s
->s
<< " (IP spoofing enabled)");
3210 if (!Ip::Interceptor
.ProbeForTproxy(s
->s
)) {
3211 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: TPROXY support in the system does not work.");
3215 } else if (strncmp(token
, "defaultsite=", 12) == 0) {
3217 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: defaultsite option requires Acceleration mode flag.");
3220 safe_free(s
->defaultsite
);
3221 s
->defaultsite
= xstrdup(token
+ 12);
3222 } else if (strcmp(token
, "vhost") == 0) {
3224 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vhost option requires Acceleration mode flag.");
3228 } else if (strcmp(token
, "vport") == 0) {
3230 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3234 } else if (strncmp(token
, "vport=", 6) == 0) {
3236 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3239 s
->vport
= xatos(token
+ 6);
3240 } else if (strncmp(token
, "protocol=", 9) == 0) {
3242 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: protocol option requires Acceleration mode flag.");
3245 s
->protocol
= xstrdup(token
+ 9);
3246 } else if (strcmp(token
, "allow-direct") == 0) {
3248 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: vport option requires Acceleration mode flag.");
3251 s
->allow_direct
= 1;
3252 } else if (strcmp(token
, "ignore-cc") == 0) {
3253 #if !USE_HTTP_VIOLATIONS
3255 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: ignore-cc option requires Scceleration mode flag.");
3260 } else if (strncmp(token
, "name=", 5) == 0) {
3262 s
->name
= xstrdup(token
+ 5);
3263 } else if (strcmp(token
, "no-connection-auth") == 0) {
3264 s
->connection_auth_disabled
= true;
3265 } else if (strcmp(token
, "connection-auth=off") == 0) {
3266 s
->connection_auth_disabled
= true;
3267 } else if (strcmp(token
, "connection-auth") == 0) {
3268 s
->connection_auth_disabled
= false;
3269 } else if (strcmp(token
, "connection-auth=on") == 0) {
3270 s
->connection_auth_disabled
= false;
3271 } else if (strncmp(token
, "disable-pmtu-discovery=", 23) == 0) {
3272 if (!strcasecmp(token
+ 23, "off"))
3273 s
->disable_pmtu_discovery
= DISABLE_PMTU_OFF
;
3274 else if (!strcasecmp(token
+ 23, "transparent"))
3275 s
->disable_pmtu_discovery
= DISABLE_PMTU_TRANSPARENT
;
3276 else if (!strcasecmp(token
+ 23, "always"))
3277 s
->disable_pmtu_discovery
= DISABLE_PMTU_ALWAYS
;
3280 } else if (strcmp(token
, "ipv4") == 0) {
3281 if ( !s
->s
.SetIPv4() ) {
3282 debugs(3, DBG_CRITICAL
, "FATAL: http(s)_port: IPv6 addresses cannot be used as IPv4-Only. " << s
->s
);
3285 } else if (strcmp(token
, "tcpkeepalive") == 0) {
3286 s
->tcp_keepalive
.enabled
= 1;
3287 } else if (strncmp(token
, "tcpkeepalive=", 13) == 0) {
3288 char *t
= token
+ 13;
3289 s
->tcp_keepalive
.enabled
= 1;
3290 s
->tcp_keepalive
.idle
= atoi(t
);
3294 s
->tcp_keepalive
.interval
= atoi(t
);
3299 s
->tcp_keepalive
.timeout
= atoi(t
);
3303 } else if (strcasecmp(token
, "sslBump") == 0) {
3304 debugs(3, DBG_CRITICAL
, "WARNING: '" << token
<< "' is deprecated " <<
3305 "in http_port. Use 'ssl-bump' instead.");
3306 s
->sslBump
= 1; // accelerated when bumped, otherwise not
3307 } else if (strcmp(token
, "ssl-bump") == 0) {
3308 s
->sslBump
= 1; // accelerated when bumped, otherwise not
3309 } else if (strncmp(token
, "cert=", 5) == 0) {
3311 s
->cert
= xstrdup(token
+ 5);
3312 } else if (strncmp(token
, "key=", 4) == 0) {
3314 s
->key
= xstrdup(token
+ 4);
3315 } else if (strncmp(token
, "version=", 8) == 0) {
3316 s
->version
= xatoi(token
+ 8);
3317 if (s
->version
< 1 || s
->version
> 4)
3319 } else if (strncmp(token
, "options=", 8) == 0) {
3320 safe_free(s
->options
);
3321 s
->options
= xstrdup(token
+ 8);
3322 } else if (strncmp(token
, "cipher=", 7) == 0) {
3323 safe_free(s
->cipher
);
3324 s
->cipher
= xstrdup(token
+ 7);
3325 } else if (strncmp(token
, "clientca=", 9) == 0) {
3326 safe_free(s
->clientca
);
3327 s
->clientca
= xstrdup(token
+ 9);
3328 } else if (strncmp(token
, "cafile=", 7) == 0) {
3329 safe_free(s
->cafile
);
3330 s
->cafile
= xstrdup(token
+ 7);
3331 } else if (strncmp(token
, "capath=", 7) == 0) {
3332 safe_free(s
->capath
);
3333 s
->capath
= xstrdup(token
+ 7);
3334 } else if (strncmp(token
, "crlfile=", 8) == 0) {
3335 safe_free(s
->crlfile
);
3336 s
->crlfile
= xstrdup(token
+ 8);
3337 } else if (strncmp(token
, "dhparams=", 9) == 0) {
3338 safe_free(s
->dhfile
);
3339 s
->dhfile
= xstrdup(token
+ 9);
3340 } else if (strncmp(token
, "sslflags=", 9) == 0) {
3341 safe_free(s
->sslflags
);
3342 s
->sslflags
= xstrdup(token
+ 9);
3343 } else if (strncmp(token
, "sslcontext=", 11) == 0) {
3344 safe_free(s
->sslcontext
);
3345 s
->sslcontext
= xstrdup(token
+ 11);
3352 static http_port_list
*
3353 create_http_port(char *portspec
)
3355 http_port_list
*s
= new http_port_list("http");
3356 parse_http_port_specification(s
, portspec
);
3361 add_http_port(char *portspec
)
3363 http_port_list
*s
= create_http_port(portspec
);
3364 // we may need to merge better of the above returns a list with clones
3365 assert(s
->next
== NULL
);
3366 s
->next
= Config
.Sockaddr
.http
;
3367 Config
.Sockaddr
.http
= s
;
3371 clone_http_port_list(http_port_list
*a
)
3373 http_port_list
*b
= new http_port_list(a
->protocol
);
3377 b
->name
= xstrdup(a
->name
);
3379 b
->defaultsite
= xstrdup(a
->defaultsite
);
3381 b
->intercepted
= a
->intercepted
;
3382 b
->spoof_client_ip
= a
->spoof_client_ip
;
3383 b
->accel
= a
->accel
;
3384 b
->allow_direct
= a
->allow_direct
;
3385 b
->vhost
= a
->vhost
;
3386 b
->sslBump
= a
->sslBump
;
3387 b
->vport
= a
->vport
;
3388 b
->connection_auth_disabled
= a
->connection_auth_disabled
;
3389 b
->disable_pmtu_discovery
= a
->disable_pmtu_discovery
;
3391 memcpy( &(b
->tcp_keepalive
), &(a
->tcp_keepalive
), sizeof(a
->tcp_keepalive
));
3394 // AYJ: 2009-07-18: for now SSL does not clone. Configure separate ports with IPs and SSL settings
3397 // XXX: temporary hack to ease move of SSL options to http_port
3398 http_port_list
&http
;
3412 SSL_CTX
*sslContext
;
3421 parse_http_port_list(http_port_list
** head
)
3423 char *token
= strtok(NULL
, w_space
);
3430 http_port_list
*s
= create_http_port(token
);
3432 /* parse options ... */
3433 while ((token
= strtok(NULL
, w_space
))) {
3434 parse_http_port_option(s
, token
);
3437 if (Ip::EnableIpv6
&IPV6_SPECIAL_SPLITSTACK
&& s
->s
.IsAnyAddr()) {
3438 // clone the port options from *s to *(s->next)
3439 s
->next
= clone_http_port_list(s
);
3440 s
->next
->s
.SetIPv4();
3441 debugs(3, 3, "http(s)_port: clone wildcard address for split-stack: " << s
->s
<< " and " << s
->next
->s
);
3445 head
= &(*head
)->next
;
3451 dump_generic_http_port(StoreEntry
* e
, const char *n
, const http_port_list
* s
)
3453 char buf
[MAX_IPSTRLEN
];
3455 storeAppendPrintf(e
, "%s %s",
3457 s
->s
.ToURL(buf
,MAX_IPSTRLEN
));
3460 storeAppendPrintf(e
, " intercept");
3462 if (s
->spoof_client_ip
)
3463 storeAppendPrintf(e
, " tproxy");
3466 storeAppendPrintf(e
, " accel");
3469 storeAppendPrintf(e
, " vhost");
3472 storeAppendPrintf(e
, " vport");
3475 storeAppendPrintf(e
, " defaultsite=%s", s
->defaultsite
);
3477 if (s
->connection_auth_disabled
)
3478 storeAppendPrintf(e
, " connection-auth=off");
3480 storeAppendPrintf(e
, " connection-auth=on");
3482 if (s
->disable_pmtu_discovery
!= DISABLE_PMTU_OFF
) {
3485 if (s
->disable_pmtu_discovery
== DISABLE_PMTU_ALWAYS
)
3488 pmtu
= "transparent";
3490 storeAppendPrintf(e
, " disable-pmtu-discovery=%s", pmtu
);
3493 if (s
->tcp_keepalive
.enabled
) {
3494 if (s
->tcp_keepalive
.idle
|| s
->tcp_keepalive
.interval
|| s
->tcp_keepalive
.timeout
) {
3495 storeAppendPrintf(e
, " tcpkeepalive=%d,%d,%d", s
->tcp_keepalive
.idle
, s
->tcp_keepalive
.interval
, s
->tcp_keepalive
.timeout
);
3497 storeAppendPrintf(e
, " tcpkeepalive");
3503 storeAppendPrintf(e
, " sslBump");
3506 storeAppendPrintf(e
, " cert=%s", s
->cert
);
3509 storeAppendPrintf(e
, " key=%s", s
->key
);
3512 storeAppendPrintf(e
, " version=%d", s
->version
);
3515 storeAppendPrintf(e
, " options=%s", s
->options
);
3518 storeAppendPrintf(e
, " cipher=%s", s
->cipher
);
3521 storeAppendPrintf(e
, " cafile=%s", s
->cafile
);
3524 storeAppendPrintf(e
, " capath=%s", s
->capath
);
3527 storeAppendPrintf(e
, " crlfile=%s", s
->crlfile
);
3530 storeAppendPrintf(e
, " dhparams=%s", s
->dhfile
);
3533 storeAppendPrintf(e
, " sslflags=%s", s
->sslflags
);
3536 storeAppendPrintf(e
, " sslcontext=%s", s
->sslcontext
);
3541 dump_http_port_list(StoreEntry
* e
, const char *n
, const http_port_list
* s
)
3544 dump_generic_http_port(e
, n
, s
);
3545 storeAppendPrintf(e
, "\n");
3551 free_http_port_list(http_port_list
** head
)
3555 while ((s
= *head
) != NULL
) {
3563 // TODO: merge better with parse_http_port_list
3565 parse_https_port_list(https_port_list
** head
)
3570 token
= strtok(NULL
, w_space
);
3575 s
= new https_port_list
;
3576 parse_http_port_specification(&s
->http
, token
);
3578 /* parse options ... */
3579 while ((token
= strtok(NULL
, w_space
))) {
3580 parse_http_port_option(s
, token
);
3584 http_port_list
** headTmp
= &(*head
)->http
.next
;
3585 head
= (https_port_list
**)headTmp
;
3592 dump_https_port_list(StoreEntry
* e
, const char *n
, const https_port_list
* s
)
3594 dump_http_port_list(e
, n
, s
);
3598 free_https_port_list(https_port_list
** head
)
3600 free_http_port_list((http_port_list
**)head
);
3605 check_null_https_port_list(const https_port_list
* s
)
3612 #endif /* USE_SSL */
3615 configFreeMemory(void)
3621 requirePathnameExists(const char *name
, const char *path
)
3625 char pathbuf
[BUFSIZ
];
3626 assert(path
!= NULL
);
3628 if (Config
.chroot_dir
&& (geteuid() == 0)) {
3629 snprintf(pathbuf
, BUFSIZ
, "%s/%s", Config
.chroot_dir
, path
);
3633 if (stat(path
, &sb
) < 0) {
3634 if (opt_send_signal
== -1 || opt_send_signal
== SIGHUP
)
3635 fatalf("%s %s: %s", name
, path
, xstrerror());
3637 fprintf(stderr
, "WARNING: %s %s: %s\n", name
, path
, xstrerror());
3644 return ConfigParser::strtokFile();
3647 #include "AccessLogEntry.h"
3648 /* TODO: split out parsing somehow ...*/
3650 parse_logformat(logformat
** logformat_definitions
)
3655 if ((name
= strtok(NULL
, w_space
)) == NULL
)
3658 if ((def
= strtok(NULL
, "\r\n")) == NULL
) {
3663 debugs(3, 2, "Logformat for '" << name
<< "' is '" << def
<< "'");
3665 nlf
= (logformat
*)xcalloc(1, sizeof(logformat
));
3667 nlf
->name
= xstrdup(name
);
3669 if (!accessLogParseLogFormat(&nlf
->format
, def
)) {
3674 nlf
->next
= *logformat_definitions
;
3676 *logformat_definitions
= nlf
;
3680 parse_access_log(customlog
** logs
)
3682 const char *filename
, *logdef_name
;
3686 cl
= (customlog
*)xcalloc(1, sizeof(*cl
));
3688 if ((filename
= strtok(NULL
, w_space
)) == NULL
) {
3693 if (strcmp(filename
, "none") == 0) {
3694 cl
->type
= CLF_NONE
;
3698 if ((logdef_name
= strtok(NULL
, w_space
)) == NULL
)
3699 logdef_name
= "auto";
3701 debugs(3, 9, "Log definition name '" << logdef_name
<< "' file '" << filename
<< "'");
3703 cl
->filename
= xstrdup(filename
);
3705 /* look for the definition pointer corresponding to this name */
3706 lf
= Config
.Log
.logformats
;
3708 while (lf
!= NULL
) {
3709 debugs(3, 9, "Comparing against '" << lf
->name
<< "'");
3711 if (strcmp(lf
->name
, logdef_name
) == 0)
3718 cl
->type
= CLF_CUSTOM
;
3720 } else if (strcmp(logdef_name
, "auto") == 0) {
3721 cl
->type
= CLF_AUTO
;
3722 } else if (strcmp(logdef_name
, "squid") == 0) {
3723 cl
->type
= CLF_SQUID
;
3724 } else if (strcmp(logdef_name
, "common") == 0) {
3725 cl
->type
= CLF_COMMON
;
3727 } else if (strcmp(logdef_name
, "icap_squid") == 0) {
3728 cl
->type
= CLF_ICAP_SQUID
;
3731 debugs(3, 0, "Log format '" << logdef_name
<< "' is not defined");
3737 aclParseAclList(LegacyParser
, &cl
->aclList
);
3740 logs
= &(*logs
)->next
;
3746 check_null_access_log(customlog
*customlog_definitions
)
3748 return customlog_definitions
== NULL
;
3752 dump_logformat(StoreEntry
* entry
, const char *name
, logformat
* definitions
)
3754 accessLogDumpLogFormat(entry
, name
, definitions
);
3758 dump_access_log(StoreEntry
* entry
, const char *name
, customlog
* logs
)
3762 for (log
= logs
; log
; log
= log
->next
) {
3763 storeAppendPrintf(entry
, "%s ", name
);
3765 switch (log
->type
) {
3768 storeAppendPrintf(entry
, "%s %s", log
->filename
, log
->logFormat
->name
);
3772 storeAppendPrintf(entry
, "none");
3776 storeAppendPrintf(entry
, "%s squid", log
->filename
);
3780 storeAppendPrintf(entry
, "%s squid", log
->filename
);
3783 case CLF_ICAP_SQUID
:
3784 storeAppendPrintf(entry
, "%s icap_squid", log
->filename
);
3790 storeAppendPrintf(entry
, "%s auto", log
->filename
);
3792 storeAppendPrintf(entry
, "%s", log
->filename
);
3801 dump_acl_list(entry
, log
->aclList
);
3803 storeAppendPrintf(entry
, "\n");
3808 free_logformat(logformat
** definitions
)
3810 while (*definitions
) {
3811 logformat
*format
= *definitions
;
3812 *definitions
= format
->next
;
3813 safe_free(format
->name
);
3814 accessLogFreeLogFormat(&format
->format
);
3820 free_access_log(customlog
** definitions
)
3822 while (*definitions
) {
3823 customlog
*log
= *definitions
;
3824 *definitions
= log
->next
;
3826 log
->logFormat
= NULL
;
3827 log
->type
= CLF_UNKNOWN
;
3830 aclDestroyAclList(&log
->aclList
);
3832 safe_free(log
->filename
);
3841 parse_adaptation_service_set_type()
3843 Adaptation::Config::ParseServiceSet();
3847 parse_adaptation_service_chain_type()
3849 Adaptation::Config::ParseServiceChain();
3853 parse_adaptation_access_type()
3855 Adaptation::Config::ParseAccess(LegacyParser
);
3858 #endif /* USE_ADAPTATION */
3864 parse_icap_service_type(Adaptation::Icap::Config
* cfg
)
3866 cfg
->parseService();
3870 free_icap_service_type(Adaptation::Icap::Config
* cfg
)
3876 dump_icap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
3878 cfg
.dumpService(entry
, name
);
3882 parse_icap_class_type()
3884 debugs(93, 0, "WARNING: 'icap_class' is depricated. " <<
3885 "Use 'adaptation_service_set' instead");
3886 Adaptation::Config::ParseServiceSet();
3890 parse_icap_access_type()
3892 debugs(93, 0, "WARNING: 'icap_access' is depricated. " <<
3893 "Use 'adaptation_access' instead");
3894 Adaptation::Config::ParseAccess(LegacyParser
);
3903 parse_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
3905 cfg
->parseService();
3909 free_ecap_service_type(Adaptation::Ecap::Config
* cfg
)
3915 dump_ecap_service_type(StoreEntry
* entry
, const char *name
, const Adaptation::Ecap::Config
&cfg
)
3917 cfg
.dumpService(entry
, name
);
3920 #endif /* USE_ECAP */
3923 static void parse_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
3928 cfg
->service_failure_limit
= GetInteger();
3930 if ((token
= strtok(NULL
, w_space
)) == NULL
)
3933 if (strcmp(token
,"in") != 0) {
3934 debugs(3, 0, "expecting 'in' on'" << config_input_line
<< "'");
3938 if ((token
= strtok(NULL
, w_space
)) == NULL
) {
3942 d
= static_cast<time_t> (xatoi(token
));
3944 m
= static_cast<time_t> (1);
3948 else if ((token
= strtok(NULL
, w_space
)) == NULL
) {
3949 debugs(3, 0, "No time-units on '" << config_input_line
<< "'");
3951 } else if ((m
= parseTimeUnits(token
)) == 0)
3954 cfg
->oldest_service_failure
= (m
* d
);
3957 static void dump_icap_service_failure_limit(StoreEntry
*entry
, const char *name
, const Adaptation::Icap::Config
&cfg
)
3959 storeAppendPrintf(entry
, "%s %d", name
, cfg
.service_failure_limit
);
3960 if (cfg
.oldest_service_failure
> 0) {
3961 storeAppendPrintf(entry
, " in %d seconds", (int)cfg
.oldest_service_failure
);
3963 storeAppendPrintf(entry
, "\n");
3966 static void free_icap_service_failure_limit(Adaptation::Icap::Config
*cfg
)
3968 cfg
->oldest_service_failure
= 0;
3969 cfg
->service_failure_limit
= 0;