]>
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")) { | |
908 | debugs(3, DBG_CRITICAL, "WARNING: url_rewrite_concurrency upgrade overriding url_rewrite_children settings."); | |
909 | parse_int(&Config.redirectChildren.concurrency); | |
910 | } | |
911 | } | |
912 | ||
270b86af | 913 | /* Parse a time specification from the config file. Store the |
f1dc9b30 | 914 | * result in 'tptr', after converting it to 'units' */ |
8203a132 | 915 | static void |
a47b9029 | 916 | parseTimeLine(time_t * tptr, const char *units) |
090089c4 | 917 | { |
918 | char *token; | |
270b86af | 919 | double d; |
f1dc9b30 | 920 | time_t m; |
921 | time_t u; | |
62e76326 | 922 | |
270b86af | 923 | if ((u = parseTimeUnits(units)) == 0) |
62e76326 | 924 | self_destruct(); |
925 | ||
270b86af | 926 | if ((token = strtok(NULL, w_space)) == NULL) |
62e76326 | 927 | self_destruct(); |
928 | ||
5c20d6fa | 929 | d = xatof(token); |
62e76326 | 930 | |
270b86af | 931 | m = u; /* default to 'units' if none specified */ |
62e76326 | 932 | |
10738561 | 933 | if (0 == d) |
62e76326 | 934 | (void) 0; |
10738561 | 935 | else if ((token = strtok(NULL, w_space)) == NULL) |
26ac0430 AJ |
936 | debugs(3, 0, "WARNING: No units on '" << |
937 | config_input_line << "', assuming " << | |
938 | d << " " << units ); | |
9e975e4e | 939 | else if ((m = parseTimeUnits(token)) == 0) |
62e76326 | 940 | self_destruct(); |
941 | ||
e6ccf245 | 942 | *tptr = static_cast<time_t> (m * d / u); |
090089c4 | 943 | } |
944 | ||
270b86af | 945 | static int |
946 | parseTimeUnits(const char *unit) | |
947 | { | |
948 | if (!strncasecmp(unit, T_SECOND_STR, strlen(T_SECOND_STR))) | |
62e76326 | 949 | return 1; |
950 | ||
270b86af | 951 | if (!strncasecmp(unit, T_MINUTE_STR, strlen(T_MINUTE_STR))) |
62e76326 | 952 | return 60; |
953 | ||
270b86af | 954 | if (!strncasecmp(unit, T_HOUR_STR, strlen(T_HOUR_STR))) |
62e76326 | 955 | return 3600; |
956 | ||
270b86af | 957 | if (!strncasecmp(unit, T_DAY_STR, strlen(T_DAY_STR))) |
62e76326 | 958 | return 86400; |
959 | ||
270b86af | 960 | if (!strncasecmp(unit, T_WEEK_STR, strlen(T_WEEK_STR))) |
62e76326 | 961 | return 86400 * 7; |
962 | ||
270b86af | 963 | if (!strncasecmp(unit, T_FORTNIGHT_STR, strlen(T_FORTNIGHT_STR))) |
62e76326 | 964 | return 86400 * 14; |
965 | ||
270b86af | 966 | if (!strncasecmp(unit, T_MONTH_STR, strlen(T_MONTH_STR))) |
62e76326 | 967 | return 86400 * 30; |
968 | ||
270b86af | 969 | if (!strncasecmp(unit, T_YEAR_STR, strlen(T_YEAR_STR))) |
62e76326 | 970 | return static_cast<int>(86400 * 365.2522); |
971 | ||
270b86af | 972 | if (!strncasecmp(unit, T_DECADE_STR, strlen(T_DECADE_STR))) |
62e76326 | 973 | return static_cast<int>(86400 * 365.2522 * 10); |
974 | ||
bf8fe701 | 975 | debugs(3, 1, "parseTimeUnits: unknown time unit '" << unit << "'"); |
62e76326 | 976 | |
270b86af | 977 | return 0; |
978 | } | |
979 | ||
47f6e231 | 980 | static void |
981 | parseBytesLine64(int64_t * bptr, const char *units) | |
982 | { | |
983 | char *token; | |
984 | double d; | |
985 | int64_t m; | |
986 | int64_t u; | |
987 | ||
9eeb8e4b | 988 | if ((u = parseBytesUnits(units)) == 0) { |
47f6e231 | 989 | self_destruct(); |
9eeb8e4b | 990 | return; |
991 | } | |
47f6e231 | 992 | |
9eeb8e4b | 993 | if ((token = strtok(NULL, w_space)) == NULL) { |
47f6e231 | 994 | self_destruct(); |
9eeb8e4b | 995 | return; |
996 | } | |
47f6e231 | 997 | |
998 | if (strcmp(token, "none") == 0 || strcmp(token, "-1") == 0) { | |
bc41416d | 999 | *bptr = -1; |
47f6e231 | 1000 | return; |
1001 | } | |
1002 | ||
1003 | d = xatof(token); | |
1004 | ||
1005 | m = u; /* default to 'units' if none specified */ | |
1006 | ||
1007 | if (0.0 == d) | |
1008 | (void) 0; | |
1009 | else if ((token = strtok(NULL, w_space)) == NULL) | |
26ac0430 AJ |
1010 | debugs(3, 0, "WARNING: No units on '" << |
1011 | config_input_line << "', assuming " << | |
1012 | d << " " << units ); | |
9eeb8e4b | 1013 | else if ((m = parseBytesUnits(token)) == 0) { |
47f6e231 | 1014 | self_destruct(); |
9eeb8e4b | 1015 | return; |
1016 | } | |
47f6e231 | 1017 | |
1018 | *bptr = static_cast<int64_t>(m * d / u); | |
1019 | ||
1020 | if (static_cast<double>(*bptr) * 2 != m * d / u * 2) | |
1021 | self_destruct(); | |
1022 | } | |
1023 | ||
1024 | ||
9906e724 | 1025 | static void |
9e975e4e | 1026 | parseBytesLine(size_t * bptr, const char *units) |
9906e724 | 1027 | { |
1028 | char *token; | |
1029 | double d; | |
47f6e231 | 1030 | int m; |
1031 | int u; | |
62e76326 | 1032 | |
9eeb8e4b | 1033 | if ((u = parseBytesUnits(units)) == 0) { |
62e76326 | 1034 | self_destruct(); |
9eeb8e4b | 1035 | return; |
1036 | } | |
62e76326 | 1037 | |
9eeb8e4b | 1038 | if ((token = strtok(NULL, w_space)) == NULL) { |
62e76326 | 1039 | self_destruct(); |
9eeb8e4b | 1040 | return; |
1041 | } | |
62e76326 | 1042 | |
f8ecd7d7 | 1043 | if (strcmp(token, "none") == 0 || strcmp(token, "-1") == 0) { |
b2d729e6 | 1044 | *bptr = static_cast<size_t>(-1); |
ef1955a5 | 1045 | return; |
1046 | } | |
1047 | ||
5c20d6fa | 1048 | d = xatof(token); |
62e76326 | 1049 | |
9906e724 | 1050 | m = u; /* default to 'units' if none specified */ |
62e76326 | 1051 | |
343f47a3 | 1052 | if (0.0 == d) |
62e76326 | 1053 | (void) 0; |
4860dc1b | 1054 | else if ((token = strtok(NULL, w_space)) == NULL) |
26ac0430 AJ |
1055 | debugs(3, 0, "WARNING: No units on '" << |
1056 | config_input_line << "', assuming " << | |
1057 | d << " " << units ); | |
9eeb8e4b | 1058 | else if ((m = parseBytesUnits(token)) == 0) { |
62e76326 | 1059 | self_destruct(); |
9eeb8e4b | 1060 | return; |
1061 | } | |
62e76326 | 1062 | |
e6ccf245 | 1063 | *bptr = static_cast<size_t>(m * d / u); |
347ae7c4 | 1064 | |
a69d485c | 1065 | if (static_cast<double>(*bptr) * 2 != m * d / u * 2) |
347ae7c4 | 1066 | self_destruct(); |
9906e724 | 1067 | } |
1068 | ||
e210930b AJ |
1069 | #if !USE_DNSSERVERS |
1070 | static void | |
1071 | parseBytesLineSigned(ssize_t * bptr, const char *units) | |
1072 | { | |
1073 | char *token; | |
1074 | double d; | |
1075 | int m; | |
1076 | int u; | |
1077 | ||
1078 | if ((u = parseBytesUnits(units)) == 0) { | |
1079 | self_destruct(); | |
1080 | return; | |
1081 | } | |
1082 | ||
1083 | if ((token = strtok(NULL, w_space)) == NULL) { | |
1084 | self_destruct(); | |
1085 | return; | |
1086 | } | |
1087 | ||
1088 | if (strcmp(token, "none") == 0 || token[0] == '-' /* -N */) { | |
1089 | *bptr = -1; | |
1090 | return; | |
1091 | } | |
1092 | ||
1093 | d = xatof(token); | |
1094 | ||
1095 | m = u; /* default to 'units' if none specified */ | |
1096 | ||
1097 | if (0.0 == d) | |
1098 | (void) 0; | |
1099 | else if ((token = strtok(NULL, w_space)) == NULL) | |
1100 | debugs(3, 0, "WARNING: No units on '" << | |
1101 | config_input_line << "', assuming " << | |
1102 | d << " " << units ); | |
1103 | else if ((m = parseBytesUnits(token)) == 0) { | |
1104 | self_destruct(); | |
1105 | return; | |
1106 | } | |
1107 | ||
1108 | *bptr = static_cast<size_t>(m * d / u); | |
1109 | ||
1110 | if (static_cast<double>(*bptr) * 2 != m * d / u * 2) | |
1111 | self_destruct(); | |
1112 | } | |
1113 | #endif | |
1114 | ||
9906e724 | 1115 | static size_t |
1116 | parseBytesUnits(const char *unit) | |
1117 | { | |
1118 | if (!strncasecmp(unit, B_BYTES_STR, strlen(B_BYTES_STR))) | |
62e76326 | 1119 | return 1; |
1120 | ||
9906e724 | 1121 | if (!strncasecmp(unit, B_KBYTES_STR, strlen(B_KBYTES_STR))) |
62e76326 | 1122 | return 1 << 10; |
1123 | ||
9906e724 | 1124 | if (!strncasecmp(unit, B_MBYTES_STR, strlen(B_MBYTES_STR))) |
62e76326 | 1125 | return 1 << 20; |
1126 | ||
9906e724 | 1127 | if (!strncasecmp(unit, B_GBYTES_STR, strlen(B_GBYTES_STR))) |
62e76326 | 1128 | return 1 << 30; |
1129 | ||
fa37412f | 1130 | debugs(3, DBG_CRITICAL, "WARNING: Unknown bytes unit '" << unit << "'"); |
62e76326 | 1131 | |
9906e724 | 1132 | return 0; |
1133 | } | |
1134 | ||
270b86af | 1135 | /***************************************************************************** |
1136 | * Max | |
1137 | *****************************************************************************/ | |
1138 | ||
8203a132 | 1139 | static void |
97427e90 | 1140 | dump_acl(StoreEntry * entry, const char *name, ACL * ae) |
090089c4 | 1141 | { |
56b63fa1 | 1142 | wordlist *w; |
1143 | wordlist *v; | |
62e76326 | 1144 | |
9ef28b60 | 1145 | while (ae != NULL) { |
bf8fe701 | 1146 | debugs(3, 3, "dump_acl: " << name << " " << ae->name); |
62e76326 | 1147 | storeAppendPrintf(entry, "%s %s %s ", |
1148 | name, | |
1149 | ae->name, | |
1150 | ae->typeString()); | |
6bf4f823 | 1151 | v = w = ae->dump(); |
62e76326 | 1152 | |
1153 | while (v != NULL) { | |
bf8fe701 | 1154 | debugs(3, 3, "dump_acl: " << name << " " << ae->name << " " << v->key); |
62e76326 | 1155 | storeAppendPrintf(entry, "%s ", v->key); |
1156 | v = v->next; | |
1157 | } | |
1158 | ||
1159 | storeAppendPrintf(entry, "\n"); | |
1160 | wordlistDestroy(&w); | |
1161 | ae = ae->next; | |
56b63fa1 | 1162 | } |
090089c4 | 1163 | } |
1164 | ||
8203a132 | 1165 | static void |
97427e90 | 1166 | parse_acl(ACL ** ae) |
090089c4 | 1167 | { |
a9f20260 | 1168 | ACL::ParseAclLine(LegacyParser, ae); |
f1dc9b30 | 1169 | } |
1170 | ||
1171 | static void | |
97427e90 | 1172 | free_acl(ACL ** ae) |
f1dc9b30 | 1173 | { |
9ef28b60 | 1174 | aclDestroyAcls(ae); |
090089c4 | 1175 | } |
1176 | ||
425de4c8 | 1177 | void |
76cd39d7 | 1178 | dump_acl_list(StoreEntry * entry, ACLList * head) |
30a4f2a8 | 1179 | { |
76cd39d7 | 1180 | ACLList *l; |
62e76326 | 1181 | |
d6827718 | 1182 | for (l = head; l; l = l->next) { |
62e76326 | 1183 | storeAppendPrintf(entry, " %s%s", |
1184 | l->op ? null_string : "!", | |
1185 | l->_acl->name); | |
d6827718 | 1186 | } |
1187 | } | |
1188 | ||
b67e2c8c | 1189 | void |
d6827718 | 1190 | dump_acl_access(StoreEntry * entry, const char *name, acl_access * head) |
1191 | { | |
1192 | acl_access *l; | |
62e76326 | 1193 | |
d6827718 | 1194 | for (l = head; l; l = l->next) { |
62e76326 | 1195 | storeAppendPrintf(entry, "%s %s", |
1196 | name, | |
1197 | l->allow ? "Allow" : "Deny"); | |
1198 | dump_acl_list(entry, l->aclList); | |
1199 | storeAppendPrintf(entry, "\n"); | |
56b63fa1 | 1200 | } |
30a4f2a8 | 1201 | } |
090089c4 | 1202 | |
8203a132 | 1203 | static void |
16300b58 | 1204 | parse_acl_access(acl_access ** head) |
090089c4 | 1205 | { |
a9f20260 | 1206 | aclParseAccessLine(LegacyParser, head); |
090089c4 | 1207 | } |
1208 | ||
0153d498 | 1209 | static void |
16300b58 | 1210 | free_acl_access(acl_access ** head) |
0153d498 | 1211 | { |
a47b9029 | 1212 | aclDestroyAccessList(head); |
0153d498 | 1213 | } |
1214 | ||
8203a132 | 1215 | static void |
b7ac5457 | 1216 | dump_address(StoreEntry * entry, const char *name, Ip::Address &addr) |
270b86af | 1217 | { |
cc192b50 | 1218 | char buf[MAX_IPSTRLEN]; |
1219 | storeAppendPrintf(entry, "%s %s\n", name, addr.NtoA(buf,MAX_IPSTRLEN) ); | |
270b86af | 1220 | } |
1221 | ||
1222 | static void | |
b7ac5457 | 1223 | parse_address(Ip::Address *addr) |
090089c4 | 1224 | { |
270b86af | 1225 | char *token = strtok(NULL, w_space); |
1226 | ||
9eeb8e4b | 1227 | if (!token) { |
62e76326 | 1228 | self_destruct(); |
9eeb8e4b | 1229 | return; |
1230 | } | |
62e76326 | 1231 | |
26ac0430 | 1232 | if (!strcmp(token,"any_addr")) { |
cc192b50 | 1233 | addr->SetAnyAddr(); |
26ac0430 AJ |
1234 | (void) 0; |
1235 | } else if ( (!strcmp(token,"no_addr")) || (!strcmp(token,"full_mask")) ) { | |
cc192b50 | 1236 | addr->SetNoAddr(); |
26ac0430 AJ |
1237 | (void) 0; |
1238 | } else | |
cc192b50 | 1239 | *addr = token; |
090089c4 | 1240 | } |
1241 | ||
0153d498 | 1242 | static void |
b7ac5457 | 1243 | free_address(Ip::Address *addr) |
0153d498 | 1244 | { |
cc192b50 | 1245 | addr->SetEmpty(); |
0153d498 | 1246 | } |
1247 | ||
d6827718 | 1248 | CBDATA_TYPE(acl_address); |
1249 | ||
1250 | static void | |
1251 | dump_acl_address(StoreEntry * entry, const char *name, acl_address * head) | |
1252 | { | |
cc192b50 | 1253 | char buf[MAX_IPSTRLEN]; |
d6827718 | 1254 | acl_address *l; |
62e76326 | 1255 | |
d6827718 | 1256 | for (l = head; l; l = l->next) { |
cc192b50 | 1257 | if (!l->addr.IsAnyAddr()) |
1258 | storeAppendPrintf(entry, "%s %s", name, l->addr.NtoA(buf,MAX_IPSTRLEN)); | |
62e76326 | 1259 | else |
1260 | storeAppendPrintf(entry, "%s autoselect", name); | |
1261 | ||
1262 | dump_acl_list(entry, l->aclList); | |
1263 | ||
1264 | storeAppendPrintf(entry, "\n"); | |
d6827718 | 1265 | } |
1266 | } | |
1267 | ||
1268 | static void | |
1269 | freed_acl_address(void *data) | |
1270 | { | |
e6ccf245 | 1271 | acl_address *l = static_cast<acl_address *>(data); |
29b8d8d6 | 1272 | aclDestroyAclList(&l->aclList); |
d6827718 | 1273 | } |
1274 | ||
1275 | static void | |
1276 | parse_acl_address(acl_address ** head) | |
1277 | { | |
1278 | acl_address *l; | |
1279 | acl_address **tail = head; /* sane name below */ | |
1280 | CBDATA_INIT_TYPE_FREECB(acl_address, freed_acl_address); | |
1281 | l = cbdataAlloc(acl_address); | |
1282 | parse_address(&l->addr); | |
a9f20260 | 1283 | aclParseAclList(LegacyParser, &l->aclList); |
62e76326 | 1284 | |
d6827718 | 1285 | while (*tail) |
62e76326 | 1286 | tail = &(*tail)->next; |
1287 | ||
d6827718 | 1288 | *tail = l; |
1289 | } | |
1290 | ||
1291 | static void | |
1292 | free_acl_address(acl_address ** head) | |
1293 | { | |
1294 | while (*head) { | |
62e76326 | 1295 | acl_address *l = *head; |
1296 | *head = l->next; | |
1297 | cbdataFree(l); | |
d6827718 | 1298 | } |
1299 | } | |
1300 | ||
1301 | CBDATA_TYPE(acl_tos); | |
1302 | ||
1303 | static void | |
1304 | dump_acl_tos(StoreEntry * entry, const char *name, acl_tos * head) | |
1305 | { | |
1306 | acl_tos *l; | |
62e76326 | 1307 | |
d6827718 | 1308 | for (l = head; l; l = l->next) { |
62e76326 | 1309 | if (l->tos > 0) |
1310 | storeAppendPrintf(entry, "%s 0x%02X", name, l->tos); | |
1311 | else | |
1312 | storeAppendPrintf(entry, "%s none", name); | |
1313 | ||
1314 | dump_acl_list(entry, l->aclList); | |
1315 | ||
1316 | storeAppendPrintf(entry, "\n"); | |
d6827718 | 1317 | } |
1318 | } | |
1319 | ||
1320 | static void | |
1321 | freed_acl_tos(void *data) | |
1322 | { | |
e6ccf245 | 1323 | acl_tos *l = static_cast<acl_tos *>(data); |
29b8d8d6 | 1324 | aclDestroyAclList(&l->aclList); |
d6827718 | 1325 | } |
1326 | ||
1327 | static void | |
1328 | parse_acl_tos(acl_tos ** head) | |
1329 | { | |
1330 | acl_tos *l; | |
1331 | acl_tos **tail = head; /* sane name below */ | |
425de4c8 | 1332 | unsigned int tos; /* Initially uint for strtoui. Casted to tos_t before return */ |
d6827718 | 1333 | char *token = strtok(NULL, w_space); |
62e76326 | 1334 | |
9eeb8e4b | 1335 | if (!token) { |
62e76326 | 1336 | self_destruct(); |
9eeb8e4b | 1337 | return; |
1338 | } | |
62e76326 | 1339 | |
425de4c8 | 1340 | if (!xstrtoui(token, NULL, &tos, 0, std::numeric_limits<tos_t>::max())) { |
62e76326 | 1341 | self_destruct(); |
9eeb8e4b | 1342 | return; |
1343 | } | |
62e76326 | 1344 | |
d6827718 | 1345 | CBDATA_INIT_TYPE_FREECB(acl_tos, freed_acl_tos); |
62e76326 | 1346 | |
d6827718 | 1347 | l = cbdataAlloc(acl_tos); |
62e76326 | 1348 | |
425de4c8 | 1349 | l->tos = (tos_t)tos; |
62e76326 | 1350 | |
a9f20260 | 1351 | aclParseAclList(LegacyParser, &l->aclList); |
62e76326 | 1352 | |
d6827718 | 1353 | while (*tail) |
62e76326 | 1354 | tail = &(*tail)->next; |
1355 | ||
d6827718 | 1356 | *tail = l; |
1357 | } | |
1358 | ||
1359 | static void | |
1360 | free_acl_tos(acl_tos ** head) | |
1361 | { | |
1362 | while (*head) { | |
62e76326 | 1363 | acl_tos *l = *head; |
1364 | *head = l->next; | |
1365 | l->next = NULL; | |
1366 | cbdataFree(l); | |
d6827718 | 1367 | } |
1368 | } | |
1369 | ||
f4f6c2e0 AJ |
1370 | #if defined(SO_MARK) |
1371 | ||
425de4c8 AJ |
1372 | CBDATA_TYPE(acl_nfmark); |
1373 | ||
1374 | static void | |
1375 | dump_acl_nfmark(StoreEntry * entry, const char *name, acl_nfmark * head) | |
1376 | { | |
1377 | acl_nfmark *l; | |
1378 | ||
1379 | for (l = head; l; l = l->next) { | |
1380 | if (l->nfmark > 0) | |
1381 | storeAppendPrintf(entry, "%s 0x%02X", name, l->nfmark); | |
1382 | else | |
1383 | storeAppendPrintf(entry, "%s none", name); | |
1384 | ||
1385 | dump_acl_list(entry, l->aclList); | |
1386 | ||
1387 | storeAppendPrintf(entry, "\n"); | |
1388 | } | |
1389 | } | |
1390 | ||
1391 | static void | |
1392 | freed_acl_nfmark(void *data) | |
1393 | { | |
1394 | acl_nfmark *l = static_cast<acl_nfmark *>(data); | |
1395 | aclDestroyAclList(&l->aclList); | |
1396 | } | |
1397 | ||
1398 | static void | |
1399 | parse_acl_nfmark(acl_nfmark ** head) | |
1400 | { | |
1401 | acl_nfmark *l; | |
1402 | acl_nfmark **tail = head; /* sane name below */ | |
1403 | nfmark_t mark; | |
1404 | char *token = strtok(NULL, w_space); | |
1405 | ||
1406 | if (!token) { | |
1407 | self_destruct(); | |
1408 | return; | |
1409 | } | |
1410 | ||
1411 | if (!xstrtoui(token, NULL, &mark, 0, std::numeric_limits<nfmark_t>::max())) { | |
1412 | self_destruct(); | |
1413 | return; | |
1414 | } | |
1415 | ||
1416 | CBDATA_INIT_TYPE_FREECB(acl_nfmark, freed_acl_nfmark); | |
1417 | ||
1418 | l = cbdataAlloc(acl_nfmark); | |
1419 | ||
1420 | l->nfmark = mark; | |
1421 | ||
1422 | aclParseAclList(LegacyParser, &l->aclList); | |
1423 | ||
1424 | while (*tail) | |
1425 | tail = &(*tail)->next; | |
1426 | ||
1427 | *tail = l; | |
1428 | } | |
1429 | ||
1430 | static void | |
1431 | free_acl_nfmark(acl_nfmark ** head) | |
1432 | { | |
1433 | while (*head) { | |
1434 | acl_nfmark *l = *head; | |
1435 | *head = l->next; | |
1436 | l->next = NULL; | |
1437 | cbdataFree(l); | |
1438 | } | |
1439 | } | |
f4f6c2e0 | 1440 | #endif /* SO_MARK */ |
425de4c8 | 1441 | |
ef1955a5 | 1442 | CBDATA_TYPE(acl_size_t); |
1443 | ||
1444 | static void | |
1445 | dump_acl_b_size_t(StoreEntry * entry, const char *name, acl_size_t * head) | |
1446 | { | |
1447 | acl_size_t *l; | |
1448 | ||
1449 | for (l = head; l; l = l->next) { | |
ed013b6c | 1450 | if (l->size != -1) |
ef1955a5 | 1451 | storeAppendPrintf(entry, "%s %d %s\n", name, (int) l->size, B_BYTES_STR); |
1452 | else | |
1453 | storeAppendPrintf(entry, "%s none", name); | |
1454 | ||
1455 | dump_acl_list(entry, l->aclList); | |
1456 | ||
1457 | storeAppendPrintf(entry, "\n"); | |
1458 | } | |
1459 | } | |
1460 | ||
1461 | static void | |
1462 | freed_acl_b_size_t(void *data) | |
1463 | { | |
1464 | acl_size_t *l = static_cast<acl_size_t *>(data); | |
1465 | aclDestroyAclList(&l->aclList); | |
1466 | } | |
1467 | ||
1468 | static void | |
1469 | parse_acl_b_size_t(acl_size_t ** head) | |
1470 | { | |
1471 | acl_size_t *l; | |
1472 | acl_size_t **tail = head; /* sane name below */ | |
1473 | ||
1474 | CBDATA_INIT_TYPE_FREECB(acl_size_t, freed_acl_b_size_t); | |
1475 | ||
1476 | l = cbdataAlloc(acl_size_t); | |
1477 | ||
47f6e231 | 1478 | parse_b_int64_t(&l->size); |
ef1955a5 | 1479 | |
a9f20260 | 1480 | aclParseAclList(LegacyParser, &l->aclList); |
ef1955a5 | 1481 | |
1482 | while (*tail) | |
1483 | tail = &(*tail)->next; | |
1484 | ||
1485 | *tail = l; | |
1486 | } | |
1487 | ||
1488 | static void | |
1489 | free_acl_b_size_t(acl_size_t ** head) | |
1490 | { | |
1491 | while (*head) { | |
1492 | acl_size_t *l = *head; | |
1493 | *head = l->next; | |
1494 | l->next = NULL; | |
1495 | cbdataFree(l); | |
1496 | } | |
1497 | } | |
1498 | ||
59715b38 | 1499 | #if DELAY_POOLS |
1500 | ||
b67e2c8c | 1501 | #include "DelayPools.h" |
1502 | #include "DelayConfig.h" | |
59715b38 | 1503 | /* do nothing - free_delay_pool_count is the magic free function. |
1504 | * this is why delay_pool_count isn't just marked TYPE: ushort | |
1505 | */ | |
1506 | #define free_delay_pool_class(X) | |
1507 | #define free_delay_pool_access(X) | |
1508 | #define free_delay_pool_rates(X) | |
1509 | #define dump_delay_pool_class(X, Y, Z) | |
1510 | #define dump_delay_pool_access(X, Y, Z) | |
1511 | #define dump_delay_pool_rates(X, Y, Z) | |
1512 | ||
1513 | static void | |
b67e2c8c | 1514 | free_delay_pool_count(DelayConfig * cfg) |
59715b38 | 1515 | { |
b67e2c8c | 1516 | cfg->freePoolCount(); |
59715b38 | 1517 | } |
1518 | ||
1519 | static void | |
b67e2c8c | 1520 | dump_delay_pool_count(StoreEntry * entry, const char *name, DelayConfig &cfg) |
59715b38 | 1521 | { |
b67e2c8c | 1522 | cfg.dumpPoolCount (entry, name); |
59715b38 | 1523 | } |
1524 | ||
1525 | static void | |
b67e2c8c | 1526 | parse_delay_pool_count(DelayConfig * cfg) |
59715b38 | 1527 | { |
b67e2c8c | 1528 | cfg->parsePoolCount(); |
59715b38 | 1529 | } |
1530 | ||
1531 | static void | |
b67e2c8c | 1532 | parse_delay_pool_class(DelayConfig * cfg) |
59715b38 | 1533 | { |
b67e2c8c | 1534 | cfg->parsePoolClass(); |
59715b38 | 1535 | } |
1536 | ||
1537 | static void | |
b67e2c8c | 1538 | parse_delay_pool_rates(DelayConfig * cfg) |
59715b38 | 1539 | { |
b67e2c8c | 1540 | cfg->parsePoolRates(); |
59715b38 | 1541 | } |
1542 | ||
1543 | static void | |
b67e2c8c | 1544 | parse_delay_pool_access(DelayConfig * cfg) |
59715b38 | 1545 | { |
a9f20260 | 1546 | cfg->parsePoolAccess(LegacyParser); |
59715b38 | 1547 | } |
62e76326 | 1548 | |
59715b38 | 1549 | #endif |
1550 | ||
626096be | 1551 | #if USE_HTTP_VIOLATIONS |
97474590 | 1552 | static void |
6bccf575 | 1553 | dump_http_header_access(StoreEntry * entry, const char *name, header_mangler header[]) |
e3dd531e | 1554 | { |
efd900cb | 1555 | int i; |
62e76326 | 1556 | |
6bccf575 | 1557 | for (i = 0; i < HDR_ENUM_END; i++) { |
62e76326 | 1558 | if (header[i].access_list != NULL) { |
1559 | storeAppendPrintf(entry, "%s ", name); | |
1560 | dump_acl_access(entry, httpHeaderNameById(i), | |
1561 | header[i].access_list); | |
1562 | } | |
efd900cb | 1563 | } |
97474590 | 1564 | } |
e3dd531e | 1565 | |
97474590 | 1566 | static void |
6bccf575 | 1567 | parse_http_header_access(header_mangler header[]) |
97474590 | 1568 | { |
6bccf575 | 1569 | int id, i; |
97474590 | 1570 | char *t = NULL; |
62e76326 | 1571 | |
97474590 | 1572 | if ((t = strtok(NULL, w_space)) == NULL) { |
bf8fe701 | 1573 | debugs(3, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line); |
1574 | debugs(3, 0, "parse_http_header_access: missing header name."); | |
62e76326 | 1575 | return; |
97474590 | 1576 | } |
62e76326 | 1577 | |
6bccf575 | 1578 | /* Now lookup index of header. */ |
1579 | id = httpHeaderIdByNameDef(t, strlen(t)); | |
62e76326 | 1580 | |
6bccf575 | 1581 | if (strcmp(t, "All") == 0) |
62e76326 | 1582 | id = HDR_ENUM_END; |
6bccf575 | 1583 | else if (strcmp(t, "Other") == 0) |
62e76326 | 1584 | id = HDR_OTHER; |
6bccf575 | 1585 | else if (id == -1) { |
bf8fe701 | 1586 | debugs(3, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line); |
1587 | debugs(3, 0, "parse_http_header_access: unknown header name '" << t << "'"); | |
62e76326 | 1588 | return; |
97474590 | 1589 | } |
62e76326 | 1590 | |
6bccf575 | 1591 | if (id != HDR_ENUM_END) { |
62e76326 | 1592 | parse_acl_access(&header[id].access_list); |
6bccf575 | 1593 | } else { |
62e76326 | 1594 | char *next_string = t + strlen(t) - 1; |
1595 | *next_string = 'A'; | |
1596 | *(next_string + 1) = ' '; | |
1597 | ||
1598 | for (i = 0; i < HDR_ENUM_END; i++) { | |
1599 | char *new_string = xstrdup(next_string); | |
1600 | strtok(new_string, w_space); | |
1601 | parse_acl_access(&header[i].access_list); | |
1602 | safe_free(new_string); | |
1603 | } | |
97474590 | 1604 | } |
6bccf575 | 1605 | } |
1606 | ||
1607 | static void | |
1608 | free_http_header_access(header_mangler header[]) | |
1609 | { | |
1610 | int i; | |
62e76326 | 1611 | |
6bccf575 | 1612 | for (i = 0; i < HDR_ENUM_END; i++) { |
62e76326 | 1613 | free_acl_access(&header[i].access_list); |
6bccf575 | 1614 | } |
1615 | } | |
1616 | ||
1617 | static void | |
1618 | dump_http_header_replace(StoreEntry * entry, const char *name, header_mangler | |
62e76326 | 1619 | header[]) |
6bccf575 | 1620 | { |
1621 | int i; | |
62e76326 | 1622 | |
6bccf575 | 1623 | for (i = 0; i < HDR_ENUM_END; i++) { |
62e76326 | 1624 | if (NULL == header[i].replacement) |
1625 | continue; | |
1626 | ||
1627 | storeAppendPrintf(entry, "%s %s %s\n", name, httpHeaderNameById(i), | |
1628 | header[i].replacement); | |
97474590 | 1629 | } |
1630 | } | |
e3dd531e | 1631 | |
97474590 | 1632 | static void |
6bccf575 | 1633 | parse_http_header_replace(header_mangler header[]) |
e3dd531e | 1634 | { |
6bccf575 | 1635 | int id, i; |
1636 | char *t = NULL; | |
62e76326 | 1637 | |
6bccf575 | 1638 | if ((t = strtok(NULL, w_space)) == NULL) { |
bf8fe701 | 1639 | debugs(3, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line); |
1640 | debugs(3, 0, "parse_http_header_replace: missing header name."); | |
62e76326 | 1641 | return; |
6bccf575 | 1642 | } |
62e76326 | 1643 | |
6bccf575 | 1644 | /* Now lookup index of header. */ |
1645 | id = httpHeaderIdByNameDef(t, strlen(t)); | |
62e76326 | 1646 | |
6bccf575 | 1647 | if (strcmp(t, "All") == 0) |
62e76326 | 1648 | id = HDR_ENUM_END; |
6bccf575 | 1649 | else if (strcmp(t, "Other") == 0) |
62e76326 | 1650 | id = HDR_OTHER; |
6bccf575 | 1651 | else if (id == -1) { |
bf8fe701 | 1652 | debugs(3, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line); |
1653 | debugs(3, 0, "parse_http_header_replace: unknown header name " << t << "."); | |
1654 | ||
62e76326 | 1655 | return; |
6bccf575 | 1656 | } |
62e76326 | 1657 | |
6bccf575 | 1658 | if (id != HDR_ENUM_END) { |
62e76326 | 1659 | if (header[id].replacement != NULL) |
1660 | safe_free(header[id].replacement); | |
1661 | ||
1662 | header[id].replacement = xstrdup(t + strlen(t) + 1); | |
6bccf575 | 1663 | } else { |
62e76326 | 1664 | for (i = 0; i < HDR_ENUM_END; i++) { |
1665 | if (header[i].replacement != NULL) | |
1666 | safe_free(header[i].replacement); | |
1667 | ||
1668 | header[i].replacement = xstrdup(t + strlen(t) + 1); | |
1669 | } | |
6bccf575 | 1670 | } |
1671 | } | |
1672 | ||
1673 | static void | |
1674 | free_http_header_replace(header_mangler header[]) | |
1675 | { | |
1676 | int i; | |
62e76326 | 1677 | |
6bccf575 | 1678 | for (i = 0; i < HDR_ENUM_END; i++) { |
62e76326 | 1679 | if (header[i].replacement != NULL) |
1680 | safe_free(header[i].replacement); | |
6bccf575 | 1681 | } |
97474590 | 1682 | } |
62e76326 | 1683 | |
9e8b2f1c | 1684 | #endif |
97474590 | 1685 | |
e90100aa | 1686 | static void |
e1f7507e | 1687 | dump_cachedir(StoreEntry * entry, const char *name, SquidConfig::_cacheSwap swap) |
e90100aa | 1688 | { |
f53b06f9 | 1689 | SwapDir *s; |
1690 | int i; | |
d3b3ab85 | 1691 | assert (entry); |
62e76326 | 1692 | |
a7d59104 | 1693 | for (i = 0; i < swap.n_configured; i++) { |
c8f4eac4 | 1694 | s = dynamic_cast<SwapDir *>(swap.swapDirs[i].getRaw()); |
26ac0430 | 1695 | if (!s) continue; |
59b2d47f | 1696 | storeAppendPrintf(entry, "%s %s %s", name, s->type(), s->path); |
62e76326 | 1697 | s->dump(*entry); |
62e76326 | 1698 | storeAppendPrintf(entry, "\n"); |
f53b06f9 | 1699 | } |
1700 | } | |
1701 | ||
53ad48e6 | 1702 | static int |
1703 | check_null_string(char *s) | |
1704 | { | |
1705 | return s == NULL; | |
1706 | } | |
1707 | ||
94439e4e | 1708 | static void |
5817ee13 | 1709 | parse_authparam(Auth::authConfig * config) |
94439e4e | 1710 | { |
1711 | char *type_str; | |
1712 | char *param_str; | |
94439e4e | 1713 | |
1714 | if ((type_str = strtok(NULL, w_space)) == NULL) | |
62e76326 | 1715 | self_destruct(); |
94439e4e | 1716 | |
1717 | if ((param_str = strtok(NULL, w_space)) == NULL) | |
62e76326 | 1718 | self_destruct(); |
94439e4e | 1719 | |
5817ee13 AJ |
1720 | /* find a configuration for the scheme in the currently parsed configs... */ |
1721 | AuthConfig *schemeCfg = AuthConfig::Find(type_str); | |
62e76326 | 1722 | |
5817ee13 AJ |
1723 | if (schemeCfg == NULL) { |
1724 | /* Create a configuration based on the scheme info */ | |
1725 | AuthScheme::Pointer theScheme = AuthScheme::Find(type_str); | |
f5691f9c | 1726 | |
5817ee13 AJ |
1727 | if (theScheme == NULL) { |
1728 | debugs(3, DBG_CRITICAL, "Parsing Config File: Unknown authentication scheme '" << type_str << "'."); | |
1729 | self_destruct(); | |
62e76326 | 1730 | } |
94439e4e | 1731 | |
f5691f9c | 1732 | config->push_back(theScheme->createConfig()); |
5817ee13 AJ |
1733 | schemeCfg = AuthConfig::Find(type_str); |
1734 | if (schemeCfg == NULL) { | |
1735 | debugs(3, DBG_CRITICAL, "Parsing Config File: Corruption configuring authentication scheme '" << type_str << "'."); | |
1736 | self_destruct(); | |
1737 | } | |
94439e4e | 1738 | } |
62e76326 | 1739 | |
5817ee13 | 1740 | schemeCfg->parse(schemeCfg, config->size(), param_str); |
94439e4e | 1741 | } |
1742 | ||
1743 | static void | |
5817ee13 | 1744 | free_authparam(Auth::authConfig * cfg) |
94439e4e | 1745 | { |
5817ee13 AJ |
1746 | /* Wipe the Auth globals and Detach/Destruct component config + state. */ |
1747 | cfg->clean(); | |
62e76326 | 1748 | |
5817ee13 | 1749 | /* remove our pointers to the probably-dead sub-configs */ |
f5691f9c | 1750 | while (cfg->size()) { |
5817ee13 AJ |
1751 | cfg->pop_back(); |
1752 | } | |
1753 | ||
1754 | /* on reconfigure initialize new auth schemes for the new config. */ | |
ec5858ff | 1755 | if (reconfiguring) { |
5817ee13 | 1756 | InitAuthSchemes(); |
94439e4e | 1757 | } |
94439e4e | 1758 | } |
1759 | ||
1760 | static void | |
1761 | dump_authparam(StoreEntry * entry, const char *name, authConfig cfg) | |
1762 | { | |
f5691f9c | 1763 | for (authConfig::iterator i = cfg.begin(); i != cfg.end(); ++i) |
1764 | (*i)->dump(entry, name, (*i)); | |
94439e4e | 1765 | } |
1766 | ||
59b2d47f | 1767 | /* TODO: just return the object, the # is irrelevant */ |
cd748f27 | 1768 | static int |
1769 | find_fstype(char *type) | |
1770 | { | |
59b2d47f | 1771 | for (size_t i = 0; i < StoreFileSystem::FileSystems().size(); ++i) |
1772 | if (strcasecmp(type, StoreFileSystem::FileSystems().items[i]->type()) == 0) | |
1773 | return (int)i; | |
62e76326 | 1774 | |
cd748f27 | 1775 | return (-1); |
1776 | } | |
1777 | ||
0e4e0e7d | 1778 | static void |
e1f7507e | 1779 | parse_cachedir(SquidConfig::_cacheSwap * swap) |
0e4e0e7d | 1780 | { |
acf69d74 AJ |
1781 | // The workers option must preceed cache_dir for the IamWorkerProcess check |
1782 | // below to work. TODO: Redo IamWorkerProcess to work w/o Config and remove | |
1783 | if (KidIdentifier > 1 && Config.workers == 1) { | |
1784 | debugs(3, DBG_CRITICAL, | |
1785 | "FATAL: cache_dir found before the workers option. Reorder."); | |
1786 | self_destruct(); | |
1787 | } | |
1788 | ||
1789 | // Among all processes, only workers may need and can handle cache_dir. | |
1790 | if (!IamWorkerProcess()) | |
1791 | return; | |
1792 | ||
0e4e0e7d | 1793 | char *type_str; |
cd748f27 | 1794 | char *path_str; |
c8f4eac4 | 1795 | RefCount<SwapDir> sd; |
cd748f27 | 1796 | int i; |
1797 | int fs; | |
cd748f27 | 1798 | |
0e4e0e7d | 1799 | if ((type_str = strtok(NULL, w_space)) == NULL) |
62e76326 | 1800 | self_destruct(); |
cd748f27 | 1801 | |
cd748f27 | 1802 | if ((path_str = strtok(NULL, w_space)) == NULL) |
62e76326 | 1803 | self_destruct(); |
cd748f27 | 1804 | |
c9e2e0e8 | 1805 | fs = find_fstype(type_str); |
1806 | ||
1807 | if (fs < 0) | |
1808 | self_destruct(); | |
1809 | ||
1810 | /* reconfigure existing dir */ | |
cd748f27 | 1811 | |
1812 | for (i = 0; i < swap->n_configured; i++) { | |
c8f4eac4 | 1813 | assert (swap->swapDirs[i].getRaw()); |
62e76326 | 1814 | |
2c9e9cba | 1815 | if ((strcasecmp(path_str, dynamic_cast<SwapDir *>(swap->swapDirs[i].getRaw())->path)) == 0) { |
c9e2e0e8 | 1816 | /* this is specific to on-fs Stores. The right |
26ac0430 | 1817 | * way to handle this is probably to have a mapping |
c9e2e0e8 | 1818 | * from paths to stores, and have on-fs stores |
1819 | * register with that, and lookip in that in their | |
1820 | * own setup logic. RBC 20041225. TODO. | |
1821 | */ | |
c8f4eac4 | 1822 | |
1823 | sd = dynamic_cast<SwapDir *>(swap->swapDirs[i].getRaw()); | |
1824 | ||
c9e2e0e8 | 1825 | if (sd->type() != StoreFileSystem::FileSystems().items[fs]->type()) { |
bf8fe701 | 1826 | debugs(3, 0, "ERROR: Can't change type of existing cache_dir " << |
1827 | sd->type() << " " << sd->path << " to " << type_str << ". Restart required"); | |
c9e2e0e8 | 1828 | return; |
1829 | } | |
1830 | ||
62e76326 | 1831 | sd->reconfigure (i, path_str); |
c8f4eac4 | 1832 | |
62e76326 | 1833 | update_maxobjsize(); |
c8f4eac4 | 1834 | |
62e76326 | 1835 | return; |
1836 | } | |
cd748f27 | 1837 | } |
1838 | ||
c9e2e0e8 | 1839 | /* new cache_dir */ |
af6a12ee | 1840 | if (swap->n_configured > 63) { |
2c9e9cba AJ |
1841 | /* 7 bits, signed */ |
1842 | debugs(3, DBG_CRITICAL, "WARNING: There is a fixed maximum of 63 cache_dir entries Squid can handle."); | |
1843 | debugs(3, DBG_CRITICAL, "WARNING: '" << path_str << "' is one to many."); | |
1844 | self_destruct(); | |
1845 | return; | |
1846 | } | |
dc986280 | 1847 | |
cd748f27 | 1848 | allocate_new_swapdir(swap); |
c9e2e0e8 | 1849 | |
59b2d47f | 1850 | swap->swapDirs[swap->n_configured] = StoreFileSystem::FileSystems().items[fs]->createSwapDir(); |
c9e2e0e8 | 1851 | |
c8f4eac4 | 1852 | sd = dynamic_cast<SwapDir *>(swap->swapDirs[swap->n_configured].getRaw()); |
c9e2e0e8 | 1853 | |
8e8d4f30 | 1854 | /* parse the FS parameters and options */ |
d3b3ab85 | 1855 | sd->parse(swap->n_configured, path_str); |
c9e2e0e8 | 1856 | |
d3b3ab85 | 1857 | ++swap->n_configured; |
c9e2e0e8 | 1858 | |
cd748f27 | 1859 | /* Update the max object size */ |
1860 | update_maxobjsize(); | |
752c3b27 | 1861 | } |
1862 | ||
2d72d4fd | 1863 | static const char * |
505e35db | 1864 | peer_type_str(const peer_t type) |
1865 | { | |
1f140227 | 1866 | const char * result; |
1867 | ||
0cdcddb9 | 1868 | switch (type) { |
62e76326 | 1869 | |
505e35db | 1870 | case PEER_PARENT: |
1f140227 | 1871 | result = "parent"; |
62e76326 | 1872 | break; |
1873 | ||
505e35db | 1874 | case PEER_SIBLING: |
1f140227 | 1875 | result = "sibling"; |
62e76326 | 1876 | break; |
1877 | ||
505e35db | 1878 | case PEER_MULTICAST: |
1f140227 | 1879 | result = "multicast"; |
62e76326 | 1880 | break; |
1881 | ||
505e35db | 1882 | default: |
1f140227 | 1883 | result = "unknown"; |
62e76326 | 1884 | break; |
505e35db | 1885 | } |
1f140227 | 1886 | |
1887 | return result; | |
505e35db | 1888 | } |
1889 | ||
f1dc9b30 | 1890 | static void |
a7d59104 | 1891 | dump_peer(StoreEntry * entry, const char *name, peer * p) |
98ffb7e4 | 1892 | { |
505e35db | 1893 | domain_ping *d; |
505e35db | 1894 | domain_type *t; |
1895 | LOCAL_ARRAY(char, xname, 128); | |
62e76326 | 1896 | |
d41de3c1 | 1897 | while (p != NULL) { |
4bc48d15 | 1898 | storeAppendPrintf(entry, "%s %s %s %d %d name=%s", |
62e76326 | 1899 | name, |
1900 | p->host, | |
1901 | neighborTypeStr(p), | |
1902 | p->http_port, | |
4bc48d15 AJ |
1903 | p->icp.port, |
1904 | p->name); | |
62e76326 | 1905 | dump_peer_options(entry, p); |
1906 | ||
1907 | for (d = p->peer_domain; d; d = d->next) { | |
1908 | storeAppendPrintf(entry, "cache_peer_domain %s %s%s\n", | |
1909 | p->host, | |
1910 | d->do_ping ? null_string : "!", | |
1911 | d->domain); | |
1912 | } | |
1913 | ||
1914 | if (p->access) { | |
1915 | snprintf(xname, 128, "cache_peer_access %s", p->name); | |
1916 | dump_acl_access(entry, xname, p->access); | |
1917 | } | |
1918 | ||
1919 | for (t = p->typelist; t; t = t->next) { | |
1920 | storeAppendPrintf(entry, "neighbor_type_domain %s %s %s\n", | |
1921 | p->host, | |
1922 | peer_type_str(t->type), | |
1923 | t->domain); | |
1924 | } | |
1925 | ||
1926 | p = p->next; | |
d41de3c1 | 1927 | } |
98ffb7e4 | 1928 | } |
1929 | ||
86ae97bb AJ |
1930 | /** |
1931 | * utility function to prevent getservbyname() being called with a numeric value | |
1932 | * on Windows at least it returns garage results. | |
1933 | */ | |
1934 | static bool | |
1935 | isUnsignedNumeric(const char *str, size_t len) | |
1936 | { | |
1937 | if (len < 1) return false; | |
1938 | ||
1939 | for (; len >0 && *str; str++, len--) { | |
1940 | if (! isdigit(*str)) | |
1941 | return false; | |
1942 | } | |
1943 | return true; | |
1944 | } | |
1945 | ||
609fac72 | 1946 | /** |
1947 | \param proto 'tcp' or 'udp' for protocol | |
1948 | \returns Port the named service is supposed to be listening on. | |
1949 | */ | |
1950 | static u_short | |
1951 | GetService(const char *proto) | |
1952 | { | |
1953 | struct servent *port = NULL; | |
1954 | /** Parses a port number or service name from the squid.conf */ | |
1955 | char *token = strtok(NULL, w_space); | |
1956 | if (token == NULL) { | |
26ac0430 AJ |
1957 | self_destruct(); |
1958 | return 0; /* NEVER REACHED */ | |
609fac72 | 1959 | } |
1960 | /** Returns either the service port number from /etc/services */ | |
e1381638 | 1961 | if ( !isUnsignedNumeric(token, strlen(token)) ) |
86ae97bb | 1962 | port = getservbyname(token, proto); |
609fac72 | 1963 | if (port != NULL) { |
1964 | return ntohs((u_short)port->s_port); | |
1965 | } | |
1966 | /** Or a numeric translation of the config text. */ | |
1967 | return xatos(token); | |
1968 | } | |
1969 | ||
1970 | /** | |
1971 | \returns Port the named TCP service is supposed to be listening on. | |
1972 | \copydoc GetService(const char *proto) | |
1973 | */ | |
1974 | inline u_short | |
1975 | GetTcpService(void) | |
1976 | { | |
1977 | return GetService("tcp"); | |
1978 | } | |
1979 | ||
1980 | /** | |
1981 | \returns Port the named UDP service is supposed to be listening on. | |
1982 | \copydoc GetService(const char *proto) | |
1983 | */ | |
1984 | inline u_short | |
1985 | GetUdpService(void) | |
1986 | { | |
1987 | return GetService("udp"); | |
1988 | } | |
1989 | ||
8203a132 | 1990 | static void |
40a1495e | 1991 | parse_peer(peer ** head) |
7813c6d5 | 1992 | { |
270b86af | 1993 | char *token = NULL; |
40a1495e | 1994 | peer *p; |
f5691f9c | 1995 | CBDATA_INIT_TYPE_FREECB(peer, peerDestroy); |
72711e31 | 1996 | p = cbdataAlloc(peer); |
40a1495e | 1997 | p->http_port = CACHE_HTTP_PORT; |
399cabec | 1998 | p->icp.port = CACHE_ICP_PORT; |
40a1495e | 1999 | p->weight = 1; |
d1b63fc8 | 2000 | p->basetime = 0; |
dc835977 | 2001 | p->stats.logged_state = PEER_ALIVE; |
62e76326 | 2002 | |
e481c2dc | 2003 | if ((token = strtok(NULL, w_space)) == NULL) |
62e76326 | 2004 | self_destruct(); |
2005 | ||
40a1495e | 2006 | p->host = xstrdup(token); |
26ac0430 | 2007 | |
be753325 | 2008 | p->name = xstrdup(token); |
62e76326 | 2009 | |
e481c2dc | 2010 | if ((token = strtok(NULL, w_space)) == NULL) |
62e76326 | 2011 | self_destruct(); |
2012 | ||
40a1495e | 2013 | p->type = parseNeighborType(token); |
62e76326 | 2014 | |
0d5a2006 | 2015 | if (p->type == PEER_MULTICAST) { |
2016 | p->options.no_digest = 1; | |
2017 | p->options.no_netdb_exchange = 1; | |
2018 | } | |
2019 | ||
609fac72 | 2020 | p->http_port = GetTcpService(); |
62e76326 | 2021 | |
0e656b69 | 2022 | if (!p->http_port) |
2023 | self_destruct(); | |
62e76326 | 2024 | |
609fac72 | 2025 | p->icp.port = GetUdpService(); |
d67acb4e | 2026 | p->connection_auth = 2; /* auto */ |
62e76326 | 2027 | |
270b86af | 2028 | while ((token = strtok(NULL, w_space))) { |
62e76326 | 2029 | if (!strcasecmp(token, "proxy-only")) { |
2030 | p->options.proxy_only = 1; | |
2031 | } else if (!strcasecmp(token, "no-query")) { | |
2032 | p->options.no_query = 1; | |
2033 | } else if (!strcasecmp(token, "background-ping")) { | |
2034 | p->options.background_ping = 1; | |
2035 | } else if (!strcasecmp(token, "no-digest")) { | |
2036 | p->options.no_digest = 1; | |
b0758e04 AJ |
2037 | } else if (!strcasecmp(token, "no-tproxy")) { |
2038 | p->options.no_tproxy = 1; | |
62e76326 | 2039 | } else if (!strcasecmp(token, "multicast-responder")) { |
2040 | p->options.mcast_responder = 1; | |
8a368316 | 2041 | #if PEER_MULTICAST_SIBLINGS |
79ddb8e2 | 2042 | } else if (!strcasecmp(token, "multicast-siblings")) { |
8a368316 AJ |
2043 | p->options.mcast_siblings = 1; |
2044 | #endif | |
62e76326 | 2045 | } else if (!strncasecmp(token, "weight=", 7)) { |
2046 | p->weight = xatoi(token + 7); | |
2047 | } else if (!strncasecmp(token, "basetime=", 9)) { | |
2048 | p->basetime = xatoi(token + 9); | |
2049 | } else if (!strcasecmp(token, "closest-only")) { | |
2050 | p->options.closest_only = 1; | |
2051 | } else if (!strncasecmp(token, "ttl=", 4)) { | |
2052 | p->mcast.ttl = xatoi(token + 4); | |
2053 | ||
2054 | if (p->mcast.ttl < 0) | |
2055 | p->mcast.ttl = 0; | |
2056 | ||
2057 | if (p->mcast.ttl > 128) | |
2058 | p->mcast.ttl = 128; | |
2059 | } else if (!strcasecmp(token, "default")) { | |
2060 | p->options.default_parent = 1; | |
2061 | } else if (!strcasecmp(token, "round-robin")) { | |
2062 | p->options.roundrobin = 1; | |
2063 | } else if (!strcasecmp(token, "weighted-round-robin")) { | |
2064 | p->options.weighted_roundrobin = 1; | |
dc9d133b | 2065 | #if USE_HTCP |
62e76326 | 2066 | } else if (!strcasecmp(token, "htcp")) { |
2067 | p->options.htcp = 1; | |
18191440 AJ |
2068 | } else if (!strncasecmp(token, "htcp=", 5) || !strncasecmp(token, "htcp-", 5)) { |
2069 | /* Note: The htcp- form is deprecated, replaced by htcp= */ | |
4f4fa815 | 2070 | p->options.htcp = 1; |
18191440 AJ |
2071 | char *tmp = xstrdup(token+5); |
2072 | char *mode, *nextmode; | |
2073 | for (mode = nextmode = tmp; mode; mode = nextmode) { | |
2074 | nextmode = strchr(mode, ','); | |
18191440 AJ |
2075 | if (nextmode) |
2076 | *nextmode++ = '\0'; | |
2077 | if (!strcasecmp(mode, "no-clr")) { | |
2078 | if (p->options.htcp_only_clr) | |
2079 | fatalf("parse_peer: can't set htcp-no-clr and htcp-only-clr simultaneously"); | |
2080 | p->options.htcp_no_clr = 1; | |
2081 | } else if (!strcasecmp(mode, "no-purge-clr")) { | |
2082 | p->options.htcp_no_purge_clr = 1; | |
2083 | } else if (!strcasecmp(mode, "only-clr")) { | |
2084 | if (p->options.htcp_no_clr) | |
2085 | fatalf("parse_peer: can't set htcp no-clr and only-clr simultaneously"); | |
2086 | p->options.htcp_only_clr = 1; | |
2087 | } else if (!strcasecmp(mode, "forward-clr")) { | |
2088 | p->options.htcp_forward_clr = 1; | |
2089 | } else if (!strcasecmp(mode, "oldsquid")) { | |
2090 | p->options.htcp_oldsquid = 1; | |
2091 | } else { | |
2092 | fatalf("invalid HTCP mode '%s'", mode); | |
2093 | } | |
2094 | } | |
2095 | safe_free(tmp); | |
dc9d133b | 2096 | #endif |
62e76326 | 2097 | } else if (!strcasecmp(token, "no-netdb-exchange")) { |
2098 | p->options.no_netdb_exchange = 1; | |
62e76326 | 2099 | |
2100 | } else if (!strcasecmp(token, "carp")) { | |
2101 | if (p->type != PEER_PARENT) | |
2102 | fatalf("parse_peer: non-parent carp peer %s/%d\n", p->host, p->http_port); | |
2103 | ||
2104 | p->options.carp = 1; | |
2105 | ||
f7e1d9ce HN |
2106 | } else if (!strcasecmp(token, "userhash")) { |
2107 | if (p->type != PEER_PARENT) | |
2108 | fatalf("parse_peer: non-parent userhash peer %s/%d\n", p->host, p->http_port); | |
2109 | ||
2110 | p->options.userhash = 1; | |
2111 | ||
2112 | } else if (!strcasecmp(token, "sourcehash")) { | |
2113 | if (p->type != PEER_PARENT) | |
2114 | fatalf("parse_peer: non-parent sourcehash peer %s/%d\n", p->host, p->http_port); | |
2115 | ||
2116 | p->options.sourcehash = 1; | |
2117 | ||
95e36d02 | 2118 | #if DELAY_POOLS |
62e76326 | 2119 | |
2120 | } else if (!strcasecmp(token, "no-delay")) { | |
2121 | p->options.no_delay = 1; | |
afd88fbe | 2122 | #endif |
62e76326 | 2123 | |
2124 | } else if (!strncasecmp(token, "login=", 6)) { | |
2125 | p->login = xstrdup(token + 6); | |
2126 | rfc1738_unescape(p->login); | |
2127 | } else if (!strncasecmp(token, "connect-timeout=", 16)) { | |
2128 | p->connect_timeout = xatoi(token + 16); | |
ff9970cc AJ |
2129 | } else if (!strncasecmp(token, "connect-fail-limit=", 19)) { |
2130 | p->connect_fail_limit = xatoi(token + 19); | |
7e3ce7b9 | 2131 | #if USE_CACHE_DIGESTS |
62e76326 | 2132 | } else if (!strncasecmp(token, "digest-url=", 11)) { |
2133 | p->digest_url = xstrdup(token + 11); | |
7e3ce7b9 | 2134 | #endif |
62e76326 | 2135 | |
2136 | } else if (!strcasecmp(token, "allow-miss")) { | |
2137 | p->options.allow_miss = 1; | |
2138 | } else if (!strncasecmp(token, "max-conn=", 9)) { | |
2139 | p->max_conn = xatoi(token + 9); | |
2140 | } else if (!strcasecmp(token, "originserver")) { | |
2141 | p->options.originserver = 1; | |
2142 | } else if (!strncasecmp(token, "name=", 5)) { | |
2143 | safe_free(p->name); | |
2144 | ||
2145 | if (token[5]) | |
2146 | p->name = xstrdup(token + 5); | |
2147 | } else if (!strncasecmp(token, "forceddomain=", 13)) { | |
2148 | safe_free(p->domain); | |
2149 | ||
2150 | if (token[13]) | |
2151 | p->domain = xstrdup(token + 13); | |
2152 | ||
a7ad6e4e | 2153 | #if USE_SSL |
62e76326 | 2154 | |
2155 | } else if (strcmp(token, "ssl") == 0) { | |
2156 | p->use_ssl = 1; | |
2157 | } else if (strncmp(token, "sslcert=", 8) == 0) { | |
2158 | safe_free(p->sslcert); | |
2159 | p->sslcert = xstrdup(token + 8); | |
2160 | } else if (strncmp(token, "sslkey=", 7) == 0) { | |
2161 | safe_free(p->sslkey); | |
2162 | p->sslkey = xstrdup(token + 7); | |
2163 | } else if (strncmp(token, "sslversion=", 11) == 0) { | |
2164 | p->sslversion = atoi(token + 11); | |
2165 | } else if (strncmp(token, "ssloptions=", 11) == 0) { | |
2166 | safe_free(p->ssloptions); | |
2167 | p->ssloptions = xstrdup(token + 11); | |
2168 | } else if (strncmp(token, "sslcipher=", 10) == 0) { | |
2169 | safe_free(p->sslcipher); | |
2170 | p->sslcipher = xstrdup(token + 10); | |
2171 | } else if (strncmp(token, "sslcafile=", 10) == 0) { | |
2172 | safe_free(p->sslcafile); | |
a82a4fe4 | 2173 | p->sslcafile = xstrdup(token + 10); |
62e76326 | 2174 | } else if (strncmp(token, "sslcapath=", 10) == 0) { |
2175 | safe_free(p->sslcapath); | |
a82a4fe4 | 2176 | p->sslcapath = xstrdup(token + 10); |
2177 | } else if (strncmp(token, "sslcrlfile=", 11) == 0) { | |
2178 | safe_free(p->sslcrlfile); | |
2179 | p->sslcapath = xstrdup(token + 10); | |
62e76326 | 2180 | } else if (strncmp(token, "sslflags=", 9) == 0) { |
2181 | safe_free(p->sslflags); | |
2182 | p->sslflags = xstrdup(token + 9); | |
2183 | } else if (strncmp(token, "ssldomain=", 10) == 0) { | |
2184 | safe_free(p->ssldomain); | |
2185 | p->ssldomain = xstrdup(token + 10); | |
a7ad6e4e | 2186 | #endif |
62e76326 | 2187 | |
2188 | } else if (strcmp(token, "front-end-https") == 0) { | |
2189 | p->front_end_https = 1; | |
2190 | } else if (strcmp(token, "front-end-https=on") == 0) { | |
2191 | p->front_end_https = 1; | |
2192 | } else if (strcmp(token, "front-end-https=auto") == 0) { | |
2193 | p->front_end_https = 2; | |
26ac0430 | 2194 | } else if (strcmp(token, "connection-auth=off") == 0) { |
d67acb4e AJ |
2195 | p->connection_auth = 0; |
2196 | } else if (strcmp(token, "connection-auth") == 0) { | |
2197 | p->connection_auth = 1; | |
2198 | } else if (strcmp(token, "connection-auth=on") == 0) { | |
2199 | p->connection_auth = 1; | |
2200 | } else if (strcmp(token, "connection-auth=auto") == 0) { | |
2201 | p->connection_auth = 2; | |
62e76326 | 2202 | } else { |
bf8fe701 | 2203 | debugs(3, 0, "parse_peer: token='" << token << "'"); |
62e76326 | 2204 | self_destruct(); |
2205 | } | |
270b86af | 2206 | } |
62e76326 | 2207 | |
be753325 | 2208 | if (peerFindByName(p->name)) |
62e76326 | 2209 | fatalf("ERROR: cache_peer %s specified twice\n", p->name); |
2210 | ||
40a1495e | 2211 | if (p->weight < 1) |
62e76326 | 2212 | p->weight = 1; |
2213 | ||
ff9970cc | 2214 | if (p->connect_fail_limit < 1) |
a4d889e0 | 2215 | p->connect_fail_limit = 10; |
ff9970cc | 2216 | |
399cabec | 2217 | p->icp.version = ICP_VERSION_CURRENT; |
62e76326 | 2218 | |
eb406bb7 | 2219 | p->test_fd = -1; |
62e76326 | 2220 | |
e13ee7ad | 2221 | #if USE_CACHE_DIGESTS |
62e76326 | 2222 | |
e13ee7ad | 2223 | if (!p->options.no_digest) { |
62e76326 | 2224 | /* XXX This looks odd.. who has the original pointer |
2225 | * then? | |
2226 | */ | |
2227 | PeerDigest *pd = peerDigestCreate(p); | |
2228 | p->digest = cbdataReference(pd); | |
8a6218c6 | 2229 | } |
62e76326 | 2230 | |
e13ee7ad | 2231 | #endif |
cc192b50 | 2232 | |
2233 | p->index = ++Config.npeers; | |
2234 | ||
0153d498 | 2235 | while (*head != NULL) |
62e76326 | 2236 | head = &(*head)->next; |
2237 | ||
0153d498 | 2238 | *head = p; |
62e76326 | 2239 | |
32a47e3e | 2240 | peerClearRRStart(); |
0153d498 | 2241 | } |
2242 | ||
2243 | static void | |
40a1495e | 2244 | free_peer(peer ** P) |
0153d498 | 2245 | { |
40a1495e | 2246 | peer *p; |
62e76326 | 2247 | |
79d39a72 | 2248 | while ((p = *P) != NULL) { |
62e76326 | 2249 | *P = p->next; |
3855c318 | 2250 | #if USE_CACHE_DIGESTS |
62e76326 | 2251 | |
2252 | cbdataReferenceDone(p->digest); | |
3855c318 | 2253 | #endif |
62e76326 | 2254 | |
2255 | cbdataFree(p); | |
a47b9029 | 2256 | } |
62e76326 | 2257 | |
987c67d1 | 2258 | Config.npeers = 0; |
270b86af | 2259 | } |
2260 | ||
2261 | static void | |
a7d59104 | 2262 | dump_cachemgrpasswd(StoreEntry * entry, const char *name, cachemgr_passwd * list) |
270b86af | 2263 | { |
d41de3c1 | 2264 | wordlist *w; |
62e76326 | 2265 | |
d41de3c1 | 2266 | while (list != NULL) { |
62e76326 | 2267 | if (strcmp(list->passwd, "none") && strcmp(list->passwd, "disable")) |
2268 | storeAppendPrintf(entry, "%s XXXXXXXXXX", name); | |
2269 | else | |
2270 | storeAppendPrintf(entry, "%s %s", name, list->passwd); | |
2271 | ||
2272 | for (w = list->actions; w != NULL; w = w->next) { | |
2273 | storeAppendPrintf(entry, " %s", w->key); | |
2274 | } | |
2275 | ||
2276 | storeAppendPrintf(entry, "\n"); | |
2277 | list = list->next; | |
d41de3c1 | 2278 | } |
270b86af | 2279 | } |
2280 | ||
2281 | static void | |
a47b9029 | 2282 | parse_cachemgrpasswd(cachemgr_passwd ** head) |
270b86af | 2283 | { |
2284 | char *passwd = NULL; | |
2285 | wordlist *actions = NULL; | |
22f3fd98 | 2286 | cachemgr_passwd *p; |
2287 | cachemgr_passwd **P; | |
270b86af | 2288 | parse_string(&passwd); |
2289 | parse_wordlist(&actions); | |
e6ccf245 | 2290 | p = static_cast<cachemgr_passwd *>(xcalloc(1, sizeof(cachemgr_passwd))); |
22f3fd98 | 2291 | p->passwd = passwd; |
2292 | p->actions = actions; | |
62e76326 | 2293 | |
26aa7e31 | 2294 | for (P = head; *P; P = &(*P)->next) { |
62e76326 | 2295 | /* |
2296 | * See if any of the actions from this line already have a | |
2297 | * password from previous lines. The password checking | |
2298 | * routines in cache_manager.c take the the password from | |
2299 | * the first cachemgr_passwd struct that contains the | |
2300 | * requested action. Thus, we should warn users who might | |
2301 | * think they can have two passwords for the same action. | |
2302 | */ | |
2303 | wordlist *w; | |
2304 | wordlist *u; | |
2305 | ||
2306 | for (w = (*P)->actions; w; w = w->next) { | |
2307 | for (u = actions; u; u = u->next) { | |
2308 | if (strcmp(w->key, u->key)) | |
2309 | continue; | |
2310 | ||
bf8fe701 | 2311 | debugs(0, 0, "WARNING: action '" << u->key << "' (line " << config_lineno << ") already has a password"); |
62e76326 | 2312 | } |
2313 | } | |
26aa7e31 | 2314 | } |
62e76326 | 2315 | |
22f3fd98 | 2316 | *P = p; |
270b86af | 2317 | } |
2318 | ||
2319 | static void | |
a47b9029 | 2320 | free_cachemgrpasswd(cachemgr_passwd ** head) |
270b86af | 2321 | { |
a47b9029 | 2322 | cachemgr_passwd *p; |
62e76326 | 2323 | |
79d39a72 | 2324 | while ((p = *head) != NULL) { |
62e76326 | 2325 | *head = p->next; |
2326 | xfree(p->passwd); | |
2327 | wordlistDestroy(&p->actions); | |
2328 | xfree(p); | |
a47b9029 | 2329 | } |
270b86af | 2330 | } |
2331 | ||
8203a132 | 2332 | static void |
16300b58 | 2333 | dump_denyinfo(StoreEntry * entry, const char *name, acl_deny_info_list * var) |
270b86af | 2334 | { |
d41de3c1 | 2335 | acl_name_list *a; |
62e76326 | 2336 | |
d41de3c1 | 2337 | while (var != NULL) { |
62e76326 | 2338 | storeAppendPrintf(entry, "%s %s", name, var->err_page_name); |
2339 | ||
2340 | for (a = var->acl_list; a != NULL; a = a->next) | |
2341 | storeAppendPrintf(entry, " %s", a->name); | |
2342 | ||
2343 | storeAppendPrintf(entry, "\n"); | |
2344 | ||
2345 | var = var->next; | |
d41de3c1 | 2346 | } |
270b86af | 2347 | } |
2348 | ||
2349 | static void | |
16300b58 | 2350 | parse_denyinfo(acl_deny_info_list ** var) |
6e40f263 | 2351 | { |
f1dc9b30 | 2352 | aclParseDenyInfoLine(var); |
6e40f263 | 2353 | } |
403279e0 | 2354 | |
1273d501 | 2355 | void |
a47b9029 | 2356 | free_denyinfo(acl_deny_info_list ** list) |
3c5557f9 | 2357 | { |
56b63fa1 | 2358 | acl_deny_info_list *a = NULL; |
2359 | acl_deny_info_list *a_next = NULL; | |
2360 | acl_name_list *l = NULL; | |
2361 | acl_name_list *l_next = NULL; | |
62e76326 | 2362 | |
1273d501 | 2363 | for (a = *list; a; a = a_next) { |
62e76326 | 2364 | for (l = a->acl_list; l; l = l_next) { |
2365 | l_next = l->next; | |
2366 | memFree(l, MEM_ACL_NAME_LIST); | |
2367 | l = NULL; | |
2368 | } | |
2369 | ||
2370 | a_next = a->next; | |
2371 | memFree(a, MEM_ACL_DENY_INFO_LIST); | |
2372 | a = NULL; | |
1273d501 | 2373 | } |
62e76326 | 2374 | |
1273d501 | 2375 | *list = NULL; |
270b86af | 2376 | } |
2377 | ||
2378 | static void | |
505e35db | 2379 | parse_peer_access(void) |
270b86af | 2380 | { |
2381 | char *host = NULL; | |
505e35db | 2382 | peer *p; |
62e76326 | 2383 | |
270b86af | 2384 | if (!(host = strtok(NULL, w_space))) |
62e76326 | 2385 | self_destruct(); |
2386 | ||
0cdcddb9 | 2387 | if ((p = peerFindByName(host)) == NULL) { |
bf8fe701 | 2388 | debugs(15, 0, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'"); |
62e76326 | 2389 | return; |
0cdcddb9 | 2390 | } |
62e76326 | 2391 | |
a9f20260 | 2392 | aclParseAccessLine(LegacyParser, &p->access); |
270b86af | 2393 | } |
2394 | ||
270b86af | 2395 | static void |
2396 | parse_hostdomain(void) | |
2397 | { | |
2398 | char *host = NULL; | |
2399 | char *domain = NULL; | |
62e76326 | 2400 | |
270b86af | 2401 | if (!(host = strtok(NULL, w_space))) |
62e76326 | 2402 | self_destruct(); |
2403 | ||
f1dc9b30 | 2404 | while ((domain = strtok(NULL, list_sep))) { |
62e76326 | 2405 | domain_ping *l = NULL; |
2406 | domain_ping **L = NULL; | |
2407 | peer *p; | |
2408 | ||
2409 | if ((p = peerFindByName(host)) == NULL) { | |
bf8fe701 | 2410 | debugs(15, 0, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'"); |
62e76326 | 2411 | continue; |
2412 | } | |
2413 | ||
2414 | l = static_cast<domain_ping *>(xcalloc(1, sizeof(domain_ping))); | |
2415 | l->do_ping = 1; | |
2416 | ||
2417 | if (*domain == '!') { /* check for !.edu */ | |
2418 | l->do_ping = 0; | |
2419 | domain++; | |
2420 | } | |
2421 | ||
2422 | l->domain = xstrdup(domain); | |
2423 | ||
3d0ac046 | 2424 | for (L = &(p->peer_domain); *L; L = &((*L)->next)); |
62e76326 | 2425 | *L = l; |
f1dc9b30 | 2426 | } |
270b86af | 2427 | } |
2428 | ||
2429 | static void | |
2430 | parse_hostdomaintype(void) | |
2431 | { | |
2432 | char *host = NULL; | |
2433 | char *type = NULL; | |
2434 | char *domain = NULL; | |
62e76326 | 2435 | |
270b86af | 2436 | if (!(host = strtok(NULL, w_space))) |
62e76326 | 2437 | self_destruct(); |
2438 | ||
270b86af | 2439 | if (!(type = strtok(NULL, w_space))) |
62e76326 | 2440 | self_destruct(); |
2441 | ||
f1dc9b30 | 2442 | while ((domain = strtok(NULL, list_sep))) { |
62e76326 | 2443 | domain_type *l = NULL; |
2444 | domain_type **L = NULL; | |
2445 | peer *p; | |
2446 | ||
2447 | if ((p = peerFindByName(host)) == NULL) { | |
bf8fe701 | 2448 | debugs(15, 0, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'"); |
62e76326 | 2449 | return; |
2450 | } | |
2451 | ||
2452 | l = static_cast<domain_type *>(xcalloc(1, sizeof(domain_type))); | |
2453 | l->type = parseNeighborType(type); | |
2454 | l->domain = xstrdup(domain); | |
2455 | ||
3d0ac046 | 2456 | for (L = &(p->typelist); *L; L = &((*L)->next)); |
62e76326 | 2457 | *L = l; |
f1dc9b30 | 2458 | } |
270b86af | 2459 | } |
2460 | ||
270b86af | 2461 | static void |
a7d59104 | 2462 | dump_int(StoreEntry * entry, const char *name, int var) |
270b86af | 2463 | { |
f53b06f9 | 2464 | storeAppendPrintf(entry, "%s %d\n", name, var); |
270b86af | 2465 | } |
c1c29eb6 | 2466 | |
94439e4e | 2467 | void |
270b86af | 2468 | parse_int(int *var) |
2469 | { | |
270b86af | 2470 | int i; |
0e4e0e7d | 2471 | i = GetInteger(); |
270b86af | 2472 | *var = i; |
2473 | } | |
090089c4 | 2474 | |
0153d498 | 2475 | static void |
2476 | free_int(int *var) | |
2477 | { | |
a47b9029 | 2478 | *var = 0; |
0153d498 | 2479 | } |
2480 | ||
270b86af | 2481 | static void |
a7d59104 | 2482 | dump_onoff(StoreEntry * entry, const char *name, int var) |
270b86af | 2483 | { |
f53b06f9 | 2484 | storeAppendPrintf(entry, "%s %s\n", name, var ? "on" : "off"); |
270b86af | 2485 | } |
090089c4 | 2486 | |
d205783b | 2487 | void |
270b86af | 2488 | parse_onoff(int *var) |
2489 | { | |
2490 | char *token = strtok(NULL, w_space); | |
090089c4 | 2491 | |
270b86af | 2492 | if (token == NULL) |
62e76326 | 2493 | self_destruct(); |
2494 | ||
270b86af | 2495 | if (!strcasecmp(token, "on") || !strcasecmp(token, "enable")) |
62e76326 | 2496 | *var = 1; |
270b86af | 2497 | else |
62e76326 | 2498 | *var = 0; |
270b86af | 2499 | } |
e90100aa | 2500 | |
0153d498 | 2501 | #define free_onoff free_int |
52d3f198 | 2502 | |
2503 | static void | |
2504 | dump_tristate(StoreEntry * entry, const char *name, int var) | |
2505 | { | |
2506 | const char *state; | |
2507 | ||
2508 | if (var > 0) | |
2509 | state = "on"; | |
2510 | else if (var < 0) | |
2511 | state = "warn"; | |
2512 | else | |
2513 | state = "off"; | |
2514 | ||
2515 | storeAppendPrintf(entry, "%s %s\n", name, state); | |
2516 | } | |
2517 | ||
2518 | static void | |
2519 | parse_tristate(int *var) | |
2520 | { | |
2521 | char *token = strtok(NULL, w_space); | |
2522 | ||
2523 | if (token == NULL) | |
2524 | self_destruct(); | |
2525 | ||
2526 | if (!strcasecmp(token, "on") || !strcasecmp(token, "enable")) | |
2527 | *var = 1; | |
2528 | else if (!strcasecmp(token, "warn")) | |
2529 | *var = -1; | |
2530 | else | |
2531 | *var = 0; | |
2532 | } | |
2533 | ||
2534 | #define free_tristate free_int | |
30a4f2a8 | 2535 | |
270b86af | 2536 | static void |
a7d59104 | 2537 | dump_refreshpattern(StoreEntry * entry, const char *name, refresh_t * head) |
270b86af | 2538 | { |
d41de3c1 | 2539 | while (head != NULL) { |
0e1d7629 | 2540 | storeAppendPrintf(entry, "%s%s %s %d %d%% %d", |
62e76326 | 2541 | name, |
2542 | head->flags.icase ? " -i" : null_string, | |
2543 | head->pattern, | |
2544 | (int) head->min / 60, | |
2545 | (int) (100.0 * head->pct + 0.5), | |
2546 | (int) head->max / 60); | |
4c3ef9b2 | 2547 | |
2548 | if (head->flags.refresh_ims) | |
2549 | storeAppendPrintf(entry, " refresh-ims"); | |
2550 | ||
3d8b6ba4 AJ |
2551 | if (head->flags.store_stale) |
2552 | storeAppendPrintf(entry, " store-stale"); | |
2553 | ||
626096be | 2554 | #if USE_HTTP_VIOLATIONS |
62e76326 | 2555 | |
2556 | if (head->flags.override_expire) | |
2557 | storeAppendPrintf(entry, " override-expire"); | |
2558 | ||
2559 | if (head->flags.override_lastmod) | |
2560 | storeAppendPrintf(entry, " override-lastmod"); | |
2561 | ||
2562 | if (head->flags.reload_into_ims) | |
2563 | storeAppendPrintf(entry, " reload-into-ims"); | |
2564 | ||
2565 | if (head->flags.ignore_reload) | |
2566 | storeAppendPrintf(entry, " ignore-reload"); | |
2567 | ||
38f9c547 | 2568 | if (head->flags.ignore_no_cache) |
2569 | storeAppendPrintf(entry, " ignore-no-cache"); | |
2570 | ||
2571 | if (head->flags.ignore_no_store) | |
2572 | storeAppendPrintf(entry, " ignore-no-store"); | |
2573 | ||
4ca08219 AJ |
2574 | if (head->flags.ignore_must_revalidate) |
2575 | storeAppendPrintf(entry, " ignore-must-revalidate"); | |
2576 | ||
38f9c547 | 2577 | if (head->flags.ignore_private) |
2578 | storeAppendPrintf(entry, " ignore-private"); | |
2579 | ||
2580 | if (head->flags.ignore_auth) | |
2581 | storeAppendPrintf(entry, " ignore-auth"); | |
2582 | ||
9f60cfdf | 2583 | #endif |
62e76326 | 2584 | |
2585 | storeAppendPrintf(entry, "\n"); | |
2586 | ||
2587 | head = head->next; | |
d41de3c1 | 2588 | } |
270b86af | 2589 | } |
090089c4 | 2590 | |
270b86af | 2591 | static void |
f1dc9b30 | 2592 | parse_refreshpattern(refresh_t ** head) |
270b86af | 2593 | { |
f1dc9b30 | 2594 | char *token; |
2595 | char *pattern; | |
2596 | time_t min = 0; | |
c3f6d204 | 2597 | double pct = 0.0; |
f1dc9b30 | 2598 | time_t max = 0; |
4c3ef9b2 | 2599 | int refresh_ims = 0; |
3d8b6ba4 AJ |
2600 | int store_stale = 0; |
2601 | ||
626096be | 2602 | #if USE_HTTP_VIOLATIONS |
62e76326 | 2603 | |
1dfa1d81 | 2604 | int override_expire = 0; |
2605 | int override_lastmod = 0; | |
cbe3a719 | 2606 | int reload_into_ims = 0; |
2607 | int ignore_reload = 0; | |
38f9c547 | 2608 | int ignore_no_cache = 0; |
2609 | int ignore_no_store = 0; | |
4ca08219 | 2610 | int ignore_must_revalidate = 0; |
38f9c547 | 2611 | int ignore_private = 0; |
2612 | int ignore_auth = 0; | |
9f60cfdf | 2613 | #endif |
62e76326 | 2614 | |
f1dc9b30 | 2615 | int i; |
2616 | refresh_t *t; | |
2617 | regex_t comp; | |
2618 | int errcode; | |
2619 | int flags = REG_EXTENDED | REG_NOSUB; | |
62e76326 | 2620 | |
9eeb8e4b | 2621 | if ((token = strtok(NULL, w_space)) == NULL) { |
62e76326 | 2622 | self_destruct(); |
9eeb8e4b | 2623 | return; |
2624 | } | |
62e76326 | 2625 | |
f1dc9b30 | 2626 | if (strcmp(token, "-i") == 0) { |
62e76326 | 2627 | flags |= REG_ICASE; |
2628 | token = strtok(NULL, w_space); | |
f1dc9b30 | 2629 | } else if (strcmp(token, "+i") == 0) { |
62e76326 | 2630 | flags &= ~REG_ICASE; |
2631 | token = strtok(NULL, w_space); | |
f1dc9b30 | 2632 | } |
62e76326 | 2633 | |
9eeb8e4b | 2634 | if (token == NULL) { |
62e76326 | 2635 | self_destruct(); |
9eeb8e4b | 2636 | return; |
2637 | } | |
62e76326 | 2638 | |
f1dc9b30 | 2639 | pattern = xstrdup(token); |
62e76326 | 2640 | |
0e4e0e7d | 2641 | i = GetInteger(); /* token: min */ |
62e76326 | 2642 | |
a632ba71 AJ |
2643 | /* catch negative and insanely huge values close to 32-bit wrap */ |
2644 | if (i < 0) { | |
2645 | debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern minimum age negative. Cropped back to zero."); | |
2646 | i = 0; | |
2647 | } | |
2648 | if (i > 60*24*365) { | |
2649 | debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern minimum age too high. Cropped back to 1 year."); | |
2650 | i = 60*24*365; | |
2651 | } | |
2652 | ||
f1dc9b30 | 2653 | min = (time_t) (i * 60); /* convert minutes to seconds */ |
62e76326 | 2654 | |
0e4e0e7d | 2655 | i = GetInteger(); /* token: pct */ |
62e76326 | 2656 | |
c3f6d204 | 2657 | pct = (double) i / 100.0; |
62e76326 | 2658 | |
0e4e0e7d | 2659 | i = GetInteger(); /* token: max */ |
62e76326 | 2660 | |
a632ba71 AJ |
2661 | /* catch negative and insanely huge values close to 32-bit wrap */ |
2662 | if (i < 0) { | |
2663 | debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern maximum age negative. Cropped back to zero."); | |
2664 | i = 0; | |
2665 | } | |
2666 | if (i > 60*24*365) { | |
2667 | debugs(3, DBG_IMPORTANT, "WARNING: refresh_pattern maximum age too high. Cropped back to 1 year."); | |
2668 | i = 60*24*365; | |
2669 | } | |
2670 | ||
f1dc9b30 | 2671 | max = (time_t) (i * 60); /* convert minutes to seconds */ |
62e76326 | 2672 | |
1dfa1d81 | 2673 | /* Options */ |
2674 | while ((token = strtok(NULL, w_space)) != NULL) { | |
4c3ef9b2 | 2675 | if (!strcmp(token, "refresh-ims")) { |
2676 | refresh_ims = 1; | |
3d8b6ba4 AJ |
2677 | } else if (!strcmp(token, "store-stale")) { |
2678 | store_stale = 1; | |
626096be | 2679 | #if USE_HTTP_VIOLATIONS |
62e76326 | 2680 | |
4c3ef9b2 | 2681 | } else if (!strcmp(token, "override-expire")) |
62e76326 | 2682 | override_expire = 1; |
2683 | else if (!strcmp(token, "override-lastmod")) | |
2684 | override_lastmod = 1; | |
38f9c547 | 2685 | else if (!strcmp(token, "ignore-no-cache")) |
2686 | ignore_no_cache = 1; | |
2687 | else if (!strcmp(token, "ignore-no-store")) | |
2688 | ignore_no_store = 1; | |
4ca08219 AJ |
2689 | else if (!strcmp(token, "ignore-must-revalidate")) |
2690 | ignore_must_revalidate = 1; | |
38f9c547 | 2691 | else if (!strcmp(token, "ignore-private")) |
2692 | ignore_private = 1; | |
2693 | else if (!strcmp(token, "ignore-auth")) | |
2694 | ignore_auth = 1; | |
62e76326 | 2695 | else if (!strcmp(token, "reload-into-ims")) { |
2696 | reload_into_ims = 1; | |
2697 | refresh_nocache_hack = 1; | |
2698 | /* tell client_side.c that this is used */ | |
2699 | } else if (!strcmp(token, "ignore-reload")) { | |
2700 | ignore_reload = 1; | |
2701 | refresh_nocache_hack = 1; | |
2702 | /* tell client_side.c that this is used */ | |
9f60cfdf | 2703 | #endif |
62e76326 | 2704 | |
4c3ef9b2 | 2705 | } else |
26ac0430 | 2706 | debugs(22, 0, "redreshAddToList: Unknown option '" << pattern << "': " << token); |
1dfa1d81 | 2707 | } |
62e76326 | 2708 | |
f1dc9b30 | 2709 | if ((errcode = regcomp(&comp, pattern, flags)) != 0) { |
62e76326 | 2710 | char errbuf[256]; |
2711 | regerror(errcode, &comp, errbuf, sizeof errbuf); | |
bf8fe701 | 2712 | debugs(22, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line); |
2713 | debugs(22, 0, "refreshAddToList: Invalid regular expression '" << pattern << "': " << errbuf); | |
62e76326 | 2714 | return; |
f1dc9b30 | 2715 | } |
62e76326 | 2716 | |
c3f6d204 | 2717 | pct = pct < 0.0 ? 0.0 : pct; |
f1dc9b30 | 2718 | max = max < 0 ? 0 : max; |
e6ccf245 | 2719 | t = static_cast<refresh_t *>(xcalloc(1, sizeof(refresh_t))); |
f1dc9b30 | 2720 | t->pattern = (char *) xstrdup(pattern); |
2721 | t->compiled_pattern = comp; | |
2722 | t->min = min; | |
c3f6d204 | 2723 | t->pct = pct; |
f1dc9b30 | 2724 | t->max = max; |
62e76326 | 2725 | |
c3f6d204 | 2726 | if (flags & REG_ICASE) |
62e76326 | 2727 | t->flags.icase = 1; |
2728 | ||
4c3ef9b2 | 2729 | if (refresh_ims) |
2730 | t->flags.refresh_ims = 1; | |
2731 | ||
3d8b6ba4 AJ |
2732 | if (store_stale) |
2733 | t->flags.store_stale = 1; | |
2734 | ||
626096be | 2735 | #if USE_HTTP_VIOLATIONS |
62e76326 | 2736 | |
1dfa1d81 | 2737 | if (override_expire) |
62e76326 | 2738 | t->flags.override_expire = 1; |
2739 | ||
1dfa1d81 | 2740 | if (override_lastmod) |
62e76326 | 2741 | t->flags.override_lastmod = 1; |
2742 | ||
cbe3a719 | 2743 | if (reload_into_ims) |
62e76326 | 2744 | t->flags.reload_into_ims = 1; |
2745 | ||
cbe3a719 | 2746 | if (ignore_reload) |
62e76326 | 2747 | t->flags.ignore_reload = 1; |
2748 | ||
38f9c547 | 2749 | if (ignore_no_cache) |
2750 | t->flags.ignore_no_cache = 1; | |
2751 | ||
2752 | if (ignore_no_store) | |
2753 | t->flags.ignore_no_store = 1; | |
2754 | ||
4ca08219 AJ |
2755 | if (ignore_must_revalidate) |
2756 | t->flags.ignore_must_revalidate = 1; | |
2757 | ||
38f9c547 | 2758 | if (ignore_private) |
2759 | t->flags.ignore_private = 1; | |
2760 | ||
2761 | if (ignore_auth) | |
2762 | t->flags.ignore_auth = 1; | |
2763 | ||
9f60cfdf | 2764 | #endif |
62e76326 | 2765 | |
f1dc9b30 | 2766 | t->next = NULL; |
62e76326 | 2767 | |
f1dc9b30 | 2768 | while (*head) |
62e76326 | 2769 | head = &(*head)->next; |
2770 | ||
f1dc9b30 | 2771 | *head = t; |
62e76326 | 2772 | |
f1dc9b30 | 2773 | safe_free(pattern); |
270b86af | 2774 | } |
090089c4 | 2775 | |
270b86af | 2776 | static void |
a47b9029 | 2777 | free_refreshpattern(refresh_t ** head) |
270b86af | 2778 | { |
f1dc9b30 | 2779 | refresh_t *t; |
62e76326 | 2780 | |
79d39a72 | 2781 | while ((t = *head) != NULL) { |
62e76326 | 2782 | *head = t->next; |
2783 | safe_free(t->pattern); | |
2784 | regfree(&t->compiled_pattern); | |
2785 | safe_free(t); | |
f1dc9b30 | 2786 | } |
c2066637 | 2787 | |
626096be | 2788 | #if USE_HTTP_VIOLATIONS |
c2066637 | 2789 | refresh_nocache_hack = 0; |
8970d351 | 2790 | |
2791 | #endif | |
270b86af | 2792 | } |
12b9e9b1 | 2793 | |
270b86af | 2794 | static void |
a7d59104 | 2795 | dump_string(StoreEntry * entry, const char *name, char *var) |
270b86af | 2796 | { |
f53b06f9 | 2797 | if (var != NULL) |
62e76326 | 2798 | storeAppendPrintf(entry, "%s %s\n", name, var); |
270b86af | 2799 | } |
98ffb7e4 | 2800 | |
270b86af | 2801 | static void |
0153d498 | 2802 | parse_string(char **var) |
270b86af | 2803 | { |
2804 | char *token = strtok(NULL, w_space); | |
270b86af | 2805 | safe_free(*var); |
62e76326 | 2806 | |
270b86af | 2807 | if (token == NULL) |
62e76326 | 2808 | self_destruct(); |
2809 | ||
270b86af | 2810 | *var = xstrdup(token); |
2811 | } | |
b15e6857 | 2812 | |
3a69ddf3 | 2813 | void |
2814 | ConfigParser::ParseString(char **var) | |
2815 | { | |
2816 | parse_string(var); | |
2817 | } | |
2818 | ||
2819 | void | |
30abd221 | 2820 | ConfigParser::ParseString(String *var) |
3a69ddf3 | 2821 | { |
2822 | char *token = strtok(NULL, w_space); | |
2823 | ||
2824 | if (token == NULL) | |
2825 | self_destruct(); | |
2826 | ||
30abd221 | 2827 | var->reset(token); |
3a69ddf3 | 2828 | } |
2829 | ||
0153d498 | 2830 | static void |
2831 | free_string(char **var) | |
2832 | { | |
027acbaf | 2833 | safe_free(*var); |
0153d498 | 2834 | } |
caebbe00 | 2835 | |
94439e4e | 2836 | void |
f1dc9b30 | 2837 | parse_eol(char *volatile *var) |
270b86af | 2838 | { |
852751f7 | 2839 | unsigned char *token = (unsigned char *) strtok(NULL, null_string); |
270b86af | 2840 | safe_free(*var); |
62e76326 | 2841 | |
9eeb8e4b | 2842 | if (!token) { |
62e76326 | 2843 | self_destruct(); |
9eeb8e4b | 2844 | return; |
2845 | } | |
62e76326 | 2846 | |
e4755e29 | 2847 | while (*token && xisspace(*token)) |
62e76326 | 2848 | token++; |
2849 | ||
9eeb8e4b | 2850 | if (!*token) { |
62e76326 | 2851 | self_destruct(); |
9eeb8e4b | 2852 | return; |
2853 | } | |
62e76326 | 2854 | |
852751f7 | 2855 | *var = xstrdup((char *) token); |
270b86af | 2856 | } |
090089c4 | 2857 | |
52d3f198 | 2858 | #define dump_eol dump_string |
2859 | #define free_eol free_string | |
2860 | ||
270b86af | 2861 | static void |
a7d59104 | 2862 | dump_time_t(StoreEntry * entry, const char *name, time_t var) |
090089c4 | 2863 | { |
f53b06f9 | 2864 | storeAppendPrintf(entry, "%s %d seconds\n", name, (int) var); |
090089c4 | 2865 | } |
2866 | ||
94439e4e | 2867 | void |
a47b9029 | 2868 | parse_time_t(time_t * var) |
0ffd22bc | 2869 | { |
f1dc9b30 | 2870 | parseTimeLine(var, T_SECOND_STR); |
0ffd22bc | 2871 | } |
2872 | ||
270b86af | 2873 | static void |
a47b9029 | 2874 | free_time_t(time_t * var) |
270b86af | 2875 | { |
a47b9029 | 2876 | *var = 0; |
270b86af | 2877 | } |
9906e724 | 2878 | |
0477a072 | 2879 | #if UNUSED_CODE |
9906e724 | 2880 | static void |
a7d59104 | 2881 | dump_size_t(StoreEntry * entry, const char *name, size_t var) |
1b635117 | 2882 | { |
f53b06f9 | 2883 | storeAppendPrintf(entry, "%s %d\n", name, (int) var); |
1b635117 | 2884 | } |
0477a072 | 2885 | #endif |
1b635117 | 2886 | |
2887 | static void | |
a7d59104 | 2888 | dump_b_size_t(StoreEntry * entry, const char *name, size_t var) |
9906e724 | 2889 | { |
f53b06f9 | 2890 | storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_BYTES_STR); |
9906e724 | 2891 | } |
2892 | ||
e210930b AJ |
2893 | #if !USE_DNSSERVERS |
2894 | static void | |
2895 | dump_b_ssize_t(StoreEntry * entry, const char *name, ssize_t var) | |
2896 | { | |
2897 | storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_BYTES_STR); | |
2898 | } | |
2899 | #endif | |
2900 | ||
3e62bd58 | 2901 | #if UNUSED_CODE |
9906e724 | 2902 | static void |
a7d59104 | 2903 | dump_kb_size_t(StoreEntry * entry, const char *name, size_t var) |
9906e724 | 2904 | { |
f53b06f9 | 2905 | storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_KBYTES_STR); |
9906e724 | 2906 | } |
3e62bd58 | 2907 | #endif |
9906e724 | 2908 | |
47f6e231 | 2909 | static void |
2910 | dump_b_int64_t(StoreEntry * entry, const char *name, int64_t var) | |
2911 | { | |
2912 | storeAppendPrintf(entry, "%s %"PRId64" %s\n", name, var, B_BYTES_STR); | |
2913 | } | |
2914 | ||
2915 | static void | |
2916 | dump_kb_int64_t(StoreEntry * entry, const char *name, int64_t var) | |
2917 | { | |
2918 | storeAppendPrintf(entry, "%s %"PRId64" %s\n", name, var, B_KBYTES_STR); | |
2919 | } | |
2920 | ||
0477a072 | 2921 | #if UNUSED_CODE |
9906e724 | 2922 | static void |
a47b9029 | 2923 | parse_size_t(size_t * var) |
1b635117 | 2924 | { |
1b635117 | 2925 | int i; |
0e4e0e7d | 2926 | i = GetInteger(); |
1b635117 | 2927 | *var = (size_t) i; |
2928 | } | |
0477a072 | 2929 | #endif |
1b635117 | 2930 | |
2931 | static void | |
2932 | parse_b_size_t(size_t * var) | |
9906e724 | 2933 | { |
2934 | parseBytesLine(var, B_BYTES_STR); | |
2935 | } | |
2936 | ||
e210930b AJ |
2937 | #if !USE_DNSSERVERS |
2938 | static void | |
2939 | parse_b_ssize_t(ssize_t * var) | |
2940 | { | |
2941 | parseBytesLineSigned(var, B_BYTES_STR); | |
2942 | } | |
2943 | #endif | |
2944 | ||
3e62bd58 | 2945 | #if UNUSED_CODE |
9906e724 | 2946 | static void |
a47b9029 | 2947 | parse_kb_size_t(size_t * var) |
9906e724 | 2948 | { |
2949 | parseBytesLine(var, B_KBYTES_STR); | |
2950 | } | |
3e62bd58 | 2951 | #endif |
9906e724 | 2952 | |
47f6e231 | 2953 | static void |
2954 | parse_b_int64_t(int64_t * var) | |
2955 | { | |
2956 | parseBytesLine64(var, B_BYTES_STR); | |
2957 | } | |
2958 | ||
2959 | static void | |
2960 | parse_kb_int64_t(int64_t * var) | |
2961 | { | |
2962 | parseBytesLine64(var, B_KBYTES_STR); | |
2963 | } | |
2964 | ||
9906e724 | 2965 | static void |
a47b9029 | 2966 | free_size_t(size_t * var) |
9906e724 | 2967 | { |
a47b9029 | 2968 | *var = 0; |
9906e724 | 2969 | } |
2970 | ||
e210930b AJ |
2971 | #if !USE_DNSSERVERS |
2972 | static void | |
2973 | free_ssize_t(ssize_t * var) | |
2974 | { | |
2975 | *var = 0; | |
2976 | } | |
2977 | #endif | |
2978 | ||
47f6e231 | 2979 | static void |
2980 | free_b_int64_t(int64_t * var) | |
2981 | { | |
2982 | *var = 0; | |
2983 | } | |
2984 | ||
1b635117 | 2985 | #define free_b_size_t free_size_t |
e210930b | 2986 | #define free_b_ssize_t free_ssize_t |
9906e724 | 2987 | #define free_kb_size_t free_size_t |
2988 | #define free_mb_size_t free_size_t | |
2989 | #define free_gb_size_t free_size_t | |
47f6e231 | 2990 | #define free_kb_int64_t free_b_int64_t |
090089c4 | 2991 | |
8203a132 | 2992 | static void |
a7d59104 | 2993 | dump_ushort(StoreEntry * entry, const char *name, u_short var) |
090089c4 | 2994 | { |
f53b06f9 | 2995 | storeAppendPrintf(entry, "%s %d\n", name, var); |
270b86af | 2996 | } |
090089c4 | 2997 | |
0153d498 | 2998 | static void |
a47b9029 | 2999 | free_ushort(u_short * u) |
0153d498 | 3000 | { |
3001 | *u = 0; | |
3002 | } | |
3003 | ||
270b86af | 3004 | static void |
3005 | parse_ushort(u_short * var) | |
b67e2c8c | 3006 | { |
3007 | ConfigParser::ParseUShort(var); | |
3008 | } | |
3009 | ||
3010 | void | |
3011 | ConfigParser::ParseUShort(u_short *var) | |
270b86af | 3012 | { |
0e656b69 | 3013 | *var = GetShort(); |
090089c4 | 3014 | } |
3015 | ||
3a69ddf3 | 3016 | void |
3017 | ConfigParser::ParseBool(bool *var) | |
3018 | { | |
3019 | int i = GetInteger(); | |
3020 | ||
3021 | if (0 == i) | |
3022 | *var = false; | |
3023 | else if (1 == i) | |
3024 | *var = true; | |
3025 | else | |
3026 | self_destruct(); | |
3027 | } | |
3028 | ||
270b86af | 3029 | static void |
a7d59104 | 3030 | dump_wordlist(StoreEntry * entry, const char *name, wordlist * list) |
270b86af | 3031 | { |
270b86af | 3032 | while (list != NULL) { |
62e76326 | 3033 | storeAppendPrintf(entry, "%s %s\n", name, list->key); |
3034 | list = list->next; | |
429fdbec | 3035 | } |
429fdbec | 3036 | } |
3037 | ||
3a69ddf3 | 3038 | void |
3039 | ConfigParser::ParseWordList(wordlist ** list) | |
3040 | { | |
3041 | parse_wordlist(list); | |
3042 | } | |
3043 | ||
94439e4e | 3044 | void |
270b86af | 3045 | parse_wordlist(wordlist ** list) |
429fdbec | 3046 | { |
270b86af | 3047 | char *token; |
a3c6890f | 3048 | char *t = strtok(NULL, ""); |
62e76326 | 3049 | |
a3c6890f | 3050 | while ((token = strwordtok(NULL, &t))) |
62e76326 | 3051 | wordlistAdd(list, token); |
429fdbec | 3052 | } |
270b86af | 3053 | |
b3d8a9e8 | 3054 | #if 0 /* now unused */ |
f8d9f54a | 3055 | static int |
5da06f20 | 3056 | check_null_wordlist(wordlist * w) |
f8d9f54a | 3057 | { |
3058 | return w == NULL; | |
3059 | } | |
b3d8a9e8 | 3060 | #endif |
f8d9f54a | 3061 | |
63e9d884 | 3062 | static int |
c6d5b87b | 3063 | check_null_acl_access(acl_access * a) |
63e9d884 | 3064 | { |
3065 | return a == NULL; | |
3066 | } | |
3067 | ||
0153d498 | 3068 | #define free_wordlist wordlistDestroy |
270b86af | 3069 | |
d548ee64 | 3070 | #define free_uri_whitespace free_int |
3071 | ||
3072 | static void | |
3073 | parse_uri_whitespace(int *var) | |
3074 | { | |
3075 | char *token = strtok(NULL, w_space); | |
62e76326 | 3076 | |
d548ee64 | 3077 | if (token == NULL) |
62e76326 | 3078 | self_destruct(); |
3079 | ||
7e3ce7b9 | 3080 | if (!strcasecmp(token, "strip")) |
62e76326 | 3081 | *var = URI_WHITESPACE_STRIP; |
7e3ce7b9 | 3082 | else if (!strcasecmp(token, "deny")) |
62e76326 | 3083 | *var = URI_WHITESPACE_DENY; |
d548ee64 | 3084 | else if (!strcasecmp(token, "allow")) |
62e76326 | 3085 | *var = URI_WHITESPACE_ALLOW; |
d548ee64 | 3086 | else if (!strcasecmp(token, "encode")) |
62e76326 | 3087 | *var = URI_WHITESPACE_ENCODE; |
d548ee64 | 3088 | else if (!strcasecmp(token, "chop")) |
62e76326 | 3089 | *var = URI_WHITESPACE_CHOP; |
d548ee64 | 3090 | else |
62e76326 | 3091 | self_destruct(); |
d548ee64 | 3092 | } |
3093 | ||
d548ee64 | 3094 | static void |
3095 | dump_uri_whitespace(StoreEntry * entry, const char *name, int var) | |
3096 | { | |
c193c972 | 3097 | const char *s; |
62e76326 | 3098 | |
d548ee64 | 3099 | if (var == URI_WHITESPACE_ALLOW) |
62e76326 | 3100 | s = "allow"; |
d548ee64 | 3101 | else if (var == URI_WHITESPACE_ENCODE) |
62e76326 | 3102 | s = "encode"; |
d548ee64 | 3103 | else if (var == URI_WHITESPACE_CHOP) |
62e76326 | 3104 | s = "chop"; |
7e3ce7b9 | 3105 | else if (var == URI_WHITESPACE_DENY) |
62e76326 | 3106 | s = "deny"; |
7e3ce7b9 | 3107 | else |
62e76326 | 3108 | s = "strip"; |
3109 | ||
d548ee64 | 3110 | storeAppendPrintf(entry, "%s %s\n", name, s); |
3111 | } | |
3112 | ||
6a566b9c | 3113 | static void |
c1dd71ae | 3114 | free_removalpolicy(RemovalPolicySettings ** settings) |
6a566b9c | 3115 | { |
3116 | if (!*settings) | |
62e76326 | 3117 | return; |
3118 | ||
6a566b9c | 3119 | free_string(&(*settings)->type); |
62e76326 | 3120 | |
6a566b9c | 3121 | free_wordlist(&(*settings)->args); |
62e76326 | 3122 | |
c8f4eac4 | 3123 | delete *settings; |
62e76326 | 3124 | |
6a566b9c | 3125 | *settings = NULL; |
3126 | } | |
3127 | ||
3128 | static void | |
c1dd71ae | 3129 | parse_removalpolicy(RemovalPolicySettings ** settings) |
6a566b9c | 3130 | { |
3131 | if (*settings) | |
62e76326 | 3132 | free_removalpolicy(settings); |
3133 | ||
c8f4eac4 | 3134 | *settings = new RemovalPolicySettings; |
62e76326 | 3135 | |
6a566b9c | 3136 | parse_string(&(*settings)->type); |
62e76326 | 3137 | |
6a566b9c | 3138 | parse_wordlist(&(*settings)->args); |
3139 | } | |
3140 | ||
3141 | static void | |
c1dd71ae | 3142 | dump_removalpolicy(StoreEntry * entry, const char *name, RemovalPolicySettings * settings) |
6a566b9c | 3143 | { |
3144 | wordlist *args; | |
3145 | storeAppendPrintf(entry, "%s %s", name, settings->type); | |
3146 | args = settings->args; | |
62e76326 | 3147 | |
6a566b9c | 3148 | while (args) { |
62e76326 | 3149 | storeAppendPrintf(entry, " %s", args->key); |
3150 | args = args->next; | |
6a566b9c | 3151 | } |
62e76326 | 3152 | |
be58afb5 | 3153 | storeAppendPrintf(entry, "\n"); |
6a566b9c | 3154 | } |
c1dd71ae | 3155 | |
ea21d497 HN |
3156 | static void |
3157 | free_memcachemode(SquidConfig * config) | |
3158 | { | |
3159 | return; | |
3160 | } | |
3161 | ||
3162 | static void | |
3163 | parse_memcachemode(SquidConfig * config) | |
3164 | { | |
3165 | char *token = strtok(NULL, w_space); | |
3166 | if (!token) | |
e1381638 | 3167 | self_destruct(); |
ea21d497 | 3168 | |
10aeba1d | 3169 | if (strcmp(token, "always") == 0) { |
e1381638 AJ |
3170 | Config.onoff.memory_cache_first = 1; |
3171 | Config.onoff.memory_cache_disk = 1; | |
10aeba1d | 3172 | } else if (strcmp(token, "disk") == 0) { |
e1381638 AJ |
3173 | Config.onoff.memory_cache_first = 0; |
3174 | Config.onoff.memory_cache_disk = 1; | |
ea21d497 | 3175 | } else if (strncmp(token, "net", 3) == 0) { |
e1381638 AJ |
3176 | Config.onoff.memory_cache_first = 1; |
3177 | Config.onoff.memory_cache_disk = 0; | |
10aeba1d | 3178 | } else if (strcmp(token, "never") == 0) { |
e1381638 AJ |
3179 | Config.onoff.memory_cache_first = 0; |
3180 | Config.onoff.memory_cache_disk = 0; | |
ea21d497 | 3181 | } else |
e1381638 | 3182 | self_destruct(); |
ea21d497 HN |
3183 | } |
3184 | ||
3185 | static void | |
3186 | dump_memcachemode(StoreEntry * entry, const char *name, SquidConfig &config) | |
3187 | { | |
3188 | storeAppendPrintf(entry, "%s ", name); | |
3189 | if (Config.onoff.memory_cache_first && Config.onoff.memory_cache_disk) | |
e1381638 | 3190 | storeAppendPrintf(entry, "always"); |
ea21d497 | 3191 | else if (!Config.onoff.memory_cache_first && Config.onoff.memory_cache_disk) |
e1381638 | 3192 | storeAppendPrintf(entry, "disk"); |
ea21d497 | 3193 | else if (Config.onoff.memory_cache_first && !Config.onoff.memory_cache_disk) |
e1381638 | 3194 | storeAppendPrintf(entry, "network"); |
ea21d497 | 3195 | else if (!Config.onoff.memory_cache_first && !Config.onoff.memory_cache_disk) |
e1381638 | 3196 | storeAppendPrintf(entry, "none"); |
ea21d497 HN |
3197 | storeAppendPrintf(entry, "\n"); |
3198 | } | |
3199 | ||
cca8ba0d | 3200 | #include "cf_parser.cci" |
f1dc9b30 | 3201 | |
3202 | peer_t | |
3203 | parseNeighborType(const char *s) | |
3204 | { | |
3205 | if (!strcasecmp(s, "parent")) | |
62e76326 | 3206 | return PEER_PARENT; |
3207 | ||
f1dc9b30 | 3208 | if (!strcasecmp(s, "neighbor")) |
62e76326 | 3209 | return PEER_SIBLING; |
3210 | ||
f1dc9b30 | 3211 | if (!strcasecmp(s, "neighbour")) |
62e76326 | 3212 | return PEER_SIBLING; |
3213 | ||
f1dc9b30 | 3214 | if (!strcasecmp(s, "sibling")) |
62e76326 | 3215 | return PEER_SIBLING; |
3216 | ||
f1dc9b30 | 3217 | if (!strcasecmp(s, "multicast")) |
62e76326 | 3218 | return PEER_MULTICAST; |
3219 | ||
bf8fe701 | 3220 | debugs(15, 0, "WARNING: Unknown neighbor type: " << s); |
62e76326 | 3221 | |
f1dc9b30 | 3222 | return PEER_SIBLING; |
3223 | } | |
f150dd4b | 3224 | |
0b0cfcf2 | 3225 | #if USE_WCCPv2 |
52f772de | 3226 | static void |
b7ac5457 | 3227 | parse_IpAddress_list(Ip::Address_list ** head) |
52f772de | 3228 | { |
3229 | char *token; | |
b7ac5457 AJ |
3230 | Ip::Address_list *s; |
3231 | Ip::Address ipa; | |
62e76326 | 3232 | |
52f772de | 3233 | while ((token = strtok(NULL, w_space))) { |
82b7abe3 AJ |
3234 | if (GetHostWithPort(token, &ipa)) { |
3235 | ||
3236 | while (*head) | |
3237 | head = &(*head)->next; | |
3238 | ||
b7ac5457 | 3239 | s = static_cast<Ip::Address_list *>(xcalloc(1, sizeof(*s))); |
82b7abe3 AJ |
3240 | s->s = ipa; |
3241 | ||
3242 | *head = s; | |
9d65168e | 3243 | } else |
82b7abe3 | 3244 | self_destruct(); |
7e3ce7b9 | 3245 | } |
3246 | } | |
3247 | ||
3248 | static void | |
b7ac5457 | 3249 | dump_IpAddress_list(StoreEntry * e, const char *n, const Ip::Address_list * s) |
7e3ce7b9 | 3250 | { |
cc192b50 | 3251 | char ntoabuf[MAX_IPSTRLEN]; |
3252 | ||
7e3ce7b9 | 3253 | while (s) { |
cc192b50 | 3254 | storeAppendPrintf(e, "%s %s\n", |
62e76326 | 3255 | n, |
cc192b50 | 3256 | s->s.NtoA(ntoabuf,MAX_IPSTRLEN)); |
62e76326 | 3257 | s = s->next; |
7e3ce7b9 | 3258 | } |
3259 | } | |
3260 | ||
3261 | static void | |
b7ac5457 | 3262 | free_IpAddress_list(Ip::Address_list ** head) |
7e3ce7b9 | 3263 | { |
26ac0430 AJ |
3264 | if (*head) delete *head; |
3265 | *head = NULL; | |
7e3ce7b9 | 3266 | } |
3267 | ||
0b0cfcf2 | 3268 | #if CURRENTLY_UNUSED |
3269 | /* This code was previously used by http_port. Left as it really should | |
3270 | * be used by icp_port and htcp_port | |
3271 | */ | |
7e3ce7b9 | 3272 | static int |
b7ac5457 | 3273 | check_null_IpAddress_list(const Ip::Address_list * s) |
7e3ce7b9 | 3274 | { |
3275 | return NULL == s; | |
3276 | } | |
62e76326 | 3277 | |
3f38a55e | 3278 | #endif /* CURRENTLY_UNUSED */ |
0b0cfcf2 | 3279 | #endif /* USE_WCCPv2 */ |
7e3ce7b9 | 3280 | |
154dc884 | 3281 | CBDATA_CLASS_INIT(http_port_list); |
3282 | ||
d193a436 | 3283 | static void |
3f38a55e | 3284 | parse_http_port_specification(http_port_list * s, char *token) |
d193a436 | 3285 | { |
3f38a55e | 3286 | char *host = NULL; |
3f38a55e | 3287 | unsigned short port = 0; |
cc192b50 | 3288 | char *t = NULL; |
3289 | char *junk = NULL; | |
62e76326 | 3290 | |
5529ca8a | 3291 | s->disable_pmtu_discovery = DISABLE_PMTU_OFF; |
13adaf1f | 3292 | s->name = xstrdup(token); |
d67acb4e | 3293 | s->connection_auth_disabled = false; |
5529ca8a | 3294 | |
cc192b50 | 3295 | if (*token == '[') { |
3296 | /* [ipv6]:port */ | |
26ac0430 AJ |
3297 | host = token + 1; |
3298 | t = strchr(host, ']'); | |
3299 | if (!t) { | |
cc192b50 | 3300 | debugs(3, 0, "http(s)_port: missing ']' on IPv6 address: " << token); |
26ac0430 | 3301 | self_destruct(); |
cc192b50 | 3302 | } |
26ac0430 AJ |
3303 | *t++ = '\0'; |
3304 | if (*t != ':') { | |
cc192b50 | 3305 | debugs(3, 0, "http(s)_port: missing Port in: " << token); |
26ac0430 | 3306 | self_destruct(); |
cc192b50 | 3307 | } |
055421ee AJ |
3308 | if (!Ip::EnableIpv6) { |
3309 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: IPv6 is not available."); | |
26ac0430 AJ |
3310 | self_destruct(); |
3311 | } | |
055421ee AJ |
3312 | port = xatos(t + 1); |
3313 | } else if ((t = strchr(token, ':'))) { | |
3314 | /* host:port */ | |
3315 | /* ipv4:port */ | |
3316 | host = token; | |
3317 | *t = '\0'; | |
3318 | port = xatos(t + 1); | |
3319 | ||
3320 | } else if ((port = strtol(token, &junk, 10)), !*junk) { | |
3321 | /* port */ | |
3322 | debugs(3, 3, "http(s)_port: found Listen on Port: " << port); | |
3323 | } else { | |
3324 | debugs(3, 0, "http(s)_port: missing Port: " << token); | |
3325 | self_destruct(); | |
3326 | } | |
62e76326 | 3327 | |
cc192b50 | 3328 | if (port == 0) { |
3329 | debugs(3, 0, "http(s)_port: Port cannot be 0: " << token); | |
0e656b69 | 3330 | self_destruct(); |
cc192b50 | 3331 | } |
0e656b69 | 3332 | |
cc192b50 | 3333 | if (NULL == host) { |
3334 | s->s.SetAnyAddr(); | |
3335 | s->s.SetPort(port); | |
6df7ad56 AJ |
3336 | if (!Ip::EnableIpv6) |
3337 | s->s.SetIPv4(); | |
7e07ced1 | 3338 | debugs(3, 3, "http(s)_port: found Listen on wildcard address: *:" << s->s.GetPort() ); |
26ac0430 | 3339 | } else if ( s->s = host ) { /* check/parse numeric IPA */ |
cc192b50 | 3340 | s->s.SetPort(port); |
6df7ad56 AJ |
3341 | if (!Ip::EnableIpv6) |
3342 | s->s.SetIPv4(); | |
cc192b50 | 3343 | debugs(3, 3, "http(s)_port: Listen on Host/IP: " << host << " --> " << s->s); |
26ac0430 | 3344 | } else if ( s->s.GetHostByName(host) ) { /* check/parse for FQDN */ |
62e76326 | 3345 | /* dont use ipcache */ |
62e76326 | 3346 | s->defaultsite = xstrdup(host); |
cc192b50 | 3347 | s->s.SetPort(port); |
6df7ad56 AJ |
3348 | if (!Ip::EnableIpv6) |
3349 | s->s.SetIPv4(); | |
cc192b50 | 3350 | debugs(3, 3, "http(s)_port: found Listen as Host " << s->defaultsite << " on IP: " << s->s); |
26ac0430 | 3351 | } else { |
cc192b50 | 3352 | debugs(3, 0, "http(s)_port: failed to resolve Host/IP: " << host); |
62e76326 | 3353 | self_destruct(); |
cc192b50 | 3354 | } |
3f38a55e | 3355 | } |
3356 | ||
3357 | static void | |
3358 | parse_http_port_option(http_port_list * s, char *token) | |
3359 | { | |
c7b1dd5d AJ |
3360 | /* modes first */ |
3361 | ||
3362 | if (strcmp(token, "accel") == 0) { | |
3363 | if (s->intercepted || s->spoof_client_ip) { | |
3364 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: Accelerator mode requires its own port. It cannot be shared with other modes."); | |
3365 | self_destruct(); | |
3366 | } | |
3367 | s->accel = 1; | |
3368 | } else if (strcmp(token, "transparent") == 0 || strcmp(token, "intercept") == 0) { | |
3369 | if (s->accel || s->spoof_client_ip) { | |
3370 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: Intercept mode requires its own interception port. It cannot be shared with other modes."); | |
3371 | self_destruct(); | |
3372 | } | |
3373 | s->intercepted = 1; | |
3374 | Ip::Interceptor.StartInterception(); | |
3375 | /* Log information regarding the port modes under interception. */ | |
3376 | debugs(3, DBG_IMPORTANT, "Starting Authentication on port " << s->s); | |
3377 | debugs(3, DBG_IMPORTANT, "Disabling Authentication on port " << s->s << " (interception enabled)"); | |
3378 | ||
c7b1dd5d | 3379 | /* INET6: until transparent REDIRECT works on IPv6 SOCKET, force wildcard to IPv4 */ |
055421ee AJ |
3380 | if (Ip::EnableIpv6) |
3381 | debugs(3, DBG_IMPORTANT, "Disabling IPv6 on port " << s->s << " (interception enabled)"); | |
c7b1dd5d AJ |
3382 | if ( !s->s.SetIPv4() ) { |
3383 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: IPv6 addresses cannot be transparent (protocol does not provide NAT)" << s->s ); | |
3384 | self_destruct(); | |
3385 | } | |
c7b1dd5d AJ |
3386 | } else if (strcmp(token, "tproxy") == 0) { |
3387 | if (s->intercepted || s->accel) { | |
3388 | debugs(3,DBG_CRITICAL, "FATAL: http(s)_port: TPROXY option requires its own interception port. It cannot be shared with other modes."); | |
3389 | self_destruct(); | |
3390 | } | |
3391 | s->spoof_client_ip = 1; | |
3392 | Ip::Interceptor.StartTransparency(); | |
3393 | /* Log information regarding the port modes under transparency. */ | |
3394 | debugs(3, DBG_IMPORTANT, "Starting IP Spoofing on port " << s->s); | |
3395 | debugs(3, DBG_IMPORTANT, "Disabling Authentication on port " << s->s << " (IP spoofing enabled)"); | |
3396 | ||
3397 | if (!Ip::Interceptor.ProbeForTproxy(s->s)) { | |
3398 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: TPROXY support in the system does not work."); | |
3399 | self_destruct(); | |
3400 | } | |
3401 | ||
3402 | } else if (strncmp(token, "defaultsite=", 12) == 0) { | |
3403 | if (!s->accel) { | |
3404 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: defaultsite option requires Acceleration mode flag."); | |
3405 | self_destruct(); | |
3406 | } | |
62e76326 | 3407 | safe_free(s->defaultsite); |
3408 | s->defaultsite = xstrdup(token + 12); | |
3f38a55e | 3409 | } else if (strcmp(token, "vhost") == 0) { |
c7b1dd5d AJ |
3410 | if (!s->accel) { |
3411 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: vhost option requires Acceleration mode flag."); | |
3412 | self_destruct(); | |
3413 | } | |
62e76326 | 3414 | s->vhost = 1; |
3f38a55e | 3415 | } else if (strcmp(token, "vport") == 0) { |
c7b1dd5d AJ |
3416 | if (!s->accel) { |
3417 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: vport option requires Acceleration mode flag."); | |
3418 | self_destruct(); | |
3419 | } | |
62e76326 | 3420 | s->vport = -1; |
3f38a55e | 3421 | } else if (strncmp(token, "vport=", 6) == 0) { |
c7b1dd5d AJ |
3422 | if (!s->accel) { |
3423 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: vport option requires Acceleration mode flag."); | |
3424 | self_destruct(); | |
3425 | } | |
0e656b69 | 3426 | s->vport = xatos(token + 6); |
3f38a55e | 3427 | } else if (strncmp(token, "protocol=", 9) == 0) { |
c7b1dd5d AJ |
3428 | if (!s->accel) { |
3429 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: protocol option requires Acceleration mode flag."); | |
3430 | self_destruct(); | |
3431 | } | |
62e76326 | 3432 | s->protocol = xstrdup(token + 9); |
7f7bdd96 | 3433 | } else if (strcmp(token, "allow-direct") == 0) { |
c7b1dd5d AJ |
3434 | if (!s->accel) { |
3435 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: vport option requires Acceleration mode flag."); | |
3436 | self_destruct(); | |
3437 | } | |
7f7bdd96 | 3438 | s->allow_direct = 1; |
432bc83c | 3439 | } else if (strcmp(token, "ignore-cc") == 0) { |
626096be | 3440 | #if !USE_HTTP_VIOLATIONS |
838daf3f | 3441 | if (!s->accel) { |
c7b1dd5d | 3442 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: ignore-cc option requires Scceleration mode flag."); |
838daf3f A |
3443 | self_destruct(); |
3444 | } | |
432bc83c | 3445 | #endif |
c7b1dd5d AJ |
3446 | s->ignore_cc = 1; |
3447 | } else if (strncmp(token, "name=", 5) == 0) { | |
3448 | safe_free(s->name); | |
3449 | s->name = xstrdup(token + 5); | |
d67acb4e AJ |
3450 | } else if (strcmp(token, "no-connection-auth") == 0) { |
3451 | s->connection_auth_disabled = true; | |
3452 | } else if (strcmp(token, "connection-auth=off") == 0) { | |
26ac0430 | 3453 | s->connection_auth_disabled = true; |
d67acb4e | 3454 | } else if (strcmp(token, "connection-auth") == 0) { |
26ac0430 | 3455 | s->connection_auth_disabled = false; |
d67acb4e | 3456 | } else if (strcmp(token, "connection-auth=on") == 0) { |
26ac0430 | 3457 | s->connection_auth_disabled = false; |
5529ca8a | 3458 | } else if (strncmp(token, "disable-pmtu-discovery=", 23) == 0) { |
3459 | if (!strcasecmp(token + 23, "off")) | |
3460 | s->disable_pmtu_discovery = DISABLE_PMTU_OFF; | |
3461 | else if (!strcasecmp(token + 23, "transparent")) | |
3462 | s->disable_pmtu_discovery = DISABLE_PMTU_TRANSPARENT; | |
3463 | else if (!strcasecmp(token + 23, "always")) | |
3464 | s->disable_pmtu_discovery = DISABLE_PMTU_ALWAYS; | |
3465 | else | |
3466 | self_destruct(); | |
cc192b50 | 3467 | } else if (strcmp(token, "ipv4") == 0) { |
26ac0430 | 3468 | if ( !s->s.SetIPv4() ) { |
055421ee | 3469 | debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: IPv6 addresses cannot be used as IPv4-Only. " << s->s ); |
cc192b50 | 3470 | self_destruct(); |
3471 | } | |
26ac0430 AJ |
3472 | } else if (strcmp(token, "tcpkeepalive") == 0) { |
3473 | s->tcp_keepalive.enabled = 1; | |
b2130d58 | 3474 | } else if (strncmp(token, "tcpkeepalive=", 13) == 0) { |
26ac0430 AJ |
3475 | char *t = token + 13; |
3476 | s->tcp_keepalive.enabled = 1; | |
3477 | s->tcp_keepalive.idle = atoi(t); | |
3478 | t = strchr(t, ','); | |
3479 | if (t) { | |
3480 | t++; | |
3481 | s->tcp_keepalive.interval = atoi(t); | |
3482 | t = strchr(t, ','); | |
3483 | } | |
3484 | if (t) { | |
3485 | t++; | |
3486 | s->tcp_keepalive.timeout = atoi(t); | |
3487 | t = strchr(t, ','); | |
3488 | } | |
154dc884 | 3489 | #if USE_SSL |
3a0c8eb5 AR |
3490 | } else if (strcasecmp(token, "sslBump") == 0) { |
3491 | debugs(3, DBG_CRITICAL, "WARNING: '" << token << "' is deprecated " << | |
9945bf3f | 3492 | "in http_port. Use 'ssl-bump' instead."); |
3a0c8eb5 AR |
3493 | s->sslBump = 1; // accelerated when bumped, otherwise not |
3494 | } else if (strcmp(token, "ssl-bump") == 0) { | |
c7b1dd5d | 3495 | s->sslBump = 1; // accelerated when bumped, otherwise not |
154dc884 | 3496 | } else if (strncmp(token, "cert=", 5) == 0) { |
3497 | safe_free(s->cert); | |
3498 | s->cert = xstrdup(token + 5); | |
3499 | } else if (strncmp(token, "key=", 4) == 0) { | |
3500 | safe_free(s->key); | |
3501 | s->key = xstrdup(token + 4); | |
3502 | } else if (strncmp(token, "version=", 8) == 0) { | |
3503 | s->version = xatoi(token + 8); | |
154dc884 | 3504 | if (s->version < 1 || s->version > 4) |
3505 | self_destruct(); | |
3506 | } else if (strncmp(token, "options=", 8) == 0) { | |
3507 | safe_free(s->options); | |
3508 | s->options = xstrdup(token + 8); | |
3509 | } else if (strncmp(token, "cipher=", 7) == 0) { | |
3510 | safe_free(s->cipher); | |
3511 | s->cipher = xstrdup(token + 7); | |
3512 | } else if (strncmp(token, "clientca=", 9) == 0) { | |
3513 | safe_free(s->clientca); | |
3514 | s->clientca = xstrdup(token + 9); | |
3515 | } else if (strncmp(token, "cafile=", 7) == 0) { | |
3516 | safe_free(s->cafile); | |
3517 | s->cafile = xstrdup(token + 7); | |
3518 | } else if (strncmp(token, "capath=", 7) == 0) { | |
3519 | safe_free(s->capath); | |
3520 | s->capath = xstrdup(token + 7); | |
3521 | } else if (strncmp(token, "crlfile=", 8) == 0) { | |
3522 | safe_free(s->crlfile); | |
3523 | s->crlfile = xstrdup(token + 8); | |
3524 | } else if (strncmp(token, "dhparams=", 9) == 0) { | |
3525 | safe_free(s->dhfile); | |
3526 | s->dhfile = xstrdup(token + 9); | |
3527 | } else if (strncmp(token, "sslflags=", 9) == 0) { | |
3528 | safe_free(s->sslflags); | |
3529 | s->sslflags = xstrdup(token + 9); | |
3530 | } else if (strncmp(token, "sslcontext=", 11) == 0) { | |
3531 | safe_free(s->sslcontext); | |
3532 | s->sslcontext = xstrdup(token + 11); | |
154dc884 | 3533 | #endif |
3f38a55e | 3534 | } else { |
62e76326 | 3535 | self_destruct(); |
3f38a55e | 3536 | } |
3537 | } | |
3538 | ||
3f38a55e | 3539 | static http_port_list * |
3540 | create_http_port(char *portspec) | |
3541 | { | |
154dc884 | 3542 | http_port_list *s = new http_port_list("http"); |
3f38a55e | 3543 | parse_http_port_specification(s, portspec); |
3544 | return s; | |
3545 | } | |
3546 | ||
3547 | void | |
3548 | add_http_port(char *portspec) | |
3549 | { | |
3550 | http_port_list *s = create_http_port(portspec); | |
7e07ced1 AJ |
3551 | // we may need to merge better of the above returns a list with clones |
3552 | assert(s->next == NULL); | |
3f38a55e | 3553 | s->next = Config.Sockaddr.http; |
3554 | Config.Sockaddr.http = s; | |
3555 | } | |
3556 | ||
7e07ced1 AJ |
3557 | http_port_list * |
3558 | clone_http_port_list(http_port_list *a) | |
3559 | { | |
3560 | http_port_list *b = new http_port_list(a->protocol); | |
3561 | ||
3562 | b->s = a->s; | |
3563 | if (a->name) | |
3564 | b->name = xstrdup(a->name); | |
3565 | if (a->defaultsite) | |
3566 | b->defaultsite = xstrdup(a->defaultsite); | |
3567 | ||
3568 | b->intercepted = a->intercepted; | |
3569 | b->spoof_client_ip = a->spoof_client_ip; | |
3570 | b->accel = a->accel; | |
3571 | b->allow_direct = a->allow_direct; | |
3572 | b->vhost = a->vhost; | |
3573 | b->sslBump = a->sslBump; | |
3574 | b->vport = a->vport; | |
3575 | b->connection_auth_disabled = a->connection_auth_disabled; | |
3576 | b->disable_pmtu_discovery = a->disable_pmtu_discovery; | |
3577 | ||
3578 | memcpy( &(b->tcp_keepalive), &(a->tcp_keepalive), sizeof(a->tcp_keepalive)); | |
3579 | ||
3580 | #if 0 | |
3581 | // AYJ: 2009-07-18: for now SSL does not clone. Configure separate ports with IPs and SSL settings | |
3582 | ||
3583 | #if USE_SSL | |
3584 | // XXX: temporary hack to ease move of SSL options to http_port | |
3585 | http_port_list &http; | |
3586 | ||
3587 | char *cert; | |
3588 | char *key; | |
3589 | int version; | |
3590 | char *cipher; | |
3591 | char *options; | |
3592 | char *clientca; | |
3593 | char *cafile; | |
3594 | char *capath; | |
3595 | char *crlfile; | |
3596 | char *dhfile; | |
3597 | char *sslflags; | |
3598 | char *sslcontext; | |
3599 | SSL_CTX *sslContext; | |
3600 | #endif | |
3601 | ||
3602 | #endif /*0*/ | |
3603 | ||
3604 | return b; | |
3605 | } | |
7e07ced1 | 3606 | |
3f38a55e | 3607 | static void |
3608 | parse_http_port_list(http_port_list ** head) | |
3609 | { | |
3610 | char *token = strtok(NULL, w_space); | |
62e76326 | 3611 | |
9eeb8e4b | 3612 | if (!token) { |
62e76326 | 3613 | self_destruct(); |
9eeb8e4b | 3614 | return; |
3615 | } | |
62e76326 | 3616 | |
3f38a55e | 3617 | http_port_list *s = create_http_port(token); |
62e76326 | 3618 | |
3f38a55e | 3619 | /* parse options ... */ |
3620 | while ((token = strtok(NULL, w_space))) { | |
62e76326 | 3621 | parse_http_port_option(s, token); |
3f38a55e | 3622 | } |
62e76326 | 3623 | |
055421ee | 3624 | if (Ip::EnableIpv6&IPV6_SPECIAL_SPLITSTACK && s->s.IsAnyAddr()) { |
7e07ced1 AJ |
3625 | // clone the port options from *s to *(s->next) |
3626 | s->next = clone_http_port_list(s); | |
3627 | s->next->s.SetIPv4(); | |
3628 | debugs(3, 3, "http(s)_port: clone wildcard address for split-stack: " << s->s << " and " << s->next->s); | |
3629 | } | |
7e07ced1 | 3630 | |
3f38a55e | 3631 | while (*head) |
62e76326 | 3632 | head = &(*head)->next; |
3633 | ||
3f38a55e | 3634 | *head = s; |
3635 | } | |
3636 | ||
3637 | static void | |
3638 | dump_generic_http_port(StoreEntry * e, const char *n, const http_port_list * s) | |
3639 | { | |
cc192b50 | 3640 | char buf[MAX_IPSTRLEN]; |
3641 | ||
3642 | storeAppendPrintf(e, "%s %s", | |
62e76326 | 3643 | n, |
cc192b50 | 3644 | s->s.ToURL(buf,MAX_IPSTRLEN)); |
62e76326 | 3645 | |
2ad20b4f AJ |
3646 | if (s->intercepted) |
3647 | storeAppendPrintf(e, " intercept"); | |
62e76326 | 3648 | |
c7b1dd5d AJ |
3649 | if (s->spoof_client_ip) |
3650 | storeAppendPrintf(e, " tproxy"); | |
3651 | ||
3652 | if (s->accel) | |
3653 | storeAppendPrintf(e, " accel"); | |
3654 | ||
3f38a55e | 3655 | if (s->vhost) |
62e76326 | 3656 | storeAppendPrintf(e, " vhost"); |
3657 | ||
3f38a55e | 3658 | if (s->vport) |
62e76326 | 3659 | storeAppendPrintf(e, " vport"); |
5529ca8a | 3660 | |
c7b1dd5d AJ |
3661 | if (s->defaultsite) |
3662 | storeAppendPrintf(e, " defaultsite=%s", s->defaultsite); | |
3663 | ||
d67acb4e AJ |
3664 | if (s->connection_auth_disabled) |
3665 | storeAppendPrintf(e, " connection-auth=off"); | |
3666 | else | |
3667 | storeAppendPrintf(e, " connection-auth=on"); | |
3668 | ||
5529ca8a | 3669 | if (s->disable_pmtu_discovery != DISABLE_PMTU_OFF) { |
3670 | const char *pmtu; | |
3671 | ||
3672 | if (s->disable_pmtu_discovery == DISABLE_PMTU_ALWAYS) | |
3673 | pmtu = "always"; | |
3674 | else | |
3675 | pmtu = "transparent"; | |
3676 | ||
3677 | storeAppendPrintf(e, " disable-pmtu-discovery=%s", pmtu); | |
3678 | } | |
b2130d58 | 3679 | |
3680 | if (s->tcp_keepalive.enabled) { | |
26ac0430 | 3681 | if (s->tcp_keepalive.idle || s->tcp_keepalive.interval || s->tcp_keepalive.timeout) { |
68924b6d | 3682 | storeAppendPrintf(e, " tcpkeepalive=%d,%d,%d", s->tcp_keepalive.idle, s->tcp_keepalive.interval, s->tcp_keepalive.timeout); |
26ac0430 | 3683 | } else { |
68924b6d | 3684 | storeAppendPrintf(e, " tcpkeepalive"); |
26ac0430 | 3685 | } |
b2130d58 | 3686 | } |
154dc884 | 3687 | |
3688 | #if USE_SSL | |
c7b1dd5d AJ |
3689 | if (s->sslBump) |
3690 | storeAppendPrintf(e, " sslBump"); | |
3691 | ||
26ac0430 AJ |
3692 | if (s->cert) |
3693 | storeAppendPrintf(e, " cert=%s", s->cert); | |
154dc884 | 3694 | |
26ac0430 AJ |
3695 | if (s->key) |
3696 | storeAppendPrintf(e, " key=%s", s->key); | |
154dc884 | 3697 | |
26ac0430 AJ |
3698 | if (s->version) |
3699 | storeAppendPrintf(e, " version=%d", s->version); | |
154dc884 | 3700 | |
26ac0430 AJ |
3701 | if (s->options) |
3702 | storeAppendPrintf(e, " options=%s", s->options); | |
154dc884 | 3703 | |
26ac0430 AJ |
3704 | if (s->cipher) |
3705 | storeAppendPrintf(e, " cipher=%s", s->cipher); | |
154dc884 | 3706 | |
26ac0430 AJ |
3707 | if (s->cafile) |
3708 | storeAppendPrintf(e, " cafile=%s", s->cafile); | |
154dc884 | 3709 | |
26ac0430 AJ |
3710 | if (s->capath) |
3711 | storeAppendPrintf(e, " capath=%s", s->capath); | |
154dc884 | 3712 | |
26ac0430 AJ |
3713 | if (s->crlfile) |
3714 | storeAppendPrintf(e, " crlfile=%s", s->crlfile); | |
154dc884 | 3715 | |
26ac0430 AJ |
3716 | if (s->dhfile) |
3717 | storeAppendPrintf(e, " dhparams=%s", s->dhfile); | |
154dc884 | 3718 | |
26ac0430 AJ |
3719 | if (s->sslflags) |
3720 | storeAppendPrintf(e, " sslflags=%s", s->sslflags); | |
154dc884 | 3721 | |
26ac0430 AJ |
3722 | if (s->sslcontext) |
3723 | storeAppendPrintf(e, " sslcontext=%s", s->sslcontext); | |
154dc884 | 3724 | #endif |
3f38a55e | 3725 | } |
62e76326 | 3726 | |
3f38a55e | 3727 | static void |
3728 | dump_http_port_list(StoreEntry * e, const char *n, const http_port_list * s) | |
3729 | { | |
3730 | while (s) { | |
62e76326 | 3731 | dump_generic_http_port(e, n, s); |
3732 | storeAppendPrintf(e, "\n"); | |
3733 | s = s->next; | |
3f38a55e | 3734 | } |
3735 | } | |
3736 | ||
3737 | static void | |
3738 | free_http_port_list(http_port_list ** head) | |
3739 | { | |
3740 | http_port_list *s; | |
62e76326 | 3741 | |
3f38a55e | 3742 | while ((s = *head) != NULL) { |
62e76326 | 3743 | *head = s->next; |
154dc884 | 3744 | delete s; |
3f38a55e | 3745 | } |
3746 | } | |
3747 | ||
3f38a55e | 3748 | #if USE_SSL |
3f38a55e | 3749 | |
154dc884 | 3750 | // TODO: merge better with parse_http_port_list |
3f38a55e | 3751 | static void |
3752 | parse_https_port_list(https_port_list ** head) | |
3753 | { | |
3f38a55e | 3754 | char *token; |
3755 | https_port_list *s; | |
154dc884 | 3756 | |
3f38a55e | 3757 | token = strtok(NULL, w_space); |
62e76326 | 3758 | |
3f38a55e | 3759 | if (!token) |
62e76326 | 3760 | self_destruct(); |
3761 | ||
154dc884 | 3762 | s = new https_port_list; |
3f38a55e | 3763 | parse_http_port_specification(&s->http, token); |
62e76326 | 3764 | |
d193a436 | 3765 | /* parse options ... */ |
3766 | while ((token = strtok(NULL, w_space))) { | |
154dc884 | 3767 | parse_http_port_option(s, token); |
d193a436 | 3768 | } |
62e76326 | 3769 | |
8abf232c | 3770 | while (*head) { |
3771 | http_port_list ** headTmp = &(*head)->http.next; | |
3772 | head = (https_port_list **)headTmp; | |
3773 | } | |
62e76326 | 3774 | |
d193a436 | 3775 | *head = s; |
3776 | } | |
3777 | ||
3778 | static void | |
3779 | dump_https_port_list(StoreEntry * e, const char *n, const https_port_list * s) | |
3780 | { | |
154dc884 | 3781 | dump_http_port_list(e, n, s); |
d193a436 | 3782 | } |
3783 | ||
3784 | static void | |
3785 | free_https_port_list(https_port_list ** head) | |
3786 | { | |
154dc884 | 3787 | free_http_port_list((http_port_list**)head); |
d193a436 | 3788 | } |
3789 | ||
3790 | #if 0 | |
3791 | static int | |
3792 | check_null_https_port_list(const https_port_list * s) | |
3793 | { | |
3794 | return NULL == s; | |
3795 | } | |
62e76326 | 3796 | |
d193a436 | 3797 | #endif |
3798 | ||
3799 | #endif /* USE_SSL */ | |
3800 | ||
f150dd4b | 3801 | void |
3802 | configFreeMemory(void) | |
3803 | { | |
23ff6968 | 3804 | free_all(); |
f150dd4b | 3805 | } |
f0b19334 | 3806 | |
94439e4e | 3807 | void |
f0b19334 | 3808 | requirePathnameExists(const char *name, const char *path) |
3809 | { | |
62e76326 | 3810 | |
f0b19334 | 3811 | struct stat sb; |
08577e16 | 3812 | char pathbuf[BUFSIZ]; |
f0b19334 | 3813 | assert(path != NULL); |
62e76326 | 3814 | |
0b796acd | 3815 | if (Config.chroot_dir && (geteuid() == 0)) { |
62e76326 | 3816 | snprintf(pathbuf, BUFSIZ, "%s/%s", Config.chroot_dir, path); |
3817 | path = pathbuf; | |
08577e16 | 3818 | } |
62e76326 | 3819 | |
a572d8be | 3820 | if (stat(path, &sb) < 0) { |
3821 | if (opt_send_signal == -1 || opt_send_signal == SIGHUP) | |
3822 | fatalf("%s %s: %s", name, path, xstrerror()); | |
3823 | else | |
3824 | fprintf(stderr, "WARNING: %s %s: %s\n", name, path, xstrerror()); | |
3825 | } | |
f0b19334 | 3826 | } |
d860a1aa | 3827 | |
3828 | char * | |
3829 | strtokFile(void) | |
3830 | { | |
d295d770 | 3831 | return ConfigParser::strtokFile(); |
d860a1aa | 3832 | } |
7684c4b1 | 3833 | |
450e0c10 | 3834 | #include "AccessLogEntry.h" |
3835 | /* TODO: split out parsing somehow ...*/ | |
7684c4b1 | 3836 | static void |
3837 | parse_logformat(logformat ** logformat_definitions) | |
3838 | { | |
3839 | logformat *nlf; | |
3840 | char *name, *def; | |
3841 | ||
3842 | if ((name = strtok(NULL, w_space)) == NULL) | |
3843 | self_destruct(); | |
3844 | ||
9eeb8e4b | 3845 | if ((def = strtok(NULL, "\r\n")) == NULL) { |
7684c4b1 | 3846 | self_destruct(); |
9eeb8e4b | 3847 | return; |
3848 | } | |
7684c4b1 | 3849 | |
bf8fe701 | 3850 | debugs(3, 2, "Logformat for '" << name << "' is '" << def << "'"); |
7684c4b1 | 3851 | |
3852 | nlf = (logformat *)xcalloc(1, sizeof(logformat)); | |
3853 | ||
3854 | nlf->name = xstrdup(name); | |
3855 | ||
9eeb8e4b | 3856 | if (!accessLogParseLogFormat(&nlf->format, def)) { |
7684c4b1 | 3857 | self_destruct(); |
9eeb8e4b | 3858 | return; |
3859 | } | |
7684c4b1 | 3860 | |
3861 | nlf->next = *logformat_definitions; | |
3862 | ||
3863 | *logformat_definitions = nlf; | |
3864 | } | |
3865 | ||
3866 | static void | |
3867 | parse_access_log(customlog ** logs) | |
3868 | { | |
3869 | const char *filename, *logdef_name; | |
3870 | customlog *cl; | |
3871 | logformat *lf; | |
3872 | ||
3873 | cl = (customlog *)xcalloc(1, sizeof(*cl)); | |
3874 | ||
9eeb8e4b | 3875 | if ((filename = strtok(NULL, w_space)) == NULL) { |
7684c4b1 | 3876 | self_destruct(); |
9eeb8e4b | 3877 | return; |
3878 | } | |
7684c4b1 | 3879 | |
3880 | if (strcmp(filename, "none") == 0) { | |
3881 | cl->type = CLF_NONE; | |
3882 | goto done; | |
3883 | } | |
3884 | ||
3885 | if ((logdef_name = strtok(NULL, w_space)) == NULL) | |
3886 | logdef_name = "auto"; | |
3887 | ||
bf8fe701 | 3888 | debugs(3, 9, "Log definition name '" << logdef_name << "' file '" << filename << "'"); |
7684c4b1 | 3889 | |
3890 | cl->filename = xstrdup(filename); | |
3891 | ||
3892 | /* look for the definition pointer corresponding to this name */ | |
3893 | lf = Config.Log.logformats; | |
3894 | ||
3895 | while (lf != NULL) { | |
bf8fe701 | 3896 | debugs(3, 9, "Comparing against '" << lf->name << "'"); |
7684c4b1 | 3897 | |
3898 | if (strcmp(lf->name, logdef_name) == 0) | |
3899 | break; | |
3900 | ||
3901 | lf = lf->next; | |
3902 | } | |
3903 | ||
3904 | if (lf != NULL) { | |
3905 | cl->type = CLF_CUSTOM; | |
3906 | cl->logFormat = lf; | |
3907 | } else if (strcmp(logdef_name, "auto") == 0) { | |
3908 | cl->type = CLF_AUTO; | |
3909 | } else if (strcmp(logdef_name, "squid") == 0) { | |
3910 | cl->type = CLF_SQUID; | |
3911 | } else if (strcmp(logdef_name, "common") == 0) { | |
3912 | cl->type = CLF_COMMON; | |
3ff65596 AR |
3913 | #if ICAP_CLIENT |
3914 | } else if (strcmp(logdef_name, "icap_squid") == 0) { | |
3915 | cl->type = CLF_ICAP_SQUID; | |
3916 | #endif | |
7684c4b1 | 3917 | } else { |
bf8fe701 | 3918 | debugs(3, 0, "Log format '" << logdef_name << "' is not defined"); |
7684c4b1 | 3919 | self_destruct(); |
9eeb8e4b | 3920 | return; |
7684c4b1 | 3921 | } |
3922 | ||
3923 | done: | |
a9f20260 | 3924 | aclParseAclList(LegacyParser, &cl->aclList); |
7684c4b1 | 3925 | |
3926 | while (*logs) | |
3927 | logs = &(*logs)->next; | |
3928 | ||
3929 | *logs = cl; | |
3930 | } | |
3931 | ||
d64bef4c | 3932 | static int |
3933 | check_null_access_log(customlog *customlog_definitions) | |
3934 | { | |
3935 | return customlog_definitions == NULL; | |
3936 | } | |
3937 | ||
7684c4b1 | 3938 | static void |
3939 | dump_logformat(StoreEntry * entry, const char *name, logformat * definitions) | |
3940 | { | |
3941 | accessLogDumpLogFormat(entry, name, definitions); | |
3942 | } | |
3943 | ||
3944 | static void | |
3945 | dump_access_log(StoreEntry * entry, const char *name, customlog * logs) | |
3946 | { | |
3947 | customlog *log; | |
3948 | ||
3949 | for (log = logs; log; log = log->next) { | |
3950 | storeAppendPrintf(entry, "%s ", name); | |
3951 | ||
3952 | switch (log->type) { | |
3953 | ||
3954 | case CLF_CUSTOM: | |
3955 | storeAppendPrintf(entry, "%s %s", log->filename, log->logFormat->name); | |
3956 | break; | |
3957 | ||
3958 | case CLF_NONE: | |
3959 | storeAppendPrintf(entry, "none"); | |
3960 | break; | |
3961 | ||
3962 | case CLF_SQUID: | |
3963 | storeAppendPrintf(entry, "%s squid", log->filename); | |
3964 | break; | |
3965 | ||
3966 | case CLF_COMMON: | |
3967 | storeAppendPrintf(entry, "%s squid", log->filename); | |
3968 | break; | |
3ff65596 AR |
3969 | #if ICAP_CLIENT |
3970 | case CLF_ICAP_SQUID: | |
3971 | storeAppendPrintf(entry, "%s icap_squid", log->filename); | |
3972 | break; | |
3973 | #endif | |
7684c4b1 | 3974 | case CLF_AUTO: |
3975 | ||
3976 | if (log->aclList) | |
3977 | storeAppendPrintf(entry, "%s auto", log->filename); | |
3978 | else | |
3979 | storeAppendPrintf(entry, "%s", log->filename); | |
3980 | ||
3981 | break; | |
3982 | ||
3983 | case CLF_UNKNOWN: | |
3984 | break; | |
3985 | } | |
3986 | ||
3987 | if (log->aclList) | |
3988 | dump_acl_list(entry, log->aclList); | |
3989 | ||
3990 | storeAppendPrintf(entry, "\n"); | |
3991 | } | |
3992 | } | |
3993 | ||
3994 | static void | |
3995 | free_logformat(logformat ** definitions) | |
3996 | { | |
3997 | while (*definitions) { | |
3998 | logformat *format = *definitions; | |
3999 | *definitions = format->next; | |
61831b4a | 4000 | safe_free(format->name); |
7684c4b1 | 4001 | accessLogFreeLogFormat(&format->format); |
4002 | xfree(format); | |
4003 | } | |
4004 | } | |
4005 | ||
4006 | static void | |
4007 | free_access_log(customlog ** definitions) | |
4008 | { | |
4009 | while (*definitions) { | |
4010 | customlog *log = *definitions; | |
4011 | *definitions = log->next; | |
4012 | ||
4013 | log->logFormat = NULL; | |
4014 | log->type = CLF_UNKNOWN; | |
4015 | ||
4016 | if (log->aclList) | |
4017 | aclDestroyAclList(&log->aclList); | |
4018 | ||
4019 | safe_free(log->filename); | |
4020 | ||
4021 | xfree(log); | |
4022 | } | |
4023 | } | |
3a69ddf3 | 4024 | |
96c2bb61 AR |
4025 | /// parses list of integers form name=N1,N2,N3,... |
4026 | static bool | |
4027 | parseNamedIntList(const char *data, const String &name, Vector<int> &list) | |
4028 | { | |
4029 | if (data && (strncmp(data, name.rawBuf(), name.size()) == 0)) { | |
4030 | data += name.size(); | |
4031 | if (*data == '=') { | |
4032 | while (true) { | |
4033 | ++data; | |
4034 | int value = 0; | |
4035 | if (!StringToInt(data, value, &data, 10)) | |
4036 | break; | |
4037 | list.push_back(value); | |
4038 | if (*data == '\0' || *data != ',') | |
4039 | break; | |
4040 | } | |
4041 | } | |
4042 | } | |
cff99cec | 4043 | return data && *data == '\0'; |
96c2bb61 AR |
4044 | } |
4045 | ||
4046 | static void | |
212af65c A |
4047 | parse_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap) |
4048 | { | |
96c2bb61 AR |
4049 | #if !HAVE_CPU_AFFINITY |
4050 | debugs(3, DBG_CRITICAL, "FATAL: Squid built with no CPU affinity " << | |
4051 | "support, do not set 'cpu_affinity_map'"); | |
4052 | self_destruct(); | |
4053 | #endif /* HAVE_CPU_AFFINITY */ | |
4054 | ||
4055 | if (!*cpuAffinityMap) | |
4056 | *cpuAffinityMap = new CpuAffinityMap; | |
4057 | ||
4058 | const char *const pToken = strtok(NULL, w_space); | |
4059 | const char *const cToken = strtok(NULL, w_space); | |
4060 | Vector<int> processes, cores; | |
4061 | if (!parseNamedIntList(pToken, "process_numbers", processes)) { | |
4062 | debugs(3, DBG_CRITICAL, "FATAL: bad 'process_numbers' parameter " << | |
4063 | "in 'cpu_affinity_map'"); | |
4064 | self_destruct(); | |
4065 | } else if (!parseNamedIntList(cToken, "cores", cores)) { | |
4066 | debugs(3, DBG_CRITICAL, "FATAL: bad 'cores' parameter in " << | |
4067 | "'cpu_affinity_map'"); | |
4068 | self_destruct(); | |
4069 | } else if (!(*cpuAffinityMap)->add(processes, cores)) { | |
4070 | debugs(3, DBG_CRITICAL, "FATAL: bad 'cpu_affinity_map'; " << | |
4071 | "process_numbers and cores lists differ in length or " << | |
4072 | "contain numbers <= 0"); | |
4073 | self_destruct(); | |
4074 | } | |
4075 | } | |
4076 | ||
4077 | static void | |
212af65c A |
4078 | dump_CpuAffinityMap(StoreEntry *const entry, const char *const name, const CpuAffinityMap *const cpuAffinityMap) |
4079 | { | |
96c2bb61 AR |
4080 | if (cpuAffinityMap) { |
4081 | storeAppendPrintf(entry, "%s process_numbers=", name); | |
4082 | for (size_t i = 0; i < cpuAffinityMap->processes().size(); ++i) { | |
4083 | storeAppendPrintf(entry, "%s%i", (i ? "," : ""), | |
4084 | cpuAffinityMap->processes()[i]); | |
4085 | } | |
4086 | storeAppendPrintf(entry, " cores="); | |
4087 | for (size_t i = 0; i < cpuAffinityMap->processes().size(); ++i) { | |
4088 | storeAppendPrintf(entry, "%s%i", (i ? "," : ""), | |
4089 | cpuAffinityMap->cores()[i]); | |
4090 | } | |
4091 | storeAppendPrintf(entry, "\n"); | |
4092 | } | |
4093 | } | |
4094 | ||
4095 | static void | |
212af65c A |
4096 | free_CpuAffinityMap(CpuAffinityMap **const cpuAffinityMap) |
4097 | { | |
96c2bb61 AR |
4098 | delete *cpuAffinityMap; |
4099 | *cpuAffinityMap = NULL; | |
4100 | } | |
4101 | ||
62c7f90e AR |
4102 | #if USE_ADAPTATION |
4103 | ||
4104 | static void | |
4105 | parse_adaptation_service_set_type() | |
4106 | { | |
4107 | Adaptation::Config::ParseServiceSet(); | |
4108 | } | |
4109 | ||
a22e6cd3 AR |
4110 | static void |
4111 | parse_adaptation_service_chain_type() | |
4112 | { | |
4113 | Adaptation::Config::ParseServiceChain(); | |
4114 | } | |
4115 | ||
62c7f90e AR |
4116 | static void |
4117 | parse_adaptation_access_type() | |
4118 | { | |
4119 | Adaptation::Config::ParseAccess(LegacyParser); | |
4120 | } | |
4121 | ||
62c7f90e AR |
4122 | #endif /* USE_ADAPTATION */ |
4123 | ||
4124 | ||
3a69ddf3 | 4125 | #if ICAP_CLIENT |
4126 | ||
4127 | static void | |
26cc52cb | 4128 | parse_icap_service_type(Adaptation::Icap::Config * cfg) |
3a69ddf3 | 4129 | { |
462e63d3 | 4130 | cfg->parseService(); |
3a69ddf3 | 4131 | } |
4132 | ||
4133 | static void | |
26cc52cb | 4134 | free_icap_service_type(Adaptation::Icap::Config * cfg) |
3a69ddf3 | 4135 | { |
462e63d3 | 4136 | cfg->freeService(); |
3a69ddf3 | 4137 | } |
4138 | ||
4139 | static void | |
26cc52cb | 4140 | dump_icap_service_type(StoreEntry * entry, const char *name, const Adaptation::Icap::Config &cfg) |
3a69ddf3 | 4141 | { |
462e63d3 | 4142 | cfg.dumpService(entry, name); |
3a69ddf3 | 4143 | } |
4144 | ||
4145 | static void | |
c939dc70 | 4146 | parse_icap_class_type() |
3a69ddf3 | 4147 | { |
62c7f90e | 4148 | debugs(93, 0, "WARNING: 'icap_class' is depricated. " << |
26ac0430 | 4149 | "Use 'adaptation_service_set' instead"); |
62c7f90e | 4150 | Adaptation::Config::ParseServiceSet(); |
3a69ddf3 | 4151 | } |
4152 | ||
3a69ddf3 | 4153 | static void |
c939dc70 | 4154 | parse_icap_access_type() |
3a69ddf3 | 4155 | { |
62c7f90e | 4156 | debugs(93, 0, "WARNING: 'icap_access' is depricated. " << |
26ac0430 | 4157 | "Use 'adaptation_access' instead"); |
21a26d31 | 4158 | Adaptation::Config::ParseAccess(LegacyParser); |
3a69ddf3 | 4159 | } |
4160 | ||
3a69ddf3 | 4161 | #endif |
21a26d31 AR |
4162 | |
4163 | ||
4164 | #if USE_ECAP | |
4165 | ||
4166 | static void | |
574b508c | 4167 | parse_ecap_service_type(Adaptation::Ecap::Config * cfg) |
21a26d31 AR |
4168 | { |
4169 | cfg->parseService(); | |
4170 | } | |
4171 | ||
4172 | static void | |
574b508c | 4173 | free_ecap_service_type(Adaptation::Ecap::Config * cfg) |
21a26d31 AR |
4174 | { |
4175 | cfg->freeService(); | |
4176 | } | |
4177 | ||
4178 | static void | |
574b508c | 4179 | dump_ecap_service_type(StoreEntry * entry, const char *name, const Adaptation::Ecap::Config &cfg) |
21a26d31 AR |
4180 | { |
4181 | cfg.dumpService(entry, name); | |
4182 | } | |
4183 | ||
4184 | #endif /* USE_ECAP */ | |
8277060a CT |
4185 | |
4186 | #if ICAP_CLIENT | |
4187 | static void parse_icap_service_failure_limit(Adaptation::Icap::Config *cfg) | |
4188 | { | |
4189 | char *token; | |
4190 | time_t d; | |
4191 | time_t m; | |
4192 | cfg->service_failure_limit = GetInteger(); | |
4193 | ||
4194 | if ((token = strtok(NULL, w_space)) == NULL) | |
4195 | return; | |
4196 | ||
4197 | if (strcmp(token,"in") != 0) { | |
4198 | debugs(3, 0, "expecting 'in' on'" << config_input_line << "'"); | |
4199 | self_destruct(); | |
4200 | } | |
4201 | ||
4202 | if ((token = strtok(NULL, w_space)) == NULL) { | |
4203 | self_destruct(); | |
4204 | } | |
4205 | ||
4206 | d = static_cast<time_t> (xatoi(token)); | |
a459e80a | 4207 | |
8277060a CT |
4208 | m = static_cast<time_t> (1); |
4209 | ||
4210 | if (0 == d) | |
4211 | (void) 0; | |
4212 | else if ((token = strtok(NULL, w_space)) == NULL) { | |
4213 | debugs(3, 0, "No time-units on '" << config_input_line << "'"); | |
4214 | self_destruct(); | |
a459e80a | 4215 | } else if ((m = parseTimeUnits(token)) == 0) |
8277060a CT |
4216 | self_destruct(); |
4217 | ||
4218 | cfg->oldest_service_failure = (m * d); | |
4219 | } | |
4220 | ||
4221 | static void dump_icap_service_failure_limit(StoreEntry *entry, const char *name, const Adaptation::Icap::Config &cfg) | |
4222 | { | |
4223 | storeAppendPrintf(entry, "%s %d", name, cfg.service_failure_limit); | |
4224 | if (cfg.oldest_service_failure > 0) { | |
4225 | storeAppendPrintf(entry, " in %d seconds", (int)cfg.oldest_service_failure); | |
4226 | } | |
4227 | storeAppendPrintf(entry, "\n"); | |
4228 | } | |
4229 | ||
4230 | static void free_icap_service_failure_limit(Adaptation::Icap::Config *cfg) | |
4231 | { | |
4232 | cfg->oldest_service_failure = 0; | |
4233 | cfg->service_failure_limit = 0; | |
4234 | } | |
4235 | ||
4236 | #endif |