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