]>
Commit | Line | Data |
---|---|---|
30a4f2a8 | 1 | /* |
262a0e14 | 2 | * $Id$ |
30a4f2a8 | 3 | * |
b510f3a1 | 4 | * DEBUG: section 03 Configuration File Parsing |
30a4f2a8 | 5 | * AUTHOR: Harvest Derived |
6 | * | |
2b6662ba | 7 | * SQUID Web Proxy Cache http://www.squid-cache.org/ |
e25c139f | 8 | * ---------------------------------------------------------- |
30a4f2a8 | 9 | * |
2b6662ba | 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. | |
30a4f2a8 | 18 | * |
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. | |
26ac0430 | 23 | * |
30a4f2a8 | 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. | |
26ac0430 | 28 | * |
30a4f2a8 | 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 | |
cbdec147 | 31 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. |
e25c139f | 32 | * |
30a4f2a8 | 33 | */ |
cf5fd929 | 34 | |
44a47c6e | 35 | #include "squid.h" |
82b7abe3 AJ |
36 | |
37 | #include "acl/Acl.h" | |
38 | #include "acl/Gadgets.h" | |
39 | #include "acl/MethodData.h" | |
40 | #if USE_ADAPTATION | |
41 | #include "adaptation/Config.h" | |
42 | #endif | |
43 | #if ICAP_CLIENT | |
44 | #include "adaptation/icap/Config.h" | |
45 | #endif | |
46 | #if USE_ECAP | |
47 | #include "adaptation/ecap/Config.h" | |
48 | #endif | |
95d2589c | 49 | #if USE_SSL |
4db984be | 50 | #include "ssl/support.h" |
95d2589c CT |
51 | #include "ssl/Config.h" |
52 | #endif | |
2f1431ea | 53 | #if USE_AUTH |
2d2b0bb7 AR |
54 | #include "auth/Config.h" |
55 | #include "auth/Scheme.h" | |
2f1431ea | 56 | #endif |
a80a77cf | 57 | #include "ConfigParser.h" |
96c2bb61 | 58 | #include "CpuAffinityMap.h" |
82b7abe3 AJ |
59 | #include "eui/Config.h" |
60 | #if USE_SQUID_ESI | |
61 | #include "esi/Parser.h" | |
62 | #endif | |
38e16f92 | 63 | #include "format/Format.h" |
82b7abe3 AJ |
64 | #include "HttpRequestMethod.h" |
65 | #include "ident/Config.h" | |
96d89ea0 | 66 | #include "ip/Intercept.h" |
b7ac5457 | 67 | #include "ip/QosConfig.h" |
055421ee | 68 | #include "ip/tools.h" |
82b7abe3 AJ |
69 | #include "log/Config.h" |
70 | #include "MemBuf.h" | |
8822ebee | 71 | #include "mgr/Registration.h" |
c8f4eac4 | 72 | #include "Parsing.h" |
82b7abe3 | 73 | #include "ProtoPort.h" |
1fa9b1a7 | 74 | #include "rfc1738.h" |
82b7abe3 AJ |
75 | #if SQUID_SNMP |
76 | #include "snmp.h" | |
77 | #endif | |
78 | #include "Store.h" | |
79 | #include "StoreFileSystem.h" | |
80 | #include "SwapDir.h" | |
d295d770 | 81 | #include "wordlist.h" |
40daaeb8 | 82 | #include "ipc/Kids.h" |
04f87469 | 83 | |
52303a3d | 84 | #if HAVE_GLOB_H |
592a09dc | 85 | #include <glob.h> |
52303a3d | 86 | #endif |
1df370e3 | 87 | |
425de4c8 AJ |
88 | #if HAVE_LIMITS_H |
89 | #include <limits> | |
90 | #endif | |
91 | ||
95d2589c CT |
92 | #if USE_SSL |
93 | #include "ssl/gadgets.h" | |
94 | #endif | |
95 | ||
62c7f90e | 96 | #if USE_ADAPTATION |
62c7f90e | 97 | static void parse_adaptation_service_set_type(); |
a22e6cd3 | 98 | static void parse_adaptation_service_chain_type(); |
62c7f90e | 99 | static void parse_adaptation_access_type(); |
62c7f90e AR |
100 | #endif |
101 | ||
3a69ddf3 | 102 | #if ICAP_CLIENT |
26cc52cb AR |
103 | static void parse_icap_service_type(Adaptation::Icap::Config *); |
104 | static void dump_icap_service_type(StoreEntry *, const char *, const Adaptation::Icap::Config &); | |
105 | static void free_icap_service_type(Adaptation::Icap::Config *); | |
c939dc70 AR |
106 | static void parse_icap_class_type(); |
107 | static void parse_icap_access_type(); | |
8277060a CT |
108 | |
109 | static void parse_icap_service_failure_limit(Adaptation::Icap::Config *); | |
110 | static void dump_icap_service_failure_limit(StoreEntry *, const char *, const Adaptation::Icap::Config &); | |
111 | static void free_icap_service_failure_limit(Adaptation::Icap::Config *); | |
3a69ddf3 | 112 | #endif |
113 | ||
21a26d31 | 114 | #if USE_ECAP |
574b508c AR |
115 | static void parse_ecap_service_type(Adaptation::Ecap::Config *); |
116 | static void dump_ecap_service_type(StoreEntry *, const char *, const Adaptation::Ecap::Config &); | |
117 | static void free_ecap_service_type(Adaptation::Ecap::Config *); | |
21a26d31 AR |
118 | #endif |
119 | ||
f5691f9c | 120 | CBDATA_TYPE(peer); |
121 | ||
fd0f51c4 | 122 | static const char *const T_MILLISECOND_STR = "millisecond"; |
8813e606 | 123 | static const char *const T_SECOND_STR = "second"; |
124 | static const char *const T_MINUTE_STR = "minute"; | |
125 | static const char *const T_HOUR_STR = "hour"; | |
126 | static const char *const T_DAY_STR = "day"; | |
127 | static const char *const T_WEEK_STR = "week"; | |
128 | static const char *const T_FORTNIGHT_STR = "fortnight"; | |
129 | static const char *const T_MONTH_STR = "month"; | |
130 | static const char *const T_YEAR_STR = "year"; | |
131 | static const char *const T_DECADE_STR = "decade"; | |
aa0a0c7c | 132 | |
9906e724 | 133 | static const char *const B_BYTES_STR = "bytes"; |
134 | static const char *const B_KBYTES_STR = "KB"; | |
135 | static const char *const B_MBYTES_STR = "MB"; | |
136 | static const char *const B_GBYTES_STR = "GB"; | |
137 | ||
4db43fab | 138 | static const char *const list_sep = ", \t\n\r"; |
b0e7d2d5 | 139 | |
7684c4b1 | 140 | static void parse_access_log(customlog ** customlog_definitions); |
d64bef4c | 141 | static int check_null_access_log(customlog *customlog_definitions); |
7684c4b1 | 142 | static void dump_access_log(StoreEntry * entry, const char *name, customlog * definitions); |
7684c4b1 | 143 | static void free_access_log(customlog ** definitions); |
144 | ||
cd748f27 | 145 | static void update_maxobjsize(void); |
f5b8bbc4 | 146 | static void configDoConfigure(void); |
147 | static void parse_refreshpattern(refresh_t **); | |
9b741834 CT |
148 | static uint64_t parseTimeUnits(const char *unit, bool allowMsec); |
149 | static void parseTimeLine(time_msec_t * tptr, const char *units, bool allowMsec); | |
f45dd259 | 150 | static void parse_u_short(unsigned short * var); |
f5b8bbc4 | 151 | static void parse_string(char **); |
f5b8bbc4 | 152 | static void default_all(void); |
153 | static void defaults_if_none(void); | |
154 | static int parse_line(char *); | |
76f44481 | 155 | static void parse_obsolete(const char *); |
f5b8bbc4 | 156 | static void parseBytesLine(size_t * bptr, const char *units); |
95d2589c CT |
157 | #if USE_SSL |
158 | static void parseBytesOptionValue(size_t * bptr, const char *units, char const * value); | |
159 | #endif | |
e210930b AJ |
160 | #if !USE_DNSSERVERS |
161 | static void parseBytesLineSigned(ssize_t * bptr, const char *units); | |
162 | #endif | |
f5b8bbc4 | 163 | static size_t parseBytesUnits(const char *unit); |
f5b8bbc4 | 164 | static void free_all(void); |
94439e4e | 165 | void requirePathnameExists(const char *name, const char *path); |
ed7f5615 | 166 | static OBJH dump_config; |
626096be | 167 | #if USE_HTTP_VIOLATIONS |
6bccf575 | 168 | static void dump_http_header_access(StoreEntry * entry, const char *name, header_mangler header[]); |
169 | static void parse_http_header_access(header_mangler header[]); | |
170 | static void free_http_header_access(header_mangler header[]); | |
171 | static void dump_http_header_replace(StoreEntry * entry, const char *name, header_mangler header[]); | |
172 | static void parse_http_header_replace(header_mangler * header); | |
173 | static void free_http_header_replace(header_mangler * header); | |
9e8b2f1c | 174 | #endif |
6bccf575 | 175 | static void parse_denyinfo(acl_deny_info_list ** var); |
176 | static void dump_denyinfo(StoreEntry * entry, const char *name, acl_deny_info_list * var); | |
177 | static void free_denyinfo(acl_deny_info_list ** var); | |
e1a88700 | 178 | |
0b0cfcf2 | 179 | #if USE_WCCPv2 |
b7ac5457 AJ |
180 | static void parse_IpAddress_list(Ip::Address_list **); |
181 | static void dump_IpAddress_list(StoreEntry *, const char *, const Ip::Address_list *); | |
182 | static void free_IpAddress_list(Ip::Address_list **); | |
0b0cfcf2 | 183 | #if CURRENTLY_UNUSED |
b7ac5457 | 184 | static int check_null_IpAddress_list(const Ip::Address_list *); |
3f38a55e | 185 | #endif /* CURRENTLY_UNUSED */ |
e1a88700 | 186 | #endif /* USE_WCCPv2 */ |
187 | ||
3f38a55e | 188 | static void parse_http_port_list(http_port_list **); |
189 | static void dump_http_port_list(StoreEntry *, const char *, const http_port_list *); | |
190 | static void free_http_port_list(http_port_list **); | |
e1a88700 | 191 | |
d193a436 | 192 | #if USE_SSL |
193 | static void parse_https_port_list(https_port_list **); | |
194 | static void dump_https_port_list(StoreEntry *, const char *, const https_port_list *); | |
195 | static void free_https_port_list(https_port_list **); | |
196 | #if 0 | |
197 | static int check_null_https_port_list(const https_port_list *); | |
198 | #endif | |
199 | #endif /* USE_SSL */ | |
e1a88700 | 200 | |
ef1955a5 | 201 | static void parse_b_size_t(size_t * var); |
47f6e231 | 202 | static void parse_b_int64_t(int64_t * var); |
270b86af | 203 | |
96c2bb61 AR |
204 | static bool parseNamedIntList(const char *data, const String &name, Vector<int> &list); |
205 | ||
206 | static void parse_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap); | |
207 | static void dump_CpuAffinityMap(StoreEntry *const entry, const char *const name, const CpuAffinityMap *const cpuAffinityMap); | |
208 | static void free_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap); | |
209 | ||
cfcb6b30 | 210 | static int parseOneConfigFile(const char *file_name, unsigned int depth); |
211 | ||
a385afc3 | 212 | /* |
213 | * LegacyParser is a parser for legacy code that uses the global | |
214 | * approach. This is static so that it is only exposed to cache_cf. | |
215 | * Other modules needing access to a ConfigParser should have it | |
216 | * provided to them in their parserFOO methods. | |
217 | */ | |
218 | static ConfigParser LegacyParser = ConfigParser(); | |
a9f20260 | 219 | |
0e4e0e7d | 220 | void |
0673c0ba | 221 | self_destruct(void) |
090089c4 | 222 | { |
a9f20260 | 223 | LegacyParser.destruct(); |
6b8e7481 | 224 | } |
225 | ||
cd748f27 | 226 | static void |
227 | update_maxobjsize(void) | |
228 | { | |
229 | int i; | |
47f6e231 | 230 | int64_t ms = -1; |
cd748f27 | 231 | |
232 | for (i = 0; i < Config.cacheSwap.n_configured; i++) { | |
c8f4eac4 | 233 | assert (Config.cacheSwap.swapDirs[i].getRaw()); |
62e76326 | 234 | |
c8f4eac4 | 235 | if (dynamic_cast<SwapDir *>(Config.cacheSwap.swapDirs[i].getRaw())-> |
236 | max_objsize > ms) | |
237 | ms = dynamic_cast<SwapDir *>(Config.cacheSwap.swapDirs[i].getRaw())->max_objsize; | |
cd748f27 | 238 | } |
239 | store_maxobjsize = ms; | |
240 | } | |
241 | ||
76b9daa5 | 242 | static void |
243 | SetConfigFilename(char const *file_name, bool is_pipe) | |
244 | { | |
245 | cfg_filename = file_name; | |
246 | ||
247 | char const *token; | |
248 | ||
249 | if (is_pipe) | |
250 | cfg_filename = file_name + 1; | |
251 | else if ((token = strrchr(cfg_filename, '/'))) | |
252 | cfg_filename = token + 1; | |
253 | } | |
254 | ||
130bff33 | 255 | static const char* |
256 | skip_ws(const char* s) | |
257 | { | |
258 | while (xisspace(*s)) | |
259 | ++s; | |
260 | ||
261 | return s; | |
262 | } | |
263 | ||
cfcb6b30 | 264 | static int |
265 | parseManyConfigFiles(char* files, int depth) | |
266 | { | |
267 | int error_count = 0; | |
d7ac36b9 | 268 | char* saveptr = NULL; |
52303a3d | 269 | #if HAVE_GLOB |
592a09dc | 270 | char *path; |
271 | glob_t globbuf; | |
272 | int i; | |
273 | memset(&globbuf, 0, sizeof(globbuf)); | |
274 | for (path = strwordtok(files, &saveptr); path; path = strwordtok(NULL, &saveptr)) { | |
26ac0430 AJ |
275 | if (glob(path, globbuf.gl_pathc ? GLOB_APPEND : 0, NULL, &globbuf) != 0) { |
276 | fatalf("Unable to find configuration file: %s: %s", | |
277 | path, xstrerror()); | |
278 | } | |
279 | } | |
592a09dc | 280 | for (i = 0; i < (int)globbuf.gl_pathc; i++) { |
26ac0430 | 281 | error_count += parseOneConfigFile(globbuf.gl_pathv[i], depth); |
cfcb6b30 | 282 | } |
592a09dc | 283 | globfree(&globbuf); |
52303a3d | 284 | #else |
285 | char* file = strwordtok(files, &saveptr); | |
286 | while (file != NULL) { | |
26ac0430 AJ |
287 | error_count += parseOneConfigFile(file, depth); |
288 | file = strwordtok(NULL, &saveptr); | |
52303a3d | 289 | } |
290 | #endif /* HAVE_GLOB */ | |
cfcb6b30 | 291 | return error_count; |
292 | } | |
293 | ||
d4a3e179 AR |
294 | static void |
295 | ReplaceSubstr(char*& str, int& len, unsigned substrIdx, unsigned substrLen, const char* newSubstr) | |
296 | { | |
297 | assert(str != NULL); | |
298 | assert(newSubstr != NULL); | |
299 | ||
300 | unsigned newSubstrLen = strlen(newSubstr); | |
301 | if (newSubstrLen > substrLen) | |
302 | str = (char*)realloc(str, len - substrLen + newSubstrLen + 1); | |
303 | ||
304 | // move tail part including zero | |
305 | memmove(str + substrIdx + newSubstrLen, str + substrIdx + substrLen, len - substrIdx - substrLen + 1); | |
306 | // copy new substring in place | |
307 | memcpy(str + substrIdx, newSubstr, newSubstrLen); | |
308 | ||
309 | len = strlen(str); | |
310 | } | |
311 | ||
312 | static void | |
313 | SubstituteMacro(char*& line, int& len, const char* macroName, const char* substStr) | |
314 | { | |
315 | assert(line != NULL); | |
316 | assert(macroName != NULL); | |
317 | assert(substStr != NULL); | |
318 | unsigned macroNameLen = strlen(macroName); | |
319 | while (const char* macroPos = strstr(line, macroName)) // we would replace all occurrences | |
320 | ReplaceSubstr(line, len, macroPos - line, macroNameLen, substStr); | |
321 | } | |
322 | ||
323 | static void | |
324 | ProcessMacros(char*& line, int& len) | |
325 | { | |
9de6c973 | 326 | SubstituteMacro(line, len, "${process_name}", TheKidName); |
d4a3e179 AR |
327 | SubstituteMacro(line, len, "${process_number}", xitoa(KidIdentifier)); |
328 | } | |
329 | ||
a7ea9b13 AR |
330 | static void |
331 | trim_trailing_ws(char* str) | |
332 | { | |
333 | assert(str != NULL); | |
334 | unsigned i = strlen(str); | |
335 | while ((i > 0) && xisspace(str[i - 1])) | |
336 | --i; | |
337 | str[i] = '\0'; | |
338 | } | |
339 | ||
340 | static const char* | |
341 | FindStatement(const char* line, const char* statement) | |
342 | { | |
343 | assert(line != NULL); | |
344 | assert(statement != NULL); | |
345 | ||
346 | const char* str = skip_ws(line); | |
347 | unsigned len = strlen(statement); | |
348 | if (strncmp(str, statement, len) == 0) { | |
349 | str += len; | |
350 | if (*str == '\0') | |
351 | return str; | |
352 | else if (xisspace(*str)) | |
353 | return skip_ws(str); | |
354 | } | |
355 | ||
356 | return NULL; | |
357 | } | |
358 | ||
359 | static bool | |
360 | StrToInt(const char* str, long& number) | |
361 | { | |
362 | assert(str != NULL); | |
363 | ||
364 | char* end; | |
365 | number = strtol(str, &end, 0); | |
366 | ||
367 | return (end != str) && (*end == '\0'); // returns true if string contains nothing except number | |
368 | } | |
369 | ||
370 | static bool | |
371 | EvalBoolExpr(const char* expr) | |
372 | { | |
373 | assert(expr != NULL); | |
374 | if (strcmp(expr, "true") == 0) { | |
375 | return true; | |
376 | } else if (strcmp(expr, "false") == 0) { | |
377 | return false; | |
378 | } else if (const char* equation = strchr(expr, '=')) { | |
379 | const char* rvalue = skip_ws(equation + 1); | |
380 | char* lvalue = (char*)xmalloc(equation - expr + 1); | |
381 | xstrncpy(lvalue, expr, equation - expr + 1); | |
382 | trim_trailing_ws(lvalue); | |
383 | ||
384 | long number1; | |
385 | if (!StrToInt(lvalue, number1)) | |
386 | fatalf("String is not a integer number: '%s'\n", lvalue); | |
387 | long number2; | |
388 | if (!StrToInt(rvalue, number2)) | |
389 | fatalf("String is not a integer number: '%s'\n", rvalue); | |
390 | ||
391 | xfree(lvalue); | |
392 | return number1 == number2; | |
393 | } | |
394 | fatalf("Unable to evaluate expression '%s'\n", expr); | |
395 | return false; // this place cannot be reached | |
396 | } | |
397 | ||
cfcb6b30 | 398 | static int |
399 | parseOneConfigFile(const char *file_name, unsigned int depth) | |
2546fcb3 | 400 | { |
270b86af | 401 | FILE *fp = NULL; |
cfcb6b30 | 402 | const char *orig_cfg_filename = cfg_filename; |
403 | const int orig_config_lineno = config_lineno; | |
270b86af | 404 | char *token = NULL; |
81c161d0 | 405 | char *tmp_line = NULL; |
406 | int tmp_line_len = 0; | |
e13ee7ad | 407 | int err_count = 0; |
1741cbad | 408 | int is_pipe = 0; |
cfcb6b30 | 409 | |
410 | debugs(3, 1, "Processing Configuration File: " << file_name << " (depth " << depth << ")"); | |
411 | if (depth > 16) { | |
412 | fatalf("WARNING: can't include %s: includes are nested too deeply (>16)!\n", file_name); | |
413 | return 1; | |
414 | } | |
62e76326 | 415 | |
1741cbad | 416 | if (file_name[0] == '!' || file_name[0] == '|') { |
62e76326 | 417 | fp = popen(file_name + 1, "r"); |
418 | is_pipe = 1; | |
1741cbad | 419 | } else { |
62e76326 | 420 | fp = fopen(file_name, "r"); |
1741cbad | 421 | } |
62e76326 | 422 | |
1741cbad | 423 | if (fp == NULL) |
cfcb6b30 | 424 | fatalf("Unable to open configuration file: %s: %s", file_name, xstrerror()); |
62e76326 | 425 | |
be266cb2 | 426 | #if _SQUID_WINDOWS_ |
c4aefe96 | 427 | setmode(fileno(fp), O_TEXT); |
428 | #endif | |
62e76326 | 429 | |
76b9daa5 | 430 | SetConfigFilename(file_name, bool(is_pipe)); |
62e76326 | 431 | |
270b86af | 432 | memset(config_input_line, '\0', BUFSIZ); |
62e76326 | 433 | |
270b86af | 434 | config_lineno = 0; |
62e76326 | 435 | |
a7ea9b13 | 436 | Vector<bool> if_states; |
270b86af | 437 | while (fgets(config_input_line, BUFSIZ, fp)) { |
62e76326 | 438 | config_lineno++; |
439 | ||
440 | if ((token = strchr(config_input_line, '\n'))) | |
441 | *token = '\0'; | |
442 | ||
d866e2ad | 443 | if ((token = strchr(config_input_line, '\r'))) |
444 | *token = '\0'; | |
445 | ||
f068973f AJ |
446 | // strip any prefix whitespace off the line. |
447 | const char *p = skip_ws(config_input_line); | |
448 | if (config_input_line != p) | |
449 | memmove(config_input_line, p, strlen(p)+1); | |
450 | ||
62e76326 | 451 | if (strncmp(config_input_line, "#line ", 6) == 0) { |
452 | static char new_file_name[1024]; | |
453 | static char *file; | |
454 | static char new_lineno; | |
455 | token = config_input_line + 6; | |
456 | new_lineno = strtol(token, &file, 0) - 1; | |
457 | ||
458 | if (file == token) | |
459 | continue; /* Not a valid #line directive, may be a comment */ | |
460 | ||
e4755e29 | 461 | while (*file && xisspace((unsigned char) *file)) |
62e76326 | 462 | file++; |
463 | ||
464 | if (*file) { | |
465 | if (*file != '"') | |
466 | continue; /* Not a valid #line directive, may be a comment */ | |
467 | ||
468 | xstrncpy(new_file_name, file + 1, sizeof(new_file_name)); | |
469 | ||
470 | if ((token = strchr(new_file_name, '"'))) | |
471 | *token = '\0'; | |
472 | ||
473 | cfg_filename = new_file_name; | |
62e76326 | 474 | } |
475 | ||
476 | config_lineno = new_lineno; | |
477 | } | |
478 | ||
479 | if (config_input_line[0] == '#') | |
480 | continue; | |
481 | ||
482 | if (config_input_line[0] == '\0') | |
483 | continue; | |
484 | ||
130bff33 | 485 | const char* append = tmp_line_len ? skip_ws(config_input_line) : config_input_line; |
486 | ||
487 | size_t append_len = strlen(append); | |
62e76326 | 488 | |
130bff33 | 489 | tmp_line = (char*)xrealloc(tmp_line, tmp_line_len + append_len + 1); |
81c161d0 | 490 | |
130bff33 | 491 | strcpy(tmp_line + tmp_line_len, append); |
81c161d0 | 492 | |
130bff33 | 493 | tmp_line_len += append_len; |
81c161d0 | 494 | |
495 | if (tmp_line[tmp_line_len-1] == '\\') { | |
bf8fe701 | 496 | debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line << "'"); |
81c161d0 | 497 | tmp_line[--tmp_line_len] = '\0'; |
498 | continue; | |
499 | } | |
500 | ||
a7ea9b13 | 501 | trim_trailing_ws(tmp_line); |
d4a3e179 | 502 | ProcessMacros(tmp_line, tmp_line_len); |
dad047ab | 503 | debugs(3, (opt_parse_cfg_only?1:5), "Processing: " << tmp_line); |
62e76326 | 504 | |
a7ea9b13 AR |
505 | if (const char* expr = FindStatement(tmp_line, "if")) { |
506 | if_states.push_back(EvalBoolExpr(expr)); // store last if-statement meaning | |
507 | } else if (FindStatement(tmp_line, "endif")) { | |
508 | if (!if_states.empty()) | |
509 | if_states.pop_back(); // remove last if-statement meaning | |
510 | else | |
511 | fatalf("'endif' without 'if'\n"); | |
512 | } else if (FindStatement(tmp_line, "else")) { | |
513 | if (!if_states.empty()) | |
514 | if_states.back() = !if_states.back(); | |
515 | else | |
516 | fatalf("'else' without 'if'\n"); | |
517 | } else if (if_states.empty() || if_states.back()) { // test last if-statement meaning if present | |
518 | /* Handle includes here */ | |
519 | if (tmp_line_len >= 9 && strncmp(tmp_line, "include", 7) == 0 && xisspace(tmp_line[7])) { | |
520 | err_count += parseManyConfigFiles(tmp_line + 8, depth + 1); | |
521 | } else if (!parse_line(tmp_line)) { | |
522 | debugs(3, 0, HERE << cfg_filename << ":" << config_lineno << " unrecognized: '" << tmp_line << "'"); | |
523 | err_count++; | |
524 | } | |
26ac0430 | 525 | } |
62e76326 | 526 | |
527 | safe_free(tmp_line); | |
81c161d0 | 528 | tmp_line_len = 0; |
529 | ||
270b86af | 530 | } |
a7ea9b13 AR |
531 | if (!if_states.empty()) |
532 | fatalf("if-statement without 'endif'\n"); | |
62e76326 | 533 | |
1741cbad | 534 | if (is_pipe) { |
62e76326 | 535 | int ret = pclose(fp); |
536 | ||
537 | if (ret != 0) | |
538 | fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name, ret); | |
1741cbad | 539 | } else { |
62e76326 | 540 | fclose(fp); |
1741cbad | 541 | } |
62e76326 | 542 | |
cfcb6b30 | 543 | cfg_filename = orig_cfg_filename; |
544 | config_lineno = orig_config_lineno; | |
545 | ||
546 | return err_count; | |
547 | } | |
548 | ||
549 | int | |
dd9b1081 | 550 | parseConfigFile(const char *file_name) |
cfcb6b30 | 551 | { |
552 | int err_count = 0; | |
553 | ||
5817ee13 AJ |
554 | debugs(5, 4, HERE); |
555 | ||
cfcb6b30 | 556 | configFreeMemory(); |
557 | ||
5491c11e | 558 | ACLMethodData::ThePurgeCount = 0; |
cfcb6b30 | 559 | default_all(); |
560 | ||
561 | err_count = parseOneConfigFile(file_name, 0); | |
562 | ||
f0b19334 | 563 | defaults_if_none(); |
f9ad0106 | 564 | |
9c46ca97 | 565 | /* |
566 | * We must call configDoConfigure() before leave_suid() because | |
567 | * configDoConfigure() is where we turn username strings into | |
568 | * uid values. | |
569 | */ | |
570 | configDoConfigure(); | |
571 | ||
f9ad0106 | 572 | if (!Config.chroot_dir) { |
573 | leave_suid(); | |
c642c141 | 574 | setUmask(Config.umask); |
62493678 | 575 | _db_init(Debug::cache_log, Debug::debugOptions); |
f9ad0106 | 576 | enter_suid(); |
577 | } | |
578 | ||
478c4f2f | 579 | if (opt_send_signal == -1) { |
8822ebee | 580 | Mgr::RegisterAction("config", |
d9fc6862 A |
581 | "Current Squid Configuration", |
582 | dump_config, | |
583 | 1, 1); | |
478c4f2f | 584 | } |
585 | ||
e13ee7ad | 586 | return err_count; |
f0b19334 | 587 | } |
270b86af | 588 | |
cfcb6b30 | 589 | |
f0b19334 | 590 | static void |
591 | configDoConfigure(void) | |
592 | { | |
f0b19334 | 593 | memset(&Config2, '\0', sizeof(SquidConfig2)); |
7021844c | 594 | /* init memory as early as possible */ |
595 | memConfigure(); | |
270b86af | 596 | /* Sanity checks */ |
62e76326 | 597 | |
7895fa18 AJ |
598 | if (Config.cacheSwap.swapDirs == NULL) { |
599 | /* Memory-only cache probably in effect. */ | |
600 | /* turn off the cache rebuild delays... */ | |
601 | StoreController::store_dirs_rebuilding = 0; | |
602 | } | |
603 | ||
47df1aa7 AJ |
604 | if (Debug::rotateNumber < 0) { |
605 | Debug::rotateNumber = Config.Log.rotateNumber; | |
606 | } | |
607 | ||
5aecb102 | 608 | #if SIZEOF_OFF_T <= 4 |
609 | if (Config.Store.maxObjectSize > 0x7FFF0000) { | |
26ac0430 AJ |
610 | debugs(3, 0, "WARNING: This Squid binary can not handle files larger than 2GB. Limiting maximum_object_size to just below 2GB"); |
611 | Config.Store.maxObjectSize = 0x7FFF0000; | |
5aecb102 | 612 | } |
613 | #endif | |
c8f4eac4 | 614 | if (0 == Store::Root().maxSize()) |
62e76326 | 615 | /* people might want a zero-sized cache on purpose */ |
616 | (void) 0; | |
cc34568d | 617 | else if (Store::Root().maxSize() < Config.memMaxSize) |
c8f4eac4 | 618 | /* This is bogus. folk with NULL caches will want this */ |
bf8fe701 | 619 | debugs(3, 0, "WARNING cache_mem is larger than total disk cache space!"); |
62e76326 | 620 | |
84f42bac | 621 | if (Config.Announce.period > 0) { |
62e76326 | 622 | Config.onoff.announce = 1; |
84f42bac | 623 | } else if (Config.Announce.period < 1) { |
62e76326 | 624 | Config.Announce.period = 86400 * 365; /* one year */ |
625 | Config.onoff.announce = 0; | |
270b86af | 626 | } |
62e76326 | 627 | |
d3caee79 | 628 | if (Config.onoff.httpd_suppress_version_string) |
629 | visible_appname_string = (char *)appname_string; | |
630 | else | |
7dbca7a4 | 631 | visible_appname_string = (char const *)APP_FULLNAME; |
d3caee79 | 632 | |
6b53c392 | 633 | #if USE_DNSSERVERS |
d3caee79 | 634 | |
48d54e4d | 635 | if (Config.dnsChildren.n_max < 1) |
62e76326 | 636 | fatal("No dnsservers allocated"); |
637 | ||
efd900cb | 638 | #endif |
62e76326 | 639 | |
270b86af | 640 | if (Config.Program.redirect) { |
48d54e4d AJ |
641 | if (Config.redirectChildren.n_max < 1) { |
642 | Config.redirectChildren.n_max = 0; | |
62e76326 | 643 | wordlistDestroy(&Config.Program.redirect); |
644 | } | |
fea2e6e0 | 645 | } |
62e76326 | 646 | |
f1dc9b30 | 647 | if (Config.appendDomain) |
62e76326 | 648 | if (*Config.appendDomain != '.') |
649 | fatal("append_domain must begin with a '.'"); | |
650 | ||
270b86af | 651 | if (Config.errHtmlText == NULL) |
62e76326 | 652 | Config.errHtmlText = xstrdup(null_string); |
653 | ||
1b7fae06 AJ |
654 | #if !HAVE_SETRLIMIT || !defined(RLIMIT_NOFILE) |
655 | if (Config.max_filedescriptors > 0) { | |
3a9087af | 656 | debugs(0, DBG_IMPORTANT, "WARNING: max_filedescriptors disabled. Operating System setrlimit(RLIMIT_NOFILE) is missing."); |
1b7fae06 AJ |
657 | } |
658 | #elif USE_SELECT || USE_SELECT_WIN32 | |
659 | if (Config.max_filedescriptors > FD_SETSIZE) { | |
3a9087af | 660 | debugs(0, DBG_IMPORTANT, "WARNING: max_filedescriptors limited to " << FD_SETSIZE << " by select() algorithm."); |
1b7fae06 AJ |
661 | } |
662 | #endif | |
663 | ||
270b86af | 664 | storeConfigure(); |
62e76326 | 665 | |
52f772de | 666 | snprintf(ThisCache, sizeof(ThisCache), "%s (%s)", |
62e76326 | 667 | uniqueHostname(), |
d3caee79 | 668 | visible_appname_string); |
fbdba7c4 | 669 | |
38a6c74e | 670 | /* |
671 | * the extra space is for loop detection in client_side.c -- we search | |
672 | * for substrings in the Via header. | |
673 | */ | |
52f772de | 674 | snprintf(ThisCache2, sizeof(ThisCache), " %s (%s)", |
62e76326 | 675 | uniqueHostname(), |
d3caee79 | 676 | visible_appname_string); |
62e76326 | 677 | |
b2b40d8c AJ |
678 | /* Use visible_hostname as default surrogate_id */ |
679 | if (!Config.Accel.surrogate_id) { | |
680 | const char *t = getMyHostname(); | |
681 | Config.Accel.surrogate_id = xstrdup( (t?t:"unset-id") ); | |
682 | } | |
683 | ||
270b86af | 684 | if (!Config.udpMaxHitObjsz || Config.udpMaxHitObjsz > SQUID_UDP_SO_SNDBUF) |
62e76326 | 685 | Config.udpMaxHitObjsz = SQUID_UDP_SO_SNDBUF; |
686 | ||
270b86af | 687 | if (Config.appendDomain) |
62e76326 | 688 | Config.appendDomainLen = strlen(Config.appendDomain); |
270b86af | 689 | else |
62e76326 | 690 | Config.appendDomainLen = 0; |
691 | ||
31ef19cd AJ |
692 | if (Config.connect_retries > 10) { |
693 | debugs(0,DBG_CRITICAL, "WARNING: connect_retries cannot be larger than 10. Resetting to 10."); | |
694 | Config.connect_retries = 10; | |
5210854d | 695 | } |
62e76326 | 696 | |
f0b19334 | 697 | requirePathnameExists("MIME Config Table", Config.mimeTablePathname); |
6b53c392 | 698 | #if USE_DNSSERVERS |
62e76326 | 699 | |
f0b19334 | 700 | requirePathnameExists("cache_dns_program", Config.Program.dnsserver); |
efd900cb | 701 | #endif |
a3d0a19d | 702 | #if USE_UNLINKD |
62e76326 | 703 | |
f0b19334 | 704 | requirePathnameExists("unlinkd_program", Config.Program.unlinkd); |
a3d0a19d | 705 | #endif |
82b7abe3 | 706 | requirePathnameExists("logfile_daemon", Log::TheConfig.logfile_daemon); |
f0b19334 | 707 | if (Config.Program.redirect) |
62e76326 | 708 | requirePathnameExists("redirect_program", Config.Program.redirect->key); |
709 | ||
f0b19334 | 710 | requirePathnameExists("Icon Directory", Config.icons.directory); |
62e76326 | 711 | |
26ac0430 | 712 | if (Config.errorDirectory) |
43000484 | 713 | requirePathnameExists("Error Directory", Config.errorDirectory); |
62e76326 | 714 | |
626096be | 715 | #if USE_HTTP_VIOLATIONS |
62e76326 | 716 | |
9f60cfdf | 717 | { |
62e76326 | 718 | const refresh_t *R; |
719 | ||
26ac0430 | 720 | for (R = Config.Refresh; R; R = R->next) { |
62e76326 | 721 | if (!R->flags.override_expire) |
722 | continue; | |
723 | ||
bf8fe701 | 724 | debugs(22, 1, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP"); |
62e76326 | 725 | |
726 | break; | |
727 | } | |
728 | ||
26ac0430 | 729 | for (R = Config.Refresh; R; R = R->next) { |
62e76326 | 730 | if (!R->flags.override_lastmod) |
731 | continue; | |
732 | ||
bf8fe701 | 733 | debugs(22, 1, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP"); |
62e76326 | 734 | |
735 | break; | |
736 | } | |
737 | ||
26ac0430 | 738 | for (R = Config.Refresh; R; R = R->next) { |
38f9c547 | 739 | if (!R->flags.reload_into_ims) |
740 | continue; | |
741 | ||
bf8fe701 | 742 | debugs(22, 1, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP"); |
38f9c547 | 743 | |
744 | break; | |
745 | } | |
746 | ||
26ac0430 | 747 | for (R = Config.Refresh; R; R = R->next) { |
38f9c547 | 748 | if (!R->flags.ignore_reload) |
749 | continue; | |
750 | ||
bf8fe701 | 751 | debugs(22, 1, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP"); |
38f9c547 | 752 | |
753 | break; | |
754 | } | |
755 | ||
26ac0430 | 756 | for (R = Config.Refresh; R; R = R->next) { |
38f9c547 | 757 | if (!R->flags.ignore_no_cache) |
758 | continue; | |
759 | ||
bf8fe701 | 760 | debugs(22, 1, "WARNING: use of 'ignore-no-cache' in 'refresh_pattern' violates HTTP"); |
38f9c547 | 761 | |
762 | break; | |
763 | } | |
764 | ||
26ac0430 | 765 | for (R = Config.Refresh; R; R = R->next) { |
38f9c547 | 766 | if (!R->flags.ignore_no_store) |
767 | continue; | |
768 | ||
bf8fe701 | 769 | debugs(22, 1, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP"); |
38f9c547 | 770 | |
771 | break; | |
772 | } | |
773 | ||
4ca08219 | 774 | for (R = Config.Refresh; R; R = R->next) { |
04f7fd38 AJ |
775 | if (!R->flags.ignore_must_revalidate) |
776 | continue; | |
777 | debugs(22, 1, "WARNING: use of 'ignore-must-revalidate' in 'refresh_pattern' violates HTTP"); | |
778 | break; | |
4ca08219 AJ |
779 | } |
780 | ||
26ac0430 | 781 | for (R = Config.Refresh; R; R = R->next) { |
38f9c547 | 782 | if (!R->flags.ignore_private) |
783 | continue; | |
784 | ||
bf8fe701 | 785 | debugs(22, 1, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP"); |
38f9c547 | 786 | |
787 | break; | |
788 | } | |
789 | ||
26ac0430 | 790 | for (R = Config.Refresh; R; R = R->next) { |
38f9c547 | 791 | if (!R->flags.ignore_auth) |
792 | continue; | |
793 | ||
bf8fe701 | 794 | debugs(22, 1, "WARNING: use of 'ignore-auth' in 'refresh_pattern' violates HTTP"); |
38f9c547 | 795 | |
796 | break; | |
797 | } | |
798 | ||
9f60cfdf | 799 | } |
c2f5c744 | 800 | #endif |
626096be | 801 | #if !USE_HTTP_VIOLATIONS |
c2f5c744 | 802 | Config.onoff.via = 1; |
803 | #else | |
62e76326 | 804 | |
c2f5c744 | 805 | if (!Config.onoff.via) |
bf8fe701 | 806 | debugs(22, 1, "WARNING: HTTP requires the use of Via"); |
62e76326 | 807 | |
9f60cfdf | 808 | #endif |
62e76326 | 809 | |
5491c11e AR |
810 | // we enable runtime PURGE checks if there is at least one PURGE method ACL |
811 | // TODO: replace with a dedicated "purge" ACL option? | |
3d9019c7 | 812 | Config2.onoff.enable_purge = (ACLMethodData::ThePurgeCount > 0); |
62e76326 | 813 | |
4f56514c | 814 | Config2.onoff.mangle_request_headers = httpReqHdrManglersConfigured(); |
5967c0bf | 815 | |
8749fa47 | 816 | if (geteuid() == 0) { |
62e76326 | 817 | if (NULL != Config.effectiveUser) { |
818 | ||
819 | struct passwd *pwd = getpwnam(Config.effectiveUser); | |
820 | ||
5ad8d199 | 821 | if (NULL == pwd) { |
62e76326 | 822 | /* |
823 | * Andres Kroonmaa <andre@online.ee>: | |
824 | * Some getpwnam() implementations (Solaris?) require | |
825 | * an available FD < 256 for opening a FILE* to the | |
826 | * passwd file. | |
827 | * DW: | |
828 | * This should be safe at startup, but might still fail | |
829 | * during reconfigure. | |
830 | */ | |
831 | fatalf("getpwnam failed to find userid for effective user '%s'", | |
832 | Config.effectiveUser); | |
5ad8d199 | 833 | return; |
834 | } | |
62e76326 | 835 | |
836 | Config2.effectiveUserID = pwd->pw_uid; | |
837 | ||
838 | Config2.effectiveGroupID = pwd->pw_gid; | |
08ac5ea7 | 839 | |
cff61cb8 | 840 | #if HAVE_PUTENV |
841 | ||
842 | if (pwd->pw_dir && *pwd->pw_dir) { | |
843 | int len; | |
844 | char *env_str = (char *)xcalloc((len = strlen(pwd->pw_dir) + 6), 1); | |
845 | snprintf(env_str, len, "HOME=%s", pwd->pw_dir); | |
846 | putenv(env_str); | |
847 | } | |
848 | ||
849 | #endif | |
850 | ||
62e76326 | 851 | } |
8749fa47 | 852 | } else { |
62e76326 | 853 | Config2.effectiveUserID = geteuid(); |
854 | Config2.effectiveGroupID = getegid(); | |
d20b1cd0 | 855 | } |
62e76326 | 856 | |
d20b1cd0 | 857 | if (NULL != Config.effectiveGroup) { |
62e76326 | 858 | |
859 | struct group *grp = getgrnam(Config.effectiveGroup); | |
860 | ||
5ad8d199 | 861 | if (NULL == grp) { |
62e76326 | 862 | fatalf("getgrnam failed to find groupid for effective group '%s'", |
863 | Config.effectiveGroup); | |
5ad8d199 | 864 | return; |
865 | } | |
62e76326 | 866 | |
867 | Config2.effectiveGroupID = grp->gr_gid; | |
d20b1cd0 | 868 | } |
62e76326 | 869 | |
985c86bc | 870 | HttpRequestMethod::Configure(Config); |
a7ad6e4e | 871 | #if USE_SSL |
62e76326 | 872 | |
bf8fe701 | 873 | debugs(3, 1, "Initializing https proxy context"); |
f9ad0106 | 874 | |
a82a4fe4 | 875 | 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); |
f9ad0106 | 876 | |
877 | { | |
878 | ||
879 | peer *p; | |
880 | ||
881 | for (p = Config.peers; p != NULL; p = p->next) { | |
882 | if (p->use_ssl) { | |
bf8fe701 | 883 | debugs(3, 1, "Initializing cache_peer " << p->name << " SSL context"); |
a82a4fe4 | 884 | p->sslContext = sslCreateClientContext(p->sslcert, p->sslkey, p->sslversion, p->sslcipher, p->ssloptions, p->sslflags, p->sslcafile, p->sslcapath, p->sslcrlfile); |
f9ad0106 | 885 | } |
886 | } | |
887 | } | |
888 | ||
154dc884 | 889 | { |
890 | ||
891 | http_port_list *s; | |
892 | ||
893 | for (s = Config.Sockaddr.http; s != NULL; s = (http_port_list *) s->next) { | |
894 | if (!s->cert && !s->key) | |
895 | continue; | |
896 | ||
897 | debugs(3, 1, "Initializing http_port " << s->http.s << " SSL context"); | |
898 | ||
95d2589c CT |
899 | s->staticSslContext.reset( |
900 | sslCreateServerContext(s->cert, s->key, | |
901 | s->version, s->cipher, s->options, s->sslflags, s->clientca, | |
902 | s->cafile, s->capath, s->crlfile, s->dhfile, | |
903 | s->sslContextSessionId)); | |
904 | ||
905 | Ssl::readCertAndPrivateKeyFromFiles(s->signingCert, s->signPkey, s->cert, s->key); | |
154dc884 | 906 | } |
907 | } | |
908 | ||
f9ad0106 | 909 | { |
910 | ||
911 | https_port_list *s; | |
912 | ||
b844522c | 913 | for (s = Config.Sockaddr.https; s != NULL; s = (https_port_list *) s->http.next) { |
cc192b50 | 914 | debugs(3, 1, "Initializing https_port " << s->http.s << " SSL context"); |
bf8fe701 | 915 | |
95d2589c CT |
916 | s->staticSslContext.reset( |
917 | sslCreateServerContext(s->cert, s->key, | |
918 | s->version, s->cipher, s->options, s->sslflags, s->clientca, | |
919 | s->cafile, s->capath, s->crlfile, s->dhfile, | |
920 | s->sslContextSessionId)); | |
f9ad0106 | 921 | } |
922 | } | |
923 | ||
a7ad6e4e | 924 | #endif |
1f771fed AJ |
925 | |
926 | // prevent infinite fetch loops in the request parser | |
927 | // due to buffer full but not enough data recived to finish parse | |
928 | if (Config.maxRequestBufferSize <= Config.maxRequestHeaderSize) { | |
d0bbf50e | 929 | fatalf("Client request buffer of %u bytes cannot hold a request with %u bytes of headers." \ |
1f771fed | 930 | " Change client_request_buffer_max or request_header_max_size limits.", |
d0bbf50e | 931 | (uint32_t)Config.maxRequestBufferSize, (uint32_t)Config.maxRequestHeaderSize); |
1f771fed | 932 | } |
a0e23afd | 933 | |
2f1431ea | 934 | #if USE_AUTH |
a0e23afd AJ |
935 | /* |
936 | * disable client side request pipelining. There is a race with | |
937 | * Negotiate and NTLM when the client sends a second request on an | |
938 | * connection before the authenticate challenge is sent. With | |
939 | * pipelining OFF, the client may fail to authenticate, but squid's | |
940 | * state will be preserved. | |
941 | */ | |
942 | if (Config.onoff.pipeline_prefetch) { | |
9f3d2b2e AJ |
943 | Auth::Config *nego = Auth::Config::Find("Negotiate"); |
944 | Auth::Config *ntlm = Auth::Config::Find("NTLM"); | |
a0e23afd AJ |
945 | if ((nego && nego->active()) || (ntlm && ntlm->active())) { |
946 | debugs(3, DBG_IMPORTANT, "WARNING: pipeline_prefetch breaks NTLM and Negotiate authentication. Forced OFF."); | |
947 | Config.onoff.pipeline_prefetch = 0; | |
948 | } | |
949 | } | |
2f1431ea | 950 | #endif |
090089c4 | 951 | } |
952 | ||
76f44481 AJ |
953 | /** Parse a line containing an obsolete directive. |
954 | * To upgrade it where possible instead of just "Bungled config" for | |
955 | * directives which cannot be marked as simply aliases of the some name. | |
956 | * For example if the parameter order and content has changed. | |
957 | * Or if the directive has been completely removed. | |
958 | */ | |
959 | void | |
960 | parse_obsolete(const char *name) | |
961 | { | |
962 | // Directives which have been radically changed rather than removed | |
963 | if (!strcmp(name, "url_rewrite_concurrency")) { | |
254d8ef1 AJ |
964 | int cval; |
965 | parse_int(&cval); | |
76f44481 | 966 | debugs(3, DBG_CRITICAL, "WARNING: url_rewrite_concurrency upgrade overriding url_rewrite_children settings."); |
254d8ef1 | 967 | Config.redirectChildren.concurrency = cval; |
76f44481 AJ |
968 | } |
969 | } | |
970 | ||
270b86af | 971 | /* Parse a time specification from the config file. Store the |
f1dc9b30 | 972 | * result in 'tptr', after converting it to 'units' */ |
8203a132 | 973 | static void |
9b741834 | 974 | parseTimeLine(time_msec_t * tptr, const char *units, bool allowMsec) |
090089c4 | 975 | { |
976 | char *token; | |
270b86af | 977 | double d; |
fd0f51c4 CT |
978 | time_msec_t m; |
979 | time_msec_t u; | |
62e76326 | 980 | |
9b741834 | 981 | if ((u = parseTimeUnits(units, allowMsec)) == 0) |
62e76326 | 982 | self_destruct(); |
983 | ||
270b86af | 984 | if ((token = strtok(NULL, w_space)) == NULL) |
62e76326 | 985 | self_destruct(); |
986 | ||
5c20d6fa | 987 | d = xatof(token); |
62e76326 | 988 | |
270b86af | 989 | m = u; /* default to 'units' if none specified */ |
62e76326 | 990 | |
10738561 | 991 | if (0 == d) |
62e76326 | 992 | (void) 0; |
10738561 | 993 | else if ((token = strtok(NULL, w_space)) == NULL) |
26ac0430 AJ |
994 | debugs(3, 0, "WARNING: No units on '" << |
995 | config_input_line << "', assuming " << | |
996 | d << " " << units ); | |
9b741834 | 997 | else if ((m = parseTimeUnits(token, allowMsec)) == 0) |
62e76326 | 998 | self_destruct(); |
999 | ||
fd0f51c4 | 1000 | *tptr = static_cast<time_msec_t>(m * d); |
090089c4 | 1001 | } |
1002 | ||
fd0f51c4 | 1003 | static uint64_t |
9b741834 | 1004 | parseTimeUnits(const char *unit, bool allowMsec) |
270b86af | 1005 | { |
9b741834 | 1006 | if (allowMsec && !strncasecmp(unit, T_MILLISECOND_STR, strlen(T_MILLISECOND_STR))) |
62e76326 | 1007 | return 1; |
1008 | ||
fd0f51c4 CT |
1009 | if (!strncasecmp(unit, T_SECOND_STR, strlen(T_SECOND_STR))) |
1010 | return 1000; | |
1011 | ||
270b86af | 1012 | if (!strncasecmp(unit, T_MINUTE_STR, strlen(T_MINUTE_STR))) |
fd0f51c4 | 1013 | return 60 * 1000; |
62e76326 | 1014 | |
270b86af | 1015 | if (!strncasecmp(unit, T_HOUR_STR, strlen(T_HOUR_STR))) |
fd0f51c4 | 1016 | return 3600 * 1000; |
62e76326 | 1017 | |
270b86af | 1018 | if (!strncasecmp(unit, T_DAY_STR, strlen(T_DAY_STR))) |
fd0f51c4 | 1019 | return 86400 * 1000; |
62e76326 | 1020 | |
270b86af | 1021 | if (!strncasecmp(unit, T_WEEK_STR, strlen(T_WEEK_STR))) |
fd0f51c4 | 1022 | return 86400 * 7 * 1000; |
62e76326 | 1023 | |
270b86af | 1024 | if (!strncasecmp(unit, T_FORTNIGHT_STR, strlen(T_FORTNIGHT_STR))) |
fd0f51c4 | 1025 | return 86400 * 14 * 1000; |
62e76326 | 1026 | |
270b86af | 1027 | if (!strncasecmp(unit, T_MONTH_STR, strlen(T_MONTH_STR))) |
fd0f51c4 | 1028 | return static_cast<uint64_t>(86400) * 30 * 1000; |
62e76326 | 1029 | |
270b86af | 1030 | if (!strncasecmp(unit, T_YEAR_STR, strlen(T_YEAR_STR))) |
fd0f51c4 | 1031 | return static_cast<uint64_t>(86400 * 1000 * 365.2522); |
62e76326 | 1032 | |
270b86af | 1033 | if (!strncasecmp(unit, T_DECADE_STR, strlen(T_DECADE_STR))) |
fd0f51c4 | 1034 | return static_cast<uint64_t>(86400 * 1000 * 365.2522 * 10); |
62e76326 | 1035 | |
bf8fe701 | 1036 | debugs(3, 1, "parseTimeUnits: unknown time unit '" << unit << "'"); |
62e76326 | 1037 | |
270b86af | 1038 | return 0; |
1039 | } | |
1040 | ||
47f6e231 | 1041 | static void |
1042 | parseBytesLine64(int64_t * bptr, const char *units) | |
1043 | { | |
1044 | char *token; | |
1045 | double d; | |
1046 | int64_t m; | |
1047 | int64_t u; | |
1048 | ||
9eeb8e4b | 1049 | if ((u = parseBytesUnits(units)) == 0) { |
47f6e231 | 1050 | self_destruct(); |
9eeb8e4b | 1051 | return; |
1052 | } | |
47f6e231 | 1053 | |
9eeb8e4b | 1054 | if ((token = strtok(NULL, w_space)) == NULL) { |
47f6e231 | 1055 | self_destruct(); |
9eeb8e4b | 1056 | return; |
1057 | } | |
47f6e231 | 1058 | |
1059 | if (strcmp(token, "none") == 0 || strcmp(token, "-1") == 0) { | |
bc41416d | 1060 | *bptr = -1; |
47f6e231 | 1061 | return; |
1062 | } | |
1063 | ||
1064 | d = xatof(token); | |
1065 | ||
1066 | m = u; /* default to 'units' if none specified */ | |
1067 | ||
1068 | if (0.0 == d) | |
1069 | (void) 0; | |
1070 | else if ((token = strtok(NULL, w_space)) == NULL) | |
26ac0430 AJ |
1071 | debugs(3, 0, "WARNING: No units on '" << |
1072 | config_input_line << "', assuming " << | |
1073 | d << " " << units ); | |
9eeb8e4b | 1074 | else if ((m = parseBytesUnits(token)) == 0) { |
47f6e231 | 1075 | self_destruct(); |
9eeb8e4b | 1076 | return; |
1077 | } | |
47f6e231 | 1078 | |
1079 | *bptr = static_cast<int64_t>(m * d / u); | |
1080 | ||
1081 | if (static_cast<double>(*bptr) * 2 != m * d / u * 2) | |
1082 | self_destruct(); | |
1083 | } | |
1084 | ||
1085 | ||
9906e724 | 1086 | static void |
9e975e4e | 1087 | parseBytesLine(size_t * bptr, const char *units) |
9906e724 | 1088 | { |
1089 | char *token; | |
1090 | double d; | |
47f6e231 | 1091 | int m; |
1092 | int u; | |
62e76326 | 1093 | |
9eeb8e4b | 1094 | if ((u = parseBytesUnits(units)) == 0) { |
62e76326 | 1095 | self_destruct(); |
9eeb8e4b | 1096 | return; |
1097 | } | |
62e76326 | 1098 | |
9eeb8e4b | 1099 | if ((token = strtok(NULL, w_space)) == NULL) { |
62e76326 | 1100 | self_destruct(); |
9eeb8e4b | 1101 | return; |
1102 | } | |
62e76326 | 1103 | |
f8ecd7d7 | 1104 | if (strcmp(token, "none") == 0 || strcmp(token, "-1") == 0) { |
b2d729e6 | 1105 | *bptr = static_cast<size_t>(-1); |
ef1955a5 | 1106 | return; |
1107 | } | |
1108 | ||
5c20d6fa | 1109 | d = xatof(token); |
62e76326 | 1110 | |
9906e724 | 1111 | m = u; /* default to 'units' if none specified */ |
62e76326 | 1112 | |
343f47a3 | 1113 | if (0.0 == d) |
62e76326 | 1114 | (void) 0; |
4860dc1b | 1115 | else if ((token = strtok(NULL, w_space)) == NULL) |
26ac0430 AJ |
1116 | debugs(3, 0, "WARNING: No units on '" << |
1117 | config_input_line << "', assuming " << | |
1118 | d << " " << units ); | |
9eeb8e4b | 1119 | else if ((m = parseBytesUnits(token)) == 0) { |
62e76326 | 1120 | self_destruct(); |
9eeb8e4b | 1121 | return; |
1122 | } | |
62e76326 | 1123 | |
e6ccf245 | 1124 | *bptr = static_cast<size_t>(m * d / u); |
347ae7c4 | 1125 | |
a69d485c | 1126 | if (static_cast<double>(*bptr) * 2 != m * d / u * 2) |
347ae7c4 | 1127 | self_destruct(); |
9906e724 | 1128 | } |
1129 | ||
e210930b AJ |
1130 | #if !USE_DNSSERVERS |
1131 | static void | |
1132 | parseBytesLineSigned(ssize_t * bptr, const char *units) | |
1133 | { | |
1134 | char *token; | |
1135 | double d; | |
1136 | int m; | |
1137 | int u; | |
1138 | ||
1139 | if ((u = parseBytesUnits(units)) == 0) { | |
1140 | self_destruct(); | |
1141 | return; | |
1142 | } | |
1143 | ||
1144 | if ((token = strtok(NULL, w_space)) == NULL) { | |
1145 | self_destruct(); | |
1146 | return; | |
1147 | } | |
1148 | ||
1149 | if (strcmp(token, "none") == 0 || token[0] == '-' /* -N */) { | |
1150 | *bptr = -1; | |
1151 | return; | |
1152 | } | |
1153 | ||
1154 | d = xatof(token); | |
1155 | ||
1156 | m = u; /* default to 'units' if none specified */ | |
1157 | ||
1158 | if (0.0 == d) | |
1159 | (void) 0; | |
1160 | else if ((token = strtok(NULL, w_space)) == NULL) | |
1161 | debugs(3, 0, "WARNING: No units on '" << | |
1162 | config_input_line << "', assuming " << | |
1163 | d << " " << units ); | |
1164 | else if ((m = parseBytesUnits(token)) == 0) { | |
1165 | self_destruct(); | |
1166 | return; | |
1167 | } | |
1168 | ||
1169 | *bptr = static_cast<size_t>(m * d / u); | |
1170 | ||
1171 | if (static_cast<double>(*bptr) * 2 != m * d / u * 2) | |
1172 | self_destruct(); | |
1173 | } | |
1174 | #endif | |
1175 | ||
95d2589c CT |
1176 | #if USE_SSL |
1177 | /** | |
1178 | * Parse bytes from a string. | |
1179 | * Similar to the parseBytesLine function but parses the string value instead of | |
1180 | * the current token value. | |
1181 | */ | |
1182 | static void parseBytesOptionValue(size_t * bptr, const char *units, char const * value) | |
1183 | { | |
1184 | int u; | |
1185 | if ((u = parseBytesUnits(units)) == 0) { | |
1186 | self_destruct(); | |
1187 | return; | |
1188 | } | |
1189 | ||
1190 | // Find number from string beginning. | |
1191 | char const * number_begin = value; | |
1192 | char const * number_end = value; | |
1193 | ||
1194 | while ((*number_end >= '0' && *number_end <= '9')) { | |
1195 | number_end++; | |
1196 | } | |
1197 | ||
1198 | String number; | |
1199 | number.limitInit(number_begin, number_end - number_begin); | |
1200 | ||
1201 | int d = xatoi(number.termedBuf()); | |
1202 | int m; | |
1203 | if ((m = parseBytesUnits(number_end)) == 0) { | |
1204 | self_destruct(); | |
1205 | return; | |
1206 | } | |
1207 | ||
1208 | *bptr = static_cast<size_t>(m * d / u); | |
1209 | if (static_cast<double>(*bptr) * 2 != m * d / u * 2) | |
1210 | self_destruct(); | |
1211 | } | |
1212 | #endif | |
1213 | ||
9906e724 | 1214 | static size_t |
1215 | parseBytesUnits(const char *unit) | |
1216 | { | |
1217 | if (!strncasecmp(unit, B_BYTES_STR, strlen(B_BYTES_STR))) | |
62e76326 | 1218 | return 1; |
1219 | ||
9906e724 | 1220 | if (!strncasecmp(unit, B_KBYTES_STR, strlen(B_KBYTES_STR))) |
62e76326 | 1221 | return 1 << 10; |
1222 | ||
9906e724 | 1223 | if (!strncasecmp(unit, B_MBYTES_STR, strlen(B_MBYTES_STR))) |
62e76326 | 1224 | return 1 << 20; |
1225 | ||
9906e724 | 1226 | if (!strncasecmp(unit, B_GBYTES_STR, strlen(B_GBYTES_STR))) |
62e76326 | 1227 | return 1 << 30; |
1228 | ||
fa37412f | 1229 | debugs(3, DBG_CRITICAL, "WARNING: Unknown bytes unit '" << unit << "'"); |
62e76326 | 1230 | |
9906e724 | 1231 | return 0; |
1232 | } | |
1233 | ||
270b86af | 1234 | /***************************************************************************** |
1235 | * Max | |
1236 | *****************************************************************************/ | |
1237 | ||
8203a132 | 1238 | static void |
97427e90 | 1239 | dump_acl(StoreEntry * entry, const char *name, ACL * ae) |
090089c4 | 1240 | { |
56b63fa1 | 1241 | wordlist *w; |
1242 | wordlist *v; | |
62e76326 | 1243 | |
9ef28b60 | 1244 | while (ae != NULL) { |
bf8fe701 | 1245 | debugs(3, 3, "dump_acl: " << name << " " << ae->name); |
62e76326 | 1246 | storeAppendPrintf(entry, "%s %s %s ", |
1247 | name, | |
1248 | ae->name, | |
1249 | ae->typeString()); | |
6bf4f823 | 1250 | v = w = ae->dump(); |
62e76326 | 1251 | |
1252 | while (v != NULL) { | |
bf8fe701 | 1253 | debugs(3, 3, "dump_acl: " << name << " " << ae->name << " " << v->key); |
62e76326 | 1254 | storeAppendPrintf(entry, "%s ", v->key); |
1255 | v = v->next; | |
1256 | } | |
1257 | ||
1258 | storeAppendPrintf(entry, "\n"); | |
1259 | wordlistDestroy(&w); | |
1260 | ae = ae->next; | |
56b63fa1 | 1261 | } |
090089c4 | 1262 | } |
1263 | ||
8203a132 | 1264 | static void |
97427e90 | 1265 | parse_acl(ACL ** ae) |
090089c4 | 1266 | { |
a9f20260 | 1267 | ACL::ParseAclLine(LegacyParser, ae); |
f1dc9b30 | 1268 | } |
1269 | ||
1270 | static void | |
97427e90 | 1271 | free_acl(ACL ** ae) |
f1dc9b30 | 1272 | { |
9ef28b60 | 1273 | aclDestroyAcls(ae); |
090089c4 | 1274 | } |
1275 | ||
425de4c8 | 1276 | void |
76cd39d7 | 1277 | dump_acl_list(StoreEntry * entry, ACLList * head) |
30a4f2a8 | 1278 | { |
76cd39d7 | 1279 | ACLList *l; |
62e76326 | 1280 | |
d6827718 | 1281 | for (l = head; l; l = l->next) { |
62e76326 | 1282 | storeAppendPrintf(entry, " %s%s", |
1283 | l->op ? null_string : "!", | |
1284 | l->_acl->name); | |
d6827718 | 1285 | } |
1286 | } | |
1287 | ||
b67e2c8c | 1288 | void |
d6827718 | 1289 | dump_acl_access(StoreEntry * entry, const char *name, acl_access * head) |
1290 | { | |
1291 | acl_access *l; | |
62e76326 | 1292 | |
d6827718 | 1293 | for (l = head; l; l = l->next) { |
62e76326 | 1294 | storeAppendPrintf(entry, "%s %s", |
1295 | name, | |
1296 | l->allow ? "Allow" : "Deny"); | |
1297 | dump_acl_list(entry, l->aclList); | |
1298 | storeAppendPrintf(entry, "\n"); | |
56b63fa1 | 1299 | } |
30a4f2a8 | 1300 | } |
090089c4 | 1301 | |
8203a132 | 1302 | static void |
16300b58 | 1303 | parse_acl_access(acl_access ** head) |
090089c4 | 1304 | { |
a9f20260 | 1305 | aclParseAccessLine(LegacyParser, head); |
090089c4 | 1306 | } |
1307 | ||
0153d498 | 1308 | static void |
16300b58 | 1309 | free_acl_access(acl_access ** head) |
0153d498 | 1310 | { |
a47b9029 | 1311 | aclDestroyAccessList(head); |
0153d498 | 1312 | } |
1313 | ||
8203a132 | 1314 | static void |
b7ac5457 | 1315 | dump_address(StoreEntry * entry, const char *name, Ip::Address &addr) |
270b86af | 1316 | { |
cc192b50 | 1317 | char buf[MAX_IPSTRLEN]; |
1318 | storeAppendPrintf(entry, "%s %s\n", name, addr.NtoA(buf,MAX_IPSTRLEN) ); | |
270b86af | 1319 | } |
1320 | ||
1321 | static void | |
b7ac5457 | 1322 | parse_address(Ip::Address *addr) |
090089c4 | 1323 | { |
270b86af | 1324 | char *token = strtok(NULL, w_space); |
1325 | ||
9eeb8e4b | 1326 | if (!token) { |
62e76326 | 1327 | self_destruct(); |
9eeb8e4b | 1328 | return; |
1329 | } | |
62e76326 | 1330 | |
26ac0430 | 1331 | if (!strcmp(token,"any_addr")) { |
cc192b50 | 1332 | addr->SetAnyAddr(); |
26ac0430 AJ |
1333 | (void) 0; |
1334 | } else if ( (!strcmp(token,"no_addr")) || (!strcmp(token,"full_mask")) ) { | |
cc192b50 | 1335 | addr->SetNoAddr(); |
26ac0430 AJ |
1336 | (void) 0; |
1337 | } else | |
cc192b50 | 1338 | *addr = token; |
090089c4 | 1339 | } |
1340 | ||
0153d498 | 1341 | static void |
b7ac5457 | 1342 | free_address(Ip::Address *addr) |
0153d498 | 1343 | { |
cc192b50 | 1344 | addr->SetEmpty(); |
0153d498 | 1345 | } |
1346 | ||
d6827718 | 1347 | CBDATA_TYPE(acl_address); |
1348 | ||
1349 | static void | |
1350 | dump_acl_address(StoreEntry * entry, const char *name, acl_address * head) | |
1351 | { | |
cc192b50 | 1352 | char buf[MAX_IPSTRLEN]; |
d6827718 | 1353 | acl_address *l; |
62e76326 | 1354 | |
d6827718 | 1355 | for (l = head; l; l = l->next) { |
cc192b50 | 1356 | if (!l->addr.IsAnyAddr()) |
1357 | storeAppendPrintf(entry, "%s %s", name, l->addr.NtoA(buf,MAX_IPSTRLEN)); | |
62e76326 | 1358 | else |
1359 | storeAppendPrintf(entry, "%s autoselect", name); | |
1360 | ||
1361 | dump_acl_list(entry, l->aclList); | |
1362 | ||
1363 | storeAppendPrintf(entry, "\n"); | |
d6827718 | 1364 | } |
1365 | } | |
1366 | ||
1367 | static void | |
1368 | freed_acl_address(void *data) | |
1369 | { | |
e6ccf245 | 1370 | acl_address *l = static_cast<acl_address *>(data); |
29b8d8d6 | 1371 | aclDestroyAclList(&l->aclList); |
d6827718 | 1372 | } |
1373 | ||
1374 | static void | |
1375 | parse_acl_address(acl_address ** head) | |
1376 | { | |
1377 | acl_address *l; | |
1378 | acl_address **tail = head; /* sane name below */ | |
1379 | CBDATA_INIT_TYPE_FREECB(acl_address, freed_acl_address); | |
1380 | l = cbdataAlloc(acl_address); | |
1381 | parse_address(&l->addr); | |
a9f20260 | 1382 | aclParseAclList(LegacyParser, &l->aclList); |
62e76326 | 1383 | |
d6827718 | 1384 | while (*tail) |
62e76326 | 1385 | tail = &(*tail)->next; |
1386 | ||
d6827718 | 1387 | *tail = l; |
1388 | } | |
1389 | ||
1390 | static void | |
1391 | free_acl_address(acl_address ** head) | |
1392 | { | |
1393 | while (*head) { | |
62e76326 | 1394 | acl_address *l = *head; |
1395 | *head = l->next; | |
1396 | cbdataFree(l); | |
d6827718 | 1397 | } |
1398 | } | |
1399 | ||
1400 | CBDATA_TYPE(acl_tos); | |
1401 | ||
1402 | static void | |
1403 | dump_acl_tos(StoreEntry * entry, const char *name, acl_tos * head) | |
1404 | { | |
1405 | acl_tos *l; | |
62e76326 | 1406 | |
d6827718 | 1407 | for (l = head; l; l = l->next) { |
62e76326 | 1408 | if (l->tos > 0) |
1409 | storeAppendPrintf(entry, "%s 0x%02X", name, l->tos); | |
1410 | else | |
1411 | storeAppendPrintf(entry, "%s none", name); | |
1412 | ||
1413 | dump_acl_list(entry, l->aclList); | |
1414 | ||
1415 | storeAppendPrintf(entry, "\n"); | |
d6827718 | 1416 | } |
1417 | } | |
1418 | ||
1419 | static void | |
1420 | freed_acl_tos(void *data) | |
1421 | { | |
e6ccf245 | 1422 | acl_tos *l = static_cast<acl_tos *>(data); |
29b8d8d6 | 1423 | aclDestroyAclList(&l->aclList); |
d6827718 | 1424 | } |
1425 | ||
1426 | static void | |
1427 | parse_acl_tos(acl_tos ** head) | |
1428 | { | |
1429 | acl_tos *l; | |
1430 | acl_tos **tail = head; /* sane name below */ | |
425de4c8 | 1431 | unsigned int tos; /* Initially uint for strtoui. Casted to tos_t before return */ |
d6827718 | 1432 | char *token = strtok(NULL, w_space); |
62e76326 | 1433 | |
9eeb8e4b | 1434 | if (!token) { |
62e76326 | 1435 | self_destruct(); |
9eeb8e4b | 1436 | return; |
1437 | } | |
62e76326 | 1438 | |
425de4c8 | 1439 | if (!xstrtoui(token, NULL, &tos, 0, std::numeric_limits<tos_t>::max())) { |
62e76326 | 1440 | self_destruct(); |
9eeb8e4b | 1441 | return; |
1442 | } | |
62e76326 | 1443 | |
d6827718 | 1444 | CBDATA_INIT_TYPE_FREECB(acl_tos, freed_acl_tos); |
62e76326 | 1445 | |
d6827718 | 1446 | l = cbdataAlloc(acl_tos); |
62e76326 | 1447 | |
425de4c8 | 1448 | l->tos = (tos_t)tos; |
62e76326 | 1449 | |
a9f20260 | 1450 | aclParseAclList(LegacyParser, &l->aclList); |
62e76326 | 1451 | |
d6827718 | 1452 | while (*tail) |
62e76326 | 1453 | tail = &(*tail)->next; |
1454 | ||
d6827718 | 1455 | *tail = l; |
1456 | } | |
1457 | ||
1458 | static void | |
1459 | free_acl_tos(acl_tos ** head) | |
1460 | { | |
1461 | while (*head) { | |
62e76326 | 1462 | acl_tos *l = *head; |
1463 | *head = l->next; | |
1464 | l->next = NULL; | |
1465 | cbdataFree(l); | |
d6827718 | 1466 | } |
1467 | } | |
1468 | ||
11e8cfe3 | 1469 | #if SO_MARK && USE_LIBCAP |
f4f6c2e0 | 1470 | |
425de4c8 AJ |
1471 | CBDATA_TYPE(acl_nfmark); |
1472 | ||
1473 | static void | |
1474 | dump_acl_nfmark(StoreEntry * entry, const char *name, acl_nfmark * head) | |
1475 | { | |
1476 | acl_nfmark *l; | |
1477 | ||
1478 | for (l = head; l; l = l->next) { | |
1479 | if (l->nfmark > 0) | |
1480 | storeAppendPrintf(entry, "%s 0x%02X", name, l->nfmark); | |
1481 | else | |
1482 | storeAppendPrintf(entry, "%s none", name); | |
1483 | ||
1484 | dump_acl_list(entry, l->aclList); | |
1485 | ||
1486 | storeAppendPrintf(entry, "\n"); | |
1487 | } | |
1488 | } | |
1489 | ||
1490 | static void | |
1491 | freed_acl_nfmark(void *data) | |
1492 | { | |
1493 | acl_nfmark *l = static_cast<acl_nfmark *>(data); | |
1494 | aclDestroyAclList(&l->aclList); | |
1495 | } | |
1496 | ||
1497 | static void | |
1498 | parse_acl_nfmark(acl_nfmark ** head) | |
1499 | { | |
1500 | acl_nfmark *l; | |
1501 | acl_nfmark **tail = head; /* sane name below */ | |
1502 | nfmark_t mark; | |
1503 | char *token = strtok(NULL, w_space); | |
1504 | ||
1505 | if (!token) { | |
1506 | self_destruct(); | |
1507 | return; | |
1508 | } | |
1509 | ||
1510 | if (!xstrtoui(token, NULL, &mark, 0, std::numeric_limits<nfmark_t>::max())) { | |
1511 | self_destruct(); | |
1512 | return; | |
1513 | } | |
1514 | ||
1515 | CBDATA_INIT_TYPE_FREECB(acl_nfmark, freed_acl_nfmark); | |
1516 | ||
1517 | l = cbdataAlloc(acl_nfmark); | |
1518 | ||
1519 | l->nfmark = mark; | |
1520 | ||
1521 | aclParseAclList(LegacyParser, &l->aclList); | |
1522 | ||
1523 | while (*tail) | |
1524 | tail = &(*tail)->next; | |
1525 | ||
1526 | *tail = l; | |
1527 | } | |
1528 | ||
1529 | static void | |
1530 | free_acl_nfmark(acl_nfmark ** head) | |
1531 | { | |
1532 | while (*head) { | |
1533 | acl_nfmark *l = *head; | |
1534 | *head = l->next; | |
1535 | l->next = NULL; | |
1536 | cbdataFree(l); | |
1537 | } | |
1538 | } | |
f4f6c2e0 | 1539 | #endif /* SO_MARK */ |
425de4c8 | 1540 | |
ef1955a5 | 1541 | CBDATA_TYPE(acl_size_t); |
1542 | ||
1543 | static void | |
1544 | dump_acl_b_size_t(StoreEntry * entry, const char *name, acl_size_t * head) | |
1545 | { | |
1546 | acl_size_t *l; | |
1547 | ||
1548 | for (l = head; l; l = l->next) { | |
ed013b6c | 1549 | if (l->size != -1) |
ef1955a5 | 1550 | storeAppendPrintf(entry, "%s %d %s\n", name, (int) l->size, B_BYTES_STR); |
1551 | else | |
1552 | storeAppendPrintf(entry, "%s none", name); | |
1553 | ||
1554 | dump_acl_list(entry, l->aclList); | |
1555 | ||
1556 | storeAppendPrintf(entry, "\n"); | |
1557 | } | |
1558 | } | |
1559 | ||
1560 | static void | |
1561 | freed_acl_b_size_t(void *data) | |
1562 | { | |
1563 | acl_size_t *l = static_cast<acl_size_t *>(data); | |
1564 | aclDestroyAclList(&l->aclList); | |
1565 | } | |
1566 | ||
1567 | static void | |
1568 | parse_acl_b_size_t(acl_size_t ** head) | |
1569 | { | |
1570 | acl_size_t *l; | |
1571 | acl_size_t **tail = head; /* sane name below */ | |
1572 | ||
1573 | CBDATA_INIT_TYPE_FREECB(acl_size_t, freed_acl_b_size_t); | |
1574 | ||
1575 | l = cbdataAlloc(acl_size_t); | |
1576 | ||
47f6e231 | 1577 | parse_b_int64_t(&l->size); |
ef1955a5 | 1578 | |
a9f20260 | 1579 | aclParseAclList(LegacyParser, &l->aclList); |
ef1955a5 | 1580 | |
1581 | while (*tail) | |
1582 | tail = &(*tail)->next; | |
1583 | ||
1584 | *tail = l; | |
1585 | } | |
1586 | ||
1587 | static void | |
1588 | free_acl_b_size_t(acl_size_t ** head) | |
1589 | { | |
1590 | while (*head) { | |
1591 | acl_size_t *l = *head; | |
1592 | *head = l->next; | |
1593 | l->next = NULL; | |
1594 | cbdataFree(l); | |
1595 | } | |
1596 | } | |
1597 | ||
9a0a18de | 1598 | #if USE_DELAY_POOLS |
59715b38 | 1599 | |
b67e2c8c | 1600 | #include "DelayPools.h" |
1601 | #include "DelayConfig.h" | |
59715b38 | 1602 | /* do nothing - free_delay_pool_count is the magic free function. |
ae870270 | 1603 | * this is why delay_pool_count isn't just marked TYPE: u_short |
59715b38 | 1604 | */ |
1605 | #define free_delay_pool_class(X) | |
1606 | #define free_delay_pool_access(X) | |
1607 | #define free_delay_pool_rates(X) | |
1608 | #define dump_delay_pool_class(X, Y, Z) | |
1609 | #define dump_delay_pool_access(X, Y, Z) | |
1610 | #define dump_delay_pool_rates(X, Y, Z) | |
1611 | ||
1612 | static void | |
b67e2c8c | 1613 | free_delay_pool_count(DelayConfig * cfg) |
59715b38 | 1614 | { |
b67e2c8c | 1615 | cfg->freePoolCount(); |
59715b38 | 1616 | } |
1617 | ||
1618 | static void | |
b67e2c8c | 1619 | dump_delay_pool_count(StoreEntry * entry, const char *name, DelayConfig &cfg) |
59715b38 | 1620 | { |
b67e2c8c | 1621 | cfg.dumpPoolCount (entry, name); |
59715b38 | 1622 | } |
1623 | ||
1624 | static void | |
b67e2c8c | 1625 | parse_delay_pool_count(DelayConfig * cfg) |
59715b38 | 1626 | { |
b67e2c8c | 1627 | cfg->parsePoolCount(); |
59715b38 | 1628 | } |
1629 | ||
1630 | static void | |
b67e2c8c | 1631 | parse_delay_pool_class(DelayConfig * cfg) |
59715b38 | 1632 | { |
b67e2c8c | 1633 | cfg->parsePoolClass(); |
59715b38 | 1634 | } |
1635 | ||
1636 | static void | |
b67e2c8c | 1637 | parse_delay_pool_rates(DelayConfig * cfg) |
59715b38 | 1638 | { |
b67e2c8c | 1639 | cfg->parsePoolRates(); |
59715b38 | 1640 | } |
1641 | ||
1642 | static void | |
b67e2c8c | 1643 | parse_delay_pool_access(DelayConfig * cfg) |
59715b38 | 1644 | { |
a9f20260 | 1645 | cfg->parsePoolAccess(LegacyParser); |
59715b38 | 1646 | } |
62e76326 | 1647 | |
59715b38 | 1648 | #endif |
1649 | ||
9a0a18de | 1650 | #if USE_DELAY_POOLS |
b4cd430a CT |
1651 | #include "ClientDelayConfig.h" |
1652 | /* do nothing - free_client_delay_pool_count is the magic free function. | |
ae870270 | 1653 | * this is why client_delay_pool_count isn't just marked TYPE: u_short |
b4cd430a CT |
1654 | */ |
1655 | ||
1656 | #define free_client_delay_pool_access(X) | |
1657 | #define free_client_delay_pool_rates(X) | |
1658 | #define dump_client_delay_pool_access(X, Y, Z) | |
1659 | #define dump_client_delay_pool_rates(X, Y, Z) | |
1660 | ||
1661 | static void | |
1662 | free_client_delay_pool_count(ClientDelayConfig * cfg) | |
1663 | { | |
1664 | cfg->freePoolCount(); | |
1665 | } | |
1666 | ||
1667 | static void | |
1668 | dump_client_delay_pool_count(StoreEntry * entry, const char *name, ClientDelayConfig &cfg) | |
1669 | { | |
1670 | cfg.dumpPoolCount (entry, name); | |
1671 | } | |
1672 | ||
1673 | static void | |
1674 | parse_client_delay_pool_count(ClientDelayConfig * cfg) | |
1675 | { | |
1676 | cfg->parsePoolCount(); | |
1677 | } | |
1678 | ||
1679 | static void | |
1680 | parse_client_delay_pool_rates(ClientDelayConfig * cfg) | |
1681 | { | |
1682 | cfg->parsePoolRates(); | |
1683 | } | |
1684 | ||
1685 | static void | |
1686 | parse_client_delay_pool_access(ClientDelayConfig * cfg) | |
1687 | { | |
1688 | cfg->parsePoolAccess(LegacyParser); | |
1689 | } | |
1690 | #endif | |
1691 | ||
626096be | 1692 | #if USE_HTTP_VIOLATIONS |
97474590 | 1693 | static void |
6bccf575 | 1694 | dump_http_header_access(StoreEntry * entry, const char *name, header_mangler header[]) |
e3dd531e | 1695 | { |
efd900cb | 1696 | int i; |
62e76326 | 1697 | |
6bccf575 | 1698 | for (i = 0; i < HDR_ENUM_END; i++) { |
62e76326 | 1699 | if (header[i].access_list != NULL) { |
1700 | storeAppendPrintf(entry, "%s ", name); | |
1701 | dump_acl_access(entry, httpHeaderNameById(i), | |
1702 | header[i].access_list); | |
1703 | } | |
efd900cb | 1704 | } |
97474590 | 1705 | } |
e3dd531e | 1706 | |
97474590 | 1707 | static void |
6bccf575 | 1708 | parse_http_header_access(header_mangler header[]) |
97474590 | 1709 | { |
6bccf575 | 1710 | int id, i; |
97474590 | 1711 | char *t = NULL; |
62e76326 | 1712 | |
97474590 | 1713 | if ((t = strtok(NULL, w_space)) == NULL) { |
bf8fe701 | 1714 | debugs(3, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line); |
1715 | debugs(3, 0, "parse_http_header_access: missing header name."); | |
62e76326 | 1716 | return; |
97474590 | 1717 | } |
62e76326 | 1718 | |
6bccf575 | 1719 | /* Now lookup index of header. */ |
1720 | id = httpHeaderIdByNameDef(t, strlen(t)); | |
62e76326 | 1721 | |
6bccf575 | 1722 | if (strcmp(t, "All") == 0) |
62e76326 | 1723 | id = HDR_ENUM_END; |
6bccf575 | 1724 | else if (strcmp(t, "Other") == 0) |
62e76326 | 1725 | id = HDR_OTHER; |
6bccf575 | 1726 | else if (id == -1) { |
bf8fe701 | 1727 | debugs(3, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line); |
1728 | debugs(3, 0, "parse_http_header_access: unknown header name '" << t << "'"); | |
62e76326 | 1729 | return; |
97474590 | 1730 | } |
62e76326 | 1731 | |
6bccf575 | 1732 | if (id != HDR_ENUM_END) { |
62e76326 | 1733 | parse_acl_access(&header[id].access_list); |
6bccf575 | 1734 | } else { |
62e76326 | 1735 | char *next_string = t + strlen(t) - 1; |
1736 | *next_string = 'A'; | |
1737 | *(next_string + 1) = ' '; | |
1738 | ||
1739 | for (i = 0; i < HDR_ENUM_END; i++) { | |
1740 | char *new_string = xstrdup(next_string); | |
1741 | strtok(new_string, w_space); | |
1742 | parse_acl_access(&header[i].access_list); | |
1743 | safe_free(new_string); | |
1744 | } | |
97474590 | 1745 | } |
6bccf575 | 1746 | } |
1747 | ||
1748 | static void | |
1749 | free_http_header_access(header_mangler header[]) | |
1750 | { | |
1751 | int i; | |
62e76326 | 1752 | |
6bccf575 | 1753 | for (i = 0; i < HDR_ENUM_END; i++) { |
62e76326 | 1754 | free_acl_access(&header[i].access_list); |
6bccf575 | 1755 | } |
1756 | } | |
1757 | ||
1758 | static void | |
1759 | dump_http_header_replace(StoreEntry * entry, const char *name, header_mangler | |
62e76326 | 1760 | header[]) |
6bccf575 | 1761 | { |
1762 | int i; | |
62e76326 | 1763 | |
6bccf575 | 1764 | for (i = 0; i < HDR_ENUM_END; i++) { |
62e76326 | 1765 | if (NULL == header[i].replacement) |
1766 | continue; | |
1767 | ||
1768 | storeAppendPrintf(entry, "%s %s %s\n", name, httpHeaderNameById(i), | |
1769 | header[i].replacement); | |
97474590 | 1770 | } |
1771 | } | |
e3dd531e | 1772 | |
97474590 | 1773 | static void |
6bccf575 | 1774 | parse_http_header_replace(header_mangler header[]) |
e3dd531e | 1775 | { |
6bccf575 | 1776 | int id, i; |
1777 | char *t = NULL; | |
62e76326 | 1778 | |
6bccf575 | 1779 | if ((t = strtok(NULL, w_space)) == NULL) { |
bf8fe701 | 1780 | debugs(3, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line); |
1781 | debugs(3, 0, "parse_http_header_replace: missing header name."); | |
62e76326 | 1782 | return; |
6bccf575 | 1783 | } |
62e76326 | 1784 | |
6bccf575 | 1785 | /* Now lookup index of header. */ |
1786 | id = httpHeaderIdByNameDef(t, strlen(t)); | |
62e76326 | 1787 | |
6bccf575 | 1788 | if (strcmp(t, "All") == 0) |
62e76326 | 1789 | id = HDR_ENUM_END; |
6bccf575 | 1790 | else if (strcmp(t, "Other") == 0) |
62e76326 | 1791 | id = HDR_OTHER; |
6bccf575 | 1792 | else if (id == -1) { |
bf8fe701 | 1793 | debugs(3, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line); |
1794 | debugs(3, 0, "parse_http_header_replace: unknown header name " << t << "."); | |
1795 | ||
62e76326 | 1796 | return; |
6bccf575 | 1797 | } |
62e76326 | 1798 | |
6bccf575 | 1799 | if (id != HDR_ENUM_END) { |
62e76326 | 1800 | if (header[id].replacement != NULL) |
1801 | safe_free(header[id].replacement); | |
1802 | ||
1803 | header[id].replacement = xstrdup(t + strlen(t) + 1); | |
6bccf575 | 1804 | } else { |
62e76326 | 1805 | for (i = 0; i < HDR_ENUM_END; i++) { |
1806 | if (header[i].replacement != NULL) | |
1807 | safe_free(header[i].replacement); | |
1808 | ||
1809 | header[i].replacement = xstrdup(t + strlen(t) + 1); | |
1810 | } | |
6bccf575 | 1811 | } |
1812 | } | |
1813 | ||
1814 | static void | |
1815 | free_http_header_replace(header_mangler header[]) | |
1816 | { | |
1817 | int i; | |
62e76326 | 1818 | |
6bccf575 | 1819 | for (i = 0; i < HDR_ENUM_END; i++) { |
62e76326 | 1820 | if (header[i].replacement != NULL) |
1821 | safe_free(header[i].replacement); | |
6bccf575 | 1822 | } |
97474590 | 1823 | } |
62e76326 | 1824 | |
9e8b2f1c | 1825 | #endif |
97474590 | 1826 | |
e90100aa | 1827 | static void |
e1f7507e | 1828 | dump_cachedir(StoreEntry * entry, const char *name, SquidConfig::_cacheSwap swap) |
e90100aa | 1829 | { |
f53b06f9 | 1830 | SwapDir *s; |
1831 | int i; | |
d3b3ab85 | 1832 | assert (entry); |
62e76326 | 1833 | |
a7d59104 | 1834 | for (i = 0; i < swap.n_configured; i++) { |
c8f4eac4 | 1835 | s = dynamic_cast<SwapDir *>(swap.swapDirs[i].getRaw()); |
26ac0430 | 1836 | if (!s) continue; |
59b2d47f | 1837 | storeAppendPrintf(entry, "%s %s %s", name, s->type(), s->path); |
62e76326 | 1838 | s->dump(*entry); |
62e76326 | 1839 | storeAppendPrintf(entry, "\n"); |
f53b06f9 | 1840 | } |
1841 | } | |
1842 | ||
53ad48e6 | 1843 | static int |
1844 | check_null_string(char *s) | |
1845 | { | |
1846 | return s == NULL; | |
1847 | } | |
1848 | ||
2f1431ea | 1849 | #if USE_AUTH |
94439e4e | 1850 | static void |
9f3d2b2e | 1851 | parse_authparam(Auth::ConfigVector * config) |
94439e4e | 1852 | { |
1853 | char *type_str; | |
1854 | char *param_str; | |
94439e4e | 1855 | |
1856 | if ((type_str = strtok(NULL, w_space)) == NULL) | |
62e76326 | 1857 | self_destruct(); |
94439e4e | 1858 | |
1859 | if ((param_str = strtok(NULL, w_space)) == NULL) | |
62e76326 | 1860 | self_destruct(); |
94439e4e | 1861 | |
5817ee13 | 1862 | /* find a configuration for the scheme in the currently parsed configs... */ |
9f3d2b2e | 1863 | Auth::Config *schemeCfg = Auth::Config::Find(type_str); |
62e76326 | 1864 | |
5817ee13 AJ |
1865 | if (schemeCfg == NULL) { |
1866 | /* Create a configuration based on the scheme info */ | |
c6cf8dee | 1867 | Auth::Scheme::Pointer theScheme = Auth::Scheme::Find(type_str); |
f5691f9c | 1868 | |
5817ee13 AJ |
1869 | if (theScheme == NULL) { |
1870 | debugs(3, DBG_CRITICAL, "Parsing Config File: Unknown authentication scheme '" << type_str << "'."); | |
1871 | self_destruct(); | |
62e76326 | 1872 | } |
94439e4e | 1873 | |
f5691f9c | 1874 | config->push_back(theScheme->createConfig()); |
9f3d2b2e | 1875 | schemeCfg = Auth::Config::Find(type_str); |
5817ee13 AJ |
1876 | if (schemeCfg == NULL) { |
1877 | debugs(3, DBG_CRITICAL, "Parsing Config File: Corruption configuring authentication scheme '" << type_str << "'."); | |
1878 | self_destruct(); | |
1879 | } | |
94439e4e | 1880 | } |
62e76326 | 1881 | |
5817ee13 | 1882 | schemeCfg->parse(schemeCfg, config->size(), param_str); |
94439e4e | 1883 | } |
1884 | ||
1885 | static void | |
9f3d2b2e | 1886 | free_authparam(Auth::ConfigVector * cfg) |
94439e4e | 1887 | { |
5817ee13 AJ |
1888 | /* Wipe the Auth globals and Detach/Destruct component config + state. */ |
1889 | cfg->clean(); | |
62e76326 | 1890 | |
5817ee13 | 1891 | /* remove our pointers to the probably-dead sub-configs */ |
f5691f9c | 1892 | while (cfg->size()) { |
5817ee13 AJ |
1893 | cfg->pop_back(); |
1894 | } | |
1895 | ||
1896 | /* on reconfigure initialize new auth schemes for the new config. */ | |
ec5858ff | 1897 | if (reconfiguring) { |
ccd8a22a | 1898 | Auth::Init(); |
94439e4e | 1899 | } |
94439e4e | 1900 | } |
1901 | ||
1902 | static void | |
9f3d2b2e | 1903 | dump_authparam(StoreEntry * entry, const char *name, Auth::ConfigVector cfg) |
94439e4e | 1904 | { |
9f3d2b2e | 1905 | for (Auth::ConfigVector::iterator i = cfg.begin(); i != cfg.end(); ++i) |
f5691f9c | 1906 | (*i)->dump(entry, name, (*i)); |
94439e4e | 1907 | } |
2f1431ea | 1908 | #endif /* USE_AUTH */ |
94439e4e | 1909 | |
59b2d47f | 1910 | /* TODO: just return the object, the # is irrelevant */ |
cd748f27 | 1911 | static int |
1912 | find_fstype(char *type) | |
1913 | { | |
59b2d47f | 1914 | for (size_t i = 0; i < StoreFileSystem::FileSystems().size(); ++i) |
1915 | if (strcasecmp(type, StoreFileSystem::FileSystems().items[i]->type()) == 0) | |
1916 | return (int)i; | |
62e76326 | 1917 | |
cd748f27 | 1918 | return (-1); |
1919 | } | |
1920 | ||
0e4e0e7d | 1921 | static void |
e1f7507e | 1922 | parse_cachedir(SquidConfig::_cacheSwap * swap) |
0e4e0e7d | 1923 | { |
1924 | char *type_str; | |
cd748f27 | 1925 | char *path_str; |
c8f4eac4 | 1926 | RefCount<SwapDir> sd; |
cd748f27 | 1927 | int i; |
1928 | int fs; | |
cd748f27 | 1929 | |
0e4e0e7d | 1930 | if ((type_str = strtok(NULL, w_space)) == NULL) |
62e76326 | 1931 | self_destruct(); |
cd748f27 | 1932 | |
cd748f27 | 1933 | if ((path_str = strtok(NULL, w_space)) == NULL) |
62e76326 | 1934 | self_destruct(); |
cd748f27 | 1935 | |
c9e2e0e8 | 1936 | fs = find_fstype(type_str); |
1937 | ||
1938 | if (fs < 0) | |
1939 | self_destruct(); | |
1940 | ||
1941 | /* reconfigure existing dir */ | |
cd748f27 | 1942 | |
1943 | for (i = 0; i < swap->n_configured; i++) { | |
c8f4eac4 | 1944 | assert (swap->swapDirs[i].getRaw()); |
62e76326 | 1945 | |
2c9e9cba | 1946 | if ((strcasecmp(path_str, dynamic_cast<SwapDir *>(swap->swapDirs[i].getRaw())->path)) == 0) { |
c9e2e0e8 | 1947 | /* this is specific to on-fs Stores. The right |
26ac0430 | 1948 | * way to handle this is probably to have a mapping |
c9e2e0e8 | 1949 | * from paths to stores, and have on-fs stores |
1950 | * register with that, and lookip in that in their | |
1951 | * own setup logic. RBC 20041225. TODO. | |
1952 | */ | |
c8f4eac4 | 1953 | |
1954 | sd = dynamic_cast<SwapDir *>(swap->swapDirs[i].getRaw()); | |
1955 | ||
ca6483eb | 1956 | if (strcmp(sd->type(), StoreFileSystem::FileSystems().items[fs]->type()) != 0) { |
bf8fe701 | 1957 | debugs(3, 0, "ERROR: Can't change type of existing cache_dir " << |
1958 | sd->type() << " " << sd->path << " to " << type_str << ". Restart required"); | |
c9e2e0e8 | 1959 | return; |
1960 | } | |
1961 | ||
62e76326 | 1962 | sd->reconfigure (i, path_str); |
c8f4eac4 | 1963 | |
62e76326 | 1964 | update_maxobjsize(); |
c8f4eac4 | 1965 | |
62e76326 | 1966 | return; |
1967 | } | |
cd748f27 | 1968 | } |
1969 | ||
c9e2e0e8 | 1970 | /* new cache_dir */ |
af6a12ee | 1971 | if (swap->n_configured > 63) { |
2c9e9cba AJ |
1972 | /* 7 bits, signed */ |
1973 | debugs(3, DBG_CRITICAL, "WARNING: There is a fixed maximum of 63 cache_dir entries Squid can handle."); | |
1974 | debugs(3, DBG_CRITICAL, "WARNING: '" << path_str << "' is one to many."); | |
1975 | self_destruct(); | |
1976 | return; | |
1977 | } | |
dc986280 | 1978 | |
cd748f27 | 1979 | allocate_new_swapdir(swap); |
c9e2e0e8 | 1980 | |
59b2d47f | 1981 | swap->swapDirs[swap->n_configured] = StoreFileSystem::FileSystems().items[fs]->createSwapDir(); |
c9e2e0e8 | 1982 | |
c8f4eac4 | 1983 | sd = dynamic_cast<SwapDir *>(swap->swapDirs[swap->n_configured].getRaw()); |
c9e2e0e8 | 1984 | |
8e8d4f30 | 1985 | /* parse the FS parameters and options */ |
d3b3ab85 | 1986 | sd->parse(swap->n_configured, path_str); |
c9e2e0e8 | 1987 | |
d3b3ab85 | 1988 | ++swap->n_configured; |
14911a4e AR |
1989 | |
1990 | if (sd->needsDiskStrand()) | |
1991 | ++swap->n_strands; | |
c9e2e0e8 | 1992 | |
cd748f27 | 1993 | /* Update the max object size */ |
1994 | update_maxobjsize(); | |
752c3b27 | 1995 | } |
1996 | ||
2d72d4fd | 1997 | static const char * |
505e35db | 1998 | peer_type_str(const peer_t type) |
1999 | { | |
1f140227 | 2000 | const char * result; |
2001 | ||
0cdcddb9 | 2002 | switch (type) { |
62e76326 | 2003 | |
505e35db | 2004 | case PEER_PARENT: |
1f140227 | 2005 | result = "parent"; |
62e76326 | 2006 | break; |
2007 | ||
505e35db | 2008 | case PEER_SIBLING: |
1f140227 | 2009 | result = "sibling"; |
62e76326 | 2010 | break; |
2011 | ||
505e35db | 2012 | case PEER_MULTICAST: |
1f140227 | 2013 | result = "multicast"; |
62e76326 | 2014 | break; |
2015 | ||
505e35db | 2016 | default: |
1f140227 | 2017 | result = "unknown"; |
62e76326 | 2018 | break; |
505e35db | 2019 | } |
1f140227 | 2020 | |
2021 | return result; | |
505e35db | 2022 | } |
2023 | ||
f1dc9b30 | 2024 | static void |
a7d59104 | 2025 | dump_peer(StoreEntry * entry, const char *name, peer * p) |
98ffb7e4 | 2026 | { |
505e35db | 2027 | domain_ping *d; |
505e35db | 2028 | domain_type *t; |
2029 | LOCAL_ARRAY(char, xname, 128); | |
62e76326 | 2030 | |
d41de3c1 | 2031 | while (p != NULL) { |
4bc48d15 | 2032 | storeAppendPrintf(entry, "%s %s %s %d %d name=%s", |
62e76326 | 2033 | name, |
2034 | p->host, | |
2035 | neighborTypeStr(p), | |
2036 | p->http_port, | |
4bc48d15 AJ |
2037 | p->icp.port, |
2038 | p->name); | |
62e76326 | 2039 | dump_peer_options(entry, p); |
2040 | ||
2041 | for (d = p->peer_domain; d; d = d->next) { | |
2042 | storeAppendPrintf(entry, "cache_peer_domain %s %s%s\n", | |
2043 | p->host, | |
2044 | d->do_ping ? null_string : "!", | |
2045 | d->domain); | |
2046 | } | |
2047 | ||
2048 | if (p->access) { | |
2049 | snprintf(xname, 128, "cache_peer_access %s", p->name); | |
2050 | dump_acl_access(entry, xname, p->access); | |
2051 | } | |
2052 | ||
2053 | for (t = p->typelist; t; t = t->next) { | |
2054 | storeAppendPrintf(entry, "neighbor_type_domain %s %s %s\n", | |
2055 | p->host, | |
2056 | peer_type_str(t->type), | |
2057 | t->domain); | |
2058 | } | |
2059 | ||
2060 | p = p->next; | |
d41de3c1 | 2061 | } |
98ffb7e4 | 2062 | } |
2063 | ||
86ae97bb AJ |
2064 | /** |
2065 | * utility function to prevent getservbyname() being called with a numeric value | |
2066 | * on Windows at least it returns garage results. | |
2067 | */ | |
2068 | static bool | |
2069 | isUnsignedNumeric(const char *str, size_t len) | |
2070 | { | |
2071 | if (len < 1) return false; | |
2072 | ||
2073 | for (; len >0 && *str; str++, len--) { | |
2074 | if (! isdigit(*str)) | |
2075 | return false; | |
2076 | } | |
2077 | return true; | |
2078 | } | |
2079 | ||
609fac72 | 2080 | /** |
2081 | \param proto 'tcp' or 'udp' for protocol | |
2082 | \returns Port the named service is supposed to be listening on. | |
2083 | */ | |
f45dd259 | 2084 | static unsigned short |
609fac72 | 2085 | GetService(const char *proto) |
2086 | { | |
2087 | struct servent *port = NULL; | |
2088 | /** Parses a port number or service name from the squid.conf */ | |
2089 | char *token = strtok(NULL, w_space); | |
2090 | if (token == NULL) { | |
26ac0430 AJ |
2091 | self_destruct(); |
2092 | return 0; /* NEVER REACHED */ | |
609fac72 | 2093 | } |
2094 | /** Returns either the service port number from /etc/services */ | |
e1381638 | 2095 | if ( !isUnsignedNumeric(token, strlen(token)) ) |
86ae97bb | 2096 | port = getservbyname(token, proto); |
609fac72 | 2097 | if (port != NULL) { |
f45dd259 | 2098 | return ntohs((unsigned short)port->s_port); |
609fac72 | 2099 | } |
2100 | /** Or a numeric translation of the config text. */ | |
2101 | return xatos(token); | |
2102 | } | |
2103 | ||
2104 | /** | |
2105 | \returns Port the named TCP service is supposed to be listening on. | |
2106 | \copydoc GetService(const char *proto) | |
2107 | */ | |
f45dd259 | 2108 | inline unsigned short |
609fac72 | 2109 | GetTcpService(void) |
2110 | { | |
2111 | return GetService("tcp"); | |
2112 | } | |
2113 | ||
2114 | /** | |
2115 | \returns Port the named UDP service is supposed to be listening on. | |
2116 | \copydoc GetService(const char *proto) | |
2117 | */ | |
f45dd259 | 2118 | inline unsigned short |
609fac72 | 2119 | GetUdpService(void) |
2120 | { | |
2121 | return GetService("udp"); | |
2122 | } | |
2123 | ||
8203a132 | 2124 | static void |
40a1495e | 2125 | parse_peer(peer ** head) |
7813c6d5 | 2126 | { |
270b86af | 2127 | char *token = NULL; |
40a1495e | 2128 | peer *p; |
f5691f9c | 2129 | CBDATA_INIT_TYPE_FREECB(peer, peerDestroy); |
72711e31 | 2130 | p = cbdataAlloc(peer); |
40a1495e | 2131 | p->http_port = CACHE_HTTP_PORT; |
399cabec | 2132 | p->icp.port = CACHE_ICP_PORT; |
40a1495e | 2133 | p->weight = 1; |
d1b63fc8 | 2134 | p->basetime = 0; |
dc835977 | 2135 | p->stats.logged_state = PEER_ALIVE; |
62e76326 | 2136 | |
e481c2dc | 2137 | if ((token = strtok(NULL, w_space)) == NULL) |
62e76326 | 2138 | self_destruct(); |
2139 | ||
40a1495e | 2140 | p->host = xstrdup(token); |
26ac0430 | 2141 | |
be753325 | 2142 | p->name = xstrdup(token); |
62e76326 | 2143 | |
e481c2dc | 2144 | if ((token = strtok(NULL, w_space)) == NULL) |
62e76326 | 2145 | self_destruct(); |
2146 | ||
40a1495e | 2147 | p->type = parseNeighborType(token); |
62e76326 | 2148 | |
0d5a2006 | 2149 | if (p->type == PEER_MULTICAST) { |
2150 | p->options.no_digest = 1; | |
2151 | p->options.no_netdb_exchange = 1; | |
2152 | } | |
2153 | ||
609fac72 | 2154 | p->http_port = GetTcpService(); |
62e76326 | 2155 | |
0e656b69 | 2156 | if (!p->http_port) |
2157 | self_destruct(); | |
62e76326 | 2158 | |
609fac72 | 2159 | p->icp.port = GetUdpService(); |
d67acb4e | 2160 | p->connection_auth = 2; /* auto */ |
62e76326 | 2161 | |
270b86af | 2162 | while ((token = strtok(NULL, w_space))) { |
62e76326 | 2163 | if (!strcasecmp(token, "proxy-only")) { |
2164 | p->options.proxy_only = 1; | |
2165 | } else if (!strcasecmp(token, "no-query")) { | |
2166 | p->options.no_query = 1; | |
2167 | } else if (!strcasecmp(token, "background-ping")) { | |
2168 | p->options.background_ping = 1; | |
2169 | } else if (!strcasecmp(token, "no-digest")) { | |
2170 | p->options.no_digest = 1; | |
b0758e04 AJ |
2171 | } else if (!strcasecmp(token, "no-tproxy")) { |
2172 | p->options.no_tproxy = 1; | |
62e76326 | 2173 | } else if (!strcasecmp(token, "multicast-responder")) { |
2174 | p->options.mcast_responder = 1; | |
8a368316 | 2175 | #if PEER_MULTICAST_SIBLINGS |
79ddb8e2 | 2176 | } else if (!strcasecmp(token, "multicast-siblings")) { |
8a368316 AJ |
2177 | p->options.mcast_siblings = 1; |
2178 | #endif | |
62e76326 | 2179 | } else if (!strncasecmp(token, "weight=", 7)) { |
2180 | p->weight = xatoi(token + 7); | |
2181 | } else if (!strncasecmp(token, "basetime=", 9)) { | |
2182 | p->basetime = xatoi(token + 9); | |
2183 | } else if (!strcasecmp(token, "closest-only")) { | |
2184 | p->options.closest_only = 1; | |
2185 | } else if (!strncasecmp(token, "ttl=", 4)) { | |
2186 | p->mcast.ttl = xatoi(token + 4); | |
2187 | ||
2188 | if (p->mcast.ttl < 0) | |
2189 | p->mcast.ttl = 0; | |
2190 | ||
2191 | if (p->mcast.ttl > 128) | |
2192 | p->mcast.ttl = 128; | |
2193 | } else if (!strcasecmp(token, "default")) { | |
2194 | p->options.default_parent = 1; | |
2195 | } else if (!strcasecmp(token, "round-robin")) { | |
2196 | p->options.roundrobin = 1; | |
2197 | } else if (!strcasecmp(token, "weighted-round-robin")) { | |
2198 | p->options.weighted_roundrobin = 1; | |
dc9d133b | 2199 | #if USE_HTCP |
62e76326 | 2200 | } else if (!strcasecmp(token, "htcp")) { |
2201 | p->options.htcp = 1; | |
18191440 AJ |
2202 | } else if (!strncasecmp(token, "htcp=", 5) || !strncasecmp(token, "htcp-", 5)) { |
2203 | /* Note: The htcp- form is deprecated, replaced by htcp= */ | |
4f4fa815 | 2204 | p->options.htcp = 1; |
18191440 AJ |
2205 | char *tmp = xstrdup(token+5); |
2206 | char *mode, *nextmode; | |
2207 | for (mode = nextmode = tmp; mode; mode = nextmode) { | |
2208 | nextmode = strchr(mode, ','); | |
18191440 AJ |
2209 | if (nextmode) |
2210 | *nextmode++ = '\0'; | |
2211 | if (!strcasecmp(mode, "no-clr")) { | |
2212 | if (p->options.htcp_only_clr) | |
2213 | fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously"); | |
2214 | p->options.htcp_no_clr = 1; | |
2215 | } else if (!strcasecmp(mode, "no-purge-clr")) { | |
2216 | p->options.htcp_no_purge_clr = 1; | |
2217 | } else if (!strcasecmp(mode, "only-clr")) { | |
2218 | if (p->options.htcp_no_clr) | |
2219 | fatalf("parse_peer: can't set htcp no-clr and only-clr simultaneously"); | |
2220 | p->options.htcp_only_clr = 1; | |
2221 | } else if (!strcasecmp(mode, "forward-clr")) { | |
2222 | p->options.htcp_forward_clr = 1; | |
2223 | } else if (!strcasecmp(mode, "oldsquid")) { | |
2224 | p->options.htcp_oldsquid = 1; | |
2225 | } else { | |
2226 | fatalf("invalid HTCP mode '%s'", mode); | |
2227 | } | |
2228 | } | |
2229 | safe_free(tmp); | |
dc9d133b | 2230 | #endif |
62e76326 | 2231 | } else if (!strcasecmp(token, "no-netdb-exchange")) { |
2232 | p->options.no_netdb_exchange = 1; | |
62e76326 | 2233 | |
2234 | } else if (!strcasecmp(token, "carp")) { | |
2235 | if (p->type != PEER_PARENT) | |
2236 | fatalf("parse_peer: non-parent carp peer %s/%d\n", p->host, p->http_port); | |
2237 | ||
2238 | p->options.carp = 1; | |
de03b596 FC |
2239 | } else if (!strncasecmp(token, "carp-key=", 9)) { |
2240 | if (p->options.carp != 1) | |
2241 | fatalf("parse_peer: carp-key specified on non-carp peer %s/%d\n", p->host, p->http_port); | |
2242 | p->options.carp_key.set=1; | |
2243 | char *nextkey=token+strlen("carp-key="), *key=nextkey; | |
2244 | for (; key; key = nextkey) { | |
96f6f33b A |
2245 | nextkey=strchr(key,','); |
2246 | if (nextkey) ++nextkey; // skip the comma, any | |
2247 | if (0==strncasecmp(key,"scheme",6)) { | |
2248 | p->options.carp_key.scheme=1; | |
2249 | } else if (0==strncasecmp(key,"host",4)) { | |
2250 | p->options.carp_key.host=1; | |
2251 | } else if (0==strncasecmp(key,"port",4)) { | |
2252 | p->options.carp_key.port=1; | |
2253 | } else if (0==strncasecmp(key,"path",4)) { | |
2254 | p->options.carp_key.path=1; | |
2255 | } else if (0==strncasecmp(key,"params",6)) { | |
2256 | p->options.carp_key.params=1; | |
2257 | } else { | |
2258 | fatalf("invalid carp-key '%s'",key); | |
2259 | } | |
de03b596 | 2260 | } |
f7e1d9ce | 2261 | } else if (!strcasecmp(token, "userhash")) { |
2f1431ea | 2262 | #if USE_AUTH |
f7e1d9ce HN |
2263 | if (p->type != PEER_PARENT) |
2264 | fatalf("parse_peer: non-parent userhash peer %s/%d\n", p->host, p->http_port); | |
2265 | ||
2266 | p->options.userhash = 1; | |
2f1431ea AJ |
2267 | #else |
2268 | fatalf("parse_peer: userhash requires authentication. peer %s/%d\n", p->host, p->http_port); | |
2269 | #endif | |
f7e1d9ce HN |
2270 | } else if (!strcasecmp(token, "sourcehash")) { |
2271 | if (p->type != PEER_PARENT) | |
2272 | fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p->host, p->http_port); | |
2273 | ||
2274 | p->options.sourcehash = 1; | |
2275 | ||
62e76326 | 2276 | } else if (!strcasecmp(token, "no-delay")) { |
9a0a18de | 2277 | #if USE_DELAY_POOLS |
62e76326 | 2278 | p->options.no_delay = 1; |
9a0a18de AJ |
2279 | #else |
2280 | debugs(0, DBG_CRITICAL, "WARNING: cache_peer option 'no-delay' requires --enable-delay-pools"); | |
afd88fbe | 2281 | #endif |
62e76326 | 2282 | } else if (!strncasecmp(token, "login=", 6)) { |
2283 | p->login = xstrdup(token + 6); | |
2284 | rfc1738_unescape(p->login); | |
2285 | } else if (!strncasecmp(token, "connect-timeout=", 16)) { | |
2286 | p->connect_timeout = xatoi(token + 16); | |
ff9970cc AJ |
2287 | } else if (!strncasecmp(token, "connect-fail-limit=", 19)) { |
2288 | p->connect_fail_limit = xatoi(token + 19); | |
7e3ce7b9 | 2289 | #if USE_CACHE_DIGESTS |
62e76326 | 2290 | } else if (!strncasecmp(token, "digest-url=", 11)) { |
2291 | p->digest_url = xstrdup(token + 11); | |
7e3ce7b9 | 2292 | #endif |
62e76326 | 2293 | |
2294 | } else if (!strcasecmp(token, "allow-miss")) { | |
2295 | p->options.allow_miss = 1; | |
2296 | } else if (!strncasecmp(token, "max-conn=", 9)) { | |
2297 | p->max_conn = xatoi(token + 9); | |
2298 | } else if (!strcasecmp(token, "originserver")) { | |
2299 | p->options.originserver = 1; | |
2300 | } else if (!strncasecmp(token, "name=", 5)) { | |
2301 | safe_free(p->name); | |
2302 | ||
2303 | if (token[5]) | |
2304 | p->name = xstrdup(token + 5); | |
2305 | } else if (!strncasecmp(token, "forceddomain=", 13)) { | |
2306 | safe_free(p->domain); | |
2307 | ||
2308 | if (token[13]) | |
2309 | p->domain = xstrdup(token + 13); | |
2310 | ||
a7ad6e4e | 2311 | #if USE_SSL |
62e76326 | 2312 | |
2313 | } else if (strcmp(token, "ssl") == 0) { | |
2314 | p->use_ssl = 1; | |
2315 | } else if (strncmp(token, "sslcert=", 8) == 0) { | |
2316 | safe_free(p->sslcert); | |
2317 | p->sslcert = xstrdup(token + 8); | |
2318 | } else if (strncmp(token, "sslkey=", 7) == 0) { | |
2319 | safe_free(p->sslkey); | |
2320 | p->sslkey = xstrdup(token + 7); | |
2321 | } else if (strncmp(token, "sslversion=", 11) == 0) { | |
2322 | p->sslversion = atoi(token + 11); | |
2323 | } else if (strncmp(token, "ssloptions=", 11) == 0) { | |
2324 | safe_free(p->ssloptions); | |
2325 | p->ssloptions = xstrdup(token + 11); | |
2326 | } else if (strncmp(token, "sslcipher=", 10) == 0) { | |
2327 | safe_free(p->sslcipher); | |
2328 | p->sslcipher = xstrdup(token + 10); | |
2329 | } else if (strncmp(token, "sslcafile=", 10) == 0) { | |
2330 | safe_free(p->sslcafile); | |
a82a4fe4 | 2331 | p->sslcafile = xstrdup(token + 10); |
62e76326 | 2332 | } else if (strncmp(token, "sslcapath=", 10) == 0) { |
2333 | safe_free(p->sslcapath); | |
a82a4fe4 | 2334 | p->sslcapath = xstrdup(token + 10); |
2335 | } else if (strncmp(token, "sslcrlfile=", 11) == 0) { | |
2336 | safe_free(p->sslcrlfile); | |
2337 | p->sslcapath = xstrdup(token + 10); | |
62e76326 | 2338 | } else if (strncmp(token, "sslflags=", 9) == 0) { |
2339 | safe_free(p->sslflags); | |
2340 | p->sslflags = xstrdup(token + 9); | |
2341 | } else if (strncmp(token, "ssldomain=", 10) == 0) { | |
2342 | safe_free(p->ssldomain); | |
2343 | p->ssldomain = xstrdup(token + 10); | |
a7ad6e4e | 2344 | #endif |
62e76326 | 2345 | |
2346 | } else if (strcmp(token, "front-end-https") == 0) { | |
2347 | p->front_end_https = 1; | |
2348 | } else if (strcmp(token, "front-end-https=on") == 0) { | |
2349 | p->front_end_https = 1; | |
2350 | } else if (strcmp(token, "front-end-https=auto") == 0) { | |
2351 | p->front_end_https = 2; | |
26ac0430 | 2352 | } else if (strcmp(token, "connection-auth=off") == 0) { |
d67acb4e AJ |
2353 | p->connection_auth = 0; |
2354 | } else if (strcmp(token, "connection-auth") == 0) { | |
2355 | p->connection_auth = 1; | |
2356 | } else if (strcmp(token, "connection-auth=on") == 0) { | |
2357 | p->connection_auth = 1; | |
2358 | } else if (strcmp(token, "connection-auth=auto") == 0) { | |
2359 | p->connection_auth = 2; | |
62e76326 | 2360 | } else { |
bf8fe701 | 2361 | debugs(3, 0, "parse_peer: token='" << token << "'"); |
62e76326 | 2362 | self_destruct(); |
2363 | } | |
270b86af | 2364 | } |
62e76326 | 2365 | |
be753325 | 2366 | if (peerFindByName(p->name)) |
62e76326 | 2367 | fatalf("ERROR: cache_peer %s specified twice\n", p->name); |
2368 | ||
40a1495e | 2369 | if (p->weight < 1) |
62e76326 | 2370 | p->weight = 1; |
2371 | ||
ff9970cc | 2372 | if (p->connect_fail_limit < 1) |
a4d889e0 | 2373 | p->connect_fail_limit = 10; |
ff9970cc | 2374 | |
399cabec | 2375 | p->icp.version = ICP_VERSION_CURRENT; |
62e76326 | 2376 | |
cfd66529 | 2377 | p->testing_now = false; |
62e76326 | 2378 | |
e13ee7ad | 2379 | #if USE_CACHE_DIGESTS |
62e76326 | 2380 | |
e13ee7ad | 2381 | if (!p->options.no_digest) { |
62e76326 | 2382 | /* XXX This looks odd.. who has the original pointer |
2383 | * then? | |
2384 | */ | |
2385 | PeerDigest *pd = peerDigestCreate(p); | |
2386 | p->digest = cbdataReference(pd); | |
8a6218c6 | 2387 | } |
62e76326 | 2388 | |
e13ee7ad | 2389 | #endif |
cc192b50 | 2390 | |
2391 | p->index = ++Config.npeers; | |
2392 | ||
0153d498 | 2393 | while (*head != NULL) |
62e76326 | 2394 | head = &(*head)->next; |
2395 | ||
0153d498 | 2396 | *head = p; |
62e76326 | 2397 | |
32a47e3e | 2398 | peerClearRRStart(); |
0153d498 | 2399 | } |
2400 | ||
2401 | static void | |
40a1495e | 2402 | free_peer(peer ** P) |
0153d498 | 2403 | { |
40a1495e | 2404 | peer *p; |
62e76326 | 2405 | |
79d39a72 | 2406 | while ((p = *P) != NULL) { |
62e76326 | 2407 | *P = p->next; |
3855c318 | 2408 | #if USE_CACHE_DIGESTS |
62e76326 | 2409 | |
2410 | cbdataReferenceDone(p->digest); | |
3855c318 | 2411 | #endif |
62e76326 | 2412 | |
2413 | cbdataFree(p); | |
a47b9029 | 2414 | } |
62e76326 | 2415 | |
987c67d1 | 2416 | Config.npeers = 0; |
270b86af | 2417 | } |
2418 | ||
2419 | static void | |
a7d59104 | 2420 | dump_cachemgrpasswd(StoreEntry * entry, const char *name, cachemgr_passwd * list) |
270b86af | 2421 | { |
d41de3c1 | 2422 | wordlist *w; |
62e76326 | 2423 | |
d41de3c1 | 2424 | while (list != NULL) { |
62e76326 | 2425 | if (strcmp(list->passwd, "none") && strcmp(list->passwd, "disable")) |
2426 | storeAppendPrintf(entry, "%s XXXXXXXXXX", name); | |
2427 | else | |
2428 | storeAppendPrintf(entry, "%s %s", name, list->passwd); | |
2429 | ||
2430 | for (w = list->actions; w != NULL; w = w->next) { | |
2431 | storeAppendPrintf(entry, " %s", w->key); | |
2432 | } | |
2433 | ||
2434 | storeAppendPrintf(entry, "\n"); | |
2435 | list = list->next; | |
d41de3c1 | 2436 | } |
270b86af | 2437 | } |
2438 | ||
2439 | static void | |
a47b9029 | 2440 | parse_cachemgrpasswd(cachemgr_passwd ** head) |
270b86af | 2441 | { |
2442 | char *passwd = NULL; | |
2443 | wordlist *actions = NULL; | |
22f3fd98 | 2444 | cachemgr_passwd *p; |
2445 | cachemgr_passwd **P; | |
270b86af | 2446 | parse_string(&passwd); |
2447 | parse_wordlist(&actions); | |
e6ccf245 | 2448 | p = static_cast<cachemgr_passwd *>(xcalloc(1, sizeof(cachemgr_passwd))); |
22f3fd98 | 2449 | p->passwd = passwd; |
2450 | p->actions = actions; | |
62e76326 | 2451 | |
26aa7e31 | 2452 | for (P = head; *P; P = &(*P)->next) { |
62e76326 | 2453 | /* |
2454 | * See if any of the actions from this line already have a | |
2455 | * password from previous lines. The password checking | |
2456 | * routines in cache_manager.c take the the password from | |
2457 | * the first cachemgr_passwd struct that contains the | |
2458 | * requested action. Thus, we should warn users who might | |
2459 | * think they can have two passwords for the same action. | |
2460 | */ | |
2461 | wordlist *w; | |
2462 | wordlist *u; | |
2463 | ||
2464 | for (w = (*P)->actions; w; w = w->next) { | |
2465 | for (u = actions; u; u = u->next) { | |
2466 | if (strcmp(w->key, u->key)) | |
2467 | continue; | |
2468 | ||
bf8fe701 | 2469 | debugs(0, 0, "WARNING: action '" << u->key << "' (line " << config_lineno << ") already has a password"); |
62e76326 | 2470 | } |
2471 | } | |
26aa7e31 | 2472 | } |
62e76326 | 2473 | |
22f3fd98 | 2474 | *P = p; |
270b86af | 2475 | } |
2476 | ||
2477 | static void | |
a47b9029 | 2478 | free_cachemgrpasswd(cachemgr_passwd ** head) |
270b86af | 2479 | { |
a47b9029 | 2480 | cachemgr_passwd *p; |
62e76326 | 2481 | |
79d39a72 | 2482 | while ((p = *head) != NULL) { |
62e76326 | 2483 | *head = p->next; |
2484 | xfree(p->passwd); | |
2485 | wordlistDestroy(&p->actions); | |
2486 | xfree(p); | |
a47b9029 | 2487 | } |
270b86af | 2488 | } |
2489 | ||
8203a132 | 2490 | static void |
16300b58 | 2491 | dump_denyinfo(StoreEntry * entry, const char *name, acl_deny_info_list * var) |
270b86af | 2492 | { |
d41de3c1 | 2493 | acl_name_list *a; |
62e76326 | 2494 | |
d41de3c1 | 2495 | while (var != NULL) { |
62e76326 | 2496 | storeAppendPrintf(entry, "%s %s", name, var->err_page_name); |
2497 | ||
2498 | for (a = var->acl_list; a != NULL; a = a->next) | |
2499 | storeAppendPrintf(entry, " %s", a->name); | |
2500 | ||
2501 | storeAppendPrintf(entry, "\n"); | |
2502 | ||
2503 | var = var->next; | |
d41de3c1 | 2504 | } |
270b86af | 2505 | } |
2506 | ||
2507 | static void | |
16300b58 | 2508 | parse_denyinfo(acl_deny_info_list ** var) |
6e40f263 | 2509 | { |
f1dc9b30 | 2510 | aclParseDenyInfoLine(var); |
6e40f263 | 2511 | } |
403279e0 | 2512 | |
1273d501 | 2513 | void |
a47b9029 | 2514 | free_denyinfo(acl_deny_info_list ** list) |
3c5557f9 | 2515 | { |
56b63fa1 | 2516 | acl_deny_info_list *a = NULL; |
2517 | acl_deny_info_list *a_next = NULL; | |
2518 | acl_name_list *l = NULL; | |
2519 | acl_name_list *l_next = NULL; | |
62e76326 | 2520 | |
1273d501 | 2521 | for (a = *list; a; a = a_next) { |
62e76326 | 2522 | for (l = a->acl_list; l; l = l_next) { |
2523 | l_next = l->next; | |
2524 | memFree(l, MEM_ACL_NAME_LIST); | |
2525 | l = NULL; | |
2526 | } | |
2527 | ||
2528 | a_next = a->next; | |
2529 | memFree(a, MEM_ACL_DENY_INFO_LIST); | |
2530 | a = NULL; | |
1273d501 | 2531 | } |
62e76326 | 2532 | |
1273d501 | 2533 | *list = NULL; |
270b86af | 2534 | } |
2535 | ||
2536 | static void | |
505e35db | 2537 | parse_peer_access(void) |
270b86af | 2538 | { |
2539 | char *host = NULL; | |
505e35db | 2540 | peer *p; |
62e76326 | 2541 | |
270b86af | 2542 | if (!(host = strtok(NULL, w_space))) |
62e76326 | 2543 | self_destruct(); |
2544 | ||
0cdcddb9 | 2545 | if ((p = peerFindByName(host)) == NULL) { |
bf8fe701 | 2546 | debugs(15, 0, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'"); |
62e76326 | 2547 | return; |
0cdcddb9 | 2548 | } |
62e76326 | 2549 | |
a9f20260 | 2550 | aclParseAccessLine(LegacyParser, &p->access); |
270b86af | 2551 | } |
2552 | ||
270b86af | 2553 | static void |
2554 | parse_hostdomain(void) | |
2555 | { | |
2556 | char *host = NULL; | |
2557 | char *domain = NULL; | |
62e76326 | 2558 | |
270b86af | 2559 | if (!(host = strtok(NULL, w_space))) |
62e76326 | 2560 | self_destruct(); |
2561 | ||
f1dc9b30 | 2562 | while ((domain = strtok(NULL, list_sep))) { |
62e76326 | 2563 | domain_ping *l = NULL; |
2564 | domain_ping **L = NULL; | |
2565 | peer *p; | |
2566 | ||
2567 | if ((p = peerFindByName(host)) == NULL) { | |
bf8fe701 | 2568 | debugs(15, 0, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'"); |
62e76326 | 2569 | continue; |
2570 | } | |
2571 | ||
2572 | l = static_cast<domain_ping *>(xcalloc(1, sizeof(domain_ping))); | |
2573 | l->do_ping = 1; | |
2574 | ||
2575 | if (*domain == '!') { /* check for !.edu */ | |
2576 | l->do_ping = 0; | |
2577 | domain++; | |
2578 | } | |
2579 | ||
2580 | l->domain = xstrdup(domain); | |
2581 | ||
3d0ac046 | 2582 | for (L = &(p->peer_domain); *L; L = &((*L)->next)); |
62e76326 | 2583 | *L = l; |
f1dc9b30 | 2584 | } |
270b86af | 2585 | } |
2586 | ||
2587 | static void | |
2588 | parse_hostdomaintype(void) | |
2589 | { | |
2590 | char *host = NULL; | |
2591 | char *type = NULL; | |
2592 | char *domain = NULL; | |
62e76326 | 2593 | |
270b86af | 2594 | if (!(host = strtok(NULL, w_space))) |
62e76326 | 2595 | self_destruct(); |
2596 | ||
270b86af | 2597 | if (!(type = strtok(NULL, w_space))) |
62e76326 | 2598 | self_destruct(); |
2599 | ||
f1dc9b30 | 2600 | while ((domain = strtok(NULL, list_sep))) { |
62e76326 | 2601 | domain_type *l = NULL; |
2602 | domain_type **L = NULL; | |
2603 | peer *p; | |
2604 | ||
2605 | if ((p = peerFindByName(host)) == NULL) { | |
bf8fe701 | 2606 | debugs(15, 0, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'"); |
62e76326 | 2607 | return; |
2608 | } | |
2609 | ||
2610 | l = static_cast<domain_type *>(xcalloc(1, sizeof(domain_type))); | |
2611 | l->type = parseNeighborType(type); | |
2612 | l->domain = xstrdup(domain); | |
2613 | ||
3d0ac046 | 2614 | for (L = &(p->typelist); *L; L = &((*L)->next)); |
62e76326 | 2615 | *L = l; |
f1dc9b30 | 2616 | } |
270b86af | 2617 | } |
2618 | ||
270b86af | 2619 | static void |
a7d59104 | 2620 | dump_int(StoreEntry * entry, const char *name, int var) |
270b86af | 2621 | { |
f53b06f9 | 2622 | storeAppendPrintf(entry, "%s %d\n", name, var); |
270b86af | 2623 | } |
c1c29eb6 | 2624 | |
94439e4e | 2625 | void |
270b86af | 2626 | parse_int(int *var) |
2627 | { | |
270b86af | 2628 | int i; |
0e4e0e7d | 2629 | i = GetInteger(); |
270b86af | 2630 | *var = i; |
2631 | } | |
090089c4 | 2632 | |
0153d498 | 2633 | static void |
2634 | free_int(int *var) | |
2635 | { | |
a47b9029 | 2636 | *var = 0; |
0153d498 | 2637 | } |
2638 | ||
270b86af | 2639 | static void |
a7d59104 | 2640 | dump_onoff(StoreEntry * entry, const char *name, int var) |
270b86af | 2641 | { |
f53b06f9 | 2642 | storeAppendPrintf(entry, "%s %s\n", name, var ? "on" : "off"); |
270b86af | 2643 | } |
090089c4 | 2644 | |
d205783b | 2645 | void |
270b86af | 2646 | parse_onoff(int *var) |
2647 | { | |
2648 | char *token = strtok(NULL, w_space); | |
090089c4 | 2649 | |
270b86af | 2650 | if (token == NULL) |
62e76326 | 2651 | self_destruct(); |
2652 | ||
270b86af | 2653 | if (!strcasecmp(token, "on") || !strcasecmp(token, "enable")) |
62e76326 | 2654 | *var = 1; |
270b86af | 2655 | else |
62e76326 | 2656 | *var = 0; |
270b86af | 2657 | } |
e90100aa | 2658 | |
0153d498 | 2659 | #define free_onoff free_int |
52d3f198 | 2660 | |
2661 | static void | |
2662 | dump_tristate(StoreEntry * entry, const char *name, int var) | |
2663 | { | |
2664 | const char *state; | |
2665 | ||
2666 | if (var > 0) | |
2667 | state = "on"; | |
2668 | else if (var < 0) | |
2669 | state = "warn"; | |
2670 | else | |
2671 | state = "off"; | |
2672 | ||
2673 | storeAppendPrintf(entry, "%s %s\n", name, state); | |
2674 | } | |
2675 | ||
2676 | static void | |
2677 | parse_tristate(int *var) | |
2678 | { | |
2679 | char *token = strtok(NULL, w_space); | |
2680 | ||
2681 | if (token == NULL) | |
2682 | self_destruct(); | |
2683 | ||
2684 | if (!strcasecmp(token, "on") || !strcasecmp(token, "enable")) | |
2685 | *var = 1; | |
2686 | else if (!strcasecmp(token, "warn")) | |
2687 | *var = -1; | |
2688 | else | |
2689 | *var = 0; | |
2690 | } | |
2691 | ||
2692 | #define free_tristate free_int | |
30a4f2a8 | 2693 | |
270b86af | 2694 | static void |
a7d59104 | 2695 | dump_refreshpattern(StoreEntry * entry, const char *name, refresh_t * head) |
270b86af | 2696 | { |
d41de3c1 | 2697 | while (head != NULL) { |
0e1d7629 | 2698 | storeAppendPrintf(entry, "%s%s %s %d %d%% %d", |
62e76326 | 2699 | name, |
2700 | head->flags.icase ? " -i" : null_string, | |
2701 | head->pattern, | |
2702 | (int) head->min / 60, | |
2703 | (int) (100.0 * head->pct + 0.5), | |
2704 | (int) head->max / 60); | |
4c3ef9b2 | 2705 | |
570d3f75 AJ |
2706 | if (head->max_stale >= 0) |
2707 | storeAppendPrintf(entry, " max-stale=%d", head->max_stale); | |
2708 | ||
4c3ef9b2 | 2709 | if (head->flags.refresh_ims) |
2710 | storeAppendPrintf(entry, " refresh-ims"); | |
2711 | ||
3d8b6ba4 AJ |
2712 | if (head->flags.store_stale) |
2713 | storeAppendPrintf(entry, " store-stale"); | |
2714 | ||
626096be | 2715 | #if USE_HTTP_VIOLATIONS |
62e76326 | 2716 | |
2717 | if (head->flags.override_expire) | |
2718 | storeAppendPrintf(entry, " override-expire"); | |
2719 | ||
2720 | if (head->flags.override_lastmod) | |
2721 | storeAppendPrintf(entry, " override-lastmod"); | |
2722 | ||
2723 | if (head->flags.reload_into_ims) | |
2724 | storeAppendPrintf(entry, " reload-into-ims"); | |
2725 | ||
2726 | if (head->flags.ignore_reload) | |
2727 | storeAppendPrintf(entry, " ignore-reload"); | |
2728 | ||
38f9c547 | 2729 | if (head->flags.ignore_no_cache) |
2730 | storeAppendPrintf(entry, " ignore-no-cache"); | |
2731 | ||
2732 | if (head->flags.ignore_no_store) | |
2733 | storeAppendPrintf(entry, " ignore-no-store"); | |
2734 | ||
4ca08219 AJ |
2735 | if (head->flags.ignore_must_revalidate) |
2736 | storeAppendPrintf(entry, " ignore-must-revalidate"); | |
2737 | ||
38f9c547 | 2738 | if (head->flags.ignore_private) |
2739 | storeAppendPrintf(entry, " ignore-private"); | |
2740 | ||
2741 | if (head->flags.ignore_auth) | |
2742 | storeAppendPrintf(entry, " ignore-auth"); | |
2743 | ||
9f60cfdf | 2744 | #endif |
62e76326 | 2745 | |
2746 | storeAppendPrintf(entry, "\n"); | |
2747 | ||
2748 | head = head->next; | |
d41de3c1 | 2749 | } |
270b86af | 2750 | } |
090089c4 | 2751 | |
270b86af | 2752 | static void |
f1dc9b30 | 2753 | parse_refreshpattern(refresh_t ** head) |
270b86af | 2754 | { |
f1dc9b30 | 2755 | char *token; |
2756 | char *pattern; | |
2757 | time_t min = 0; | |
c3f6d204 | 2758 | double pct = 0.0; |
f1dc9b30 | 2759 | time_t max = 0; |
4c3ef9b2 | 2760 | int refresh_ims = 0; |
3d8b6ba4 | 2761 | int store_stale = 0; |
570d3f75 | 2762 | int max_stale = -1; |
3d8b6ba4 | 2763 | |
626096be | 2764 | #if USE_HTTP_VIOLATIONS |
62e76326 | 2765 | |
1dfa1d81 | 2766 | int override_expire = 0; |
2767 | int override_lastmod = 0; | |
cbe3a719 | 2768 | int reload_into_ims = 0; |
2769 | int ignore_reload = 0; | |
38f9c547 | 2770 | int ignore_no_cache = 0; |
2771 | int ignore_no_store = 0; | |
4ca08219 | 2772 | int ignore_must_revalidate = 0; |
38f9c547 | 2773 | int ignore_private = 0; |
2774 | int ignore_auth = 0; | |
9f60cfdf | 2775 | #endif |
62e76326 | 2776 | |
f1dc9b30 | 2777 | int i; |
2778 | refresh_t *t; | |
2779 | regex_t comp; | |
2780 | int errcode; | |
2781 | int flags = REG_EXTENDED | REG_NOSUB; | |
62e76326 | 2782 | |
9eeb8e4b | 2783 | if ((token = strtok(NULL, w_space)) == NULL) { |
62e76326 | 2784 | self_destruct(); |
9eeb8e4b | 2785 | return; |
2786 | } | |
62e76326 | 2787 | |
f1dc9b30 | 2788 | if (strcmp(token, "-i") == 0) { |
62e76326 | 2789 | flags |= REG_ICASE; |
2790 | token = strtok(NULL, w_space); | |
f1dc9b30 | 2791 | } else if (strcmp(token, "+i") == 0) { |
62e76326 | 2792 | flags &= ~REG_ICASE; |
2793 | token = strtok(NULL, w_space); | |
f1dc9b30 | 2794 | } |
62e76326 | 2795 | |
9eeb8e4b | 2796 | if (token == NULL) { |
62e76326 | 2797 | self_destruct(); |
9eeb8e4b | 2798 | return; |
2799 | } | |
62e76326 | 2800 | |
f1dc9b30 | 2801 | pattern = xstrdup(token); |
62e76326 | 2802 | |
0e4e0e7d | 2803 | i = GetInteger(); /* token: min */ |
62e76326 | 2804 | |
a632ba71 AJ |
2805 | /* catch negative and insanely huge values close to 32-bit wrap */ |
2806 | if (i < 0) { | |
2807 | debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern minimum age negative. Cropped back to zero."); | |
2808 | i = 0; | |
2809 | } | |
2810 | if (i > 60*24*365) { | |
2811 | debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern minimum age too high. Cropped back to 1 year."); | |
2812 | i = 60*24*365; | |
2813 | } | |
2814 | ||
f1dc9b30 | 2815 | min = (time_t) (i * 60); /* convert minutes to seconds */ |
62e76326 | 2816 | |
0e4e0e7d | 2817 | i = GetInteger(); /* token: pct */ |
62e76326 | 2818 | |
c3f6d204 | 2819 | pct = (double) i / 100.0; |
62e76326 | 2820 | |
0e4e0e7d | 2821 | i = GetInteger(); /* token: max */ |
62e76326 | 2822 | |
a632ba71 AJ |
2823 | /* catch negative and insanely huge values close to 32-bit wrap */ |
2824 | if (i < 0) { | |
2825 | debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern maximum age negative. Cropped back to zero."); | |
2826 | i = 0; | |
2827 | } | |
2828 | if (i > 60*24*365) { | |
2829 | debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern maximum age too high. Cropped back to 1 year."); | |
2830 | i = 60*24*365; | |
2831 | } | |
2832 | ||
f1dc9b30 | 2833 | max = (time_t) (i * 60); /* convert minutes to seconds */ |
62e76326 | 2834 | |
1dfa1d81 | 2835 | /* Options */ |
2836 | while ((token = strtok(NULL, w_space)) != NULL) { | |
4c3ef9b2 | 2837 | if (!strcmp(token, "refresh-ims")) { |
2838 | refresh_ims = 1; | |
3d8b6ba4 AJ |
2839 | } else if (!strcmp(token, "store-stale")) { |
2840 | store_stale = 1; | |
570d3f75 AJ |
2841 | } else if (!strncmp(token, "max-stale=", 10)) { |
2842 | max_stale = atoi(token + 10); | |
626096be | 2843 | #if USE_HTTP_VIOLATIONS |
62e76326 | 2844 | |
4c3ef9b2 | 2845 | } else if (!strcmp(token, "override-expire")) |
62e76326 | 2846 | override_expire = 1; |
2847 | else if (!strcmp(token, "override-lastmod")) | |
2848 | override_lastmod = 1; | |
38f9c547 | 2849 | else if (!strcmp(token, "ignore-no-cache")) |
2850 | ignore_no_cache = 1; | |
2851 | else if (!strcmp(token, "ignore-no-store")) | |
2852 | ignore_no_store = 1; | |
4ca08219 AJ |
2853 | else if (!strcmp(token, "ignore-must-revalidate")) |
2854 | ignore_must_revalidate = 1; | |
38f9c547 | 2855 | else if (!strcmp(token, "ignore-private")) |
2856 | ignore_private = 1; | |
2857 | else if (!strcmp(token, "ignore-auth")) | |
2858 | ignore_auth = 1; | |
62e76326 | 2859 | else if (!strcmp(token, "reload-into-ims")) { |
2860 | reload_into_ims = 1; | |
2861 | refresh_nocache_hack = 1; | |
2862 | /* tell client_side.c that this is used */ | |
2863 | } else if (!strcmp(token, "ignore-reload")) { | |
2864 | ignore_reload = 1; | |
2865 | refresh_nocache_hack = 1; | |
2866 | /* tell client_side.c that this is used */ | |
9f60cfdf | 2867 | #endif |
62e76326 | 2868 | |
4c3ef9b2 | 2869 | } else |
570d3f75 | 2870 | debugs(22, 0, "refreshAddToList: Unknown option '" << pattern << "': " << token); |
1dfa1d81 | 2871 | } |
62e76326 | 2872 | |
f1dc9b30 | 2873 | if ((errcode = regcomp(&comp, pattern, flags)) != 0) { |
62e76326 | 2874 | char errbuf[256]; |
2875 | regerror(errcode, &comp, errbuf, sizeof errbuf); | |
bf8fe701 | 2876 | debugs(22, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line); |
2877 | debugs(22, 0, "refreshAddToList: Invalid regular expression '" << pattern << "': " << errbuf); | |
62e76326 | 2878 | return; |
f1dc9b30 | 2879 | } |
62e76326 | 2880 | |
c3f6d204 | 2881 | pct = pct < 0.0 ? 0.0 : pct; |
f1dc9b30 | 2882 | max = max < 0 ? 0 : max; |
e6ccf245 | 2883 | t = static_cast<refresh_t *>(xcalloc(1, sizeof(refresh_t))); |
f1dc9b30 | 2884 | t->pattern = (char *) xstrdup(pattern); |
2885 | t->compiled_pattern = comp; | |
2886 | t->min = min; | |
c3f6d204 | 2887 | t->pct = pct; |
f1dc9b30 | 2888 | t->max = max; |
62e76326 | 2889 | |
c3f6d204 | 2890 | if (flags & REG_ICASE) |
62e76326 | 2891 | t->flags.icase = 1; |
2892 | ||
4c3ef9b2 | 2893 | if (refresh_ims) |
2894 | t->flags.refresh_ims = 1; | |
2895 | ||
3d8b6ba4 AJ |
2896 | if (store_stale) |
2897 | t->flags.store_stale = 1; | |
2898 | ||
570d3f75 AJ |
2899 | t->max_stale = max_stale; |
2900 | ||
626096be | 2901 | #if USE_HTTP_VIOLATIONS |
62e76326 | 2902 | |
1dfa1d81 | 2903 | if (override_expire) |
62e76326 | 2904 | t->flags.override_expire = 1; |
2905 | ||
1dfa1d81 | 2906 | if (override_lastmod) |
62e76326 | 2907 | t->flags.override_lastmod = 1; |
2908 | ||
cbe3a719 | 2909 | if (reload_into_ims) |
62e76326 | 2910 | t->flags.reload_into_ims = 1; |
2911 | ||
cbe3a719 | 2912 | if (ignore_reload) |
62e76326 | 2913 | t->flags.ignore_reload = 1; |
2914 | ||
38f9c547 | 2915 | if (ignore_no_cache) |
2916 | t->flags.ignore_no_cache = 1; | |
2917 | ||
2918 | if (ignore_no_store) | |
2919 | t->flags.ignore_no_store = 1; | |
2920 | ||
4ca08219 AJ |
2921 | if (ignore_must_revalidate) |
2922 | t->flags.ignore_must_revalidate = 1; | |
2923 | ||
38f9c547 | 2924 | if (ignore_private) |
2925 | t->flags.ignore_private = 1; | |
2926 | ||
2927 | if (ignore_auth) | |
2928 | t->flags.ignore_auth = 1; | |
2929 | ||
9f60cfdf | 2930 | #endif |
62e76326 | 2931 | |
f1dc9b30 | 2932 | t->next = NULL; |
62e76326 | 2933 | |
f1dc9b30 | 2934 | while (*head) |
62e76326 | 2935 | head = &(*head)->next; |
2936 | ||
f1dc9b30 | 2937 | *head = t; |
62e76326 | 2938 | |
f1dc9b30 | 2939 | safe_free(pattern); |
270b86af | 2940 | } |
090089c4 | 2941 | |
270b86af | 2942 | static void |
a47b9029 | 2943 | free_refreshpattern(refresh_t ** head) |
270b86af | 2944 | { |
f1dc9b30 | 2945 | refresh_t *t; |
62e76326 | 2946 | |
79d39a72 | 2947 | while ((t = *head) != NULL) { |
62e76326 | 2948 | *head = t->next; |
2949 | safe_free(t->pattern); | |
2950 | regfree(&t->compiled_pattern); | |
2951 | safe_free(t); | |
f1dc9b30 | 2952 | } |
c2066637 | 2953 | |
626096be | 2954 | #if USE_HTTP_VIOLATIONS |
c2066637 | 2955 | refresh_nocache_hack = 0; |
8970d351 | 2956 | |
2957 | #endif | |
270b86af | 2958 | } |
12b9e9b1 | 2959 | |
270b86af | 2960 | static void |
a7d59104 | 2961 | dump_string(StoreEntry * entry, const char *name, char *var) |
270b86af | 2962 | { |
f53b06f9 | 2963 | if (var != NULL) |
62e76326 | 2964 | storeAppendPrintf(entry, "%s %s\n", name, var); |
270b86af | 2965 | } |
98ffb7e4 | 2966 | |
270b86af | 2967 | static void |
0153d498 | 2968 | parse_string(char **var) |
270b86af | 2969 | { |
2970 | char *token = strtok(NULL, w_space); | |
270b86af | 2971 | safe_free(*var); |
62e76326 | 2972 | |
270b86af | 2973 | if (token == NULL) |
62e76326 | 2974 | self_destruct(); |
2975 | ||
270b86af | 2976 | *var = xstrdup(token); |
2977 | } | |
b15e6857 | 2978 | |
3a69ddf3 | 2979 | void |
2980 | ConfigParser::ParseString(char **var) | |
2981 | { | |
2982 | parse_string(var); | |
2983 | } | |
2984 | ||
2985 | void | |
30abd221 | 2986 | ConfigParser::ParseString(String *var) |
3a69ddf3 | 2987 | { |
2988 | char *token = strtok(NULL, w_space); | |
2989 | ||
2990 | if (token == NULL) | |
2991 | self_destruct(); | |
2992 | ||
30abd221 | 2993 | var->reset(token); |
3a69ddf3 | 2994 | } |
2995 | ||
0153d498 | 2996 | static void |
2997 | free_string(char **var) | |
2998 | { | |
027acbaf | 2999 | safe_free(*var); |
0153d498 | 3000 | } |
caebbe00 | 3001 | |
94439e4e | 3002 | void |
f1dc9b30 | 3003 | parse_eol(char *volatile *var) |
270b86af | 3004 | { |
65657c1a AJ |
3005 | if (!var) { |
3006 | self_destruct(); | |
3007 | return; | |
3008 | } | |
3009 | ||
852751f7 | 3010 | unsigned char *token = (unsigned char *) strtok(NULL, null_string); |
270b86af | 3011 | safe_free(*var); |
62e76326 | 3012 | |
9eeb8e4b | 3013 | if (!token) { |
62e76326 | 3014 | self_destruct(); |
9eeb8e4b | 3015 | return; |
3016 | } | |
62e76326 | 3017 | |
e4755e29 | 3018 | while (*token && xisspace(*token)) |
62e76326 | 3019 | token++; |
3020 | ||
9eeb8e4b | 3021 | if (!*token) { |
62e76326 | 3022 | self_destruct(); |
9eeb8e4b | 3023 | return; |
3024 | } | |
62e76326 | 3025 | |
852751f7 | 3026 | *var = xstrdup((char *) token); |
270b86af | 3027 | } |
090089c4 | 3028 | |
52d3f198 | 3029 | #define dump_eol dump_string |
3030 | #define free_eol free_string | |
3031 | ||
270b86af | 3032 | static void |
a7d59104 | 3033 | dump_time_t(StoreEntry * entry, const char *name, time_t var) |
090089c4 | 3034 | { |
f53b06f9 | 3035 | storeAppendPrintf(entry, "%s %d seconds\n", name, (int) var); |
090089c4 | 3036 | } |
3037 | ||
94439e4e | 3038 | void |
a47b9029 | 3039 | parse_time_t(time_t * var) |
0ffd22bc | 3040 | { |
fd0f51c4 | 3041 | time_msec_t tval; |
9b741834 | 3042 | parseTimeLine(&tval, T_SECOND_STR, false); |
fd0f51c4 | 3043 | *var = static_cast<time_t>(tval/1000); |
0ffd22bc | 3044 | } |
3045 | ||
270b86af | 3046 | static void |
a47b9029 | 3047 | free_time_t(time_t * var) |
270b86af | 3048 | { |
a47b9029 | 3049 | *var = 0; |
270b86af | 3050 | } |
9906e724 | 3051 | |
9fc16f39 | 3052 | #if !USE_DNSSERVERS |
fd0f51c4 CT |
3053 | static void |
3054 | dump_time_msec(StoreEntry * entry, const char *name, time_msec_t var) | |
3055 | { | |
3056 | if (var % 1000) | |
3057 | storeAppendPrintf(entry, "%s %"PRId64" milliseconds\n", name, var); | |
3058 | else | |
3059 | storeAppendPrintf(entry, "%s %d seconds\n", name, (int)(var/1000) ); | |
3060 | } | |
3061 | ||
3062 | void | |
3063 | parse_time_msec(time_msec_t * var) | |
3064 | { | |
9b741834 | 3065 | parseTimeLine(var, T_SECOND_STR, true); |
fd0f51c4 CT |
3066 | } |
3067 | ||
3068 | static void | |
3069 | free_time_msec(time_msec_t * var) | |
3070 | { | |
3071 | *var = 0; | |
3072 | } | |
9fc16f39 | 3073 | #endif |
fd0f51c4 | 3074 | |
0477a072 | 3075 | #if UNUSED_CODE |
9906e724 | 3076 | static void |
a7d59104 | 3077 | dump_size_t(StoreEntry * entry, const char *name, size_t var) |
1b635117 | 3078 | { |
f53b06f9 | 3079 | storeAppendPrintf(entry, "%s %d\n", name, (int) var); |
1b635117 | 3080 | } |
0477a072 | 3081 | #endif |
1b635117 | 3082 | |
3083 | static void | |
a7d59104 | 3084 | dump_b_size_t(StoreEntry * entry, const char *name, size_t var) |
9906e724 | 3085 | { |
f53b06f9 | 3086 | storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_BYTES_STR); |
9906e724 | 3087 | } |
3088 | ||
e210930b AJ |
3089 | #if !USE_DNSSERVERS |
3090 | static void | |
3091 | dump_b_ssize_t(StoreEntry * entry, const char *name, ssize_t var) | |
3092 | { | |
3093 | storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_BYTES_STR); | |
3094 | } | |
3095 | #endif | |
3096 | ||
3e62bd58 | 3097 | #if UNUSED_CODE |
9906e724 | 3098 | static void |
a7d59104 | 3099 | dump_kb_size_t(StoreEntry * entry, const char *name, size_t var) |
9906e724 | 3100 | { |
f53b06f9 | 3101 | storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_KBYTES_STR); |
9906e724 | 3102 | } |
3e62bd58 | 3103 | #endif |
9906e724 | 3104 | |
47f6e231 | 3105 | static void |
3106 | dump_b_int64_t(StoreEntry * entry, const char *name, int64_t var) | |
3107 | { | |
3108 | storeAppendPrintf(entry, "%s %"PRId64" %s\n", name, var, B_BYTES_STR); | |
3109 | } | |
3110 | ||
3111 | static void | |
3112 | dump_kb_int64_t(StoreEntry * entry, const char *name, int64_t var) | |
3113 | { | |
3114 | storeAppendPrintf(entry, "%s %"PRId64" %s\n", name, var, B_KBYTES_STR); | |
3115 | } | |
3116 | ||
0477a072 | 3117 | #if UNUSED_CODE |
9906e724 | 3118 | static void |
a47b9029 | 3119 | parse_size_t(size_t * var) |
1b635117 | 3120 | { |
1b635117 | 3121 | int i; |
0e4e0e7d | 3122 | i = GetInteger(); |
1b635117 | 3123 | *var = (size_t) i; |
3124 | } | |
0477a072 | 3125 | #endif |
1b635117 | 3126 | |
3127 | static void | |
3128 | parse_b_size_t(size_t * var) | |
9906e724 | 3129 | { |
3130 | parseBytesLine(var, B_BYTES_STR); | |
3131 | } | |
3132 | ||
e210930b AJ |
3133 | #if !USE_DNSSERVERS |
3134 | static void | |
3135 | parse_b_ssize_t(ssize_t * var) | |
3136 | { | |
3137 | parseBytesLineSigned(var, B_BYTES_STR); | |
3138 | } | |
3139 | #endif | |
3140 | ||
3e62bd58 | 3141 | #if UNUSED_CODE |
9906e724 | 3142 | static void |
a47b9029 | 3143 | parse_kb_size_t(size_t * var) |
9906e724 | 3144 | { |
3145 | parseBytesLine(var, B_KBYTES_STR); | |
3146 | } | |
3e62bd58 | 3147 | #endif |
9906e724 | 3148 | |
47f6e231 | 3149 | static void |
3150 | parse_b_int64_t(int64_t * var) | |
3151 | { | |
3152 | parseBytesLine64(var, B_BYTES_STR); | |
3153 | } | |
3154 | ||
3155 | static void | |
3156 | parse_kb_int64_t(int64_t * var) | |
3157 | { | |
3158 | parseBytesLine64(var, B_KBYTES_STR); | |
3159 | } | |
3160 | ||
9906e724 | 3161 | static void |
a47b9029 | 3162 | free_size_t(size_t * var) |
9906e724 | 3163 | { |
a47b9029 | 3164 | *var = 0; |
9906e724 | 3165 | } |
3166 | ||
e210930b AJ |
3167 | #if !USE_DNSSERVERS |
3168 | static void | |
3169 | free_ssize_t(ssize_t * var) | |
3170 | { | |
3171 | *var = 0; | |
3172 | } | |
3173 | #endif | |
3174 | ||
47f6e231 | 3175 | static void |
3176 | free_b_int64_t(int64_t * var) | |
3177 | { | |
3178 | *var = 0; | |
3179 | } | |
3180 | ||
1b635117 | 3181 | #define free_b_size_t free_size_t |
e210930b | 3182 | #define free_b_ssize_t free_ssize_t |
9906e724 | 3183 | #define free_kb_size_t free_size_t |
3184 | #define free_mb_size_t free_size_t | |
3185 | #define free_gb_size_t free_size_t | |
47f6e231 | 3186 | #define free_kb_int64_t free_b_int64_t |
090089c4 | 3187 | |
8203a132 | 3188 | static void |
f45dd259 | 3189 | dump_u_short(StoreEntry * entry, const char *name, unsigned short var) |
090089c4 | 3190 | { |
f53b06f9 | 3191 | storeAppendPrintf(entry, "%s %d\n", name, var); |
270b86af | 3192 | } |
090089c4 | 3193 | |
0153d498 | 3194 | static void |
f45dd259 | 3195 | free_u_short(unsigned short * u) |
0153d498 | 3196 | { |
3197 | *u = 0; | |
3198 | } | |
3199 | ||
270b86af | 3200 | static void |
f45dd259 | 3201 | parse_u_short(unsigned short * var) |
b67e2c8c | 3202 | { |
3203 | ConfigParser::ParseUShort(var); | |
3204 | } | |
3205 | ||
3206 | void | |
f45dd259 | 3207 | ConfigParser::ParseUShort(unsigned short *var) |
270b86af | 3208 | { |
0e656b69 | 3209 | *var = GetShort(); |
090089c4 | 3210 | } |
3211 | ||
3a69ddf3 | 3212 | void |
3213 | ConfigParser::ParseBool(bool *var) | |
3214 | { | |
3215 | int i = GetInteger(); | |
3216 | ||
3217 | if (0 == i) | |
3218 | *var = false; | |
3219 | else if (1 == i) | |
3220 | *var = true; | |
3221 | else | |
3222 | self_destruct(); | |
3223 | } | |
3224 | ||
270b86af | 3225 | static void |
a7d59104 | 3226 | dump_wordlist(StoreEntry * entry, const char *name, wordlist * list) |
270b86af | 3227 | { |
270b86af | 3228 | while (list != NULL) { |
62e76326 | 3229 | storeAppendPrintf(entry, "%s %s\n", name, list->key); |
3230 | list = list->next; | |
429fdbec | 3231 | } |
429fdbec | 3232 | } |
3233 | ||
3a69ddf3 | 3234 | void |
3235 | ConfigParser::ParseWordList(wordlist ** list) | |
3236 | { | |
3237 | parse_wordlist(list); | |
3238 | } | |
3239 | ||
94439e4e | 3240 | void |
270b86af | 3241 | parse_wordlist(wordlist ** list) |
429fdbec | 3242 | { |
270b86af | 3243 | char *token; |
a3c6890f | 3244 | char *t = strtok(NULL, ""); |
62e76326 | 3245 | |
a3c6890f | 3246 | while ((token = strwordtok(NULL, &t))) |
62e76326 | 3247 | wordlistAdd(list, token); |
429fdbec | 3248 | } |
270b86af | 3249 | |
b3d8a9e8 | 3250 | #if 0 /* now unused */ |
f8d9f54a | 3251 | static int |
5da06f20 | 3252 | check_null_wordlist(wordlist * w) |
f8d9f54a | 3253 | { |
3254 | return w == NULL; | |
3255 | } | |
b3d8a9e8 | 3256 | #endif |
f8d9f54a | 3257 | |
63e9d884 | 3258 | static int |
c6d5b87b | 3259 | check_null_acl_access(acl_access * a) |
63e9d884 | 3260 | { |
3261 | return a == NULL; | |
3262 | } | |
3263 | ||
0153d498 | 3264 | #define free_wordlist wordlistDestroy |
270b86af | 3265 | |
d548ee64 | 3266 | #define free_uri_whitespace free_int |
3267 | ||
3268 | static void | |
3269 | parse_uri_whitespace(int *var) | |
3270 | { | |
3271 | char *token = strtok(NULL, w_space); | |
62e76326 | 3272 | |
d548ee64 | 3273 | if (token == NULL) |
62e76326 | 3274 | self_destruct(); |
3275 | ||
7e3ce7b9 | 3276 | if (!strcasecmp(token, "strip")) |
62e76326 | 3277 | *var = URI_WHITESPACE_STRIP; |
7e3ce7b9 | 3278 | else if (!strcasecmp(token, "deny")) |
62e76326 | 3279 | *var = URI_WHITESPACE_DENY; |
d548ee64 | 3280 | else if (!strcasecmp(token, "allow")) |
62e76326 | 3281 | *var = URI_WHITESPACE_ALLOW; |
d548ee64 | 3282 | else if (!strcasecmp(token, "encode")) |
62e76326 | 3283 | *var = URI_WHITESPACE_ENCODE; |
d548ee64 | 3284 | else if (!strcasecmp(token, "chop")) |
62e76326 | 3285 | *var = URI_WHITESPACE_CHOP; |
d548ee64 | 3286 | else |
62e76326 | 3287 | self_destruct(); |
d548ee64 | 3288 | } |
3289 | ||
d548ee64 | 3290 | static void |
3291 | dump_uri_whitespace(StoreEntry * entry, const char *name, int var) | |
3292 | { | |
c193c972 | 3293 | const char *s; |
62e76326 | 3294 | |
d548ee64 | 3295 | if (var == URI_WHITESPACE_ALLOW) |
62e76326 | 3296 | s = "allow"; |
d548ee64 | 3297 | else if (var == URI_WHITESPACE_ENCODE) |
62e76326 | 3298 | s = "encode"; |
d548ee64 | 3299 | else if (var == URI_WHITESPACE_CHOP) |
62e76326 | 3300 | s = "chop"; |
7e3ce7b9 | 3301 | else if (var == URI_WHITESPACE_DENY) |
62e76326 | 3302 | s = "deny"; |
7e3ce7b9 | 3303 | else |
62e76326 | 3304 | s = "strip"; |
3305 | ||
d548ee64 | 3306 | storeAppendPrintf(entry, "%s %s\n", name, s); |
3307 | } | |
3308 | ||
6a566b9c | 3309 | static void |
c1dd71ae | 3310 | free_removalpolicy(RemovalPolicySettings ** settings) |
6a566b9c | 3311 | { |
3312 | if (!*settings) | |
62e76326 | 3313 | return; |
3314 | ||
6a566b9c | 3315 | free_string(&(*settings)->type); |
62e76326 | 3316 | |
6a566b9c | 3317 | free_wordlist(&(*settings)->args); |
62e76326 | 3318 | |
c8f4eac4 | 3319 | delete *settings; |
62e76326 | 3320 | |
6a566b9c | 3321 | *settings = NULL; |
3322 | } | |
3323 | ||
3324 | static void | |
c1dd71ae | 3325 | parse_removalpolicy(RemovalPolicySettings ** settings) |
6a566b9c | 3326 | { |
3327 | if (*settings) | |
62e76326 | 3328 | free_removalpolicy(settings); |
3329 | ||
c8f4eac4 | 3330 | *settings = new RemovalPolicySettings; |
62e76326 | 3331 | |
6a566b9c | 3332 | parse_string(&(*settings)->type); |
62e76326 | 3333 | |
6a566b9c | 3334 | parse_wordlist(&(*settings)->args); |
3335 | } | |
3336 | ||
3337 | static void | |
c1dd71ae | 3338 | dump_removalpolicy(StoreEntry * entry, const char *name, RemovalPolicySettings * settings) |
6a566b9c | 3339 | { |
3340 | wordlist *args; | |
3341 | storeAppendPrintf(entry, "%s %s", name, settings->type); | |
3342 | args = settings->args; | |
62e76326 | 3343 | |
6a566b9c | 3344 | while (args) { |
62e76326 | 3345 | storeAppendPrintf(entry, " %s", args->key); |
3346 | args = args->next; | |
6a566b9c | 3347 | } |
62e76326 | 3348 | |
be58afb5 | 3349 | storeAppendPrintf(entry, "\n"); |
6a566b9c | 3350 | } |
c1dd71ae | 3351 | |
57af1e3f AR |
3352 | void |
3353 | YesNoNone::configure(bool beSet) | |
3354 | { | |
3355 | option = beSet ? +1 : -1; | |
3356 | } | |
3357 | ||
3358 | YesNoNone::operator void*() const | |
3359 | { | |
3360 | assert(option != 0); // must call configure() first | |
3361 | return option > 0 ? (void*)this : NULL; | |
3362 | } | |
3363 | ||
3364 | ||
de0cb3d8 AR |
3365 | inline void |
3366 | free_YesNoNone(YesNoNone *) | |
57af1e3f | 3367 | { |
de0cb3d8 | 3368 | // do nothing: no explicit cleanup is required |
57af1e3f AR |
3369 | } |
3370 | ||
3371 | static void | |
3372 | parse_YesNoNone(YesNoNone *option) | |
3373 | { | |
3374 | int value = 0; | |
3375 | parse_onoff(&value); | |
3376 | option->configure(value > 0); | |
3377 | } | |
3378 | ||
3379 | static void | |
3380 | dump_YesNoNone(StoreEntry * entry, const char *name, YesNoNone &option) | |
3381 | { | |
3382 | if (option.configured()) | |
3383 | dump_onoff(entry, name, option ? 1 : 0); | |
3384 | } | |
3385 | ||
ea21d497 HN |
3386 | static void |
3387 | free_memcachemode(SquidConfig * config) | |
3388 | { | |
3389 | return; | |
3390 | } | |
3391 | ||
3392 | static void | |
3393 | parse_memcachemode(SquidConfig * config) | |
3394 | { | |
3395 | char *token = strtok(NULL, w_space); | |
3396 | if (!token) | |
e1381638 | 3397 | self_destruct(); |
ea21d497 | 3398 | |
10aeba1d | 3399 | if (strcmp(token, "always") == 0) { |
e1381638 AJ |
3400 | Config.onoff.memory_cache_first = 1; |
3401 | Config.onoff.memory_cache_disk = 1; | |
10aeba1d | 3402 | } else if (strcmp(token, "disk") == 0) { |
e1381638 AJ |
3403 | Config.onoff.memory_cache_first = 0; |
3404 | Config.onoff.memory_cache_disk = 1; | |
ea21d497 | 3405 | } else if (strncmp(token, "net", 3) == 0) { |
e1381638 AJ |
3406 | Config.onoff.memory_cache_first = 1; |
3407 | Config.onoff.memory_cache_disk = 0; | |
10aeba1d | 3408 | } else if (strcmp(token, "never") == 0) { |
e1381638 AJ |
3409 | Config.onoff.memory_cache_first = 0; |
3410 | Config.onoff.memory_cache_disk = 0; | |
ea21d497 | 3411 | } else |
e1381638 | 3412 | self_destruct(); |
ea21d497 HN |
3413 | } |
3414 | ||
3415 | static void | |
3416 | dump_memcachemode(StoreEntry * entry, const char *name, SquidConfig &config) | |
3417 | { | |
3418 | storeAppendPrintf(entry, "%s ", name); | |
3419 | if (Config.onoff.memory_cache_first && Config.onoff.memory_cache_disk) | |
e1381638 | 3420 | storeAppendPrintf(entry, "always"); |
ea21d497 | 3421 | else if (!Config.onoff.memory_cache_first && Config.onoff.memory_cache_disk) |
e1381638 | 3422 | storeAppendPrintf(entry, "disk"); |
ea21d497 | 3423 | else if (Config.onoff.memory_cache_first && !Config.onoff.memory_cache_disk) |
e1381638 | 3424 | storeAppendPrintf(entry, "network"); |
ea21d497 | 3425 | else if (!Config.onoff.memory_cache_first && !Config.onoff.memory_cache_disk) |
e1381638 | 3426 | storeAppendPrintf(entry, "none"); |
ea21d497 HN |
3427 | storeAppendPrintf(entry, "\n"); |
3428 | } | |
3429 | ||
cca8ba0d | 3430 | #include "cf_parser.cci" |
f1dc9b30 | 3431 | |
3432 | peer_t | |
3433 | parseNeighborType(const char *s) | |
3434 | { | |
3435 | if (!strcasecmp(s, "parent")) | |
62e76326 | 3436 | return PEER_PARENT; |
3437 | ||
f1dc9b30 | 3438 | if (!strcasecmp(s, "neighbor")) |
62e76326 | 3439 | return PEER_SIBLING; |
3440 | ||
f1dc9b30 | 3441 | if (!strcasecmp(s, "neighbour")) |
62e76326 | 3442 | return PEER_SIBLING; |
3443 | ||
f1dc9b30 | 3444 | if (!strcasecmp(s, "sibling")) |
62e76326 | 3445 | return PEER_SIBLING; |
3446 | ||
f1dc9b30 | 3447 | if (!strcasecmp(s, "multicast")) |
62e76326 | 3448 | return PEER_MULTICAST; |
3449 | ||
bf8fe701 | 3450 | debugs(15, 0, "WARNING: Unknown neighbor type: " << s); |
62e76326 | 3451 | |
f1dc9b30 | 3452 | return PEER_SIBLING; |
3453 | } | |
f150dd4b | 3454 | |
0b0cfcf2 | 3455 | #if USE_WCCPv2 |
52f772de | 3456 | static void |
b7ac5457 | 3457 | parse_IpAddress_list(Ip::Address_list ** head) |
52f772de | 3458 | { |
3459 | char *token; | |
b7ac5457 AJ |
3460 | Ip::Address_list *s; |
3461 | Ip::Address ipa; | |
62e76326 | 3462 | |
52f772de | 3463 | while ((token = strtok(NULL, w_space))) { |
82b7abe3 AJ |
3464 | if (GetHostWithPort(token, &ipa)) { |
3465 | ||
3466 | while (*head) | |
3467 | head = &(*head)->next; | |
3468 | ||
b7ac5457 | 3469 | s = static_cast<Ip::Address_list *>(xcalloc(1, sizeof(*s))); |
82b7abe3 AJ |
3470 | s->s = ipa; |
3471 | ||
3472 | *head = s; | |
9d65168e | 3473 | } else |
82b7abe3 | 3474 | self_destruct(); |
7e3ce7b9 | 3475 | } |
3476 | } | |
3477 | ||
3478 | static void | |
b7ac5457 | 3479 | dump_IpAddress_list(StoreEntry * e, const char *n, const Ip::Address_list * s) |
7e3ce7b9 | 3480 | { |
cc192b50 | 3481 | char ntoabuf[MAX_IPSTRLEN]; |
3482 | ||
7e3ce7b9 | 3483 | while (s) { |
cc192b50 | 3484 | storeAppendPrintf(e, "%s %s\n", |
62e76326 | 3485 | n, |
cc192b50 | 3486 | s->s.NtoA(ntoabuf,MAX_IPSTRLEN)); |
62e76326 | 3487 | s = s->next; |
7e3ce7b9 | 3488 | } |
3489 | } | |
3490 | ||
3491 | static void | |
b7ac5457 | 3492 | free_IpAddress_list(Ip::Address_list ** head) |
7e3ce7b9 | 3493 | { |
26ac0430 AJ |
3494 | if (*head) delete *head; |
3495 | *head = NULL; | |
7e3ce7b9 | 3496 | } |
3497 | ||
0b0cfcf2 | 3498 | #if CURRENTLY_UNUSED |
3499 | /* This code was previously used by http_port. Left as it really should | |
3500 | * be used by icp_port and htcp_port | |
3501 | */ | |
7e3ce7b9 | 3502 | static int |
b7ac5457 | 3503 | check_null_IpAddress_list(const Ip::Address_list * s) |
7e3ce7b9 | 3504 | { |
3505 | return NULL == s; | |
3506 | } | |
62e76326 | 3507 | |
3f38a55e | 3508 | #endif /* CURRENTLY_UNUSED */ |
0b0cfcf2 | 3509 | #endif /* USE_WCCPv2 */ |
7e3ce7b9 | 3510 | |
154dc884 | 3511 | CBDATA_CLASS_INIT(http_port_list); |
3512 | ||
d193a436 | 3513 | static void |
3f38a55e | 3514 | parse_http_port_specification(http_port_list * s, char *token) |
d193a436 | 3515 | { |
3f38a55e | 3516 | char *host = NULL; |
3f38a55e | 3517 | unsigned short port = 0; |
cc192b50 | 3518 | char *t = NULL; |
3519 | char *junk = NULL; | |
62e76326 | 3520 | |
5529ca8a | 3521 | s->disable_pmtu_discovery = DISABLE_PMTU_OFF; |
13adaf1f | 3522 | s->name = xstrdup(token); |
d67acb4e | 3523 | s->connection_auth_disabled = false; |
5529ca8a | 3524 | |
cc192b50 | 3525 | if (*token == '[') { |
3526 | /* [ipv6]:port */ | |
26ac0430 AJ |
3527 | host = token + 1; |
3528 | t = strchr(host, ']'); | |
3529 | if (!t) { | |
cc192b50 | 3530 | debugs(3, 0, "http(s)_port: missing ']' on IPv6 address: " << token); |
26ac0430 | 3531 | self_destruct(); |
cc192b50 | 3532 | } |
26ac0430 AJ |
3533 | *t++ = '\0'; |
3534 | if (*t != ':') { | |
cc192b50 | 3535 | debugs(3, 0, "http(s)_port: missing Port in: " << token); |
26ac0430 | 3536 | self_destruct(); |
cc192b50 | 3537 | } |
055421ee AJ |
3538 | if (!Ip::EnableIpv6) { |
3539 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: IPv6 is not available."); | |
26ac0430 AJ |
3540 | self_destruct(); |
3541 | } | |
055421ee AJ |
3542 | port = xatos(t + 1); |
3543 | } else if ((t = strchr(token, ':'))) { | |
3544 | /* host:port */ | |
3545 | /* ipv4:port */ | |
3546 | host = token; | |
3547 | *t = '\0'; | |
3548 | port = xatos(t + 1); | |
3549 | ||
3550 | } else if ((port = strtol(token, &junk, 10)), !*junk) { | |
3551 | /* port */ | |
3552 | debugs(3, 3, "http(s)_port: found Listen on Port: " << port); | |
3553 | } else { | |
3554 | debugs(3, 0, "http(s)_port: missing Port: " << token); | |
3555 | self_destruct(); | |
3556 | } | |
62e76326 | 3557 | |
cc192b50 | 3558 | if (port == 0) { |
3559 | debugs(3, 0, "http(s)_port: Port cannot be 0: " << token); | |
0e656b69 | 3560 | self_destruct(); |
cc192b50 | 3561 | } |
0e656b69 | 3562 | |
cc192b50 | 3563 | if (NULL == host) { |
3564 | s->s.SetAnyAddr(); | |
3565 | s->s.SetPort(port); | |
6df7ad56 AJ |
3566 | if (!Ip::EnableIpv6) |
3567 | s->s.SetIPv4(); | |
7e07ced1 | 3568 | debugs(3, 3, "http(s)_port: found Listen on wildcard address: *:" << s->s.GetPort() ); |
c49d44e1 | 3569 | } else if ( (s->s = host) ) { /* check/parse numeric IPA */ |
cc192b50 | 3570 | s->s.SetPort(port); |
6df7ad56 AJ |
3571 | if (!Ip::EnableIpv6) |
3572 | s->s.SetIPv4(); | |
cc192b50 | 3573 | debugs(3, 3, "http(s)_port: Listen on Host/IP: " << host << " --> " << s->s); |
26ac0430 | 3574 | } else if ( s->s.GetHostByName(host) ) { /* check/parse for FQDN */ |
62e76326 | 3575 | /* dont use ipcache */ |
62e76326 | 3576 | s->defaultsite = xstrdup(host); |
cc192b50 | 3577 | s->s.SetPort(port); |
6df7ad56 AJ |
3578 | if (!Ip::EnableIpv6) |
3579 | s->s.SetIPv4(); | |
cc192b50 | 3580 | debugs(3, 3, "http(s)_port: found Listen as Host " << s->defaultsite << " on IP: " << s->s); |
26ac0430 | 3581 | } else { |
cc192b50 | 3582 | debugs(3, 0, "http(s)_port: failed to resolve Host/IP: " << host); |
62e76326 | 3583 | self_destruct(); |
cc192b50 | 3584 | } |
3f38a55e | 3585 | } |
3586 | ||
3587 | static void | |
3588 | parse_http_port_option(http_port_list * s, char *token) | |
3589 | { | |
c7b1dd5d AJ |
3590 | /* modes first */ |
3591 | ||
3592 | if (strcmp(token, "accel") == 0) { | |
3593 | if (s->intercepted || s->spoof_client_ip) { | |
3594 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: Accelerator mode requires its own port. It cannot be shared with other modes."); | |
3595 | self_destruct(); | |
3596 | } | |
cf673853 | 3597 | s->accel = s->vhost = 1; |
c7b1dd5d AJ |
3598 | } else if (strcmp(token, "transparent") == 0 || strcmp(token, "intercept") == 0) { |
3599 | if (s->accel || s->spoof_client_ip) { | |
3600 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: Intercept mode requires its own interception port. It cannot be shared with other modes."); | |
3601 | self_destruct(); | |
3602 | } | |
3603 | s->intercepted = 1; | |
3604 | Ip::Interceptor.StartInterception(); | |
3605 | /* Log information regarding the port modes under interception. */ | |
3606 | debugs(3, DBG_IMPORTANT, "Starting Authentication on port " << s->s); | |
3607 | debugs(3, DBG_IMPORTANT, "Disabling Authentication on port " << s->s << " (interception enabled)"); | |
3608 | ||
c7b1dd5d | 3609 | /* INET6: until transparent REDIRECT works on IPv6 SOCKET, force wildcard to IPv4 */ |
055421ee AJ |
3610 | if (Ip::EnableIpv6) |
3611 | debugs(3, DBG_IMPORTANT, "Disabling IPv6 on port " << s->s << " (interception enabled)"); | |
c7b1dd5d | 3612 | if ( !s->s.SetIPv4() ) { |
40d34a62 | 3613 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: IPv6 addresses cannot NAT intercept (protocol does not provide NAT)" << s->s ); |
c7b1dd5d AJ |
3614 | self_destruct(); |
3615 | } | |
c7b1dd5d AJ |
3616 | } else if (strcmp(token, "tproxy") == 0) { |
3617 | if (s->intercepted || s->accel) { | |
3618 | debugs(3,DBG_CRITICAL, "FATAL: http(s)_port: TPROXY option requires its own interception port. It cannot be shared with other modes."); | |
3619 | self_destruct(); | |
3620 | } | |
3621 | s->spoof_client_ip = 1; | |
3622 | Ip::Interceptor.StartTransparency(); | |
3623 | /* Log information regarding the port modes under transparency. */ | |
3624 | debugs(3, DBG_IMPORTANT, "Starting IP Spoofing on port " << s->s); | |
3625 | debugs(3, DBG_IMPORTANT, "Disabling Authentication on port " << s->s << " (IP spoofing enabled)"); | |
3626 | ||
3627 | if (!Ip::Interceptor.ProbeForTproxy(s->s)) { | |
3628 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: TPROXY support in the system does not work."); | |
3629 | self_destruct(); | |
3630 | } | |
3631 | ||
3632 | } else if (strncmp(token, "defaultsite=", 12) == 0) { | |
3633 | if (!s->accel) { | |
3634 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: defaultsite option requires Acceleration mode flag."); | |
3635 | self_destruct(); | |
3636 | } | |
62e76326 | 3637 | safe_free(s->defaultsite); |
3638 | s->defaultsite = xstrdup(token + 12); | |
3f38a55e | 3639 | } else if (strcmp(token, "vhost") == 0) { |
c7b1dd5d | 3640 | if (!s->accel) { |
cf673853 AJ |
3641 | debugs(3, DBG_CRITICAL, "WARNING: http(s)_port: vhost option is deprecated. Use 'accel' mode flag instead."); |
3642 | } | |
3643 | s->accel = s->vhost = 1; | |
3644 | } else if (strcmp(token, "no-vhost") == 0) { | |
3645 | if (!s->accel) { | |
3646 | debugs(3, DBG_IMPORTANT, "ERROR: http(s)_port: no-vhost option requires Acceleration mode flag."); | |
c7b1dd5d | 3647 | } |
cf673853 | 3648 | s->vhost = 0; |
3f38a55e | 3649 | } else if (strcmp(token, "vport") == 0) { |
c7b1dd5d AJ |
3650 | if (!s->accel) { |
3651 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: vport option requires Acceleration mode flag."); | |
3652 | self_destruct(); | |
3653 | } | |
62e76326 | 3654 | s->vport = -1; |
3f38a55e | 3655 | } else if (strncmp(token, "vport=", 6) == 0) { |
c7b1dd5d AJ |
3656 | if (!s->accel) { |
3657 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: vport option requires Acceleration mode flag."); | |
3658 | self_destruct(); | |
3659 | } | |
0e656b69 | 3660 | s->vport = xatos(token + 6); |
3f38a55e | 3661 | } else if (strncmp(token, "protocol=", 9) == 0) { |
c7b1dd5d AJ |
3662 | if (!s->accel) { |
3663 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: protocol option requires Acceleration mode flag."); | |
3664 | self_destruct(); | |
3665 | } | |
62e76326 | 3666 | s->protocol = xstrdup(token + 9); |
7f7bdd96 | 3667 | } else if (strcmp(token, "allow-direct") == 0) { |
c7b1dd5d | 3668 | if (!s->accel) { |
90fa5816 | 3669 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: allow-direct option requires Acceleration mode flag."); |
c7b1dd5d AJ |
3670 | self_destruct(); |
3671 | } | |
7f7bdd96 | 3672 | s->allow_direct = 1; |
90fa5816 AJ |
3673 | } else if (strcmp(token, "act-as-origin") == 0) { |
3674 | if (!s->accel) { | |
3675 | debugs(3, DBG_IMPORTANT, "ERROR: http(s)_port: act-as-origin option requires Acceleration mode flag."); | |
3676 | } else | |
3677 | s->actAsOrigin = 1; | |
432bc83c | 3678 | } else if (strcmp(token, "ignore-cc") == 0) { |
626096be | 3679 | #if !USE_HTTP_VIOLATIONS |
838daf3f | 3680 | if (!s->accel) { |
c7b1dd5d | 3681 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: ignore-cc option requires Scceleration mode flag."); |
838daf3f A |
3682 | self_destruct(); |
3683 | } | |
432bc83c | 3684 | #endif |
c7b1dd5d AJ |
3685 | s->ignore_cc = 1; |
3686 | } else if (strncmp(token, "name=", 5) == 0) { | |
3687 | safe_free(s->name); | |
3688 | s->name = xstrdup(token + 5); | |
d67acb4e AJ |
3689 | } else if (strcmp(token, "no-connection-auth") == 0) { |
3690 | s->connection_auth_disabled = true; | |
3691 | } else if (strcmp(token, "connection-auth=off") == 0) { | |
26ac0430 | 3692 | s->connection_auth_disabled = true; |
d67acb4e | 3693 | } else if (strcmp(token, "connection-auth") == 0) { |
26ac0430 | 3694 | s->connection_auth_disabled = false; |
d67acb4e | 3695 | } else if (strcmp(token, "connection-auth=on") == 0) { |
26ac0430 | 3696 | s->connection_auth_disabled = false; |
5529ca8a | 3697 | } else if (strncmp(token, "disable-pmtu-discovery=", 23) == 0) { |
3698 | if (!strcasecmp(token + 23, "off")) | |
3699 | s->disable_pmtu_discovery = DISABLE_PMTU_OFF; | |
3700 | else if (!strcasecmp(token + 23, "transparent")) | |
3701 | s->disable_pmtu_discovery = DISABLE_PMTU_TRANSPARENT; | |
3702 | else if (!strcasecmp(token + 23, "always")) | |
3703 | s->disable_pmtu_discovery = DISABLE_PMTU_ALWAYS; | |
3704 | else | |
3705 | self_destruct(); | |
cc192b50 | 3706 | } else if (strcmp(token, "ipv4") == 0) { |
26ac0430 | 3707 | if ( !s->s.SetIPv4() ) { |
055421ee | 3708 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: IPv6 addresses cannot be used as IPv4-Only. " << s->s ); |
cc192b50 | 3709 | self_destruct(); |
3710 | } | |
26ac0430 AJ |
3711 | } else if (strcmp(token, "tcpkeepalive") == 0) { |
3712 | s->tcp_keepalive.enabled = 1; | |
b2130d58 | 3713 | } else if (strncmp(token, "tcpkeepalive=", 13) == 0) { |
26ac0430 AJ |
3714 | char *t = token + 13; |
3715 | s->tcp_keepalive.enabled = 1; | |
3716 | s->tcp_keepalive.idle = atoi(t); | |
3717 | t = strchr(t, ','); | |
3718 | if (t) { | |
3719 | t++; | |
3720 | s->tcp_keepalive.interval = atoi(t); | |
3721 | t = strchr(t, ','); | |
3722 | } | |
3723 | if (t) { | |
3724 | t++; | |
3725 | s->tcp_keepalive.timeout = atoi(t); | |
3726 | t = strchr(t, ','); | |
3727 | } | |
154dc884 | 3728 | #if USE_SSL |
3a0c8eb5 AR |
3729 | } else if (strcasecmp(token, "sslBump") == 0) { |
3730 | debugs(3, DBG_CRITICAL, "WARNING: '" << token << "' is deprecated " << | |
9945bf3f | 3731 | "in http_port. Use 'ssl-bump' instead."); |
3a0c8eb5 AR |
3732 | s->sslBump = 1; // accelerated when bumped, otherwise not |
3733 | } else if (strcmp(token, "ssl-bump") == 0) { | |
c7b1dd5d | 3734 | s->sslBump = 1; // accelerated when bumped, otherwise not |
154dc884 | 3735 | } else if (strncmp(token, "cert=", 5) == 0) { |
3736 | safe_free(s->cert); | |
3737 | s->cert = xstrdup(token + 5); | |
3738 | } else if (strncmp(token, "key=", 4) == 0) { | |
3739 | safe_free(s->key); | |
3740 | s->key = xstrdup(token + 4); | |
3741 | } else if (strncmp(token, "version=", 8) == 0) { | |
3742 | s->version = xatoi(token + 8); | |
154dc884 | 3743 | if (s->version < 1 || s->version > 4) |
3744 | self_destruct(); | |
3745 | } else if (strncmp(token, "options=", 8) == 0) { | |
3746 | safe_free(s->options); | |
3747 | s->options = xstrdup(token + 8); | |
3748 | } else if (strncmp(token, "cipher=", 7) == 0) { | |
3749 | safe_free(s->cipher); | |
3750 | s->cipher = xstrdup(token + 7); | |
3751 | } else if (strncmp(token, "clientca=", 9) == 0) { | |
3752 | safe_free(s->clientca); | |
3753 | s->clientca = xstrdup(token + 9); | |
3754 | } else if (strncmp(token, "cafile=", 7) == 0) { | |
3755 | safe_free(s->cafile); | |
3756 | s->cafile = xstrdup(token + 7); | |
3757 | } else if (strncmp(token, "capath=", 7) == 0) { | |
3758 | safe_free(s->capath); | |
3759 | s->capath = xstrdup(token + 7); | |
3760 | } else if (strncmp(token, "crlfile=", 8) == 0) { | |
3761 | safe_free(s->crlfile); | |
3762 | s->crlfile = xstrdup(token + 8); | |
3763 | } else if (strncmp(token, "dhparams=", 9) == 0) { | |
3764 | safe_free(s->dhfile); | |
3765 | s->dhfile = xstrdup(token + 9); | |
3766 | } else if (strncmp(token, "sslflags=", 9) == 0) { | |
3767 | safe_free(s->sslflags); | |
3768 | s->sslflags = xstrdup(token + 9); | |
3769 | } else if (strncmp(token, "sslcontext=", 11) == 0) { | |
95d2589c CT |
3770 | safe_free(s->sslContextSessionId); |
3771 | s->sslContextSessionId = xstrdup(token + 11); | |
3772 | } else if (strcmp(token, "generate-host-certificates") == 0) { | |
3773 | s->generateHostCertificates = true; | |
3774 | } else if (strcmp(token, "generate-host-certificates=on") == 0) { | |
3775 | s->generateHostCertificates = true; | |
3776 | } else if (strcmp(token, "generate-host-certificates=off") == 0) { | |
3777 | s->generateHostCertificates = false; | |
3778 | } else if (strncmp(token, "dynamic_cert_mem_cache_size=", 28) == 0) { | |
3779 | parseBytesOptionValue(&s->dynamicCertMemCacheSize, B_BYTES_STR, token + 28); | |
154dc884 | 3780 | #endif |
3f38a55e | 3781 | } else { |
62e76326 | 3782 | self_destruct(); |
3f38a55e | 3783 | } |
3784 | } | |
3785 | ||
3f38a55e | 3786 | static http_port_list * |
3787 | create_http_port(char *portspec) | |
3788 | { | |
154dc884 | 3789 | http_port_list *s = new http_port_list("http"); |
3f38a55e | 3790 | parse_http_port_specification(s, portspec); |
3791 | return s; | |
3792 | } | |
3793 | ||
3794 | void | |
3795 | add_http_port(char *portspec) | |
3796 | { | |
3797 | http_port_list *s = create_http_port(portspec); | |
7e07ced1 AJ |
3798 | // we may need to merge better of the above returns a list with clones |
3799 | assert(s->next == NULL); | |
3f38a55e | 3800 | s->next = Config.Sockaddr.http; |
3801 | Config.Sockaddr.http = s; | |
3802 | } | |
3803 | ||
7e07ced1 AJ |
3804 | http_port_list * |
3805 | clone_http_port_list(http_port_list *a) | |
3806 | { | |
3807 | http_port_list *b = new http_port_list(a->protocol); | |
3808 | ||
3809 | b->s = a->s; | |
3810 | if (a->name) | |
3811 | b->name = xstrdup(a->name); | |
3812 | if (a->defaultsite) | |
3813 | b->defaultsite = xstrdup(a->defaultsite); | |
3814 | ||
3815 | b->intercepted = a->intercepted; | |
3816 | b->spoof_client_ip = a->spoof_client_ip; | |
3817 | b->accel = a->accel; | |
3818 | b->allow_direct = a->allow_direct; | |
3819 | b->vhost = a->vhost; | |
3820 | b->sslBump = a->sslBump; | |
3821 | b->vport = a->vport; | |
3822 | b->connection_auth_disabled = a->connection_auth_disabled; | |
3823 | b->disable_pmtu_discovery = a->disable_pmtu_discovery; | |
3824 | ||
3825 | memcpy( &(b->tcp_keepalive), &(a->tcp_keepalive), sizeof(a->tcp_keepalive)); | |
3826 | ||
3827 | #if 0 | |
3828 | // AYJ: 2009-07-18: for now SSL does not clone. Configure separate ports with IPs and SSL settings | |
3829 | ||
3830 | #if USE_SSL | |
3831 | // XXX: temporary hack to ease move of SSL options to http_port | |
3832 | http_port_list &http; | |
3833 | ||
3834 | char *cert; | |
3835 | char *key; | |
3836 | int version; | |
3837 | char *cipher; | |
3838 | char *options; | |
3839 | char *clientca; | |
3840 | char *cafile; | |
3841 | char *capath; | |
3842 | char *crlfile; | |
3843 | char *dhfile; | |
3844 | char *sslflags; | |
95d2589c | 3845 | char *sslContextSessionId; |
7e07ced1 AJ |
3846 | SSL_CTX *sslContext; |
3847 | #endif | |
3848 | ||
3849 | #endif /*0*/ | |
3850 | ||
3851 | return b; | |
3852 | } | |
7e07ced1 | 3853 | |
3f38a55e | 3854 | static void |
3855 | parse_http_port_list(http_port_list ** head) | |
3856 | { | |
3857 | char *token = strtok(NULL, w_space); | |
62e76326 | 3858 | |
9eeb8e4b | 3859 | if (!token) { |
62e76326 | 3860 | self_destruct(); |
9eeb8e4b | 3861 | return; |
3862 | } | |
62e76326 | 3863 | |
3f38a55e | 3864 | http_port_list *s = create_http_port(token); |
62e76326 | 3865 | |
3f38a55e | 3866 | /* parse options ... */ |
3867 | while ((token = strtok(NULL, w_space))) { | |
62e76326 | 3868 | parse_http_port_option(s, token); |
3f38a55e | 3869 | } |
62e76326 | 3870 | |
055421ee | 3871 | if (Ip::EnableIpv6&IPV6_SPECIAL_SPLITSTACK && s->s.IsAnyAddr()) { |
7e07ced1 AJ |
3872 | // clone the port options from *s to *(s->next) |
3873 | s->next = clone_http_port_list(s); | |
3874 | s->next->s.SetIPv4(); | |
3875 | debugs(3, 3, "http(s)_port: clone wildcard address for split-stack: " << s->s << " and " << s->next->s); | |
3876 | } | |
7e07ced1 | 3877 | |
3f38a55e | 3878 | while (*head) |
62e76326 | 3879 | head = &(*head)->next; |
3880 | ||
3f38a55e | 3881 | *head = s; |
3882 | } | |
3883 | ||
3884 | static void | |
3885 | dump_generic_http_port(StoreEntry * e, const char *n, const http_port_list * s) | |
3886 | { | |
cc192b50 | 3887 | char buf[MAX_IPSTRLEN]; |
3888 | ||
3889 | storeAppendPrintf(e, "%s %s", | |
62e76326 | 3890 | n, |
cc192b50 | 3891 | s->s.ToURL(buf,MAX_IPSTRLEN)); |
62e76326 | 3892 | |
df1b20e4 | 3893 | // MODES and specific sub-options. |
2ad20b4f AJ |
3894 | if (s->intercepted) |
3895 | storeAppendPrintf(e, " intercept"); | |
62e76326 | 3896 | |
df1b20e4 | 3897 | else if (s->spoof_client_ip) |
c7b1dd5d AJ |
3898 | storeAppendPrintf(e, " tproxy"); |
3899 | ||
df1b20e4 | 3900 | else if (s->accel) { |
c7b1dd5d AJ |
3901 | storeAppendPrintf(e, " accel"); |
3902 | ||
df1b20e4 AJ |
3903 | if (s->vhost) |
3904 | storeAppendPrintf(e, " vhost"); | |
62e76326 | 3905 | |
df1b20e4 AJ |
3906 | if (s->vport < 0) |
3907 | storeAppendPrintf(e, " vport"); | |
3908 | else if (s->vport > 0) | |
3909 | storeAppendPrintf(e, " vport=%d", s->vport); | |
5529ca8a | 3910 | |
df1b20e4 AJ |
3911 | if (s->defaultsite) |
3912 | storeAppendPrintf(e, " defaultsite=%s", s->defaultsite); | |
3913 | ||
3914 | if (s->protocol && strcmp(s->protocol,"http") != 0) | |
3915 | storeAppendPrintf(e, " protocol=%s", s->protocol); | |
3916 | ||
3917 | if (s->allow_direct) | |
3918 | storeAppendPrintf(e, " allow-direct"); | |
3919 | ||
3920 | if (s->ignore_cc) | |
3921 | storeAppendPrintf(e, " ignore-cc"); | |
3922 | ||
3923 | } | |
3924 | ||
3925 | // Generic independent options | |
3926 | ||
3927 | if (s->name) | |
3928 | storeAppendPrintf(e, " name=%s", s->name); | |
3929 | ||
33e701f3 | 3930 | #if USE_HTTP_VIOLATIONS |
df1b20e4 AJ |
3931 | if (!s->accel && s->ignore_cc) |
3932 | storeAppendPrintf(e, " ignore-cc"); | |
3933 | #endif | |
c7b1dd5d | 3934 | |
d67acb4e AJ |
3935 | if (s->connection_auth_disabled) |
3936 | storeAppendPrintf(e, " connection-auth=off"); | |
3937 | else | |
3938 | storeAppendPrintf(e, " connection-auth=on"); | |
3939 | ||
5529ca8a | 3940 | if (s->disable_pmtu_discovery != DISABLE_PMTU_OFF) { |
3941 | const char *pmtu; | |
3942 | ||
3943 | if (s->disable_pmtu_discovery == DISABLE_PMTU_ALWAYS) | |
3944 | pmtu = "always"; | |
3945 | else | |
3946 | pmtu = "transparent"; | |
3947 | ||
3948 | storeAppendPrintf(e, " disable-pmtu-discovery=%s", pmtu); | |
3949 | } | |
b2130d58 | 3950 | |
df1b20e4 AJ |
3951 | if (s->s.IsAnyAddr() && !s->s.IsIPv6()) |
3952 | storeAppendPrintf(e, " ipv4"); | |
3953 | ||
b2130d58 | 3954 | if (s->tcp_keepalive.enabled) { |
26ac0430 | 3955 | if (s->tcp_keepalive.idle || s->tcp_keepalive.interval || s->tcp_keepalive.timeout) { |
68924b6d | 3956 | storeAppendPrintf(e, " tcpkeepalive=%d,%d,%d", s->tcp_keepalive.idle, s->tcp_keepalive.interval, s->tcp_keepalive.timeout); |
26ac0430 | 3957 | } else { |
68924b6d | 3958 | storeAppendPrintf(e, " tcpkeepalive"); |
26ac0430 | 3959 | } |
b2130d58 | 3960 | } |
154dc884 | 3961 | |
3962 | #if USE_SSL | |
c7b1dd5d | 3963 | if (s->sslBump) |
df1b20e4 | 3964 | storeAppendPrintf(e, " ssl-bump"); |
c7b1dd5d | 3965 | |
26ac0430 AJ |
3966 | if (s->cert) |
3967 | storeAppendPrintf(e, " cert=%s", s->cert); | |
154dc884 | 3968 | |
26ac0430 AJ |
3969 | if (s->key) |
3970 | storeAppendPrintf(e, " key=%s", s->key); | |
154dc884 | 3971 | |
26ac0430 AJ |
3972 | if (s->version) |
3973 | storeAppendPrintf(e, " version=%d", s->version); | |
154dc884 | 3974 | |
26ac0430 AJ |
3975 | if (s->options) |
3976 | storeAppendPrintf(e, " options=%s", s->options); | |
154dc884 | 3977 | |
26ac0430 AJ |
3978 | if (s->cipher) |
3979 | storeAppendPrintf(e, " cipher=%s", s->cipher); | |
154dc884 | 3980 | |
26ac0430 AJ |
3981 | if (s->cafile) |
3982 | storeAppendPrintf(e, " cafile=%s", s->cafile); | |
154dc884 | 3983 | |
26ac0430 AJ |
3984 | if (s->capath) |
3985 | storeAppendPrintf(e, " capath=%s", s->capath); | |
154dc884 | 3986 | |
26ac0430 AJ |
3987 | if (s->crlfile) |
3988 | storeAppendPrintf(e, " crlfile=%s", s->crlfile); | |
154dc884 | 3989 | |
26ac0430 AJ |
3990 | if (s->dhfile) |
3991 | storeAppendPrintf(e, " dhparams=%s", s->dhfile); | |
154dc884 | 3992 | |
26ac0430 AJ |
3993 | if (s->sslflags) |
3994 | storeAppendPrintf(e, " sslflags=%s", s->sslflags); | |
154dc884 | 3995 | |
95d2589c CT |
3996 | if (s->sslContextSessionId) |
3997 | storeAppendPrintf(e, " sslcontext=%s", s->sslContextSessionId); | |
3998 | ||
3999 | if (s->generateHostCertificates) | |
4000 | storeAppendPrintf(e, " generate-host-certificates"); | |
4001 | ||
4002 | if (s->dynamicCertMemCacheSize != std::numeric_limits<size_t>::max()) | |
4003 | storeAppendPrintf(e, "dynamic_cert_mem_cache_size=%lu%s\n", (unsigned long)s->dynamicCertMemCacheSize, B_BYTES_STR); | |
154dc884 | 4004 | #endif |
3f38a55e | 4005 | } |
62e76326 | 4006 | |
3f38a55e | 4007 | static void |
4008 | dump_http_port_list(StoreEntry * e, const char *n, const http_port_list * s) | |
4009 | { | |
4010 | while (s) { | |
62e76326 | 4011 | dump_generic_http_port(e, n, s); |
4012 | storeAppendPrintf(e, "\n"); | |
4013 | s = s->next; | |
3f38a55e | 4014 | } |
4015 | } | |
4016 | ||
4017 | static void | |
4018 | free_http_port_list(http_port_list ** head) | |
4019 | { | |
4020 | http_port_list *s; | |
62e76326 | 4021 | |
3f38a55e | 4022 | while ((s = *head) != NULL) { |
62e76326 | 4023 | *head = s->next; |
154dc884 | 4024 | delete s; |
3f38a55e | 4025 | } |
4026 | } | |
4027 | ||
3f38a55e | 4028 | #if USE_SSL |
3f38a55e | 4029 | |
154dc884 | 4030 | // TODO: merge better with parse_http_port_list |
3f38a55e | 4031 | static void |
4032 | parse_https_port_list(https_port_list ** head) | |
4033 | { | |
3f38a55e | 4034 | char *token; |
4035 | https_port_list *s; | |
154dc884 | 4036 | |
3f38a55e | 4037 | token = strtok(NULL, w_space); |
62e76326 | 4038 | |
3f38a55e | 4039 | if (!token) |
62e76326 | 4040 | self_destruct(); |
4041 | ||
154dc884 | 4042 | s = new https_port_list; |
3f38a55e | 4043 | parse_http_port_specification(&s->http, token); |
62e76326 | 4044 | |
d193a436 | 4045 | /* parse options ... */ |
4046 | while ((token = strtok(NULL, w_space))) { | |
154dc884 | 4047 | parse_http_port_option(s, token); |
d193a436 | 4048 | } |
62e76326 | 4049 | |
8abf232c | 4050 | while (*head) { |
4051 | http_port_list ** headTmp = &(*head)->http.next; | |
4052 | head = (https_port_list **)headTmp; | |
4053 | } | |
62e76326 | 4054 | |
d193a436 | 4055 | *head = s; |
4056 | } | |
4057 | ||
4058 | static void | |
4059 | dump_https_port_list(StoreEntry * e, const char *n, const https_port_list * s) | |
4060 | { | |
154dc884 | 4061 | dump_http_port_list(e, n, s); |
d193a436 | 4062 | } |
4063 | ||
4064 | static void | |
4065 | free_https_port_list(https_port_list ** head) | |
4066 | { | |
154dc884 | 4067 | free_http_port_list((http_port_list**)head); |
d193a436 | 4068 | } |
4069 | ||
4070 | #if 0 | |
4071 | static int | |
4072 | check_null_https_port_list(const https_port_list * s) | |
4073 | { | |
4074 | return NULL == s; | |
4075 | } | |
62e76326 | 4076 | |
d193a436 | 4077 | #endif |
4078 | ||
4079 | #endif /* USE_SSL */ | |
4080 | ||
f150dd4b | 4081 | void |
4082 | configFreeMemory(void) | |
4083 | { | |
23ff6968 | 4084 | free_all(); |
29bf4910 CT |
4085 | #if USE_SSL |
4086 | SSL_CTX_free(Config.ssl_client.sslContext); | |
4087 | #endif | |
f150dd4b | 4088 | } |
f0b19334 | 4089 | |
94439e4e | 4090 | void |
f0b19334 | 4091 | requirePathnameExists(const char *name, const char *path) |
4092 | { | |
62e76326 | 4093 | |
f0b19334 | 4094 | struct stat sb; |
08577e16 | 4095 | char pathbuf[BUFSIZ]; |
f0b19334 | 4096 | assert(path != NULL); |
62e76326 | 4097 | |
0b796acd | 4098 | if (Config.chroot_dir && (geteuid() == 0)) { |
62e76326 | 4099 | snprintf(pathbuf, BUFSIZ, "%s/%s", Config.chroot_dir, path); |
4100 | path = pathbuf; | |
08577e16 | 4101 | } |
62e76326 | 4102 | |
a572d8be | 4103 | if (stat(path, &sb) < 0) { |
a32a190b AJ |
4104 | debugs(0, DBG_CRITICAL, (opt_parse_cfg_only?"FATAL ":"") << "ERROR: " << name << " " << path << ": " << xstrerror()); |
4105 | // keep going to find more issues if we are only checking the config file with "-k parse" | |
4106 | if (opt_parse_cfg_only) | |
4107 | return; | |
4108 | // this is fatal if it is found during startup or reconfigure | |
a572d8be | 4109 | if (opt_send_signal == -1 || opt_send_signal == SIGHUP) |
4110 | fatalf("%s %s: %s", name, path, xstrerror()); | |
a572d8be | 4111 | } |
f0b19334 | 4112 | } |
d860a1aa | 4113 | |
4114 | char * | |
4115 | strtokFile(void) | |
4116 | { | |
d295d770 | 4117 | return ConfigParser::strtokFile(); |
d860a1aa | 4118 | } |
7684c4b1 | 4119 | |
450e0c10 | 4120 | #include "AccessLogEntry.h" |
7684c4b1 | 4121 | |
4122 | static void | |
4123 | parse_access_log(customlog ** logs) | |
4124 | { | |
4125 | const char *filename, *logdef_name; | |
7684c4b1 | 4126 | |
38e16f92 | 4127 | customlog *cl = (customlog *)xcalloc(1, sizeof(*cl)); |
7684c4b1 | 4128 | |
9eeb8e4b | 4129 | if ((filename = strtok(NULL, w_space)) == NULL) { |
7684c4b1 | 4130 | self_destruct(); |
9eeb8e4b | 4131 | return; |
4132 | } | |
7684c4b1 | 4133 | |
4134 | if (strcmp(filename, "none") == 0) { | |
20efa1c2 | 4135 | cl->type = Log::Format::CLF_NONE; |
6375a714 AJ |
4136 | aclParseAclList(LegacyParser, &cl->aclList); |
4137 | while (*logs) | |
4138 | logs = &(*logs)->next; | |
4139 | *logs = cl; | |
4140 | return; | |
7684c4b1 | 4141 | } |
4142 | ||
4143 | if ((logdef_name = strtok(NULL, w_space)) == NULL) | |
20efa1c2 | 4144 | logdef_name = "squid"; |
7684c4b1 | 4145 | |
bf8fe701 | 4146 | debugs(3, 9, "Log definition name '" << logdef_name << "' file '" << filename << "'"); |
7684c4b1 | 4147 | |
4148 | cl->filename = xstrdup(filename); | |
4149 | ||
4150 | /* look for the definition pointer corresponding to this name */ | |
38e16f92 | 4151 | Format::Format *lf = Log::TheConfig.logformats; |
7684c4b1 | 4152 | |
4153 | while (lf != NULL) { | |
bf8fe701 | 4154 | debugs(3, 9, "Comparing against '" << lf->name << "'"); |
7684c4b1 | 4155 | |
4156 | if (strcmp(lf->name, logdef_name) == 0) | |
4157 | break; | |
4158 | ||
4159 | lf = lf->next; | |
4160 | } | |
4161 | ||
4162 | if (lf != NULL) { | |
20efa1c2 | 4163 | cl->type = Log::Format::CLF_CUSTOM; |
7684c4b1 | 4164 | cl->logFormat = lf; |
4165 | } else if (strcmp(logdef_name, "auto") == 0) { | |
20efa1c2 AJ |
4166 | debugs(0,0, "WARNING: Log format 'auto' no longer exists. Using 'squid' instead."); |
4167 | cl->type = Log::Format::CLF_SQUID; | |
7684c4b1 | 4168 | } else if (strcmp(logdef_name, "squid") == 0) { |
20efa1c2 | 4169 | cl->type = Log::Format::CLF_SQUID; |
7684c4b1 | 4170 | } else if (strcmp(logdef_name, "common") == 0) { |
20efa1c2 AJ |
4171 | cl->type = Log::Format::CLF_COMMON; |
4172 | } else if (strcmp(logdef_name, "combined") == 0) { | |
4173 | cl->type = Log::Format::CLF_COMBINED; | |
3ff65596 AR |
4174 | #if ICAP_CLIENT |
4175 | } else if (strcmp(logdef_name, "icap_squid") == 0) { | |
20efa1c2 | 4176 | cl->type = Log::Format::CLF_ICAP_SQUID; |
3ff65596 | 4177 | #endif |
20efa1c2 AJ |
4178 | } else if (strcmp(logdef_name, "useragent") == 0) { |
4179 | cl->type = Log::Format::CLF_USERAGENT; | |
4180 | } else if (strcmp(logdef_name, "referrer") == 0) { | |
4181 | cl->type = Log::Format::CLF_REFERER; | |
7684c4b1 | 4182 | } else { |
bf8fe701 | 4183 | debugs(3, 0, "Log format '" << logdef_name << "' is not defined"); |
7684c4b1 | 4184 | self_destruct(); |
9eeb8e4b | 4185 | return; |
7684c4b1 | 4186 | } |
4187 | ||
a9f20260 | 4188 | aclParseAclList(LegacyParser, &cl->aclList); |
7684c4b1 | 4189 | |
4190 | while (*logs) | |
4191 | logs = &(*logs)->next; | |
4192 | ||
4193 | *logs = cl; | |
4194 | } | |
4195 | ||
d64bef4c | 4196 | static int |
4197 | check_null_access_log(customlog *customlog_definitions) | |
4198 | { | |
4199 | return customlog_definitions == NULL; | |
4200 | } | |
4201 | ||
7684c4b1 | 4202 | static void |
4203 | dump_access_log(StoreEntry * entry, const char *name, customlog * logs) | |
4204 | { | |
4205 | customlog *log; | |
4206 | ||
4207 | for (log = logs; log; log = log->next) { | |
4208 | storeAppendPrintf(entry, "%s ", name); | |
4209 | ||
4210 | switch (log->type) { | |
4211 | ||
20efa1c2 | 4212 | case Log::Format::CLF_CUSTOM: |
7684c4b1 | 4213 | storeAppendPrintf(entry, "%s %s", log->filename, log->logFormat->name); |
4214 | break; | |
4215 | ||
20efa1c2 | 4216 | case Log::Format::CLF_NONE: |
7684c4b1 | 4217 | storeAppendPrintf(entry, "none"); |
4218 | break; | |
4219 | ||
20efa1c2 | 4220 | case Log::Format::CLF_SQUID: |
7684c4b1 | 4221 | storeAppendPrintf(entry, "%s squid", log->filename); |
4222 | break; | |
4223 | ||
20efa1c2 AJ |
4224 | case Log::Format::CLF_COMBINED: |
4225 | storeAppendPrintf(entry, "%s combined", log->filename); | |
4226 | break; | |
4227 | ||
4228 | case Log::Format::CLF_COMMON: | |
4229 | storeAppendPrintf(entry, "%s common", log->filename); | |
7684c4b1 | 4230 | break; |
20efa1c2 | 4231 | |
3ff65596 | 4232 | #if ICAP_CLIENT |
20efa1c2 | 4233 | case Log::Format::CLF_ICAP_SQUID: |
3ff65596 AR |
4234 | storeAppendPrintf(entry, "%s icap_squid", log->filename); |
4235 | break; | |
4236 | #endif | |
20efa1c2 AJ |
4237 | case Log::Format::CLF_USERAGENT: |
4238 | storeAppendPrintf(entry, "%s useragent", log->filename); | |
4239 | break; | |
7684c4b1 | 4240 | |
20efa1c2 AJ |
4241 | case Log::Format::CLF_REFERER: |
4242 | storeAppendPrintf(entry, "%s referrer", log->filename); | |
7684c4b1 | 4243 | break; |
4244 | ||
20efa1c2 | 4245 | case Log::Format::CLF_UNKNOWN: |
7684c4b1 | 4246 | break; |
4247 | } | |
4248 | ||
4249 | if (log->aclList) | |
4250 | dump_acl_list(entry, log->aclList); | |
4251 | ||
4252 | storeAppendPrintf(entry, "\n"); | |
4253 | } | |
4254 | } | |
4255 | ||
7684c4b1 | 4256 | static void |
4257 | free_access_log(customlog ** definitions) | |
4258 | { | |
4259 | while (*definitions) { | |
4260 | customlog *log = *definitions; | |
4261 | *definitions = log->next; | |
4262 | ||
4263 | log->logFormat = NULL; | |
20efa1c2 | 4264 | log->type = Log::Format::CLF_UNKNOWN; |
7684c4b1 | 4265 | |
4266 | if (log->aclList) | |
4267 | aclDestroyAclList(&log->aclList); | |
4268 | ||
4269 | safe_free(log->filename); | |
4270 | ||
4271 | xfree(log); | |
4272 | } | |
4273 | } | |
3a69ddf3 | 4274 | |
96c2bb61 AR |
4275 | /// parses list of integers form name=N1,N2,N3,... |
4276 | static bool | |
4277 | parseNamedIntList(const char *data, const String &name, Vector<int> &list) | |
4278 | { | |
4279 | if (data && (strncmp(data, name.rawBuf(), name.size()) == 0)) { | |
4280 | data += name.size(); | |
4281 | if (*data == '=') { | |
4282 | while (true) { | |
4283 | ++data; | |
4284 | int value = 0; | |
4285 | if (!StringToInt(data, value, &data, 10)) | |
4286 | break; | |
4287 | list.push_back(value); | |
4288 | if (*data == '\0' || *data != ',') | |
4289 | break; | |
4290 | } | |
4291 | } | |
4292 | } | |
cff99cec | 4293 | return data && *data == '\0'; |
96c2bb61 AR |
4294 | } |
4295 | ||
4296 | static void | |
212af65c A |
4297 | parse_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap) |
4298 | { | |
96c2bb61 AR |
4299 | #if !HAVE_CPU_AFFINITY |
4300 | debugs(3, DBG_CRITICAL, "FATAL: Squid built with no CPU affinity " << | |
4301 | "support, do not set 'cpu_affinity_map'"); | |
4302 | self_destruct(); | |
4303 | #endif /* HAVE_CPU_AFFINITY */ | |
4304 | ||
4305 | if (!*cpuAffinityMap) | |
4306 | *cpuAffinityMap = new CpuAffinityMap; | |
4307 | ||
4308 | const char *const pToken = strtok(NULL, w_space); | |
4309 | const char *const cToken = strtok(NULL, w_space); | |
4310 | Vector<int> processes, cores; | |
4311 | if (!parseNamedIntList(pToken, "process_numbers", processes)) { | |
4312 | debugs(3, DBG_CRITICAL, "FATAL: bad 'process_numbers' parameter " << | |
4313 | "in 'cpu_affinity_map'"); | |
4314 | self_destruct(); | |
4315 | } else if (!parseNamedIntList(cToken, "cores", cores)) { | |
4316 | debugs(3, DBG_CRITICAL, "FATAL: bad 'cores' parameter in " << | |
4317 | "'cpu_affinity_map'"); | |
4318 | self_destruct(); | |
4319 | } else if (!(*cpuAffinityMap)->add(processes, cores)) { | |
4320 | debugs(3, DBG_CRITICAL, "FATAL: bad 'cpu_affinity_map'; " << | |
4321 | "process_numbers and cores lists differ in length or " << | |
4322 | "contain numbers <= 0"); | |
4323 | self_destruct(); | |
4324 | } | |
4325 | } | |
4326 | ||
4327 | static void | |
212af65c A |
4328 | dump_CpuAffinityMap(StoreEntry *const entry, const char *const name, const CpuAffinityMap *const cpuAffinityMap) |
4329 | { | |
96c2bb61 AR |
4330 | if (cpuAffinityMap) { |
4331 | storeAppendPrintf(entry, "%s process_numbers=", name); | |
4332 | for (size_t i = 0; i < cpuAffinityMap->processes().size(); ++i) { | |
4333 | storeAppendPrintf(entry, "%s%i", (i ? "," : ""), | |
4334 | cpuAffinityMap->processes()[i]); | |
4335 | } | |
4336 | storeAppendPrintf(entry, " cores="); | |
4337 | for (size_t i = 0; i < cpuAffinityMap->processes().size(); ++i) { | |
4338 | storeAppendPrintf(entry, "%s%i", (i ? "," : ""), | |
4339 | cpuAffinityMap->cores()[i]); | |
4340 | } | |
4341 | storeAppendPrintf(entry, "\n"); | |
4342 | } | |
4343 | } | |
4344 | ||
4345 | static void | |
212af65c A |
4346 | free_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap) |
4347 | { | |
96c2bb61 AR |
4348 | delete *cpuAffinityMap; |
4349 | *cpuAffinityMap = NULL; | |
4350 | } | |
4351 | ||
62c7f90e AR |
4352 | #if USE_ADAPTATION |
4353 | ||
4354 | static void | |
4355 | parse_adaptation_service_set_type() | |
4356 | { | |
4357 | Adaptation::Config::ParseServiceSet(); | |
4358 | } | |
4359 | ||
a22e6cd3 AR |
4360 | static void |
4361 | parse_adaptation_service_chain_type() | |
4362 | { | |
4363 | Adaptation::Config::ParseServiceChain(); | |
4364 | } | |
4365 | ||
62c7f90e AR |
4366 | static void |
4367 | parse_adaptation_access_type() | |
4368 | { | |
4369 | Adaptation::Config::ParseAccess(LegacyParser); | |
4370 | } | |
4371 | ||
62c7f90e AR |
4372 | #endif /* USE_ADAPTATION */ |
4373 | ||
4374 | ||
3a69ddf3 | 4375 | #if ICAP_CLIENT |
4376 | ||
4377 | static void | |
26cc52cb | 4378 | parse_icap_service_type(Adaptation::Icap::Config * cfg) |
3a69ddf3 | 4379 | { |
462e63d3 | 4380 | cfg->parseService(); |
3a69ddf3 | 4381 | } |
4382 | ||
4383 | static void | |
26cc52cb | 4384 | free_icap_service_type(Adaptation::Icap::Config * cfg) |
3a69ddf3 | 4385 | { |
462e63d3 | 4386 | cfg->freeService(); |
3a69ddf3 | 4387 | } |
4388 | ||
4389 | static void | |
26cc52cb | 4390 | dump_icap_service_type(StoreEntry * entry, const char *name, const Adaptation::Icap::Config &cfg) |
3a69ddf3 | 4391 | { |
462e63d3 | 4392 | cfg.dumpService(entry, name); |
3a69ddf3 | 4393 | } |
4394 | ||
4395 | static void | |
c939dc70 | 4396 | parse_icap_class_type() |
3a69ddf3 | 4397 | { |
62c7f90e | 4398 | debugs(93, 0, "WARNING: 'icap_class' is depricated. " << |
26ac0430 | 4399 | "Use 'adaptation_service_set' instead"); |
62c7f90e | 4400 | Adaptation::Config::ParseServiceSet(); |
3a69ddf3 | 4401 | } |
4402 | ||
3a69ddf3 | 4403 | static void |
c939dc70 | 4404 | parse_icap_access_type() |
3a69ddf3 | 4405 | { |
62c7f90e | 4406 | debugs(93, 0, "WARNING: 'icap_access' is depricated. " << |
26ac0430 | 4407 | "Use 'adaptation_access' instead"); |
21a26d31 | 4408 | Adaptation::Config::ParseAccess(LegacyParser); |
3a69ddf3 | 4409 | } |
4410 | ||
3a69ddf3 | 4411 | #endif |
21a26d31 AR |
4412 | |
4413 | ||
4414 | #if USE_ECAP | |
4415 | ||
4416 | static void | |
574b508c | 4417 | parse_ecap_service_type(Adaptation::Ecap::Config * cfg) |
21a26d31 AR |
4418 | { |
4419 | cfg->parseService(); | |
4420 | } | |
4421 | ||
4422 | static void | |
574b508c | 4423 | free_ecap_service_type(Adaptation::Ecap::Config * cfg) |
21a26d31 AR |
4424 | { |
4425 | cfg->freeService(); | |
4426 | } | |
4427 | ||
4428 | static void | |
574b508c | 4429 | dump_ecap_service_type(StoreEntry * entry, const char *name, const Adaptation::Ecap::Config &cfg) |
21a26d31 AR |
4430 | { |
4431 | cfg.dumpService(entry, name); | |
4432 | } | |
4433 | ||
4434 | #endif /* USE_ECAP */ | |
8277060a CT |
4435 | |
4436 | #if ICAP_CLIENT | |
4437 | static void parse_icap_service_failure_limit(Adaptation::Icap::Config *cfg) | |
4438 | { | |
4439 | char *token; | |
4440 | time_t d; | |
4441 | time_t m; | |
4442 | cfg->service_failure_limit = GetInteger(); | |
4443 | ||
4444 | if ((token = strtok(NULL, w_space)) == NULL) | |
4445 | return; | |
4446 | ||
4447 | if (strcmp(token,"in") != 0) { | |
4448 | debugs(3, 0, "expecting 'in' on'" << config_input_line << "'"); | |
4449 | self_destruct(); | |
4450 | } | |
4451 | ||
4452 | if ((token = strtok(NULL, w_space)) == NULL) { | |
4453 | self_destruct(); | |
4454 | } | |
4455 | ||
4456 | d = static_cast<time_t> (xatoi(token)); | |
a459e80a | 4457 | |
8277060a CT |
4458 | m = static_cast<time_t> (1); |
4459 | ||
4460 | if (0 == d) | |
4461 | (void) 0; | |
4462 | else if ((token = strtok(NULL, w_space)) == NULL) { | |
4463 | debugs(3, 0, "No time-units on '" << config_input_line << "'"); | |
4464 | self_destruct(); | |
9b741834 | 4465 | } else if ((m = parseTimeUnits(token, false)) == 0) |
8277060a CT |
4466 | self_destruct(); |
4467 | ||
4468 | cfg->oldest_service_failure = (m * d); | |
4469 | } | |
4470 | ||
4471 | static void dump_icap_service_failure_limit(StoreEntry *entry, const char *name, const Adaptation::Icap::Config &cfg) | |
4472 | { | |
4473 | storeAppendPrintf(entry, "%s %d", name, cfg.service_failure_limit); | |
4474 | if (cfg.oldest_service_failure > 0) { | |
4475 | storeAppendPrintf(entry, " in %d seconds", (int)cfg.oldest_service_failure); | |
4476 | } | |
4477 | storeAppendPrintf(entry, "\n"); | |
4478 | } | |
4479 | ||
4480 | static void free_icap_service_failure_limit(Adaptation::Icap::Config *cfg) | |
4481 | { | |
4482 | cfg->oldest_service_failure = 0; | |
4483 | cfg->service_failure_limit = 0; | |
4484 | } | |
4485 | ||
4486 | #endif |