]>
Commit | Line | Data |
---|---|---|
be335c22 | 1 | |
30a4f2a8 | 2 | /* |
47f6e231 | 3 | * $Id: cache_cf.cc,v 1.515 2007/08/13 17:20:51 hno Exp $ |
30a4f2a8 | 4 | * |
5 | * DEBUG: section 3 Configuration File Parsing | |
6 | * AUTHOR: Harvest Derived | |
7 | * | |
2b6662ba | 8 | * SQUID Web Proxy Cache http://www.squid-cache.org/ |
e25c139f | 9 | * ---------------------------------------------------------- |
30a4f2a8 | 10 | * |
2b6662ba | 11 | * Squid is the result of efforts by numerous individuals from |
12 | * the Internet community; see the CONTRIBUTORS file for full | |
13 | * details. Many organizations have provided support for Squid's | |
14 | * development; see the SPONSORS file for full details. Squid is | |
15 | * Copyrighted (C) 2001 by the Regents of the University of | |
16 | * California; see the COPYRIGHT file for full details. Squid | |
17 | * incorporates software developed and/or copyrighted by other | |
18 | * sources; see the CREDITS file for full details. | |
30a4f2a8 | 19 | * |
20 | * This program is free software; you can redistribute it and/or modify | |
21 | * it under the terms of the GNU General Public License as published by | |
22 | * the Free Software Foundation; either version 2 of the License, or | |
23 | * (at your option) any later version. | |
24 | * | |
25 | * This program is distributed in the hope that it will be useful, | |
26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28 | * GNU General Public License for more details. | |
29 | * | |
30 | * You should have received a copy of the GNU General Public License | |
31 | * along with this program; if not, write to the Free Software | |
cbdec147 | 32 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. |
e25c139f | 33 | * |
30a4f2a8 | 34 | */ |
cf5fd929 | 35 | |
44a47c6e | 36 | #include "squid.h" |
e6ccf245 | 37 | #include "authenticate.h" |
f5691f9c | 38 | #include "AuthConfig.h" |
39 | #include "AuthScheme.h" | |
62ee09ca | 40 | #include "CacheManager.h" |
e6ccf245 | 41 | #include "Store.h" |
d3b3ab85 | 42 | #include "SwapDir.h" |
a80a77cf | 43 | #include "ConfigParser.h" |
8000a965 | 44 | #include "ACL.h" |
59b2d47f | 45 | #include "StoreFileSystem.h" |
c8f4eac4 | 46 | #include "Parsing.h" |
0eb49b6d | 47 | #include "MemBuf.h" |
d295d770 | 48 | #include "wordlist.h" |
1df370e3 | 49 | |
50 | #if SQUID_SNMP | |
a97cfa48 | 51 | #include "snmp.h" |
1df370e3 | 52 | #endif |
43ae1d95 | 53 | #if ESI |
54 | #include "ESIParser.h" | |
55 | #endif | |
090089c4 | 56 | |
3a69ddf3 | 57 | #if ICAP_CLIENT |
58 | #include "ICAP/ICAPConfig.h" | |
3a69ddf3 | 59 | |
60 | static void parse_icap_service_type(ICAPConfig *); | |
a99015b2 | 61 | static void dump_icap_service_type(StoreEntry *, const char *, const ICAPConfig &); |
3a69ddf3 | 62 | static void free_icap_service_type(ICAPConfig *); |
63 | static void parse_icap_class_type(ICAPConfig *); | |
a99015b2 | 64 | static void dump_icap_class_type(StoreEntry *, const char *, const ICAPConfig &); |
3a69ddf3 | 65 | static void free_icap_class_type(ICAPConfig *); |
66 | static void parse_icap_access_type(ICAPConfig *); | |
a99015b2 | 67 | static void dump_icap_access_type(StoreEntry *, const char *, const ICAPConfig &); |
3a69ddf3 | 68 | static void free_icap_access_type(ICAPConfig *); |
69 | ||
70 | #endif | |
71 | ||
f5691f9c | 72 | CBDATA_TYPE(peer); |
73 | ||
8813e606 | 74 | static const char *const T_SECOND_STR = "second"; |
75 | static const char *const T_MINUTE_STR = "minute"; | |
76 | static const char *const T_HOUR_STR = "hour"; | |
77 | static const char *const T_DAY_STR = "day"; | |
78 | static const char *const T_WEEK_STR = "week"; | |
79 | static const char *const T_FORTNIGHT_STR = "fortnight"; | |
80 | static const char *const T_MONTH_STR = "month"; | |
81 | static const char *const T_YEAR_STR = "year"; | |
82 | static const char *const T_DECADE_STR = "decade"; | |
aa0a0c7c | 83 | |
9906e724 | 84 | static const char *const B_BYTES_STR = "bytes"; |
85 | static const char *const B_KBYTES_STR = "KB"; | |
86 | static const char *const B_MBYTES_STR = "MB"; | |
87 | static const char *const B_GBYTES_STR = "GB"; | |
88 | ||
4db43fab | 89 | static const char *const list_sep = ", \t\n\r"; |
b0e7d2d5 | 90 | |
7684c4b1 | 91 | static void parse_logformat(logformat ** logformat_definitions); |
92 | static void parse_access_log(customlog ** customlog_definitions); | |
d64bef4c | 93 | static int check_null_access_log(customlog *customlog_definitions); |
94 | ||
7684c4b1 | 95 | static void dump_logformat(StoreEntry * entry, const char *name, logformat * definitions); |
96 | static void dump_access_log(StoreEntry * entry, const char *name, customlog * definitions); | |
97 | static void free_logformat(logformat ** definitions); | |
98 | static void free_access_log(customlog ** definitions); | |
99 | ||
cd748f27 | 100 | static void update_maxobjsize(void); |
f5b8bbc4 | 101 | static void configDoConfigure(void); |
102 | static void parse_refreshpattern(refresh_t **); | |
103 | static int parseTimeUnits(const char *unit); | |
104 | static void parseTimeLine(time_t * tptr, const char *units); | |
59715b38 | 105 | static void parse_ushort(u_short * var); |
f5b8bbc4 | 106 | static void parse_string(char **); |
f5b8bbc4 | 107 | static void default_all(void); |
108 | static void defaults_if_none(void); | |
109 | static int parse_line(char *); | |
110 | static void parseBytesLine(size_t * bptr, const char *units); | |
111 | static size_t parseBytesUnits(const char *unit); | |
f5b8bbc4 | 112 | static void free_all(void); |
94439e4e | 113 | void requirePathnameExists(const char *name, const char *path); |
ed7f5615 | 114 | static OBJH dump_config; |
c26ffae9 | 115 | #if HTTP_VIOLATIONS |
6bccf575 | 116 | static void dump_http_header_access(StoreEntry * entry, const char *name, header_mangler header[]); |
117 | static void parse_http_header_access(header_mangler header[]); | |
118 | static void free_http_header_access(header_mangler header[]); | |
119 | static void dump_http_header_replace(StoreEntry * entry, const char *name, header_mangler header[]); | |
120 | static void parse_http_header_replace(header_mangler * header); | |
121 | static void free_http_header_replace(header_mangler * header); | |
9e8b2f1c | 122 | #endif |
6bccf575 | 123 | static void parse_denyinfo(acl_deny_info_list ** var); |
124 | static void dump_denyinfo(StoreEntry * entry, const char *name, acl_deny_info_list * var); | |
125 | static void free_denyinfo(acl_deny_info_list ** var); | |
0b0cfcf2 | 126 | #if USE_WCCPv2 |
7e3ce7b9 | 127 | static void parse_sockaddr_in_list(sockaddr_in_list **); |
128 | static void dump_sockaddr_in_list(StoreEntry *, const char *, const sockaddr_in_list *); | |
129 | static void free_sockaddr_in_list(sockaddr_in_list **); | |
0b0cfcf2 | 130 | #if CURRENTLY_UNUSED |
7e3ce7b9 | 131 | static int check_null_sockaddr_in_list(const sockaddr_in_list *); |
3f38a55e | 132 | #endif /* CURRENTLY_UNUSED */ |
0b0cfcf2 | 133 | #endif |
3f38a55e | 134 | static void parse_http_port_list(http_port_list **); |
135 | static void dump_http_port_list(StoreEntry *, const char *, const http_port_list *); | |
136 | static void free_http_port_list(http_port_list **); | |
d193a436 | 137 | #if USE_SSL |
138 | static void parse_https_port_list(https_port_list **); | |
139 | static void dump_https_port_list(StoreEntry *, const char *, const https_port_list *); | |
140 | static void free_https_port_list(https_port_list **); | |
141 | #if 0 | |
142 | static int check_null_https_port_list(const https_port_list *); | |
143 | #endif | |
144 | #endif /* USE_SSL */ | |
ef1955a5 | 145 | static void parse_b_size_t(size_t * var); |
47f6e231 | 146 | static void parse_b_int64_t(int64_t * var); |
270b86af | 147 | |
a385afc3 | 148 | /* |
149 | * LegacyParser is a parser for legacy code that uses the global | |
150 | * approach. This is static so that it is only exposed to cache_cf. | |
151 | * Other modules needing access to a ConfigParser should have it | |
152 | * provided to them in their parserFOO methods. | |
153 | */ | |
154 | static ConfigParser LegacyParser = ConfigParser(); | |
a9f20260 | 155 | |
0e4e0e7d | 156 | void |
0673c0ba | 157 | self_destruct(void) |
090089c4 | 158 | { |
a9f20260 | 159 | LegacyParser.destruct(); |
6b8e7481 | 160 | } |
161 | ||
cd748f27 | 162 | static void |
163 | update_maxobjsize(void) | |
164 | { | |
165 | int i; | |
47f6e231 | 166 | int64_t ms = -1; |
cd748f27 | 167 | |
168 | for (i = 0; i < Config.cacheSwap.n_configured; i++) { | |
c8f4eac4 | 169 | assert (Config.cacheSwap.swapDirs[i].getRaw()); |
62e76326 | 170 | |
c8f4eac4 | 171 | if (dynamic_cast<SwapDir *>(Config.cacheSwap.swapDirs[i].getRaw())-> |
172 | max_objsize > ms) | |
173 | ms = dynamic_cast<SwapDir *>(Config.cacheSwap.swapDirs[i].getRaw())->max_objsize; | |
cd748f27 | 174 | } |
175 | store_maxobjsize = ms; | |
176 | } | |
177 | ||
76b9daa5 | 178 | static void |
179 | SetConfigFilename(char const *file_name, bool is_pipe) | |
180 | { | |
181 | cfg_filename = file_name; | |
182 | ||
183 | char const *token; | |
184 | ||
185 | if (is_pipe) | |
186 | cfg_filename = file_name + 1; | |
187 | else if ((token = strrchr(cfg_filename, '/'))) | |
188 | cfg_filename = token + 1; | |
189 | } | |
190 | ||
130bff33 | 191 | static const char* |
192 | skip_ws(const char* s) | |
193 | { | |
194 | while (xisspace(*s)) | |
195 | ++s; | |
196 | ||
197 | return s; | |
198 | } | |
199 | ||
270b86af | 200 | int |
62ee09ca | 201 | parseConfigFile(const char *file_name, CacheManager & manager) |
2546fcb3 | 202 | { |
270b86af | 203 | FILE *fp = NULL; |
204 | char *token = NULL; | |
81c161d0 | 205 | char *tmp_line = NULL; |
206 | int tmp_line_len = 0; | |
e13ee7ad | 207 | int err_count = 0; |
1741cbad | 208 | int is_pipe = 0; |
42bf7c64 | 209 | configFreeMemory(); |
0153d498 | 210 | default_all(); |
62e76326 | 211 | |
1741cbad | 212 | if (file_name[0] == '!' || file_name[0] == '|') { |
62e76326 | 213 | fp = popen(file_name + 1, "r"); |
214 | is_pipe = 1; | |
1741cbad | 215 | } else { |
62e76326 | 216 | fp = fopen(file_name, "r"); |
1741cbad | 217 | } |
62e76326 | 218 | |
1741cbad | 219 | if (fp == NULL) |
62e76326 | 220 | fatalf("Unable to open configuration file: %s: %s", |
221 | file_name, xstrerror()); | |
222 | ||
ec4daaa5 | 223 | #ifdef _SQUID_WIN32_ |
62e76326 | 224 | |
c4aefe96 | 225 | setmode(fileno(fp), O_TEXT); |
62e76326 | 226 | |
c4aefe96 | 227 | #endif |
62e76326 | 228 | |
76b9daa5 | 229 | SetConfigFilename(file_name, bool(is_pipe)); |
62e76326 | 230 | |
270b86af | 231 | memset(config_input_line, '\0', BUFSIZ); |
62e76326 | 232 | |
270b86af | 233 | config_lineno = 0; |
62e76326 | 234 | |
270b86af | 235 | while (fgets(config_input_line, BUFSIZ, fp)) { |
62e76326 | 236 | config_lineno++; |
237 | ||
238 | if ((token = strchr(config_input_line, '\n'))) | |
239 | *token = '\0'; | |
240 | ||
d866e2ad | 241 | if ((token = strchr(config_input_line, '\r'))) |
242 | *token = '\0'; | |
243 | ||
62e76326 | 244 | if (strncmp(config_input_line, "#line ", 6) == 0) { |
245 | static char new_file_name[1024]; | |
246 | static char *file; | |
247 | static char new_lineno; | |
248 | token = config_input_line + 6; | |
249 | new_lineno = strtol(token, &file, 0) - 1; | |
250 | ||
251 | if (file == token) | |
252 | continue; /* Not a valid #line directive, may be a comment */ | |
253 | ||
e4755e29 | 254 | while (*file && xisspace((unsigned char) *file)) |
62e76326 | 255 | file++; |
256 | ||
257 | if (*file) { | |
258 | if (*file != '"') | |
259 | continue; /* Not a valid #line directive, may be a comment */ | |
260 | ||
261 | xstrncpy(new_file_name, file + 1, sizeof(new_file_name)); | |
262 | ||
263 | if ((token = strchr(new_file_name, '"'))) | |
264 | *token = '\0'; | |
265 | ||
266 | cfg_filename = new_file_name; | |
267 | ||
1741cbad | 268 | #if PROBABLY_NOT_WANTED_HERE |
62e76326 | 269 | |
76b9daa5 | 270 | SetConfigFilename(cfg_filename, false); |
62e76326 | 271 | |
1741cbad | 272 | #endif |
62e76326 | 273 | |
274 | } | |
275 | ||
276 | config_lineno = new_lineno; | |
277 | } | |
278 | ||
279 | if (config_input_line[0] == '#') | |
280 | continue; | |
281 | ||
282 | if (config_input_line[0] == '\0') | |
283 | continue; | |
284 | ||
130bff33 | 285 | const char* append = tmp_line_len ? skip_ws(config_input_line) : config_input_line; |
286 | ||
287 | size_t append_len = strlen(append); | |
62e76326 | 288 | |
130bff33 | 289 | tmp_line = (char*)xrealloc(tmp_line, tmp_line_len + append_len + 1); |
81c161d0 | 290 | |
130bff33 | 291 | strcpy(tmp_line + tmp_line_len, append); |
81c161d0 | 292 | |
130bff33 | 293 | tmp_line_len += append_len; |
81c161d0 | 294 | |
295 | if (tmp_line[tmp_line_len-1] == '\\') { | |
bf8fe701 | 296 | debugs(3, 5, "parseConfigFile: tmp_line='" << tmp_line << "'"); |
81c161d0 | 297 | tmp_line[--tmp_line_len] = '\0'; |
298 | continue; | |
299 | } | |
300 | ||
bf8fe701 | 301 | debugs(3, 5, "Processing: '" << tmp_line << "'"); |
62e76326 | 302 | |
303 | if (!parse_line(tmp_line)) { | |
bf8fe701 | 304 | debugs(3, 0, "parseConfigFile: '" << cfg_filename << "' line " << |
305 | config_lineno << " unrecognized: '" << config_input_line << "'"); | |
62e76326 | 306 | err_count++; |
307 | } | |
308 | ||
309 | safe_free(tmp_line); | |
81c161d0 | 310 | tmp_line_len = 0; |
311 | ||
270b86af | 312 | } |
62e76326 | 313 | |
1741cbad | 314 | if (is_pipe) { |
62e76326 | 315 | int ret = pclose(fp); |
316 | ||
317 | if (ret != 0) | |
318 | fatalf("parseConfigFile: '%s' failed with exit code %d\n", file_name, ret); | |
1741cbad | 319 | } else { |
62e76326 | 320 | fclose(fp); |
1741cbad | 321 | } |
62e76326 | 322 | |
f0b19334 | 323 | defaults_if_none(); |
f9ad0106 | 324 | |
9c46ca97 | 325 | /* |
326 | * We must call configDoConfigure() before leave_suid() because | |
327 | * configDoConfigure() is where we turn username strings into | |
328 | * uid values. | |
329 | */ | |
330 | configDoConfigure(); | |
331 | ||
f9ad0106 | 332 | if (!Config.chroot_dir) { |
333 | leave_suid(); | |
334 | _db_init(Config.Log.log, Config.debugOptions); | |
335 | enter_suid(); | |
336 | } | |
337 | ||
478c4f2f | 338 | if (opt_send_signal == -1) { |
62ee09ca | 339 | manager.registerAction("config", |
340 | "Current Squid Configuration", | |
341 | dump_config, | |
342 | 1, 1); | |
478c4f2f | 343 | } |
344 | ||
e13ee7ad | 345 | return err_count; |
f0b19334 | 346 | } |
270b86af | 347 | |
f0b19334 | 348 | static void |
349 | configDoConfigure(void) | |
350 | { | |
f0b19334 | 351 | memset(&Config2, '\0', sizeof(SquidConfig2)); |
7021844c | 352 | /* init memory as early as possible */ |
353 | memConfigure(); | |
270b86af | 354 | /* Sanity checks */ |
62e76326 | 355 | |
a95856a0 | 356 | if (Config.cacheSwap.swapDirs == NULL) |
62e76326 | 357 | fatal("No cache_dir's specified in config file"); |
358 | ||
c8f4eac4 | 359 | if (0 == Store::Root().maxSize()) |
62e76326 | 360 | /* people might want a zero-sized cache on purpose */ |
361 | (void) 0; | |
c8f4eac4 | 362 | else if (Store::Root().maxSize() < (Config.memMaxSize >> 10)) |
363 | /* This is bogus. folk with NULL caches will want this */ | |
bf8fe701 | 364 | debugs(3, 0, "WARNING cache_mem is larger than total disk cache space!"); |
62e76326 | 365 | |
84f42bac | 366 | if (Config.Announce.period > 0) { |
62e76326 | 367 | Config.onoff.announce = 1; |
84f42bac | 368 | } else if (Config.Announce.period < 1) { |
62e76326 | 369 | Config.Announce.period = 86400 * 365; /* one year */ |
370 | Config.onoff.announce = 0; | |
270b86af | 371 | } |
62e76326 | 372 | |
d3caee79 | 373 | if (Config.onoff.httpd_suppress_version_string) |
374 | visible_appname_string = (char *)appname_string; | |
375 | else | |
376 | visible_appname_string = (char *)full_appname_string; | |
377 | ||
6b53c392 | 378 | #if USE_DNSSERVERS |
d3caee79 | 379 | |
f0b19334 | 380 | if (Config.dnsChildren < 1) |
62e76326 | 381 | fatal("No dnsservers allocated"); |
382 | ||
efd900cb | 383 | #endif |
62e76326 | 384 | |
270b86af | 385 | if (Config.Program.redirect) { |
62e76326 | 386 | if (Config.redirectChildren < 1) { |
387 | Config.redirectChildren = 0; | |
388 | wordlistDestroy(&Config.Program.redirect); | |
389 | } | |
fea2e6e0 | 390 | } |
62e76326 | 391 | |
f1dc9b30 | 392 | if (Config.appendDomain) |
62e76326 | 393 | if (*Config.appendDomain != '.') |
394 | fatal("append_domain must begin with a '.'"); | |
395 | ||
270b86af | 396 | if (Config.errHtmlText == NULL) |
62e76326 | 397 | Config.errHtmlText = xstrdup(null_string); |
398 | ||
270b86af | 399 | storeConfigure(); |
62e76326 | 400 | |
52f772de | 401 | snprintf(ThisCache, sizeof(ThisCache), "%s (%s)", |
62e76326 | 402 | uniqueHostname(), |
d3caee79 | 403 | visible_appname_string); |
fbdba7c4 | 404 | |
38a6c74e | 405 | /* |
406 | * the extra space is for loop detection in client_side.c -- we search | |
407 | * for substrings in the Via header. | |
408 | */ | |
52f772de | 409 | snprintf(ThisCache2, sizeof(ThisCache), " %s (%s)", |
62e76326 | 410 | uniqueHostname(), |
d3caee79 | 411 | visible_appname_string); |
62e76326 | 412 | |
270b86af | 413 | if (!Config.udpMaxHitObjsz || Config.udpMaxHitObjsz > SQUID_UDP_SO_SNDBUF) |
62e76326 | 414 | Config.udpMaxHitObjsz = SQUID_UDP_SO_SNDBUF; |
415 | ||
270b86af | 416 | if (Config.appendDomain) |
62e76326 | 417 | Config.appendDomainLen = strlen(Config.appendDomain); |
270b86af | 418 | else |
62e76326 | 419 | Config.appendDomainLen = 0; |
420 | ||
f1dc9b30 | 421 | safe_free(debug_options) |
62e76326 | 422 | debug_options = xstrdup(Config.debugOptions); |
423 | ||
22c653cd | 424 | if (Config.retry.maxtries > 10) |
62e76326 | 425 | fatal("maximum_single_addr_tries cannot be larger than 10"); |
426 | ||
22c653cd | 427 | if (Config.retry.maxtries < 1) { |
bf8fe701 | 428 | debugs(3, 0, "WARNING: resetting 'maximum_single_addr_tries to 1"); |
62e76326 | 429 | Config.retry.maxtries = 1; |
5210854d | 430 | } |
62e76326 | 431 | |
f0b19334 | 432 | requirePathnameExists("MIME Config Table", Config.mimeTablePathname); |
6b53c392 | 433 | #if USE_DNSSERVERS |
62e76326 | 434 | |
f0b19334 | 435 | requirePathnameExists("cache_dns_program", Config.Program.dnsserver); |
efd900cb | 436 | #endif |
a3d0a19d | 437 | #if USE_UNLINKD |
62e76326 | 438 | |
f0b19334 | 439 | requirePathnameExists("unlinkd_program", Config.Program.unlinkd); |
a3d0a19d | 440 | #endif |
62e76326 | 441 | |
f0b19334 | 442 | if (Config.Program.redirect) |
62e76326 | 443 | requirePathnameExists("redirect_program", Config.Program.redirect->key); |
444 | ||
f0b19334 | 445 | requirePathnameExists("Icon Directory", Config.icons.directory); |
62e76326 | 446 | |
f0b19334 | 447 | requirePathnameExists("Error Directory", Config.errorDirectory); |
62e76326 | 448 | |
9f60cfdf | 449 | #if HTTP_VIOLATIONS |
62e76326 | 450 | |
9f60cfdf | 451 | { |
62e76326 | 452 | const refresh_t *R; |
453 | ||
454 | for (R = Config.Refresh; R; R = R->next) | |
455 | { | |
456 | if (!R->flags.override_expire) | |
457 | continue; | |
458 | ||
bf8fe701 | 459 | debugs(22, 1, "WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP"); |
62e76326 | 460 | |
461 | break; | |
462 | } | |
463 | ||
464 | for (R = Config.Refresh; R; R = R->next) | |
465 | { | |
466 | if (!R->flags.override_lastmod) | |
467 | continue; | |
468 | ||
bf8fe701 | 469 | debugs(22, 1, "WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP"); |
62e76326 | 470 | |
471 | break; | |
472 | } | |
473 | ||
38f9c547 | 474 | for (R = Config.Refresh; R; R = R->next) |
475 | { | |
476 | if (!R->flags.reload_into_ims) | |
477 | continue; | |
478 | ||
bf8fe701 | 479 | debugs(22, 1, "WARNING: use of 'reload-into-ims' in 'refresh_pattern' violates HTTP"); |
38f9c547 | 480 | |
481 | break; | |
482 | } | |
483 | ||
484 | for (R = Config.Refresh; R; R = R->next) | |
485 | { | |
486 | if (!R->flags.ignore_reload) | |
487 | continue; | |
488 | ||
bf8fe701 | 489 | debugs(22, 1, "WARNING: use of 'ignore-reload' in 'refresh_pattern' violates HTTP"); |
38f9c547 | 490 | |
491 | break; | |
492 | } | |
493 | ||
494 | for (R = Config.Refresh; R; R = R->next) | |
495 | { | |
496 | if (!R->flags.ignore_no_cache) | |
497 | continue; | |
498 | ||
bf8fe701 | 499 | debugs(22, 1, "WARNING: use of 'ignore-no-cache' in 'refresh_pattern' violates HTTP"); |
38f9c547 | 500 | |
501 | break; | |
502 | } | |
503 | ||
504 | for (R = Config.Refresh; R; R = R->next) | |
505 | { | |
506 | if (!R->flags.ignore_no_store) | |
507 | continue; | |
508 | ||
bf8fe701 | 509 | debugs(22, 1, "WARNING: use of 'ignore-no-store' in 'refresh_pattern' violates HTTP"); |
38f9c547 | 510 | |
511 | break; | |
512 | } | |
513 | ||
514 | for (R = Config.Refresh; R; R = R->next) | |
515 | { | |
516 | if (!R->flags.ignore_private) | |
517 | continue; | |
518 | ||
bf8fe701 | 519 | debugs(22, 1, "WARNING: use of 'ignore-private' in 'refresh_pattern' violates HTTP"); |
38f9c547 | 520 | |
521 | break; | |
522 | } | |
523 | ||
524 | for (R = Config.Refresh; R; R = R->next) | |
525 | { | |
526 | if (!R->flags.ignore_auth) | |
527 | continue; | |
528 | ||
bf8fe701 | 529 | debugs(22, 1, "WARNING: use of 'ignore-auth' in 'refresh_pattern' violates HTTP"); |
38f9c547 | 530 | |
531 | break; | |
532 | } | |
533 | ||
9f60cfdf | 534 | } |
c2f5c744 | 535 | #endif |
536 | #if !HTTP_VIOLATIONS | |
537 | Config.onoff.via = 1; | |
538 | #else | |
62e76326 | 539 | |
c2f5c744 | 540 | if (!Config.onoff.via) |
bf8fe701 | 541 | debugs(22, 1, "WARNING: HTTP requires the use of Via"); |
62e76326 | 542 | |
9f60cfdf | 543 | #endif |
62e76326 | 544 | |
53cb32a9 | 545 | if (aclPurgeMethodInUse(Config.accessList.http)) |
62e76326 | 546 | Config2.onoff.enable_purge = 1; |
547 | ||
4f56514c | 548 | Config2.onoff.mangle_request_headers = httpReqHdrManglersConfigured(); |
5967c0bf | 549 | |
8749fa47 | 550 | if (geteuid() == 0) { |
62e76326 | 551 | if (NULL != Config.effectiveUser) { |
552 | ||
553 | struct passwd *pwd = getpwnam(Config.effectiveUser); | |
554 | ||
555 | if (NULL == pwd) | |
556 | /* | |
557 | * Andres Kroonmaa <andre@online.ee>: | |
558 | * Some getpwnam() implementations (Solaris?) require | |
559 | * an available FD < 256 for opening a FILE* to the | |
560 | * passwd file. | |
561 | * DW: | |
562 | * This should be safe at startup, but might still fail | |
563 | * during reconfigure. | |
564 | */ | |
565 | fatalf("getpwnam failed to find userid for effective user '%s'", | |
566 | Config.effectiveUser); | |
567 | ||
568 | Config2.effectiveUserID = pwd->pw_uid; | |
569 | ||
570 | Config2.effectiveGroupID = pwd->pw_gid; | |
08ac5ea7 | 571 | |
cff61cb8 | 572 | #if HAVE_PUTENV |
573 | ||
574 | if (pwd->pw_dir && *pwd->pw_dir) { | |
575 | int len; | |
576 | char *env_str = (char *)xcalloc((len = strlen(pwd->pw_dir) + 6), 1); | |
577 | snprintf(env_str, len, "HOME=%s", pwd->pw_dir); | |
578 | putenv(env_str); | |
579 | } | |
580 | ||
581 | #endif | |
582 | ||
62e76326 | 583 | } |
8749fa47 | 584 | } else { |
62e76326 | 585 | Config2.effectiveUserID = geteuid(); |
586 | Config2.effectiveGroupID = getegid(); | |
d20b1cd0 | 587 | } |
62e76326 | 588 | |
d20b1cd0 | 589 | if (NULL != Config.effectiveGroup) { |
62e76326 | 590 | |
591 | struct group *grp = getgrnam(Config.effectiveGroup); | |
592 | ||
593 | if (NULL == grp) | |
594 | fatalf("getgrnam failed to find groupid for effective group '%s'", | |
595 | Config.effectiveGroup); | |
596 | ||
597 | Config2.effectiveGroupID = grp->gr_gid; | |
d20b1cd0 | 598 | } |
62e76326 | 599 | |
985c86bc | 600 | HttpRequestMethod::Configure(Config); |
a7ad6e4e | 601 | #if USE_SSL |
62e76326 | 602 | |
bf8fe701 | 603 | debugs(3, 1, "Initializing https proxy context"); |
f9ad0106 | 604 | |
a82a4fe4 | 605 | 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 | 606 | |
607 | { | |
608 | ||
609 | peer *p; | |
610 | ||
611 | for (p = Config.peers; p != NULL; p = p->next) { | |
612 | if (p->use_ssl) { | |
bf8fe701 | 613 | debugs(3, 1, "Initializing cache_peer " << p->name << " SSL context"); |
a82a4fe4 | 614 | p->sslContext = sslCreateClientContext(p->sslcert, p->sslkey, p->sslversion, p->sslcipher, p->ssloptions, p->sslflags, p->sslcafile, p->sslcapath, p->sslcrlfile); |
f9ad0106 | 615 | } |
616 | } | |
617 | } | |
618 | ||
619 | { | |
620 | ||
621 | https_port_list *s; | |
622 | ||
b844522c | 623 | for (s = Config.Sockaddr.https; s != NULL; s = (https_port_list *) s->http.next) { |
bf8fe701 | 624 | debugs(3, 1, "Initializing https_port " << |
625 | inet_ntoa(s->http.s.sin_addr) << ":" << | |
626 | ntohs(s->http.s.sin_port) << " SSL context"); | |
627 | ||
a82a4fe4 | 628 | s->sslContext = sslCreateServerContext(s->cert, s->key, s->version, s->cipher, s->options, s->sslflags, s->clientca, s->cafile, s->capath, s->crlfile, s->dhfile, s->sslcontext); |
f9ad0106 | 629 | } |
630 | } | |
631 | ||
a7ad6e4e | 632 | #endif |
090089c4 | 633 | } |
634 | ||
270b86af | 635 | /* Parse a time specification from the config file. Store the |
f1dc9b30 | 636 | * result in 'tptr', after converting it to 'units' */ |
8203a132 | 637 | static void |
a47b9029 | 638 | parseTimeLine(time_t * tptr, const char *units) |
090089c4 | 639 | { |
640 | char *token; | |
270b86af | 641 | double d; |
f1dc9b30 | 642 | time_t m; |
643 | time_t u; | |
62e76326 | 644 | |
270b86af | 645 | if ((u = parseTimeUnits(units)) == 0) |
62e76326 | 646 | self_destruct(); |
647 | ||
270b86af | 648 | if ((token = strtok(NULL, w_space)) == NULL) |
62e76326 | 649 | self_destruct(); |
650 | ||
5c20d6fa | 651 | d = xatof(token); |
62e76326 | 652 | |
270b86af | 653 | m = u; /* default to 'units' if none specified */ |
62e76326 | 654 | |
10738561 | 655 | if (0 == d) |
62e76326 | 656 | (void) 0; |
10738561 | 657 | else if ((token = strtok(NULL, w_space)) == NULL) |
bf8fe701 | 658 | debugs(3, 0, "WARNING: No units on '" << |
659 | config_input_line << "', assuming " << | |
660 | d << " " << units ); | |
9e975e4e | 661 | else if ((m = parseTimeUnits(token)) == 0) |
62e76326 | 662 | self_destruct(); |
663 | ||
e6ccf245 | 664 | *tptr = static_cast<time_t> (m * d / u); |
090089c4 | 665 | } |
666 | ||
270b86af | 667 | static int |
668 | parseTimeUnits(const char *unit) | |
669 | { | |
670 | if (!strncasecmp(unit, T_SECOND_STR, strlen(T_SECOND_STR))) | |
62e76326 | 671 | return 1; |
672 | ||
270b86af | 673 | if (!strncasecmp(unit, T_MINUTE_STR, strlen(T_MINUTE_STR))) |
62e76326 | 674 | return 60; |
675 | ||
270b86af | 676 | if (!strncasecmp(unit, T_HOUR_STR, strlen(T_HOUR_STR))) |
62e76326 | 677 | return 3600; |
678 | ||
270b86af | 679 | if (!strncasecmp(unit, T_DAY_STR, strlen(T_DAY_STR))) |
62e76326 | 680 | return 86400; |
681 | ||
270b86af | 682 | if (!strncasecmp(unit, T_WEEK_STR, strlen(T_WEEK_STR))) |
62e76326 | 683 | return 86400 * 7; |
684 | ||
270b86af | 685 | if (!strncasecmp(unit, T_FORTNIGHT_STR, strlen(T_FORTNIGHT_STR))) |
62e76326 | 686 | return 86400 * 14; |
687 | ||
270b86af | 688 | if (!strncasecmp(unit, T_MONTH_STR, strlen(T_MONTH_STR))) |
62e76326 | 689 | return 86400 * 30; |
690 | ||
270b86af | 691 | if (!strncasecmp(unit, T_YEAR_STR, strlen(T_YEAR_STR))) |
62e76326 | 692 | return static_cast<int>(86400 * 365.2522); |
693 | ||
270b86af | 694 | if (!strncasecmp(unit, T_DECADE_STR, strlen(T_DECADE_STR))) |
62e76326 | 695 | return static_cast<int>(86400 * 365.2522 * 10); |
696 | ||
bf8fe701 | 697 | debugs(3, 1, "parseTimeUnits: unknown time unit '" << unit << "'"); |
62e76326 | 698 | |
270b86af | 699 | return 0; |
700 | } | |
701 | ||
47f6e231 | 702 | static void |
703 | parseBytesLine64(int64_t * bptr, const char *units) | |
704 | { | |
705 | char *token; | |
706 | double d; | |
707 | int64_t m; | |
708 | int64_t u; | |
709 | ||
710 | if ((u = parseBytesUnits(units)) == 0) | |
711 | self_destruct(); | |
712 | ||
713 | if ((token = strtok(NULL, w_space)) == NULL) | |
714 | self_destruct(); | |
715 | ||
716 | if (strcmp(token, "none") == 0 || strcmp(token, "-1") == 0) { | |
717 | *bptr = static_cast<size_t>(-1); | |
718 | return; | |
719 | } | |
720 | ||
721 | d = xatof(token); | |
722 | ||
723 | m = u; /* default to 'units' if none specified */ | |
724 | ||
725 | if (0.0 == d) | |
726 | (void) 0; | |
727 | else if ((token = strtok(NULL, w_space)) == NULL) | |
728 | debugs(3, 0, "WARNING: No units on '" << | |
729 | config_input_line << "', assuming " << | |
730 | d << " " << units ); | |
731 | else if ((m = parseBytesUnits(token)) == 0) | |
732 | self_destruct(); | |
733 | ||
734 | *bptr = static_cast<int64_t>(m * d / u); | |
735 | ||
736 | if (static_cast<double>(*bptr) * 2 != m * d / u * 2) | |
737 | self_destruct(); | |
738 | } | |
739 | ||
740 | ||
9906e724 | 741 | static void |
9e975e4e | 742 | parseBytesLine(size_t * bptr, const char *units) |
9906e724 | 743 | { |
744 | char *token; | |
745 | double d; | |
47f6e231 | 746 | int m; |
747 | int u; | |
62e76326 | 748 | |
9906e724 | 749 | if ((u = parseBytesUnits(units)) == 0) |
62e76326 | 750 | self_destruct(); |
751 | ||
9906e724 | 752 | if ((token = strtok(NULL, w_space)) == NULL) |
62e76326 | 753 | self_destruct(); |
754 | ||
f8ecd7d7 | 755 | if (strcmp(token, "none") == 0 || strcmp(token, "-1") == 0) { |
b2d729e6 | 756 | *bptr = static_cast<size_t>(-1); |
ef1955a5 | 757 | return; |
758 | } | |
759 | ||
5c20d6fa | 760 | d = xatof(token); |
62e76326 | 761 | |
9906e724 | 762 | m = u; /* default to 'units' if none specified */ |
62e76326 | 763 | |
343f47a3 | 764 | if (0.0 == d) |
62e76326 | 765 | (void) 0; |
4860dc1b | 766 | else if ((token = strtok(NULL, w_space)) == NULL) |
bf8fe701 | 767 | debugs(3, 0, "WARNING: No units on '" << |
768 | config_input_line << "', assuming " << | |
769 | d << " " << units ); | |
9e975e4e | 770 | else if ((m = parseBytesUnits(token)) == 0) |
62e76326 | 771 | self_destruct(); |
772 | ||
e6ccf245 | 773 | *bptr = static_cast<size_t>(m * d / u); |
347ae7c4 | 774 | |
a69d485c | 775 | if (static_cast<double>(*bptr) * 2 != m * d / u * 2) |
347ae7c4 | 776 | self_destruct(); |
9906e724 | 777 | } |
778 | ||
779 | static size_t | |
780 | parseBytesUnits(const char *unit) | |
781 | { | |
782 | if (!strncasecmp(unit, B_BYTES_STR, strlen(B_BYTES_STR))) | |
62e76326 | 783 | return 1; |
784 | ||
9906e724 | 785 | if (!strncasecmp(unit, B_KBYTES_STR, strlen(B_KBYTES_STR))) |
62e76326 | 786 | return 1 << 10; |
787 | ||
9906e724 | 788 | if (!strncasecmp(unit, B_MBYTES_STR, strlen(B_MBYTES_STR))) |
62e76326 | 789 | return 1 << 20; |
790 | ||
9906e724 | 791 | if (!strncasecmp(unit, B_GBYTES_STR, strlen(B_GBYTES_STR))) |
62e76326 | 792 | return 1 << 30; |
793 | ||
bf8fe701 | 794 | debugs(3, 1, "parseBytesUnits: unknown bytes unit '" << unit << "'"); |
62e76326 | 795 | |
9906e724 | 796 | return 0; |
797 | } | |
798 | ||
270b86af | 799 | /***************************************************************************** |
800 | * Max | |
801 | *****************************************************************************/ | |
802 | ||
8203a132 | 803 | static void |
97427e90 | 804 | dump_acl(StoreEntry * entry, const char *name, ACL * ae) |
090089c4 | 805 | { |
56b63fa1 | 806 | wordlist *w; |
807 | wordlist *v; | |
62e76326 | 808 | |
9ef28b60 | 809 | while (ae != NULL) { |
bf8fe701 | 810 | debugs(3, 3, "dump_acl: " << name << " " << ae->name); |
62e76326 | 811 | storeAppendPrintf(entry, "%s %s %s ", |
812 | name, | |
813 | ae->name, | |
814 | ae->typeString()); | |
6bf4f823 | 815 | v = w = ae->dump(); |
62e76326 | 816 | |
817 | while (v != NULL) { | |
bf8fe701 | 818 | debugs(3, 3, "dump_acl: " << name << " " << ae->name << " " << v->key); |
62e76326 | 819 | storeAppendPrintf(entry, "%s ", v->key); |
820 | v = v->next; | |
821 | } | |
822 | ||
823 | storeAppendPrintf(entry, "\n"); | |
824 | wordlistDestroy(&w); | |
825 | ae = ae->next; | |
56b63fa1 | 826 | } |
090089c4 | 827 | } |
828 | ||
8203a132 | 829 | static void |
97427e90 | 830 | parse_acl(ACL ** ae) |
090089c4 | 831 | { |
a9f20260 | 832 | ACL::ParseAclLine(LegacyParser, ae); |
f1dc9b30 | 833 | } |
834 | ||
835 | static void | |
97427e90 | 836 | free_acl(ACL ** ae) |
f1dc9b30 | 837 | { |
9ef28b60 | 838 | aclDestroyAcls(ae); |
090089c4 | 839 | } |
840 | ||
8203a132 | 841 | static void |
d6827718 | 842 | dump_acl_list(StoreEntry * entry, acl_list * head) |
30a4f2a8 | 843 | { |
56b63fa1 | 844 | acl_list *l; |
62e76326 | 845 | |
d6827718 | 846 | for (l = head; l; l = l->next) { |
62e76326 | 847 | storeAppendPrintf(entry, " %s%s", |
848 | l->op ? null_string : "!", | |
849 | l->_acl->name); | |
d6827718 | 850 | } |
851 | } | |
852 | ||
b67e2c8c | 853 | void |
d6827718 | 854 | dump_acl_access(StoreEntry * entry, const char *name, acl_access * head) |
855 | { | |
856 | acl_access *l; | |
62e76326 | 857 | |
d6827718 | 858 | for (l = head; l; l = l->next) { |
62e76326 | 859 | storeAppendPrintf(entry, "%s %s", |
860 | name, | |
861 | l->allow ? "Allow" : "Deny"); | |
862 | dump_acl_list(entry, l->aclList); | |
863 | storeAppendPrintf(entry, "\n"); | |
56b63fa1 | 864 | } |
30a4f2a8 | 865 | } |
090089c4 | 866 | |
8203a132 | 867 | static void |
16300b58 | 868 | parse_acl_access(acl_access ** head) |
090089c4 | 869 | { |
a9f20260 | 870 | aclParseAccessLine(LegacyParser, head); |
090089c4 | 871 | } |
872 | ||
0153d498 | 873 | static void |
16300b58 | 874 | free_acl_access(acl_access ** head) |
0153d498 | 875 | { |
a47b9029 | 876 | aclDestroyAccessList(head); |
0153d498 | 877 | } |
878 | ||
8203a132 | 879 | static void |
62e76326 | 880 | |
ddfcbc22 | 881 | dump_address(StoreEntry * entry, const char *name, struct IN_ADDR addr) |
270b86af | 882 | { |
f53b06f9 | 883 | storeAppendPrintf(entry, "%s %s\n", name, inet_ntoa(addr)); |
270b86af | 884 | } |
885 | ||
886 | static void | |
62e76326 | 887 | |
ddfcbc22 | 888 | parse_address(struct IN_ADDR *addr) |
090089c4 | 889 | { |
62e76326 | 890 | |
0ee4272b | 891 | const struct hostent *hp; |
270b86af | 892 | char *token = strtok(NULL, w_space); |
893 | ||
30a4f2a8 | 894 | if (token == NULL) |
62e76326 | 895 | self_destruct(); |
896 | ||
429fdbec | 897 | if (safe_inet_addr(token, addr) == 1) |
62e76326 | 898 | (void) 0; |
ceb8994e | 899 | else if ((hp = gethostbyname(token))) /* dont use ipcache */ |
62e76326 | 900 | *addr = inaddrFromHostent(hp); |
30a4f2a8 | 901 | else |
62e76326 | 902 | self_destruct(); |
090089c4 | 903 | } |
904 | ||
0153d498 | 905 | static void |
62e76326 | 906 | |
ddfcbc22 | 907 | free_address(struct IN_ADDR *addr) |
0153d498 | 908 | { |
62e76326 | 909 | |
ddfcbc22 | 910 | memset(addr, '\0', sizeof(struct IN_ADDR)); |
0153d498 | 911 | } |
912 | ||
d6827718 | 913 | CBDATA_TYPE(acl_address); |
914 | ||
915 | static void | |
916 | dump_acl_address(StoreEntry * entry, const char *name, acl_address * head) | |
917 | { | |
918 | acl_address *l; | |
62e76326 | 919 | |
d6827718 | 920 | for (l = head; l; l = l->next) { |
62e76326 | 921 | if (l->addr.s_addr != INADDR_ANY) |
922 | storeAppendPrintf(entry, "%s %s", name, inet_ntoa(l->addr)); | |
923 | else | |
924 | storeAppendPrintf(entry, "%s autoselect", name); | |
925 | ||
926 | dump_acl_list(entry, l->aclList); | |
927 | ||
928 | storeAppendPrintf(entry, "\n"); | |
d6827718 | 929 | } |
930 | } | |
931 | ||
932 | static void | |
933 | freed_acl_address(void *data) | |
934 | { | |
e6ccf245 | 935 | acl_address *l = static_cast<acl_address *>(data); |
29b8d8d6 | 936 | aclDestroyAclList(&l->aclList); |
d6827718 | 937 | } |
938 | ||
939 | static void | |
940 | parse_acl_address(acl_address ** head) | |
941 | { | |
942 | acl_address *l; | |
943 | acl_address **tail = head; /* sane name below */ | |
944 | CBDATA_INIT_TYPE_FREECB(acl_address, freed_acl_address); | |
945 | l = cbdataAlloc(acl_address); | |
946 | parse_address(&l->addr); | |
a9f20260 | 947 | aclParseAclList(LegacyParser, &l->aclList); |
62e76326 | 948 | |
d6827718 | 949 | while (*tail) |
62e76326 | 950 | tail = &(*tail)->next; |
951 | ||
d6827718 | 952 | *tail = l; |
953 | } | |
954 | ||
955 | static void | |
956 | free_acl_address(acl_address ** head) | |
957 | { | |
958 | while (*head) { | |
62e76326 | 959 | acl_address *l = *head; |
960 | *head = l->next; | |
961 | cbdataFree(l); | |
d6827718 | 962 | } |
963 | } | |
964 | ||
965 | CBDATA_TYPE(acl_tos); | |
966 | ||
967 | static void | |
968 | dump_acl_tos(StoreEntry * entry, const char *name, acl_tos * head) | |
969 | { | |
970 | acl_tos *l; | |
62e76326 | 971 | |
d6827718 | 972 | for (l = head; l; l = l->next) { |
62e76326 | 973 | if (l->tos > 0) |
974 | storeAppendPrintf(entry, "%s 0x%02X", name, l->tos); | |
975 | else | |
976 | storeAppendPrintf(entry, "%s none", name); | |
977 | ||
978 | dump_acl_list(entry, l->aclList); | |
979 | ||
980 | storeAppendPrintf(entry, "\n"); | |
d6827718 | 981 | } |
982 | } | |
983 | ||
984 | static void | |
985 | freed_acl_tos(void *data) | |
986 | { | |
e6ccf245 | 987 | acl_tos *l = static_cast<acl_tos *>(data); |
29b8d8d6 | 988 | aclDestroyAclList(&l->aclList); |
d6827718 | 989 | } |
990 | ||
991 | static void | |
992 | parse_acl_tos(acl_tos ** head) | |
993 | { | |
994 | acl_tos *l; | |
995 | acl_tos **tail = head; /* sane name below */ | |
996 | int tos; | |
997 | char junk; | |
998 | char *token = strtok(NULL, w_space); | |
62e76326 | 999 | |
d6827718 | 1000 | if (!token) |
62e76326 | 1001 | self_destruct(); |
1002 | ||
d6827718 | 1003 | if (sscanf(token, "0x%x%c", &tos, &junk) != 1) |
62e76326 | 1004 | self_destruct(); |
1005 | ||
d6827718 | 1006 | if (tos < 0 || tos > 255) |
62e76326 | 1007 | self_destruct(); |
1008 | ||
d6827718 | 1009 | CBDATA_INIT_TYPE_FREECB(acl_tos, freed_acl_tos); |
62e76326 | 1010 | |
d6827718 | 1011 | l = cbdataAlloc(acl_tos); |
62e76326 | 1012 | |
d6827718 | 1013 | l->tos = tos; |
62e76326 | 1014 | |
a9f20260 | 1015 | aclParseAclList(LegacyParser, &l->aclList); |
62e76326 | 1016 | |
d6827718 | 1017 | while (*tail) |
62e76326 | 1018 | tail = &(*tail)->next; |
1019 | ||
d6827718 | 1020 | *tail = l; |
1021 | } | |
1022 | ||
1023 | static void | |
1024 | free_acl_tos(acl_tos ** head) | |
1025 | { | |
1026 | while (*head) { | |
62e76326 | 1027 | acl_tos *l = *head; |
1028 | *head = l->next; | |
1029 | l->next = NULL; | |
1030 | cbdataFree(l); | |
d6827718 | 1031 | } |
1032 | } | |
1033 | ||
ef1955a5 | 1034 | CBDATA_TYPE(acl_size_t); |
1035 | ||
1036 | static void | |
1037 | dump_acl_b_size_t(StoreEntry * entry, const char *name, acl_size_t * head) | |
1038 | { | |
1039 | acl_size_t *l; | |
1040 | ||
1041 | for (l = head; l; l = l->next) { | |
1042 | if (l->size != static_cast<size_t>(-1)) | |
1043 | storeAppendPrintf(entry, "%s %d %s\n", name, (int) l->size, B_BYTES_STR); | |
1044 | else | |
1045 | storeAppendPrintf(entry, "%s none", name); | |
1046 | ||
1047 | dump_acl_list(entry, l->aclList); | |
1048 | ||
1049 | storeAppendPrintf(entry, "\n"); | |
1050 | } | |
1051 | } | |
1052 | ||
1053 | static void | |
1054 | freed_acl_b_size_t(void *data) | |
1055 | { | |
1056 | acl_size_t *l = static_cast<acl_size_t *>(data); | |
1057 | aclDestroyAclList(&l->aclList); | |
1058 | } | |
1059 | ||
1060 | static void | |
1061 | parse_acl_b_size_t(acl_size_t ** head) | |
1062 | { | |
1063 | acl_size_t *l; | |
1064 | acl_size_t **tail = head; /* sane name below */ | |
1065 | ||
1066 | CBDATA_INIT_TYPE_FREECB(acl_size_t, freed_acl_b_size_t); | |
1067 | ||
1068 | l = cbdataAlloc(acl_size_t); | |
1069 | ||
47f6e231 | 1070 | parse_b_int64_t(&l->size); |
ef1955a5 | 1071 | |
a9f20260 | 1072 | aclParseAclList(LegacyParser, &l->aclList); |
ef1955a5 | 1073 | |
1074 | while (*tail) | |
1075 | tail = &(*tail)->next; | |
1076 | ||
1077 | *tail = l; | |
1078 | } | |
1079 | ||
1080 | static void | |
1081 | free_acl_b_size_t(acl_size_t ** head) | |
1082 | { | |
1083 | while (*head) { | |
1084 | acl_size_t *l = *head; | |
1085 | *head = l->next; | |
1086 | l->next = NULL; | |
1087 | cbdataFree(l); | |
1088 | } | |
1089 | } | |
1090 | ||
59715b38 | 1091 | #if DELAY_POOLS |
1092 | ||
b67e2c8c | 1093 | #include "DelayPools.h" |
1094 | #include "DelayConfig.h" | |
59715b38 | 1095 | /* do nothing - free_delay_pool_count is the magic free function. |
1096 | * this is why delay_pool_count isn't just marked TYPE: ushort | |
1097 | */ | |
1098 | #define free_delay_pool_class(X) | |
1099 | #define free_delay_pool_access(X) | |
1100 | #define free_delay_pool_rates(X) | |
1101 | #define dump_delay_pool_class(X, Y, Z) | |
1102 | #define dump_delay_pool_access(X, Y, Z) | |
1103 | #define dump_delay_pool_rates(X, Y, Z) | |
1104 | ||
1105 | static void | |
b67e2c8c | 1106 | free_delay_pool_count(DelayConfig * cfg) |
59715b38 | 1107 | { |
b67e2c8c | 1108 | cfg->freePoolCount(); |
59715b38 | 1109 | } |
1110 | ||
1111 | static void | |
b67e2c8c | 1112 | dump_delay_pool_count(StoreEntry * entry, const char *name, DelayConfig &cfg) |
59715b38 | 1113 | { |
b67e2c8c | 1114 | cfg.dumpPoolCount (entry, name); |
59715b38 | 1115 | } |
1116 | ||
1117 | static void | |
b67e2c8c | 1118 | parse_delay_pool_count(DelayConfig * cfg) |
59715b38 | 1119 | { |
b67e2c8c | 1120 | cfg->parsePoolCount(); |
59715b38 | 1121 | } |
1122 | ||
1123 | static void | |
b67e2c8c | 1124 | parse_delay_pool_class(DelayConfig * cfg) |
59715b38 | 1125 | { |
b67e2c8c | 1126 | cfg->parsePoolClass(); |
59715b38 | 1127 | } |
1128 | ||
1129 | static void | |
b67e2c8c | 1130 | parse_delay_pool_rates(DelayConfig * cfg) |
59715b38 | 1131 | { |
b67e2c8c | 1132 | cfg->parsePoolRates(); |
59715b38 | 1133 | } |
1134 | ||
1135 | static void | |
b67e2c8c | 1136 | parse_delay_pool_access(DelayConfig * cfg) |
59715b38 | 1137 | { |
a9f20260 | 1138 | cfg->parsePoolAccess(LegacyParser); |
59715b38 | 1139 | } |
62e76326 | 1140 | |
59715b38 | 1141 | #endif |
1142 | ||
c26ffae9 | 1143 | #if HTTP_VIOLATIONS |
97474590 | 1144 | static void |
6bccf575 | 1145 | dump_http_header_access(StoreEntry * entry, const char *name, header_mangler header[]) |
e3dd531e | 1146 | { |
efd900cb | 1147 | int i; |
62e76326 | 1148 | |
6bccf575 | 1149 | for (i = 0; i < HDR_ENUM_END; i++) { |
62e76326 | 1150 | if (header[i].access_list != NULL) { |
1151 | storeAppendPrintf(entry, "%s ", name); | |
1152 | dump_acl_access(entry, httpHeaderNameById(i), | |
1153 | header[i].access_list); | |
1154 | } | |
efd900cb | 1155 | } |
97474590 | 1156 | } |
e3dd531e | 1157 | |
97474590 | 1158 | static void |
6bccf575 | 1159 | parse_http_header_access(header_mangler header[]) |
97474590 | 1160 | { |
6bccf575 | 1161 | int id, i; |
97474590 | 1162 | char *t = NULL; |
62e76326 | 1163 | |
97474590 | 1164 | if ((t = strtok(NULL, w_space)) == NULL) { |
bf8fe701 | 1165 | debugs(3, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line); |
1166 | debugs(3, 0, "parse_http_header_access: missing header name."); | |
62e76326 | 1167 | return; |
97474590 | 1168 | } |
62e76326 | 1169 | |
6bccf575 | 1170 | /* Now lookup index of header. */ |
1171 | id = httpHeaderIdByNameDef(t, strlen(t)); | |
62e76326 | 1172 | |
6bccf575 | 1173 | if (strcmp(t, "All") == 0) |
62e76326 | 1174 | id = HDR_ENUM_END; |
6bccf575 | 1175 | else if (strcmp(t, "Other") == 0) |
62e76326 | 1176 | id = HDR_OTHER; |
6bccf575 | 1177 | else if (id == -1) { |
bf8fe701 | 1178 | debugs(3, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line); |
1179 | debugs(3, 0, "parse_http_header_access: unknown header name '" << t << "'"); | |
62e76326 | 1180 | return; |
97474590 | 1181 | } |
62e76326 | 1182 | |
6bccf575 | 1183 | if (id != HDR_ENUM_END) { |
62e76326 | 1184 | parse_acl_access(&header[id].access_list); |
6bccf575 | 1185 | } else { |
62e76326 | 1186 | char *next_string = t + strlen(t) - 1; |
1187 | *next_string = 'A'; | |
1188 | *(next_string + 1) = ' '; | |
1189 | ||
1190 | for (i = 0; i < HDR_ENUM_END; i++) { | |
1191 | char *new_string = xstrdup(next_string); | |
1192 | strtok(new_string, w_space); | |
1193 | parse_acl_access(&header[i].access_list); | |
1194 | safe_free(new_string); | |
1195 | } | |
97474590 | 1196 | } |
6bccf575 | 1197 | } |
1198 | ||
1199 | static void | |
1200 | free_http_header_access(header_mangler header[]) | |
1201 | { | |
1202 | int i; | |
62e76326 | 1203 | |
6bccf575 | 1204 | for (i = 0; i < HDR_ENUM_END; i++) { |
62e76326 | 1205 | free_acl_access(&header[i].access_list); |
6bccf575 | 1206 | } |
1207 | } | |
1208 | ||
1209 | static void | |
1210 | dump_http_header_replace(StoreEntry * entry, const char *name, header_mangler | |
62e76326 | 1211 | header[]) |
6bccf575 | 1212 | { |
1213 | int i; | |
62e76326 | 1214 | |
6bccf575 | 1215 | for (i = 0; i < HDR_ENUM_END; i++) { |
62e76326 | 1216 | if (NULL == header[i].replacement) |
1217 | continue; | |
1218 | ||
1219 | storeAppendPrintf(entry, "%s %s %s\n", name, httpHeaderNameById(i), | |
1220 | header[i].replacement); | |
97474590 | 1221 | } |
1222 | } | |
e3dd531e | 1223 | |
97474590 | 1224 | static void |
6bccf575 | 1225 | parse_http_header_replace(header_mangler header[]) |
e3dd531e | 1226 | { |
6bccf575 | 1227 | int id, i; |
1228 | char *t = NULL; | |
62e76326 | 1229 | |
6bccf575 | 1230 | if ((t = strtok(NULL, w_space)) == NULL) { |
bf8fe701 | 1231 | debugs(3, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line); |
1232 | debugs(3, 0, "parse_http_header_replace: missing header name."); | |
62e76326 | 1233 | return; |
6bccf575 | 1234 | } |
62e76326 | 1235 | |
6bccf575 | 1236 | /* Now lookup index of header. */ |
1237 | id = httpHeaderIdByNameDef(t, strlen(t)); | |
62e76326 | 1238 | |
6bccf575 | 1239 | if (strcmp(t, "All") == 0) |
62e76326 | 1240 | id = HDR_ENUM_END; |
6bccf575 | 1241 | else if (strcmp(t, "Other") == 0) |
62e76326 | 1242 | id = HDR_OTHER; |
6bccf575 | 1243 | else if (id == -1) { |
bf8fe701 | 1244 | debugs(3, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line); |
1245 | debugs(3, 0, "parse_http_header_replace: unknown header name " << t << "."); | |
1246 | ||
62e76326 | 1247 | return; |
6bccf575 | 1248 | } |
62e76326 | 1249 | |
6bccf575 | 1250 | if (id != HDR_ENUM_END) { |
62e76326 | 1251 | if (header[id].replacement != NULL) |
1252 | safe_free(header[id].replacement); | |
1253 | ||
1254 | header[id].replacement = xstrdup(t + strlen(t) + 1); | |
6bccf575 | 1255 | } else { |
62e76326 | 1256 | for (i = 0; i < HDR_ENUM_END; i++) { |
1257 | if (header[i].replacement != NULL) | |
1258 | safe_free(header[i].replacement); | |
1259 | ||
1260 | header[i].replacement = xstrdup(t + strlen(t) + 1); | |
1261 | } | |
6bccf575 | 1262 | } |
1263 | } | |
1264 | ||
1265 | static void | |
1266 | free_http_header_replace(header_mangler header[]) | |
1267 | { | |
1268 | int i; | |
62e76326 | 1269 | |
6bccf575 | 1270 | for (i = 0; i < HDR_ENUM_END; i++) { |
62e76326 | 1271 | if (header[i].replacement != NULL) |
1272 | safe_free(header[i].replacement); | |
6bccf575 | 1273 | } |
97474590 | 1274 | } |
62e76326 | 1275 | |
9e8b2f1c | 1276 | #endif |
97474590 | 1277 | |
e90100aa | 1278 | static void |
e6ccf245 | 1279 | dump_cachedir(StoreEntry * entry, const char *name, _SquidConfig::_cacheSwap swap) |
e90100aa | 1280 | { |
f53b06f9 | 1281 | SwapDir *s; |
1282 | int i; | |
d3b3ab85 | 1283 | assert (entry); |
62e76326 | 1284 | |
a7d59104 | 1285 | for (i = 0; i < swap.n_configured; i++) { |
c8f4eac4 | 1286 | s = dynamic_cast<SwapDir *>(swap.swapDirs[i].getRaw()); |
d4e9f2ac | 1287 | if(!s) continue; |
59b2d47f | 1288 | storeAppendPrintf(entry, "%s %s %s", name, s->type(), s->path); |
62e76326 | 1289 | s->dump(*entry); |
62e76326 | 1290 | storeAppendPrintf(entry, "\n"); |
f53b06f9 | 1291 | } |
1292 | } | |
1293 | ||
1294 | static int | |
e6ccf245 | 1295 | check_null_cachedir(_SquidConfig::_cacheSwap swap) |
f53b06f9 | 1296 | { |
1297 | return swap.swapDirs == NULL; | |
e90100aa | 1298 | } |
1299 | ||
53ad48e6 | 1300 | static int |
1301 | check_null_string(char *s) | |
1302 | { | |
1303 | return s == NULL; | |
1304 | } | |
1305 | ||
94439e4e | 1306 | static void |
1307 | parse_authparam(authConfig * config) | |
1308 | { | |
1309 | char *type_str; | |
1310 | char *param_str; | |
94439e4e | 1311 | |
1312 | if ((type_str = strtok(NULL, w_space)) == NULL) | |
62e76326 | 1313 | self_destruct(); |
94439e4e | 1314 | |
1315 | if ((param_str = strtok(NULL, w_space)) == NULL) | |
62e76326 | 1316 | self_destruct(); |
94439e4e | 1317 | |
f5691f9c | 1318 | /* find a configuration for the scheme */ |
1319 | AuthConfig *scheme = AuthConfig::Find (type_str); | |
62e76326 | 1320 | |
f5691f9c | 1321 | if (scheme == NULL) { |
1322 | /* Create a configuration */ | |
1323 | AuthScheme *theScheme; | |
1324 | ||
1325 | if ((theScheme = AuthScheme::Find(type_str)) == NULL) { | |
bf8fe701 | 1326 | debugs(3, 0, "Parsing Config File: Unknown authentication scheme '" << type_str << "'."); |
f5691f9c | 1327 | return; |
62e76326 | 1328 | } |
94439e4e | 1329 | |
f5691f9c | 1330 | config->push_back(theScheme->createConfig()); |
1331 | scheme = config->back(); | |
1332 | assert (scheme); | |
94439e4e | 1333 | } |
62e76326 | 1334 | |
f5691f9c | 1335 | scheme->parse(scheme, config->size(), param_str); |
94439e4e | 1336 | } |
1337 | ||
1338 | static void | |
1339 | free_authparam(authConfig * cfg) | |
1340 | { | |
f5691f9c | 1341 | AuthConfig *scheme; |
94439e4e | 1342 | /* DON'T FREE THESE FOR RECONFIGURE */ |
62e76326 | 1343 | |
94439e4e | 1344 | if (reconfiguring) |
62e76326 | 1345 | return; |
1346 | ||
f5691f9c | 1347 | while (cfg->size()) { |
1348 | scheme = cfg->pop_back(); | |
1349 | scheme->done(); | |
94439e4e | 1350 | } |
94439e4e | 1351 | } |
1352 | ||
1353 | static void | |
1354 | dump_authparam(StoreEntry * entry, const char *name, authConfig cfg) | |
1355 | { | |
f5691f9c | 1356 | for (authConfig::iterator i = cfg.begin(); i != cfg.end(); ++i) |
1357 | (*i)->dump(entry, name, (*i)); | |
94439e4e | 1358 | } |
1359 | ||
59b2d47f | 1360 | /* TODO: just return the object, the # is irrelevant */ |
cd748f27 | 1361 | static int |
1362 | find_fstype(char *type) | |
1363 | { | |
59b2d47f | 1364 | for (size_t i = 0; i < StoreFileSystem::FileSystems().size(); ++i) |
1365 | if (strcasecmp(type, StoreFileSystem::FileSystems().items[i]->type()) == 0) | |
1366 | return (int)i; | |
62e76326 | 1367 | |
cd748f27 | 1368 | return (-1); |
1369 | } | |
1370 | ||
0e4e0e7d | 1371 | static void |
e6ccf245 | 1372 | parse_cachedir(_SquidConfig::_cacheSwap * swap) |
0e4e0e7d | 1373 | { |
1374 | char *type_str; | |
cd748f27 | 1375 | char *path_str; |
c8f4eac4 | 1376 | RefCount<SwapDir> sd; |
cd748f27 | 1377 | int i; |
1378 | int fs; | |
cd748f27 | 1379 | |
0e4e0e7d | 1380 | if ((type_str = strtok(NULL, w_space)) == NULL) |
62e76326 | 1381 | self_destruct(); |
cd748f27 | 1382 | |
cd748f27 | 1383 | if ((path_str = strtok(NULL, w_space)) == NULL) |
62e76326 | 1384 | self_destruct(); |
cd748f27 | 1385 | |
c9e2e0e8 | 1386 | fs = find_fstype(type_str); |
1387 | ||
1388 | if (fs < 0) | |
1389 | self_destruct(); | |
1390 | ||
1391 | /* reconfigure existing dir */ | |
cd748f27 | 1392 | |
1393 | for (i = 0; i < swap->n_configured; i++) { | |
c8f4eac4 | 1394 | assert (swap->swapDirs[i].getRaw()); |
62e76326 | 1395 | |
c9e2e0e8 | 1396 | if ((strcasecmp(path_str, dynamic_cast<SwapDir *>(swap->swapDirs[i].getRaw())->path) |
1397 | ) == 0) { | |
1398 | /* this is specific to on-fs Stores. The right | |
1399 | * way to handle this is probably to have a mapping | |
1400 | * from paths to stores, and have on-fs stores | |
1401 | * register with that, and lookip in that in their | |
1402 | * own setup logic. RBC 20041225. TODO. | |
1403 | */ | |
c8f4eac4 | 1404 | |
1405 | sd = dynamic_cast<SwapDir *>(swap->swapDirs[i].getRaw()); | |
1406 | ||
c9e2e0e8 | 1407 | if (sd->type() != StoreFileSystem::FileSystems().items[fs]->type()) { |
bf8fe701 | 1408 | debugs(3, 0, "ERROR: Can't change type of existing cache_dir " << |
1409 | sd->type() << " " << sd->path << " to " << type_str << ". Restart required"); | |
c9e2e0e8 | 1410 | return; |
1411 | } | |
1412 | ||
62e76326 | 1413 | sd->reconfigure (i, path_str); |
c8f4eac4 | 1414 | |
62e76326 | 1415 | update_maxobjsize(); |
c8f4eac4 | 1416 | |
62e76326 | 1417 | return; |
1418 | } | |
cd748f27 | 1419 | } |
1420 | ||
c9e2e0e8 | 1421 | /* new cache_dir */ |
2b6662ba | 1422 | assert(swap->n_configured < 63); /* 7 bits, signed */ |
dc986280 | 1423 | |
cd748f27 | 1424 | allocate_new_swapdir(swap); |
c9e2e0e8 | 1425 | |
59b2d47f | 1426 | swap->swapDirs[swap->n_configured] = StoreFileSystem::FileSystems().items[fs]->createSwapDir(); |
c9e2e0e8 | 1427 | |
c8f4eac4 | 1428 | sd = dynamic_cast<SwapDir *>(swap->swapDirs[swap->n_configured].getRaw()); |
c9e2e0e8 | 1429 | |
8e8d4f30 | 1430 | /* parse the FS parameters and options */ |
d3b3ab85 | 1431 | sd->parse(swap->n_configured, path_str); |
c9e2e0e8 | 1432 | |
d3b3ab85 | 1433 | ++swap->n_configured; |
c9e2e0e8 | 1434 | |
cd748f27 | 1435 | /* Update the max object size */ |
1436 | update_maxobjsize(); | |
752c3b27 | 1437 | } |
1438 | ||
2d72d4fd | 1439 | static const char * |
505e35db | 1440 | peer_type_str(const peer_t type) |
1441 | { | |
1f140227 | 1442 | const char * result; |
1443 | ||
0cdcddb9 | 1444 | switch (type) { |
62e76326 | 1445 | |
505e35db | 1446 | case PEER_PARENT: |
1f140227 | 1447 | result = "parent"; |
62e76326 | 1448 | break; |
1449 | ||
505e35db | 1450 | case PEER_SIBLING: |
1f140227 | 1451 | result = "sibling"; |
62e76326 | 1452 | break; |
1453 | ||
505e35db | 1454 | case PEER_MULTICAST: |
1f140227 | 1455 | result = "multicast"; |
62e76326 | 1456 | break; |
1457 | ||
505e35db | 1458 | default: |
1f140227 | 1459 | result = "unknown"; |
62e76326 | 1460 | break; |
505e35db | 1461 | } |
1f140227 | 1462 | |
1463 | return result; | |
505e35db | 1464 | } |
1465 | ||
f1dc9b30 | 1466 | static void |
a7d59104 | 1467 | dump_peer(StoreEntry * entry, const char *name, peer * p) |
98ffb7e4 | 1468 | { |
505e35db | 1469 | domain_ping *d; |
505e35db | 1470 | domain_type *t; |
1471 | LOCAL_ARRAY(char, xname, 128); | |
62e76326 | 1472 | |
d41de3c1 | 1473 | while (p != NULL) { |
62e76326 | 1474 | storeAppendPrintf(entry, "%s %s %s %d %d", |
1475 | name, | |
1476 | p->host, | |
1477 | neighborTypeStr(p), | |
1478 | p->http_port, | |
1479 | p->icp.port); | |
1480 | dump_peer_options(entry, p); | |
1481 | ||
1482 | for (d = p->peer_domain; d; d = d->next) { | |
1483 | storeAppendPrintf(entry, "cache_peer_domain %s %s%s\n", | |
1484 | p->host, | |
1485 | d->do_ping ? null_string : "!", | |
1486 | d->domain); | |
1487 | } | |
1488 | ||
1489 | if (p->access) { | |
1490 | snprintf(xname, 128, "cache_peer_access %s", p->name); | |
1491 | dump_acl_access(entry, xname, p->access); | |
1492 | } | |
1493 | ||
1494 | for (t = p->typelist; t; t = t->next) { | |
1495 | storeAppendPrintf(entry, "neighbor_type_domain %s %s %s\n", | |
1496 | p->host, | |
1497 | peer_type_str(t->type), | |
1498 | t->domain); | |
1499 | } | |
1500 | ||
1501 | p = p->next; | |
d41de3c1 | 1502 | } |
98ffb7e4 | 1503 | } |
1504 | ||
8203a132 | 1505 | static void |
40a1495e | 1506 | parse_peer(peer ** head) |
7813c6d5 | 1507 | { |
270b86af | 1508 | char *token = NULL; |
40a1495e | 1509 | peer *p; |
f5691f9c | 1510 | CBDATA_INIT_TYPE_FREECB(peer, peerDestroy); |
72711e31 | 1511 | p = cbdataAlloc(peer); |
40a1495e | 1512 | p->http_port = CACHE_HTTP_PORT; |
399cabec | 1513 | p->icp.port = CACHE_ICP_PORT; |
40a1495e | 1514 | p->weight = 1; |
d1b63fc8 | 1515 | p->basetime = 0; |
dc835977 | 1516 | p->stats.logged_state = PEER_ALIVE; |
62e76326 | 1517 | |
e481c2dc | 1518 | if ((token = strtok(NULL, w_space)) == NULL) |
62e76326 | 1519 | self_destruct(); |
1520 | ||
40a1495e | 1521 | p->host = xstrdup(token); |
62e76326 | 1522 | |
be753325 | 1523 | p->name = xstrdup(token); |
62e76326 | 1524 | |
e481c2dc | 1525 | if ((token = strtok(NULL, w_space)) == NULL) |
62e76326 | 1526 | self_destruct(); |
1527 | ||
40a1495e | 1528 | p->type = parseNeighborType(token); |
62e76326 | 1529 | |
0d5a2006 | 1530 | if (p->type == PEER_MULTICAST) { |
1531 | p->options.no_digest = 1; | |
1532 | p->options.no_netdb_exchange = 1; | |
1533 | } | |
1534 | ||
0e656b69 | 1535 | p->http_port = GetShort(); |
62e76326 | 1536 | |
0e656b69 | 1537 | if (!p->http_port) |
1538 | self_destruct(); | |
62e76326 | 1539 | |
0e656b69 | 1540 | p->icp.port = GetShort(); |
62e76326 | 1541 | |
270b86af | 1542 | while ((token = strtok(NULL, w_space))) { |
62e76326 | 1543 | if (!strcasecmp(token, "proxy-only")) { |
1544 | p->options.proxy_only = 1; | |
1545 | } else if (!strcasecmp(token, "no-query")) { | |
1546 | p->options.no_query = 1; | |
1547 | } else if (!strcasecmp(token, "background-ping")) { | |
1548 | p->options.background_ping = 1; | |
1549 | } else if (!strcasecmp(token, "no-digest")) { | |
1550 | p->options.no_digest = 1; | |
1551 | } else if (!strcasecmp(token, "multicast-responder")) { | |
1552 | p->options.mcast_responder = 1; | |
1553 | } else if (!strncasecmp(token, "weight=", 7)) { | |
1554 | p->weight = xatoi(token + 7); | |
1555 | } else if (!strncasecmp(token, "basetime=", 9)) { | |
1556 | p->basetime = xatoi(token + 9); | |
1557 | } else if (!strcasecmp(token, "closest-only")) { | |
1558 | p->options.closest_only = 1; | |
1559 | } else if (!strncasecmp(token, "ttl=", 4)) { | |
1560 | p->mcast.ttl = xatoi(token + 4); | |
1561 | ||
1562 | if (p->mcast.ttl < 0) | |
1563 | p->mcast.ttl = 0; | |
1564 | ||
1565 | if (p->mcast.ttl > 128) | |
1566 | p->mcast.ttl = 128; | |
1567 | } else if (!strcasecmp(token, "default")) { | |
1568 | p->options.default_parent = 1; | |
1569 | } else if (!strcasecmp(token, "round-robin")) { | |
1570 | p->options.roundrobin = 1; | |
1571 | } else if (!strcasecmp(token, "weighted-round-robin")) { | |
1572 | p->options.weighted_roundrobin = 1; | |
dc9d133b | 1573 | #if USE_HTCP |
62e76326 | 1574 | |
1575 | } else if (!strcasecmp(token, "htcp")) { | |
1576 | p->options.htcp = 1; | |
527ee50d | 1577 | } else if (!strcasecmp(token, "htcp-oldsquid")) { |
1578 | p->options.htcp = 1; | |
1579 | p->options.htcp_oldsquid = 1; | |
dc9d133b | 1580 | #endif |
62e76326 | 1581 | |
1582 | } else if (!strcasecmp(token, "no-netdb-exchange")) { | |
1583 | p->options.no_netdb_exchange = 1; | |
afd88fbe | 1584 | #if USE_CARP |
62e76326 | 1585 | |
1586 | } else if (!strcasecmp(token, "carp")) { | |
1587 | if (p->type != PEER_PARENT) | |
1588 | fatalf("parse_peer: non-parent carp peer %s/%d\n", p->host, p->http_port); | |
1589 | ||
1590 | p->options.carp = 1; | |
1591 | ||
95e36d02 | 1592 | #endif |
1593 | #if DELAY_POOLS | |
62e76326 | 1594 | |
1595 | } else if (!strcasecmp(token, "no-delay")) { | |
1596 | p->options.no_delay = 1; | |
afd88fbe | 1597 | #endif |
62e76326 | 1598 | |
1599 | } else if (!strncasecmp(token, "login=", 6)) { | |
1600 | p->login = xstrdup(token + 6); | |
1601 | rfc1738_unescape(p->login); | |
1602 | } else if (!strncasecmp(token, "connect-timeout=", 16)) { | |
1603 | p->connect_timeout = xatoi(token + 16); | |
7e3ce7b9 | 1604 | #if USE_CACHE_DIGESTS |
62e76326 | 1605 | |
1606 | } else if (!strncasecmp(token, "digest-url=", 11)) { | |
1607 | p->digest_url = xstrdup(token + 11); | |
7e3ce7b9 | 1608 | #endif |
62e76326 | 1609 | |
1610 | } else if (!strcasecmp(token, "allow-miss")) { | |
1611 | p->options.allow_miss = 1; | |
1612 | } else if (!strncasecmp(token, "max-conn=", 9)) { | |
1613 | p->max_conn = xatoi(token + 9); | |
1614 | } else if (!strcasecmp(token, "originserver")) { | |
1615 | p->options.originserver = 1; | |
1616 | } else if (!strncasecmp(token, "name=", 5)) { | |
1617 | safe_free(p->name); | |
1618 | ||
1619 | if (token[5]) | |
1620 | p->name = xstrdup(token + 5); | |
1621 | } else if (!strncasecmp(token, "forceddomain=", 13)) { | |
1622 | safe_free(p->domain); | |
1623 | ||
1624 | if (token[13]) | |
1625 | p->domain = xstrdup(token + 13); | |
1626 | ||
a7ad6e4e | 1627 | #if USE_SSL |
62e76326 | 1628 | |
1629 | } else if (strcmp(token, "ssl") == 0) { | |
1630 | p->use_ssl = 1; | |
1631 | } else if (strncmp(token, "sslcert=", 8) == 0) { | |
1632 | safe_free(p->sslcert); | |
1633 | p->sslcert = xstrdup(token + 8); | |
1634 | } else if (strncmp(token, "sslkey=", 7) == 0) { | |
1635 | safe_free(p->sslkey); | |
1636 | p->sslkey = xstrdup(token + 7); | |
1637 | } else if (strncmp(token, "sslversion=", 11) == 0) { | |
1638 | p->sslversion = atoi(token + 11); | |
1639 | } else if (strncmp(token, "ssloptions=", 11) == 0) { | |
1640 | safe_free(p->ssloptions); | |
1641 | p->ssloptions = xstrdup(token + 11); | |
1642 | } else if (strncmp(token, "sslcipher=", 10) == 0) { | |
1643 | safe_free(p->sslcipher); | |
1644 | p->sslcipher = xstrdup(token + 10); | |
1645 | } else if (strncmp(token, "sslcafile=", 10) == 0) { | |
1646 | safe_free(p->sslcafile); | |
a82a4fe4 | 1647 | p->sslcafile = xstrdup(token + 10); |
62e76326 | 1648 | } else if (strncmp(token, "sslcapath=", 10) == 0) { |
1649 | safe_free(p->sslcapath); | |
a82a4fe4 | 1650 | p->sslcapath = xstrdup(token + 10); |
1651 | } else if (strncmp(token, "sslcrlfile=", 11) == 0) { | |
1652 | safe_free(p->sslcrlfile); | |
1653 | p->sslcapath = xstrdup(token + 10); | |
62e76326 | 1654 | } else if (strncmp(token, "sslflags=", 9) == 0) { |
1655 | safe_free(p->sslflags); | |
1656 | p->sslflags = xstrdup(token + 9); | |
1657 | } else if (strncmp(token, "ssldomain=", 10) == 0) { | |
1658 | safe_free(p->ssldomain); | |
1659 | p->ssldomain = xstrdup(token + 10); | |
a7ad6e4e | 1660 | #endif |
62e76326 | 1661 | |
1662 | } else if (strcmp(token, "front-end-https") == 0) { | |
1663 | p->front_end_https = 1; | |
1664 | } else if (strcmp(token, "front-end-https=on") == 0) { | |
1665 | p->front_end_https = 1; | |
1666 | } else if (strcmp(token, "front-end-https=auto") == 0) { | |
1667 | p->front_end_https = 2; | |
1668 | } else { | |
bf8fe701 | 1669 | debugs(3, 0, "parse_peer: token='" << token << "'"); |
62e76326 | 1670 | self_destruct(); |
1671 | } | |
270b86af | 1672 | } |
62e76326 | 1673 | |
be753325 | 1674 | if (peerFindByName(p->name)) |
62e76326 | 1675 | fatalf("ERROR: cache_peer %s specified twice\n", p->name); |
1676 | ||
40a1495e | 1677 | if (p->weight < 1) |
62e76326 | 1678 | p->weight = 1; |
1679 | ||
399cabec | 1680 | p->icp.version = ICP_VERSION_CURRENT; |
62e76326 | 1681 | |
eb406bb7 | 1682 | p->test_fd = -1; |
62e76326 | 1683 | |
e13ee7ad | 1684 | #if USE_CACHE_DIGESTS |
62e76326 | 1685 | |
e13ee7ad | 1686 | if (!p->options.no_digest) { |
62e76326 | 1687 | /* XXX This looks odd.. who has the original pointer |
1688 | * then? | |
1689 | */ | |
1690 | PeerDigest *pd = peerDigestCreate(p); | |
1691 | p->digest = cbdataReference(pd); | |
8a6218c6 | 1692 | } |
62e76326 | 1693 | |
e13ee7ad | 1694 | #endif |
0153d498 | 1695 | while (*head != NULL) |
62e76326 | 1696 | head = &(*head)->next; |
1697 | ||
0153d498 | 1698 | *head = p; |
62e76326 | 1699 | |
40a1495e | 1700 | Config.npeers++; |
62e76326 | 1701 | |
82056f1e | 1702 | peerClearRR(p); |
0153d498 | 1703 | } |
1704 | ||
1705 | static void | |
40a1495e | 1706 | free_peer(peer ** P) |
0153d498 | 1707 | { |
40a1495e | 1708 | peer *p; |
62e76326 | 1709 | |
79d39a72 | 1710 | while ((p = *P) != NULL) { |
62e76326 | 1711 | *P = p->next; |
3855c318 | 1712 | #if USE_CACHE_DIGESTS |
62e76326 | 1713 | |
1714 | cbdataReferenceDone(p->digest); | |
3855c318 | 1715 | #endif |
62e76326 | 1716 | |
1717 | cbdataFree(p); | |
a47b9029 | 1718 | } |
62e76326 | 1719 | |
987c67d1 | 1720 | Config.npeers = 0; |
270b86af | 1721 | } |
1722 | ||
1723 | static void | |
a7d59104 | 1724 | dump_cachemgrpasswd(StoreEntry * entry, const char *name, cachemgr_passwd * list) |
270b86af | 1725 | { |
d41de3c1 | 1726 | wordlist *w; |
62e76326 | 1727 | |
d41de3c1 | 1728 | while (list != NULL) { |
62e76326 | 1729 | if (strcmp(list->passwd, "none") && strcmp(list->passwd, "disable")) |
1730 | storeAppendPrintf(entry, "%s XXXXXXXXXX", name); | |
1731 | else | |
1732 | storeAppendPrintf(entry, "%s %s", name, list->passwd); | |
1733 | ||
1734 | for (w = list->actions; w != NULL; w = w->next) { | |
1735 | storeAppendPrintf(entry, " %s", w->key); | |
1736 | } | |
1737 | ||
1738 | storeAppendPrintf(entry, "\n"); | |
1739 | list = list->next; | |
d41de3c1 | 1740 | } |
270b86af | 1741 | } |
1742 | ||
1743 | static void | |
a47b9029 | 1744 | parse_cachemgrpasswd(cachemgr_passwd ** head) |
270b86af | 1745 | { |
1746 | char *passwd = NULL; | |
1747 | wordlist *actions = NULL; | |
22f3fd98 | 1748 | cachemgr_passwd *p; |
1749 | cachemgr_passwd **P; | |
270b86af | 1750 | parse_string(&passwd); |
1751 | parse_wordlist(&actions); | |
e6ccf245 | 1752 | p = static_cast<cachemgr_passwd *>(xcalloc(1, sizeof(cachemgr_passwd))); |
22f3fd98 | 1753 | p->passwd = passwd; |
1754 | p->actions = actions; | |
62e76326 | 1755 | |
26aa7e31 | 1756 | for (P = head; *P; P = &(*P)->next) { |
62e76326 | 1757 | /* |
1758 | * See if any of the actions from this line already have a | |
1759 | * password from previous lines. The password checking | |
1760 | * routines in cache_manager.c take the the password from | |
1761 | * the first cachemgr_passwd struct that contains the | |
1762 | * requested action. Thus, we should warn users who might | |
1763 | * think they can have two passwords for the same action. | |
1764 | */ | |
1765 | wordlist *w; | |
1766 | wordlist *u; | |
1767 | ||
1768 | for (w = (*P)->actions; w; w = w->next) { | |
1769 | for (u = actions; u; u = u->next) { | |
1770 | if (strcmp(w->key, u->key)) | |
1771 | continue; | |
1772 | ||
bf8fe701 | 1773 | debugs(0, 0, "WARNING: action '" << u->key << "' (line " << config_lineno << ") already has a password"); |
62e76326 | 1774 | } |
1775 | } | |
26aa7e31 | 1776 | } |
62e76326 | 1777 | |
22f3fd98 | 1778 | *P = p; |
270b86af | 1779 | } |
1780 | ||
1781 | static void | |
a47b9029 | 1782 | free_cachemgrpasswd(cachemgr_passwd ** head) |
270b86af | 1783 | { |
a47b9029 | 1784 | cachemgr_passwd *p; |
62e76326 | 1785 | |
79d39a72 | 1786 | while ((p = *head) != NULL) { |
62e76326 | 1787 | *head = p->next; |
1788 | xfree(p->passwd); | |
1789 | wordlistDestroy(&p->actions); | |
1790 | xfree(p); | |
a47b9029 | 1791 | } |
270b86af | 1792 | } |
1793 | ||
8203a132 | 1794 | static void |
16300b58 | 1795 | dump_denyinfo(StoreEntry * entry, const char *name, acl_deny_info_list * var) |
270b86af | 1796 | { |
d41de3c1 | 1797 | acl_name_list *a; |
62e76326 | 1798 | |
d41de3c1 | 1799 | while (var != NULL) { |
62e76326 | 1800 | storeAppendPrintf(entry, "%s %s", name, var->err_page_name); |
1801 | ||
1802 | for (a = var->acl_list; a != NULL; a = a->next) | |
1803 | storeAppendPrintf(entry, " %s", a->name); | |
1804 | ||
1805 | storeAppendPrintf(entry, "\n"); | |
1806 | ||
1807 | var = var->next; | |
d41de3c1 | 1808 | } |
270b86af | 1809 | } |
1810 | ||
1811 | static void | |
16300b58 | 1812 | parse_denyinfo(acl_deny_info_list ** var) |
6e40f263 | 1813 | { |
f1dc9b30 | 1814 | aclParseDenyInfoLine(var); |
6e40f263 | 1815 | } |
403279e0 | 1816 | |
1273d501 | 1817 | void |
a47b9029 | 1818 | free_denyinfo(acl_deny_info_list ** list) |
3c5557f9 | 1819 | { |
56b63fa1 | 1820 | acl_deny_info_list *a = NULL; |
1821 | acl_deny_info_list *a_next = NULL; | |
1822 | acl_name_list *l = NULL; | |
1823 | acl_name_list *l_next = NULL; | |
62e76326 | 1824 | |
1273d501 | 1825 | for (a = *list; a; a = a_next) { |
62e76326 | 1826 | for (l = a->acl_list; l; l = l_next) { |
1827 | l_next = l->next; | |
1828 | memFree(l, MEM_ACL_NAME_LIST); | |
1829 | l = NULL; | |
1830 | } | |
1831 | ||
1832 | a_next = a->next; | |
1833 | memFree(a, MEM_ACL_DENY_INFO_LIST); | |
1834 | a = NULL; | |
1273d501 | 1835 | } |
62e76326 | 1836 | |
1273d501 | 1837 | *list = NULL; |
270b86af | 1838 | } |
1839 | ||
1840 | static void | |
505e35db | 1841 | parse_peer_access(void) |
270b86af | 1842 | { |
1843 | char *host = NULL; | |
505e35db | 1844 | peer *p; |
62e76326 | 1845 | |
270b86af | 1846 | if (!(host = strtok(NULL, w_space))) |
62e76326 | 1847 | self_destruct(); |
1848 | ||
0cdcddb9 | 1849 | if ((p = peerFindByName(host)) == NULL) { |
bf8fe701 | 1850 | debugs(15, 0, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'"); |
62e76326 | 1851 | return; |
0cdcddb9 | 1852 | } |
62e76326 | 1853 | |
a9f20260 | 1854 | aclParseAccessLine(LegacyParser, &p->access); |
270b86af | 1855 | } |
1856 | ||
270b86af | 1857 | static void |
1858 | parse_hostdomain(void) | |
1859 | { | |
1860 | char *host = NULL; | |
1861 | char *domain = NULL; | |
62e76326 | 1862 | |
270b86af | 1863 | if (!(host = strtok(NULL, w_space))) |
62e76326 | 1864 | self_destruct(); |
1865 | ||
f1dc9b30 | 1866 | while ((domain = strtok(NULL, list_sep))) { |
62e76326 | 1867 | domain_ping *l = NULL; |
1868 | domain_ping **L = NULL; | |
1869 | peer *p; | |
1870 | ||
1871 | if ((p = peerFindByName(host)) == NULL) { | |
bf8fe701 | 1872 | debugs(15, 0, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'"); |
62e76326 | 1873 | continue; |
1874 | } | |
1875 | ||
1876 | l = static_cast<domain_ping *>(xcalloc(1, sizeof(domain_ping))); | |
1877 | l->do_ping = 1; | |
1878 | ||
1879 | if (*domain == '!') { /* check for !.edu */ | |
1880 | l->do_ping = 0; | |
1881 | domain++; | |
1882 | } | |
1883 | ||
1884 | l->domain = xstrdup(domain); | |
1885 | ||
1886 | for (L = &(p->peer_domain); *L; L = &((*L)->next)) | |
1887 | ||
1888 | ; | |
1889 | *L = l; | |
f1dc9b30 | 1890 | } |
270b86af | 1891 | } |
1892 | ||
1893 | static void | |
1894 | parse_hostdomaintype(void) | |
1895 | { | |
1896 | char *host = NULL; | |
1897 | char *type = NULL; | |
1898 | char *domain = NULL; | |
62e76326 | 1899 | |
270b86af | 1900 | if (!(host = strtok(NULL, w_space))) |
62e76326 | 1901 | self_destruct(); |
1902 | ||
270b86af | 1903 | if (!(type = strtok(NULL, w_space))) |
62e76326 | 1904 | self_destruct(); |
1905 | ||
f1dc9b30 | 1906 | while ((domain = strtok(NULL, list_sep))) { |
62e76326 | 1907 | domain_type *l = NULL; |
1908 | domain_type **L = NULL; | |
1909 | peer *p; | |
1910 | ||
1911 | if ((p = peerFindByName(host)) == NULL) { | |
bf8fe701 | 1912 | debugs(15, 0, "" << cfg_filename << ", line " << config_lineno << ": No cache_peer '" << host << "'"); |
62e76326 | 1913 | return; |
1914 | } | |
1915 | ||
1916 | l = static_cast<domain_type *>(xcalloc(1, sizeof(domain_type))); | |
1917 | l->type = parseNeighborType(type); | |
1918 | l->domain = xstrdup(domain); | |
1919 | ||
1920 | for (L = &(p->typelist); *L; L = &((*L)->next)) | |
1921 | ||
1922 | ; | |
1923 | *L = l; | |
f1dc9b30 | 1924 | } |
270b86af | 1925 | } |
1926 | ||
270b86af | 1927 | static void |
a7d59104 | 1928 | dump_int(StoreEntry * entry, const char *name, int var) |
270b86af | 1929 | { |
f53b06f9 | 1930 | storeAppendPrintf(entry, "%s %d\n", name, var); |
270b86af | 1931 | } |
c1c29eb6 | 1932 | |
94439e4e | 1933 | void |
270b86af | 1934 | parse_int(int *var) |
1935 | { | |
270b86af | 1936 | int i; |
0e4e0e7d | 1937 | i = GetInteger(); |
270b86af | 1938 | *var = i; |
1939 | } | |
090089c4 | 1940 | |
0153d498 | 1941 | static void |
1942 | free_int(int *var) | |
1943 | { | |
a47b9029 | 1944 | *var = 0; |
0153d498 | 1945 | } |
1946 | ||
270b86af | 1947 | static void |
a7d59104 | 1948 | dump_onoff(StoreEntry * entry, const char *name, int var) |
270b86af | 1949 | { |
f53b06f9 | 1950 | storeAppendPrintf(entry, "%s %s\n", name, var ? "on" : "off"); |
270b86af | 1951 | } |
090089c4 | 1952 | |
d205783b | 1953 | void |
270b86af | 1954 | parse_onoff(int *var) |
1955 | { | |
1956 | char *token = strtok(NULL, w_space); | |
090089c4 | 1957 | |
270b86af | 1958 | if (token == NULL) |
62e76326 | 1959 | self_destruct(); |
1960 | ||
270b86af | 1961 | if (!strcasecmp(token, "on") || !strcasecmp(token, "enable")) |
62e76326 | 1962 | *var = 1; |
270b86af | 1963 | else |
62e76326 | 1964 | *var = 0; |
270b86af | 1965 | } |
e90100aa | 1966 | |
0153d498 | 1967 | #define free_onoff free_int |
52d3f198 | 1968 | |
1969 | static void | |
1970 | dump_tristate(StoreEntry * entry, const char *name, int var) | |
1971 | { | |
1972 | const char *state; | |
1973 | ||
1974 | if (var > 0) | |
1975 | state = "on"; | |
1976 | else if (var < 0) | |
1977 | state = "warn"; | |
1978 | else | |
1979 | state = "off"; | |
1980 | ||
1981 | storeAppendPrintf(entry, "%s %s\n", name, state); | |
1982 | } | |
1983 | ||
1984 | static void | |
1985 | parse_tristate(int *var) | |
1986 | { | |
1987 | char *token = strtok(NULL, w_space); | |
1988 | ||
1989 | if (token == NULL) | |
1990 | self_destruct(); | |
1991 | ||
1992 | if (!strcasecmp(token, "on") || !strcasecmp(token, "enable")) | |
1993 | *var = 1; | |
1994 | else if (!strcasecmp(token, "warn")) | |
1995 | *var = -1; | |
1996 | else | |
1997 | *var = 0; | |
1998 | } | |
1999 | ||
2000 | #define free_tristate free_int | |
30a4f2a8 | 2001 | |
270b86af | 2002 | static void |
a7d59104 | 2003 | dump_refreshpattern(StoreEntry * entry, const char *name, refresh_t * head) |
270b86af | 2004 | { |
d41de3c1 | 2005 | while (head != NULL) { |
62e76326 | 2006 | storeAppendPrintf(entry, "%s%s %s %d %d%% %d\n", |
2007 | name, | |
2008 | head->flags.icase ? " -i" : null_string, | |
2009 | head->pattern, | |
2010 | (int) head->min / 60, | |
2011 | (int) (100.0 * head->pct + 0.5), | |
2012 | (int) head->max / 60); | |
4c3ef9b2 | 2013 | |
2014 | if (head->flags.refresh_ims) | |
2015 | storeAppendPrintf(entry, " refresh-ims"); | |
2016 | ||
9f60cfdf | 2017 | #if HTTP_VIOLATIONS |
62e76326 | 2018 | |
2019 | if (head->flags.override_expire) | |
2020 | storeAppendPrintf(entry, " override-expire"); | |
2021 | ||
2022 | if (head->flags.override_lastmod) | |
2023 | storeAppendPrintf(entry, " override-lastmod"); | |
2024 | ||
2025 | if (head->flags.reload_into_ims) | |
2026 | storeAppendPrintf(entry, " reload-into-ims"); | |
2027 | ||
2028 | if (head->flags.ignore_reload) | |
2029 | storeAppendPrintf(entry, " ignore-reload"); | |
2030 | ||
38f9c547 | 2031 | if (head->flags.ignore_no_cache) |
2032 | storeAppendPrintf(entry, " ignore-no-cache"); | |
2033 | ||
2034 | if (head->flags.ignore_no_store) | |
2035 | storeAppendPrintf(entry, " ignore-no-store"); | |
2036 | ||
2037 | if (head->flags.ignore_private) | |
2038 | storeAppendPrintf(entry, " ignore-private"); | |
2039 | ||
2040 | if (head->flags.ignore_auth) | |
2041 | storeAppendPrintf(entry, " ignore-auth"); | |
2042 | ||
9f60cfdf | 2043 | #endif |
62e76326 | 2044 | |
2045 | storeAppendPrintf(entry, "\n"); | |
2046 | ||
2047 | head = head->next; | |
d41de3c1 | 2048 | } |
270b86af | 2049 | } |
090089c4 | 2050 | |
270b86af | 2051 | static void |
f1dc9b30 | 2052 | parse_refreshpattern(refresh_t ** head) |
270b86af | 2053 | { |
f1dc9b30 | 2054 | char *token; |
2055 | char *pattern; | |
2056 | time_t min = 0; | |
c3f6d204 | 2057 | double pct = 0.0; |
f1dc9b30 | 2058 | time_t max = 0; |
4c3ef9b2 | 2059 | int refresh_ims = 0; |
9f60cfdf | 2060 | #if HTTP_VIOLATIONS |
62e76326 | 2061 | |
1dfa1d81 | 2062 | int override_expire = 0; |
2063 | int override_lastmod = 0; | |
cbe3a719 | 2064 | int reload_into_ims = 0; |
2065 | int ignore_reload = 0; | |
38f9c547 | 2066 | int ignore_no_cache = 0; |
2067 | int ignore_no_store = 0; | |
2068 | int ignore_private = 0; | |
2069 | int ignore_auth = 0; | |
9f60cfdf | 2070 | #endif |
62e76326 | 2071 | |
f1dc9b30 | 2072 | int i; |
2073 | refresh_t *t; | |
2074 | regex_t comp; | |
2075 | int errcode; | |
2076 | int flags = REG_EXTENDED | REG_NOSUB; | |
62e76326 | 2077 | |
f1dc9b30 | 2078 | if ((token = strtok(NULL, w_space)) == NULL) |
62e76326 | 2079 | self_destruct(); |
2080 | ||
f1dc9b30 | 2081 | if (strcmp(token, "-i") == 0) { |
62e76326 | 2082 | flags |= REG_ICASE; |
2083 | token = strtok(NULL, w_space); | |
f1dc9b30 | 2084 | } else if (strcmp(token, "+i") == 0) { |
62e76326 | 2085 | flags &= ~REG_ICASE; |
2086 | token = strtok(NULL, w_space); | |
f1dc9b30 | 2087 | } |
62e76326 | 2088 | |
f1dc9b30 | 2089 | if (token == NULL) |
62e76326 | 2090 | self_destruct(); |
2091 | ||
f1dc9b30 | 2092 | pattern = xstrdup(token); |
62e76326 | 2093 | |
0e4e0e7d | 2094 | i = GetInteger(); /* token: min */ |
62e76326 | 2095 | |
f1dc9b30 | 2096 | min = (time_t) (i * 60); /* convert minutes to seconds */ |
62e76326 | 2097 | |
0e4e0e7d | 2098 | i = GetInteger(); /* token: pct */ |
62e76326 | 2099 | |
c3f6d204 | 2100 | pct = (double) i / 100.0; |
62e76326 | 2101 | |
0e4e0e7d | 2102 | i = GetInteger(); /* token: max */ |
62e76326 | 2103 | |
f1dc9b30 | 2104 | max = (time_t) (i * 60); /* convert minutes to seconds */ |
62e76326 | 2105 | |
1dfa1d81 | 2106 | /* Options */ |
2107 | while ((token = strtok(NULL, w_space)) != NULL) { | |
4c3ef9b2 | 2108 | if (!strcmp(token, "refresh-ims")) { |
2109 | refresh_ims = 1; | |
9f60cfdf | 2110 | #if HTTP_VIOLATIONS |
62e76326 | 2111 | |
4c3ef9b2 | 2112 | } else if (!strcmp(token, "override-expire")) |
62e76326 | 2113 | override_expire = 1; |
2114 | else if (!strcmp(token, "override-lastmod")) | |
2115 | override_lastmod = 1; | |
38f9c547 | 2116 | else if (!strcmp(token, "ignore-no-cache")) |
2117 | ignore_no_cache = 1; | |
2118 | else if (!strcmp(token, "ignore-no-store")) | |
2119 | ignore_no_store = 1; | |
2120 | else if (!strcmp(token, "ignore-private")) | |
2121 | ignore_private = 1; | |
2122 | else if (!strcmp(token, "ignore-auth")) | |
2123 | ignore_auth = 1; | |
62e76326 | 2124 | else if (!strcmp(token, "reload-into-ims")) { |
2125 | reload_into_ims = 1; | |
2126 | refresh_nocache_hack = 1; | |
2127 | /* tell client_side.c that this is used */ | |
2128 | } else if (!strcmp(token, "ignore-reload")) { | |
2129 | ignore_reload = 1; | |
2130 | refresh_nocache_hack = 1; | |
2131 | /* tell client_side.c that this is used */ | |
9f60cfdf | 2132 | #endif |
62e76326 | 2133 | |
4c3ef9b2 | 2134 | } else |
bf8fe701 | 2135 | debugs(22, 0, "redreshAddToList: Unknown option '" << pattern << "': " << token); |
1dfa1d81 | 2136 | } |
62e76326 | 2137 | |
f1dc9b30 | 2138 | if ((errcode = regcomp(&comp, pattern, flags)) != 0) { |
62e76326 | 2139 | char errbuf[256]; |
2140 | regerror(errcode, &comp, errbuf, sizeof errbuf); | |
bf8fe701 | 2141 | debugs(22, 0, "" << cfg_filename << " line " << config_lineno << ": " << config_input_line); |
2142 | debugs(22, 0, "refreshAddToList: Invalid regular expression '" << pattern << "': " << errbuf); | |
62e76326 | 2143 | return; |
f1dc9b30 | 2144 | } |
62e76326 | 2145 | |
c3f6d204 | 2146 | pct = pct < 0.0 ? 0.0 : pct; |
f1dc9b30 | 2147 | max = max < 0 ? 0 : max; |
e6ccf245 | 2148 | t = static_cast<refresh_t *>(xcalloc(1, sizeof(refresh_t))); |
f1dc9b30 | 2149 | t->pattern = (char *) xstrdup(pattern); |
2150 | t->compiled_pattern = comp; | |
2151 | t->min = min; | |
c3f6d204 | 2152 | t->pct = pct; |
f1dc9b30 | 2153 | t->max = max; |
62e76326 | 2154 | |
c3f6d204 | 2155 | if (flags & REG_ICASE) |
62e76326 | 2156 | t->flags.icase = 1; |
2157 | ||
4c3ef9b2 | 2158 | if (refresh_ims) |
2159 | t->flags.refresh_ims = 1; | |
2160 | ||
9f60cfdf | 2161 | #if HTTP_VIOLATIONS |
62e76326 | 2162 | |
1dfa1d81 | 2163 | if (override_expire) |
62e76326 | 2164 | t->flags.override_expire = 1; |
2165 | ||
1dfa1d81 | 2166 | if (override_lastmod) |
62e76326 | 2167 | t->flags.override_lastmod = 1; |
2168 | ||
cbe3a719 | 2169 | if (reload_into_ims) |
62e76326 | 2170 | t->flags.reload_into_ims = 1; |
2171 | ||
cbe3a719 | 2172 | if (ignore_reload) |
62e76326 | 2173 | t->flags.ignore_reload = 1; |
2174 | ||
38f9c547 | 2175 | if (ignore_no_cache) |
2176 | t->flags.ignore_no_cache = 1; | |
2177 | ||
2178 | if (ignore_no_store) | |
2179 | t->flags.ignore_no_store = 1; | |
2180 | ||
2181 | if (ignore_private) | |
2182 | t->flags.ignore_private = 1; | |
2183 | ||
2184 | if (ignore_auth) | |
2185 | t->flags.ignore_auth = 1; | |
2186 | ||
9f60cfdf | 2187 | #endif |
62e76326 | 2188 | |
f1dc9b30 | 2189 | t->next = NULL; |
62e76326 | 2190 | |
f1dc9b30 | 2191 | while (*head) |
62e76326 | 2192 | head = &(*head)->next; |
2193 | ||
f1dc9b30 | 2194 | *head = t; |
62e76326 | 2195 | |
f1dc9b30 | 2196 | safe_free(pattern); |
270b86af | 2197 | } |
090089c4 | 2198 | |
270b86af | 2199 | static void |
a47b9029 | 2200 | free_refreshpattern(refresh_t ** head) |
270b86af | 2201 | { |
f1dc9b30 | 2202 | refresh_t *t; |
62e76326 | 2203 | |
79d39a72 | 2204 | while ((t = *head) != NULL) { |
62e76326 | 2205 | *head = t->next; |
2206 | safe_free(t->pattern); | |
2207 | regfree(&t->compiled_pattern); | |
2208 | safe_free(t); | |
f1dc9b30 | 2209 | } |
c2066637 | 2210 | |
8970d351 | 2211 | #if HTTP_VIOLATIONS |
c2066637 | 2212 | refresh_nocache_hack = 0; |
8970d351 | 2213 | |
2214 | #endif | |
270b86af | 2215 | } |
12b9e9b1 | 2216 | |
270b86af | 2217 | static void |
a7d59104 | 2218 | dump_string(StoreEntry * entry, const char *name, char *var) |
270b86af | 2219 | { |
f53b06f9 | 2220 | if (var != NULL) |
62e76326 | 2221 | storeAppendPrintf(entry, "%s %s\n", name, var); |
270b86af | 2222 | } |
98ffb7e4 | 2223 | |
270b86af | 2224 | static void |
0153d498 | 2225 | parse_string(char **var) |
270b86af | 2226 | { |
2227 | char *token = strtok(NULL, w_space); | |
270b86af | 2228 | safe_free(*var); |
62e76326 | 2229 | |
270b86af | 2230 | if (token == NULL) |
62e76326 | 2231 | self_destruct(); |
2232 | ||
270b86af | 2233 | *var = xstrdup(token); |
2234 | } | |
b15e6857 | 2235 | |
3a69ddf3 | 2236 | void |
2237 | ConfigParser::ParseString(char **var) | |
2238 | { | |
2239 | parse_string(var); | |
2240 | } | |
2241 | ||
2242 | void | |
30abd221 | 2243 | ConfigParser::ParseString(String *var) |
3a69ddf3 | 2244 | { |
2245 | char *token = strtok(NULL, w_space); | |
2246 | ||
2247 | if (token == NULL) | |
2248 | self_destruct(); | |
2249 | ||
30abd221 | 2250 | var->reset(token); |
3a69ddf3 | 2251 | } |
2252 | ||
0153d498 | 2253 | static void |
2254 | free_string(char **var) | |
2255 | { | |
027acbaf | 2256 | safe_free(*var); |
0153d498 | 2257 | } |
caebbe00 | 2258 | |
94439e4e | 2259 | void |
f1dc9b30 | 2260 | parse_eol(char *volatile *var) |
270b86af | 2261 | { |
852751f7 | 2262 | unsigned char *token = (unsigned char *) strtok(NULL, null_string); |
270b86af | 2263 | safe_free(*var); |
62e76326 | 2264 | |
f1dc9b30 | 2265 | if (token == NULL) |
62e76326 | 2266 | self_destruct(); |
2267 | ||
e4755e29 | 2268 | while (*token && xisspace(*token)) |
62e76326 | 2269 | token++; |
2270 | ||
20cb98c9 | 2271 | if (!*token) |
62e76326 | 2272 | self_destruct(); |
2273 | ||
852751f7 | 2274 | *var = xstrdup((char *) token); |
270b86af | 2275 | } |
090089c4 | 2276 | |
52d3f198 | 2277 | #define dump_eol dump_string |
2278 | #define free_eol free_string | |
2279 | ||
d9e04dc7 | 2280 | void |
2281 | parse_debug(char *volatile *var) | |
2282 | { | |
2283 | parse_eol(var); | |
2284 | safe_free(debug_options) | |
2285 | debug_options = xstrdup(Config.debugOptions); | |
2286 | Debug::parseOptions(Config.debugOptions); | |
2287 | } | |
2288 | ||
52d3f198 | 2289 | #define dump_debug dump_string |
2290 | #define free_debug free_string | |
2291 | ||
270b86af | 2292 | static void |
a7d59104 | 2293 | dump_time_t(StoreEntry * entry, const char *name, time_t var) |
090089c4 | 2294 | { |
f53b06f9 | 2295 | storeAppendPrintf(entry, "%s %d seconds\n", name, (int) var); |
090089c4 | 2296 | } |
2297 | ||
94439e4e | 2298 | void |
a47b9029 | 2299 | parse_time_t(time_t * var) |
0ffd22bc | 2300 | { |
f1dc9b30 | 2301 | parseTimeLine(var, T_SECOND_STR); |
0ffd22bc | 2302 | } |
2303 | ||
270b86af | 2304 | static void |
a47b9029 | 2305 | free_time_t(time_t * var) |
270b86af | 2306 | { |
a47b9029 | 2307 | *var = 0; |
270b86af | 2308 | } |
9906e724 | 2309 | |
2310 | static void | |
a7d59104 | 2311 | dump_size_t(StoreEntry * entry, const char *name, size_t var) |
1b635117 | 2312 | { |
f53b06f9 | 2313 | storeAppendPrintf(entry, "%s %d\n", name, (int) var); |
1b635117 | 2314 | } |
2315 | ||
2316 | static void | |
a7d59104 | 2317 | dump_b_size_t(StoreEntry * entry, const char *name, size_t var) |
9906e724 | 2318 | { |
f53b06f9 | 2319 | storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_BYTES_STR); |
9906e724 | 2320 | } |
2321 | ||
2322 | static void | |
a7d59104 | 2323 | dump_kb_size_t(StoreEntry * entry, const char *name, size_t var) |
9906e724 | 2324 | { |
f53b06f9 | 2325 | storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_KBYTES_STR); |
9906e724 | 2326 | } |
2327 | ||
47f6e231 | 2328 | static void |
2329 | dump_b_int64_t(StoreEntry * entry, const char *name, int64_t var) | |
2330 | { | |
2331 | storeAppendPrintf(entry, "%s %"PRId64" %s\n", name, var, B_BYTES_STR); | |
2332 | } | |
2333 | ||
2334 | static void | |
2335 | dump_kb_int64_t(StoreEntry * entry, const char *name, int64_t var) | |
2336 | { | |
2337 | storeAppendPrintf(entry, "%s %"PRId64" %s\n", name, var, B_KBYTES_STR); | |
2338 | } | |
2339 | ||
9906e724 | 2340 | static void |
a47b9029 | 2341 | parse_size_t(size_t * var) |
1b635117 | 2342 | { |
1b635117 | 2343 | int i; |
0e4e0e7d | 2344 | i = GetInteger(); |
1b635117 | 2345 | *var = (size_t) i; |
2346 | } | |
2347 | ||
2348 | static void | |
2349 | parse_b_size_t(size_t * var) | |
9906e724 | 2350 | { |
2351 | parseBytesLine(var, B_BYTES_STR); | |
2352 | } | |
2353 | ||
2354 | static void | |
a47b9029 | 2355 | parse_kb_size_t(size_t * var) |
9906e724 | 2356 | { |
2357 | parseBytesLine(var, B_KBYTES_STR); | |
2358 | } | |
2359 | ||
47f6e231 | 2360 | static void |
2361 | parse_b_int64_t(int64_t * var) | |
2362 | { | |
2363 | parseBytesLine64(var, B_BYTES_STR); | |
2364 | } | |
2365 | ||
2366 | static void | |
2367 | parse_kb_int64_t(int64_t * var) | |
2368 | { | |
2369 | parseBytesLine64(var, B_KBYTES_STR); | |
2370 | } | |
2371 | ||
9906e724 | 2372 | static void |
a47b9029 | 2373 | free_size_t(size_t * var) |
9906e724 | 2374 | { |
a47b9029 | 2375 | *var = 0; |
9906e724 | 2376 | } |
2377 | ||
47f6e231 | 2378 | static void |
2379 | free_b_int64_t(int64_t * var) | |
2380 | { | |
2381 | *var = 0; | |
2382 | } | |
2383 | ||
1b635117 | 2384 | #define free_b_size_t free_size_t |
9906e724 | 2385 | #define free_kb_size_t free_size_t |
2386 | #define free_mb_size_t free_size_t | |
2387 | #define free_gb_size_t free_size_t | |
47f6e231 | 2388 | #define free_kb_int64_t free_b_int64_t |
090089c4 | 2389 | |
8203a132 | 2390 | static void |
a7d59104 | 2391 | dump_ushort(StoreEntry * entry, const char *name, u_short var) |
090089c4 | 2392 | { |
f53b06f9 | 2393 | storeAppendPrintf(entry, "%s %d\n", name, var); |
270b86af | 2394 | } |
090089c4 | 2395 | |
0153d498 | 2396 | static void |
a47b9029 | 2397 | free_ushort(u_short * u) |
0153d498 | 2398 | { |
2399 | *u = 0; | |
2400 | } | |
2401 | ||
270b86af | 2402 | static void |
2403 | parse_ushort(u_short * var) | |
b67e2c8c | 2404 | { |
2405 | ConfigParser::ParseUShort(var); | |
2406 | } | |
2407 | ||
2408 | void | |
2409 | ConfigParser::ParseUShort(u_short *var) | |
270b86af | 2410 | { |
0e656b69 | 2411 | *var = GetShort(); |
090089c4 | 2412 | } |
2413 | ||
3a69ddf3 | 2414 | void |
2415 | ConfigParser::ParseBool(bool *var) | |
2416 | { | |
2417 | int i = GetInteger(); | |
2418 | ||
2419 | if (0 == i) | |
2420 | *var = false; | |
2421 | else if (1 == i) | |
2422 | *var = true; | |
2423 | else | |
2424 | self_destruct(); | |
2425 | } | |
2426 | ||
270b86af | 2427 | static void |
a7d59104 | 2428 | dump_wordlist(StoreEntry * entry, const char *name, wordlist * list) |
270b86af | 2429 | { |
270b86af | 2430 | while (list != NULL) { |
62e76326 | 2431 | storeAppendPrintf(entry, "%s %s\n", name, list->key); |
2432 | list = list->next; | |
429fdbec | 2433 | } |
429fdbec | 2434 | } |
2435 | ||
3a69ddf3 | 2436 | void |
2437 | ConfigParser::ParseWordList(wordlist ** list) | |
2438 | { | |
2439 | parse_wordlist(list); | |
2440 | } | |
2441 | ||
94439e4e | 2442 | void |
270b86af | 2443 | parse_wordlist(wordlist ** list) |
429fdbec | 2444 | { |
270b86af | 2445 | char *token; |
a3c6890f | 2446 | char *t = strtok(NULL, ""); |
62e76326 | 2447 | |
a3c6890f | 2448 | while ((token = strwordtok(NULL, &t))) |
62e76326 | 2449 | wordlistAdd(list, token); |
429fdbec | 2450 | } |
270b86af | 2451 | |
f8d9f54a | 2452 | static int |
5da06f20 | 2453 | check_null_wordlist(wordlist * w) |
f8d9f54a | 2454 | { |
2455 | return w == NULL; | |
2456 | } | |
2457 | ||
63e9d884 | 2458 | static int |
c6d5b87b | 2459 | check_null_acl_access(acl_access * a) |
63e9d884 | 2460 | { |
2461 | return a == NULL; | |
2462 | } | |
2463 | ||
0153d498 | 2464 | #define free_wordlist wordlistDestroy |
270b86af | 2465 | |
d548ee64 | 2466 | #define free_uri_whitespace free_int |
2467 | ||
2468 | static void | |
2469 | parse_uri_whitespace(int *var) | |
2470 | { | |
2471 | char *token = strtok(NULL, w_space); | |
62e76326 | 2472 | |
d548ee64 | 2473 | if (token == NULL) |
62e76326 | 2474 | self_destruct(); |
2475 | ||
7e3ce7b9 | 2476 | if (!strcasecmp(token, "strip")) |
62e76326 | 2477 | *var = URI_WHITESPACE_STRIP; |
7e3ce7b9 | 2478 | else if (!strcasecmp(token, "deny")) |
62e76326 | 2479 | *var = URI_WHITESPACE_DENY; |
d548ee64 | 2480 | else if (!strcasecmp(token, "allow")) |
62e76326 | 2481 | *var = URI_WHITESPACE_ALLOW; |
d548ee64 | 2482 | else if (!strcasecmp(token, "encode")) |
62e76326 | 2483 | *var = URI_WHITESPACE_ENCODE; |
d548ee64 | 2484 | else if (!strcasecmp(token, "chop")) |
62e76326 | 2485 | *var = URI_WHITESPACE_CHOP; |
d548ee64 | 2486 | else |
62e76326 | 2487 | self_destruct(); |
d548ee64 | 2488 | } |
2489 | ||
d548ee64 | 2490 | static void |
2491 | dump_uri_whitespace(StoreEntry * entry, const char *name, int var) | |
2492 | { | |
c193c972 | 2493 | const char *s; |
62e76326 | 2494 | |
d548ee64 | 2495 | if (var == URI_WHITESPACE_ALLOW) |
62e76326 | 2496 | s = "allow"; |
d548ee64 | 2497 | else if (var == URI_WHITESPACE_ENCODE) |
62e76326 | 2498 | s = "encode"; |
d548ee64 | 2499 | else if (var == URI_WHITESPACE_CHOP) |
62e76326 | 2500 | s = "chop"; |
7e3ce7b9 | 2501 | else if (var == URI_WHITESPACE_DENY) |
62e76326 | 2502 | s = "deny"; |
7e3ce7b9 | 2503 | else |
62e76326 | 2504 | s = "strip"; |
2505 | ||
d548ee64 | 2506 | storeAppendPrintf(entry, "%s %s\n", name, s); |
2507 | } | |
2508 | ||
6a566b9c | 2509 | static void |
c1dd71ae | 2510 | free_removalpolicy(RemovalPolicySettings ** settings) |
6a566b9c | 2511 | { |
2512 | if (!*settings) | |
62e76326 | 2513 | return; |
2514 | ||
6a566b9c | 2515 | free_string(&(*settings)->type); |
62e76326 | 2516 | |
6a566b9c | 2517 | free_wordlist(&(*settings)->args); |
62e76326 | 2518 | |
c8f4eac4 | 2519 | delete *settings; |
62e76326 | 2520 | |
6a566b9c | 2521 | *settings = NULL; |
2522 | } | |
2523 | ||
2524 | static void | |
c1dd71ae | 2525 | parse_removalpolicy(RemovalPolicySettings ** settings) |
6a566b9c | 2526 | { |
2527 | if (*settings) | |
62e76326 | 2528 | free_removalpolicy(settings); |
2529 | ||
c8f4eac4 | 2530 | *settings = new RemovalPolicySettings; |
62e76326 | 2531 | |
6a566b9c | 2532 | parse_string(&(*settings)->type); |
62e76326 | 2533 | |
6a566b9c | 2534 | parse_wordlist(&(*settings)->args); |
2535 | } | |
2536 | ||
2537 | static void | |
c1dd71ae | 2538 | dump_removalpolicy(StoreEntry * entry, const char *name, RemovalPolicySettings * settings) |
6a566b9c | 2539 | { |
2540 | wordlist *args; | |
2541 | storeAppendPrintf(entry, "%s %s", name, settings->type); | |
2542 | args = settings->args; | |
62e76326 | 2543 | |
6a566b9c | 2544 | while (args) { |
62e76326 | 2545 | storeAppendPrintf(entry, " %s", args->key); |
2546 | args = args->next; | |
6a566b9c | 2547 | } |
62e76326 | 2548 | |
be58afb5 | 2549 | storeAppendPrintf(entry, "\n"); |
6a566b9c | 2550 | } |
c1dd71ae | 2551 | |
1ee67578 | 2552 | #include "cf_parser.h" |
f1dc9b30 | 2553 | |
2554 | peer_t | |
2555 | parseNeighborType(const char *s) | |
2556 | { | |
2557 | if (!strcasecmp(s, "parent")) | |
62e76326 | 2558 | return PEER_PARENT; |
2559 | ||
f1dc9b30 | 2560 | if (!strcasecmp(s, "neighbor")) |
62e76326 | 2561 | return PEER_SIBLING; |
2562 | ||
f1dc9b30 | 2563 | if (!strcasecmp(s, "neighbour")) |
62e76326 | 2564 | return PEER_SIBLING; |
2565 | ||
f1dc9b30 | 2566 | if (!strcasecmp(s, "sibling")) |
62e76326 | 2567 | return PEER_SIBLING; |
2568 | ||
f1dc9b30 | 2569 | if (!strcasecmp(s, "multicast")) |
62e76326 | 2570 | return PEER_MULTICAST; |
2571 | ||
bf8fe701 | 2572 | debugs(15, 0, "WARNING: Unknown neighbor type: " << s); |
62e76326 | 2573 | |
f1dc9b30 | 2574 | return PEER_SIBLING; |
2575 | } | |
f150dd4b | 2576 | |
0b0cfcf2 | 2577 | #if USE_WCCPv2 |
52f772de | 2578 | void |
2579 | parse_sockaddr_in_list_token(sockaddr_in_list ** head, char *token) | |
7e3ce7b9 | 2580 | { |
7e3ce7b9 | 2581 | char *t; |
efd900cb | 2582 | char *host; |
7d569f1b | 2583 | char *tmp; |
62e76326 | 2584 | |
7e3ce7b9 | 2585 | const struct hostent *hp; |
efd900cb | 2586 | unsigned short port; |
7e3ce7b9 | 2587 | sockaddr_in_list *s; |
52f772de | 2588 | |
2589 | host = NULL; | |
2590 | port = 0; | |
62e76326 | 2591 | |
52f772de | 2592 | if ((t = strchr(token, ':'))) { |
62e76326 | 2593 | /* host:port */ |
2594 | host = token; | |
2595 | *t = '\0'; | |
0e656b69 | 2596 | port = xatos(t + 1); |
62e76326 | 2597 | |
2598 | if (0 == port) | |
2599 | self_destruct(); | |
7d569f1b | 2600 | } else if ((port = strtol(token, &tmp, 10)), !*tmp) { |
62e76326 | 2601 | /* port */ |
52f772de | 2602 | } else { |
7d569f1b | 2603 | host = token; |
0d5a2006 | 2604 | port = 0; |
52f772de | 2605 | } |
62e76326 | 2606 | |
e6ccf245 | 2607 | s = static_cast<sockaddr_in_list *>(xcalloc(1, sizeof(*s))); |
52f772de | 2608 | s->s.sin_port = htons(port); |
62e76326 | 2609 | |
52f772de | 2610 | if (NULL == host) |
62e76326 | 2611 | s->s.sin_addr = any_addr; |
52f772de | 2612 | else if (1 == safe_inet_addr(host, &s->s.sin_addr)) |
62e76326 | 2613 | (void) 0; |
52f772de | 2614 | else if ((hp = gethostbyname(host))) /* dont use ipcache */ |
62e76326 | 2615 | s->s.sin_addr = inaddrFromHostent(hp); |
52f772de | 2616 | else |
62e76326 | 2617 | self_destruct(); |
2618 | ||
52f772de | 2619 | while (*head) |
62e76326 | 2620 | head = &(*head)->next; |
2621 | ||
52f772de | 2622 | *head = s; |
2623 | } | |
2624 | ||
2625 | static void | |
2626 | parse_sockaddr_in_list(sockaddr_in_list ** head) | |
2627 | { | |
2628 | char *token; | |
62e76326 | 2629 | |
52f772de | 2630 | while ((token = strtok(NULL, w_space))) { |
62e76326 | 2631 | parse_sockaddr_in_list_token(head, token); |
7e3ce7b9 | 2632 | } |
2633 | } | |
2634 | ||
2635 | static void | |
2636 | dump_sockaddr_in_list(StoreEntry * e, const char *n, const sockaddr_in_list * s) | |
2637 | { | |
2638 | while (s) { | |
62e76326 | 2639 | storeAppendPrintf(e, "%s %s:%d\n", |
2640 | n, | |
2641 | inet_ntoa(s->s.sin_addr), | |
2642 | ntohs(s->s.sin_port)); | |
2643 | s = s->next; | |
7e3ce7b9 | 2644 | } |
2645 | } | |
2646 | ||
2647 | static void | |
2648 | free_sockaddr_in_list(sockaddr_in_list ** head) | |
2649 | { | |
2650 | sockaddr_in_list *s; | |
62e76326 | 2651 | |
7e3ce7b9 | 2652 | while ((s = *head) != NULL) { |
62e76326 | 2653 | *head = s->next; |
2654 | xfree(s); | |
7e3ce7b9 | 2655 | } |
2656 | } | |
2657 | ||
0b0cfcf2 | 2658 | #if CURRENTLY_UNUSED |
2659 | /* This code was previously used by http_port. Left as it really should | |
2660 | * be used by icp_port and htcp_port | |
2661 | */ | |
7e3ce7b9 | 2662 | static int |
2663 | check_null_sockaddr_in_list(const sockaddr_in_list * s) | |
2664 | { | |
2665 | return NULL == s; | |
2666 | } | |
62e76326 | 2667 | |
3f38a55e | 2668 | #endif /* CURRENTLY_UNUSED */ |
0b0cfcf2 | 2669 | #endif /* USE_WCCPv2 */ |
7e3ce7b9 | 2670 | |
d193a436 | 2671 | static void |
3f38a55e | 2672 | parse_http_port_specification(http_port_list * s, char *token) |
d193a436 | 2673 | { |
3f38a55e | 2674 | char *host = NULL; |
62e76326 | 2675 | |
d193a436 | 2676 | const struct hostent *hp; |
3f38a55e | 2677 | unsigned short port = 0; |
2678 | char *t; | |
62e76326 | 2679 | |
5529ca8a | 2680 | s->disable_pmtu_discovery = DISABLE_PMTU_OFF; |
2681 | ||
d193a436 | 2682 | if ((t = strchr(token, ':'))) { |
62e76326 | 2683 | /* host:port */ |
2684 | host = token; | |
2685 | *t = '\0'; | |
0e656b69 | 2686 | port = xatos(t + 1); |
d193a436 | 2687 | } else { |
0e656b69 | 2688 | /* port */ |
2689 | port = xatos(token); | |
d193a436 | 2690 | } |
62e76326 | 2691 | |
0e656b69 | 2692 | if (port == 0) |
2693 | self_destruct(); | |
2694 | ||
d193a436 | 2695 | s->s.sin_port = htons(port); |
62e76326 | 2696 | |
d193a436 | 2697 | if (NULL == host) |
62e76326 | 2698 | s->s.sin_addr = any_addr; |
d193a436 | 2699 | else if (1 == safe_inet_addr(host, &s->s.sin_addr)) |
62e76326 | 2700 | (void) 0; |
3f38a55e | 2701 | else if ((hp = gethostbyname(host))) { |
62e76326 | 2702 | /* dont use ipcache */ |
2703 | s->s.sin_addr = inaddrFromHostent(hp); | |
2704 | s->defaultsite = xstrdup(host); | |
3f38a55e | 2705 | } else |
62e76326 | 2706 | self_destruct(); |
3f38a55e | 2707 | } |
2708 | ||
2709 | static void | |
2710 | parse_http_port_option(http_port_list * s, char *token) | |
2711 | { | |
2712 | if (strncmp(token, "defaultsite=", 12) == 0) { | |
62e76326 | 2713 | safe_free(s->defaultsite); |
2714 | s->defaultsite = xstrdup(token + 12); | |
2715 | s->accel = 1; | |
3f38a55e | 2716 | } else if (strncmp(token, "name=", 5) == 0) { |
62e76326 | 2717 | safe_free(s->name); |
2718 | s->name = xstrdup(token + 5); | |
3f38a55e | 2719 | } else if (strcmp(token, "transparent") == 0) { |
62e76326 | 2720 | s->transparent = 1; |
3f38a55e | 2721 | } else if (strcmp(token, "vhost") == 0) { |
62e76326 | 2722 | s->vhost = 1; |
2723 | s->accel = 1; | |
3f38a55e | 2724 | } else if (strcmp(token, "vport") == 0) { |
62e76326 | 2725 | s->vport = -1; |
2726 | s->accel = 1; | |
3f38a55e | 2727 | } else if (strncmp(token, "vport=", 6) == 0) { |
0e656b69 | 2728 | s->vport = xatos(token + 6); |
62e76326 | 2729 | s->accel = 1; |
3f38a55e | 2730 | } else if (strncmp(token, "protocol=", 9) == 0) { |
62e76326 | 2731 | s->protocol = xstrdup(token + 9); |
2732 | s->accel = 1; | |
3f38a55e | 2733 | } else if (strcmp(token, "accel") == 0) { |
62e76326 | 2734 | s->accel = 1; |
5529ca8a | 2735 | } else if (strncmp(token, "disable-pmtu-discovery=", 23) == 0) { |
2736 | if (!strcasecmp(token + 23, "off")) | |
2737 | s->disable_pmtu_discovery = DISABLE_PMTU_OFF; | |
2738 | else if (!strcasecmp(token + 23, "transparent")) | |
2739 | s->disable_pmtu_discovery = DISABLE_PMTU_TRANSPARENT; | |
2740 | else if (!strcasecmp(token + 23, "always")) | |
2741 | s->disable_pmtu_discovery = DISABLE_PMTU_ALWAYS; | |
2742 | else | |
2743 | self_destruct(); | |
fc68f6b1 | 2744 | |
2745 | #if LINUX_TPROXY | |
2746 | ||
2747 | } else if (strcmp(token, "tproxy") == 0) { | |
2748 | s->tproxy = 1; | |
2749 | need_linux_tproxy = 1; | |
2750 | #endif | |
2751 | ||
3f38a55e | 2752 | } else { |
62e76326 | 2753 | self_destruct(); |
3f38a55e | 2754 | } |
2755 | } | |
2756 | ||
2757 | static void | |
2758 | free_generic_http_port_data(http_port_list * s) | |
2759 | { | |
2760 | safe_free(s->name); | |
2761 | safe_free(s->defaultsite); | |
f9ad0106 | 2762 | safe_free(s->protocol); |
3f38a55e | 2763 | } |
2764 | ||
2765 | static void | |
2766 | cbdataFree_http_port(void *data) | |
2767 | { | |
2768 | free_generic_http_port_data((http_port_list *)data); | |
2769 | } | |
2770 | ||
3f38a55e | 2771 | static http_port_list * |
2772 | create_http_port(char *portspec) | |
2773 | { | |
2774 | CBDATA_TYPE(http_port_list); | |
2775 | CBDATA_INIT_TYPE_FREECB(http_port_list, cbdataFree_http_port); | |
2776 | ||
2777 | http_port_list *s = cbdataAlloc(http_port_list); | |
2778 | s->protocol = xstrdup("http"); | |
2779 | parse_http_port_specification(s, portspec); | |
2780 | return s; | |
2781 | } | |
2782 | ||
2783 | void | |
2784 | add_http_port(char *portspec) | |
2785 | { | |
2786 | http_port_list *s = create_http_port(portspec); | |
2787 | s->next = Config.Sockaddr.http; | |
2788 | Config.Sockaddr.http = s; | |
2789 | } | |
2790 | ||
2791 | static void | |
2792 | parse_http_port_list(http_port_list ** head) | |
2793 | { | |
2794 | char *token = strtok(NULL, w_space); | |
62e76326 | 2795 | |
3f38a55e | 2796 | if (!token) |
62e76326 | 2797 | self_destruct(); |
2798 | ||
3f38a55e | 2799 | http_port_list *s = create_http_port(token); |
62e76326 | 2800 | |
3f38a55e | 2801 | /* parse options ... */ |
2802 | while ((token = strtok(NULL, w_space))) { | |
62e76326 | 2803 | parse_http_port_option(s, token); |
3f38a55e | 2804 | } |
62e76326 | 2805 | |
3f38a55e | 2806 | while (*head) |
62e76326 | 2807 | head = &(*head)->next; |
2808 | ||
3f38a55e | 2809 | *head = s; |
2810 | } | |
2811 | ||
2812 | static void | |
2813 | dump_generic_http_port(StoreEntry * e, const char *n, const http_port_list * s) | |
2814 | { | |
2815 | storeAppendPrintf(e, "%s %s:%d", | |
62e76326 | 2816 | n, |
2817 | inet_ntoa(s->s.sin_addr), | |
2818 | ntohs(s->s.sin_port)); | |
2819 | ||
3f38a55e | 2820 | if (s->defaultsite) |
62e76326 | 2821 | storeAppendPrintf(e, " defaultsite=%s", s->defaultsite); |
2822 | ||
3f38a55e | 2823 | if (s->transparent) |
62e76326 | 2824 | storeAppendPrintf(e, " transparent"); |
2825 | ||
3f38a55e | 2826 | if (s->vhost) |
62e76326 | 2827 | storeAppendPrintf(e, " vhost"); |
2828 | ||
3f38a55e | 2829 | if (s->vport) |
62e76326 | 2830 | storeAppendPrintf(e, " vport"); |
5529ca8a | 2831 | |
2832 | if (s->disable_pmtu_discovery != DISABLE_PMTU_OFF) { | |
2833 | const char *pmtu; | |
2834 | ||
2835 | if (s->disable_pmtu_discovery == DISABLE_PMTU_ALWAYS) | |
2836 | pmtu = "always"; | |
2837 | else | |
2838 | pmtu = "transparent"; | |
2839 | ||
2840 | storeAppendPrintf(e, " disable-pmtu-discovery=%s", pmtu); | |
2841 | } | |
3f38a55e | 2842 | } |
62e76326 | 2843 | |
3f38a55e | 2844 | static void |
2845 | dump_http_port_list(StoreEntry * e, const char *n, const http_port_list * s) | |
2846 | { | |
2847 | while (s) { | |
62e76326 | 2848 | dump_generic_http_port(e, n, s); |
2849 | storeAppendPrintf(e, "\n"); | |
2850 | s = s->next; | |
3f38a55e | 2851 | } |
2852 | } | |
2853 | ||
2854 | static void | |
2855 | free_http_port_list(http_port_list ** head) | |
2856 | { | |
2857 | http_port_list *s; | |
62e76326 | 2858 | |
3f38a55e | 2859 | while ((s = *head) != NULL) { |
62e76326 | 2860 | *head = s->next; |
2861 | cbdataFree(s); | |
3f38a55e | 2862 | } |
2863 | } | |
2864 | ||
3f38a55e | 2865 | #if USE_SSL |
2866 | static void | |
2867 | cbdataFree_https_port(void *data) | |
2868 | { | |
2869 | https_port_list *s = (https_port_list *)data; | |
2870 | free_generic_http_port_data(&s->http); | |
2871 | safe_free(s->cert); | |
2872 | safe_free(s->key); | |
f9ad0106 | 2873 | safe_free(s->options); |
2874 | safe_free(s->cipher); | |
2875 | safe_free(s->cafile); | |
2876 | safe_free(s->capath); | |
2877 | safe_free(s->dhfile); | |
2878 | safe_free(s->sslflags); | |
3f38a55e | 2879 | } |
2880 | ||
2881 | static void | |
2882 | parse_https_port_list(https_port_list ** head) | |
2883 | { | |
2884 | CBDATA_TYPE(https_port_list); | |
2885 | char *token; | |
2886 | https_port_list *s; | |
2887 | CBDATA_INIT_TYPE_FREECB(https_port_list, cbdataFree_https_port); | |
2888 | token = strtok(NULL, w_space); | |
62e76326 | 2889 | |
3f38a55e | 2890 | if (!token) |
62e76326 | 2891 | self_destruct(); |
2892 | ||
3f38a55e | 2893 | s = cbdataAlloc(https_port_list); |
62e76326 | 2894 | |
3f38a55e | 2895 | s->http.protocol = xstrdup("https"); |
62e76326 | 2896 | |
3f38a55e | 2897 | parse_http_port_specification(&s->http, token); |
62e76326 | 2898 | |
d193a436 | 2899 | /* parse options ... */ |
2900 | while ((token = strtok(NULL, w_space))) { | |
62e76326 | 2901 | if (strncmp(token, "cert=", 5) == 0) { |
2902 | safe_free(s->cert); | |
2903 | s->cert = xstrdup(token + 5); | |
2904 | } else if (strncmp(token, "key=", 4) == 0) { | |
2905 | safe_free(s->key); | |
2906 | s->key = xstrdup(token + 4); | |
2907 | } else if (strncmp(token, "version=", 8) == 0) { | |
2908 | s->version = xatoi(token + 8); | |
8bbd476e | 2909 | |
2910 | if (s->version < 1 || s->version > 4) | |
2911 | self_destruct(); | |
62e76326 | 2912 | } else if (strncmp(token, "options=", 8) == 0) { |
2913 | safe_free(s->options); | |
2914 | s->options = xstrdup(token + 8); | |
2915 | } else if (strncmp(token, "cipher=", 7) == 0) { | |
2916 | safe_free(s->cipher); | |
2917 | s->cipher = xstrdup(token + 7); | |
2918 | } else if (strncmp(token, "clientca=", 9) == 0) { | |
2919 | safe_free(s->clientca); | |
2920 | s->clientca = xstrdup(token + 9); | |
2921 | } else if (strncmp(token, "cafile=", 7) == 0) { | |
2922 | safe_free(s->cafile); | |
2923 | s->cafile = xstrdup(token + 7); | |
2924 | } else if (strncmp(token, "capath=", 7) == 0) { | |
2925 | safe_free(s->capath); | |
2926 | s->capath = xstrdup(token + 7); | |
a82a4fe4 | 2927 | } else if (strncmp(token, "crlfile=", 8) == 0) { |
2928 | safe_free(s->crlfile); | |
2929 | s->crlfile = xstrdup(token + 8); | |
35105e4b | 2930 | } else if (strncmp(token, "dhparams=", 9) == 0) { |
2931 | safe_free(s->dhfile); | |
2932 | s->dhfile = xstrdup(token + 9); | |
62e76326 | 2933 | } else if (strncmp(token, "sslflags=", 9) == 0) { |
2934 | safe_free(s->sslflags); | |
2935 | s->sslflags = xstrdup(token + 9); | |
6b2936d5 | 2936 | } else if (strncmp(token, "sslcontext=", 11) == 0) { |
2937 | safe_free(s->sslcontext); | |
2938 | s->sslcontext = xstrdup(token + 11); | |
62e76326 | 2939 | } else { |
2940 | parse_http_port_option(&s->http, token); | |
2941 | } | |
d193a436 | 2942 | } |
62e76326 | 2943 | |
8abf232c | 2944 | while (*head) { |
2945 | http_port_list ** headTmp = &(*head)->http.next; | |
2946 | head = (https_port_list **)headTmp; | |
2947 | } | |
62e76326 | 2948 | |
d193a436 | 2949 | *head = s; |
2950 | } | |
2951 | ||
2952 | static void | |
2953 | dump_https_port_list(StoreEntry * e, const char *n, const https_port_list * s) | |
2954 | { | |
2955 | while (s) { | |
62e76326 | 2956 | dump_generic_http_port(e, n, &s->http); |
2957 | ||
2958 | if (s->cert) | |
2959 | storeAppendPrintf(e, " cert=%s", s->cert); | |
2960 | ||
2961 | if (s->key) | |
5c83dac8 | 2962 | storeAppendPrintf(e, " key=%s", s->key); |
62e76326 | 2963 | |
2964 | if (s->version) | |
2965 | storeAppendPrintf(e, " version=%d", s->version); | |
2966 | ||
2967 | if (s->options) | |
2968 | storeAppendPrintf(e, " options=%s", s->options); | |
2969 | ||
2970 | if (s->cipher) | |
2971 | storeAppendPrintf(e, " cipher=%s", s->cipher); | |
2972 | ||
2973 | if (s->cafile) | |
2974 | storeAppendPrintf(e, " cafile=%s", s->cafile); | |
2975 | ||
2976 | if (s->capath) | |
2977 | storeAppendPrintf(e, " capath=%s", s->capath); | |
2978 | ||
a82a4fe4 | 2979 | if (s->crlfile) |
2980 | storeAppendPrintf(e, " crlfile=%s", s->crlfile); | |
2981 | ||
35105e4b | 2982 | if (s->dhfile) |
2983 | storeAppendPrintf(e, " dhparams=%s", s->dhfile); | |
2984 | ||
62e76326 | 2985 | if (s->sslflags) |
2986 | storeAppendPrintf(e, " sslflags=%s", s->sslflags); | |
2987 | ||
6b2936d5 | 2988 | if (s->sslcontext) |
2989 | storeAppendPrintf(e, " sslcontext=%s", s->sslcontext); | |
2990 | ||
62e76326 | 2991 | storeAppendPrintf(e, "\n"); |
2992 | ||
2993 | s = (https_port_list *) s->http.next; | |
d193a436 | 2994 | } |
2995 | } | |
2996 | ||
2997 | static void | |
2998 | free_https_port_list(https_port_list ** head) | |
2999 | { | |
3000 | https_port_list *s; | |
62e76326 | 3001 | |
d193a436 | 3002 | while ((s = *head) != NULL) { |
62e76326 | 3003 | *head = (https_port_list *) s->http.next; |
3004 | cbdataFree(s); | |
d193a436 | 3005 | } |
3006 | } | |
3007 | ||
3008 | #if 0 | |
3009 | static int | |
3010 | check_null_https_port_list(const https_port_list * s) | |
3011 | { | |
3012 | return NULL == s; | |
3013 | } | |
62e76326 | 3014 | |
d193a436 | 3015 | #endif |
3016 | ||
3017 | #endif /* USE_SSL */ | |
3018 | ||
f150dd4b | 3019 | void |
3020 | configFreeMemory(void) | |
3021 | { | |
23ff6968 | 3022 | free_all(); |
f150dd4b | 3023 | } |
f0b19334 | 3024 | |
94439e4e | 3025 | void |
f0b19334 | 3026 | requirePathnameExists(const char *name, const char *path) |
3027 | { | |
62e76326 | 3028 | |
f0b19334 | 3029 | struct stat sb; |
08577e16 | 3030 | char pathbuf[BUFSIZ]; |
f0b19334 | 3031 | assert(path != NULL); |
62e76326 | 3032 | |
0b796acd | 3033 | if (Config.chroot_dir && (geteuid() == 0)) { |
62e76326 | 3034 | snprintf(pathbuf, BUFSIZ, "%s/%s", Config.chroot_dir, path); |
3035 | path = pathbuf; | |
08577e16 | 3036 | } |
62e76326 | 3037 | |
a572d8be | 3038 | if (stat(path, &sb) < 0) { |
3039 | if (opt_send_signal == -1 || opt_send_signal == SIGHUP) | |
3040 | fatalf("%s %s: %s", name, path, xstrerror()); | |
3041 | else | |
3042 | fprintf(stderr, "WARNING: %s %s: %s\n", name, path, xstrerror()); | |
3043 | } | |
f0b19334 | 3044 | } |
d860a1aa | 3045 | |
3046 | char * | |
3047 | strtokFile(void) | |
3048 | { | |
d295d770 | 3049 | return ConfigParser::strtokFile(); |
d860a1aa | 3050 | } |
7684c4b1 | 3051 | |
450e0c10 | 3052 | #include "AccessLogEntry.h" |
3053 | /* TODO: split out parsing somehow ...*/ | |
7684c4b1 | 3054 | static void |
3055 | parse_logformat(logformat ** logformat_definitions) | |
3056 | { | |
3057 | logformat *nlf; | |
3058 | char *name, *def; | |
3059 | ||
3060 | if ((name = strtok(NULL, w_space)) == NULL) | |
3061 | self_destruct(); | |
3062 | ||
3063 | if ((def = strtok(NULL, "\r\n")) == NULL) | |
3064 | self_destruct(); | |
3065 | ||
bf8fe701 | 3066 | debugs(3, 2, "Logformat for '" << name << "' is '" << def << "'"); |
7684c4b1 | 3067 | |
3068 | nlf = (logformat *)xcalloc(1, sizeof(logformat)); | |
3069 | ||
3070 | nlf->name = xstrdup(name); | |
3071 | ||
3072 | if (!accessLogParseLogFormat(&nlf->format, def)) | |
3073 | self_destruct(); | |
3074 | ||
3075 | nlf->next = *logformat_definitions; | |
3076 | ||
3077 | *logformat_definitions = nlf; | |
3078 | } | |
3079 | ||
3080 | static void | |
3081 | parse_access_log(customlog ** logs) | |
3082 | { | |
3083 | const char *filename, *logdef_name; | |
3084 | customlog *cl; | |
3085 | logformat *lf; | |
3086 | ||
3087 | cl = (customlog *)xcalloc(1, sizeof(*cl)); | |
3088 | ||
3089 | if ((filename = strtok(NULL, w_space)) == NULL) | |
3090 | self_destruct(); | |
3091 | ||
3092 | if (strcmp(filename, "none") == 0) { | |
3093 | cl->type = CLF_NONE; | |
3094 | goto done; | |
3095 | } | |
3096 | ||
3097 | if ((logdef_name = strtok(NULL, w_space)) == NULL) | |
3098 | logdef_name = "auto"; | |
3099 | ||
bf8fe701 | 3100 | debugs(3, 9, "Log definition name '" << logdef_name << "' file '" << filename << "'"); |
7684c4b1 | 3101 | |
3102 | cl->filename = xstrdup(filename); | |
3103 | ||
3104 | /* look for the definition pointer corresponding to this name */ | |
3105 | lf = Config.Log.logformats; | |
3106 | ||
3107 | while (lf != NULL) { | |
bf8fe701 | 3108 | debugs(3, 9, "Comparing against '" << lf->name << "'"); |
7684c4b1 | 3109 | |
3110 | if (strcmp(lf->name, logdef_name) == 0) | |
3111 | break; | |
3112 | ||
3113 | lf = lf->next; | |
3114 | } | |
3115 | ||
3116 | if (lf != NULL) { | |
3117 | cl->type = CLF_CUSTOM; | |
3118 | cl->logFormat = lf; | |
3119 | } else if (strcmp(logdef_name, "auto") == 0) { | |
3120 | cl->type = CLF_AUTO; | |
3121 | } else if (strcmp(logdef_name, "squid") == 0) { | |
3122 | cl->type = CLF_SQUID; | |
3123 | } else if (strcmp(logdef_name, "common") == 0) { | |
3124 | cl->type = CLF_COMMON; | |
3125 | } else { | |
bf8fe701 | 3126 | debugs(3, 0, "Log format '" << logdef_name << "' is not defined"); |
7684c4b1 | 3127 | self_destruct(); |
3128 | } | |
3129 | ||
3130 | done: | |
a9f20260 | 3131 | aclParseAclList(LegacyParser, &cl->aclList); |
7684c4b1 | 3132 | |
3133 | while (*logs) | |
3134 | logs = &(*logs)->next; | |
3135 | ||
3136 | *logs = cl; | |
3137 | } | |
3138 | ||
d64bef4c | 3139 | static int |
3140 | check_null_access_log(customlog *customlog_definitions) | |
3141 | { | |
3142 | return customlog_definitions == NULL; | |
3143 | } | |
3144 | ||
7684c4b1 | 3145 | static void |
3146 | dump_logformat(StoreEntry * entry, const char *name, logformat * definitions) | |
3147 | { | |
3148 | accessLogDumpLogFormat(entry, name, definitions); | |
3149 | } | |
3150 | ||
3151 | static void | |
3152 | dump_access_log(StoreEntry * entry, const char *name, customlog * logs) | |
3153 | { | |
3154 | customlog *log; | |
3155 | ||
3156 | for (log = logs; log; log = log->next) { | |
3157 | storeAppendPrintf(entry, "%s ", name); | |
3158 | ||
3159 | switch (log->type) { | |
3160 | ||
3161 | case CLF_CUSTOM: | |
3162 | storeAppendPrintf(entry, "%s %s", log->filename, log->logFormat->name); | |
3163 | break; | |
3164 | ||
3165 | case CLF_NONE: | |
3166 | storeAppendPrintf(entry, "none"); | |
3167 | break; | |
3168 | ||
3169 | case CLF_SQUID: | |
3170 | storeAppendPrintf(entry, "%s squid", log->filename); | |
3171 | break; | |
3172 | ||
3173 | case CLF_COMMON: | |
3174 | storeAppendPrintf(entry, "%s squid", log->filename); | |
3175 | break; | |
3176 | ||
3177 | case CLF_AUTO: | |
3178 | ||
3179 | if (log->aclList) | |
3180 | storeAppendPrintf(entry, "%s auto", log->filename); | |
3181 | else | |
3182 | storeAppendPrintf(entry, "%s", log->filename); | |
3183 | ||
3184 | break; | |
3185 | ||
3186 | case CLF_UNKNOWN: | |
3187 | break; | |
3188 | } | |
3189 | ||
3190 | if (log->aclList) | |
3191 | dump_acl_list(entry, log->aclList); | |
3192 | ||
3193 | storeAppendPrintf(entry, "\n"); | |
3194 | } | |
3195 | } | |
3196 | ||
3197 | static void | |
3198 | free_logformat(logformat ** definitions) | |
3199 | { | |
3200 | while (*definitions) { | |
3201 | logformat *format = *definitions; | |
3202 | *definitions = format->next; | |
3203 | accessLogFreeLogFormat(&format->format); | |
3204 | xfree(format); | |
3205 | } | |
3206 | } | |
3207 | ||
3208 | static void | |
3209 | free_access_log(customlog ** definitions) | |
3210 | { | |
3211 | while (*definitions) { | |
3212 | customlog *log = *definitions; | |
3213 | *definitions = log->next; | |
3214 | ||
3215 | log->logFormat = NULL; | |
3216 | log->type = CLF_UNKNOWN; | |
3217 | ||
3218 | if (log->aclList) | |
3219 | aclDestroyAclList(&log->aclList); | |
3220 | ||
3221 | safe_free(log->filename); | |
3222 | ||
3223 | xfree(log); | |
3224 | } | |
3225 | } | |
3a69ddf3 | 3226 | |
3227 | #if ICAP_CLIENT | |
3228 | ||
3229 | static void | |
3230 | parse_icap_service_type(ICAPConfig * cfg) | |
3231 | { | |
3232 | cfg->parseICAPService(); | |
3233 | } | |
3234 | ||
3235 | static void | |
3236 | free_icap_service_type(ICAPConfig * cfg) | |
3237 | { | |
3238 | cfg->freeICAPService(); | |
3239 | } | |
3240 | ||
3241 | static void | |
a99015b2 | 3242 | dump_icap_service_type(StoreEntry * entry, const char *name, const ICAPConfig &cfg) |
3a69ddf3 | 3243 | { |
3244 | cfg.dumpICAPService(entry, name); | |
3245 | } | |
3246 | ||
3247 | static void | |
3248 | parse_icap_class_type(ICAPConfig * cfg) | |
3249 | { | |
3250 | cfg->parseICAPClass(); | |
3251 | } | |
3252 | ||
3253 | static void | |
3254 | free_icap_class_type(ICAPConfig * cfg) | |
3255 | { | |
3256 | cfg->freeICAPClass(); | |
3257 | } | |
3258 | ||
3259 | static void | |
a99015b2 | 3260 | dump_icap_class_type(StoreEntry * entry, const char *name, const ICAPConfig &cfg) |
3a69ddf3 | 3261 | { |
3262 | cfg.dumpICAPClass(entry, name); | |
3263 | } | |
3264 | ||
3265 | static void | |
3266 | parse_icap_access_type(ICAPConfig * cfg) | |
3267 | { | |
a385afc3 | 3268 | cfg->parseICAPAccess(LegacyParser); |
3a69ddf3 | 3269 | } |
3270 | ||
3271 | static void | |
3272 | free_icap_access_type(ICAPConfig * cfg) | |
3273 | { | |
3274 | cfg->freeICAPAccess(); | |
3275 | } | |
3276 | ||
3277 | static void | |
a99015b2 | 3278 | dump_icap_access_type(StoreEntry * entry, const char *name, const ICAPConfig &cfg) |
3a69ddf3 | 3279 | { |
3280 | cfg.dumpICAPAccess(entry, name); | |
3281 | } | |
3282 | ||
3283 | #endif |