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