]>
Commit | Line | Data |
---|---|---|
be335c22 | 1 | |
30a4f2a8 | 2 | /* |
c4aefe96 | 3 | * $Id: cache_cf.cc,v 1.363 2001/01/04 03:42:34 wessels Exp $ |
30a4f2a8 | 4 | * |
5 | * DEBUG: section 3 Configuration File Parsing | |
6 | * AUTHOR: Harvest Derived | |
7 | * | |
42c04c16 | 8 | * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ |
e25c139f | 9 | * ---------------------------------------------------------- |
30a4f2a8 | 10 | * |
11 | * Squid is the result of efforts by numerous individuals from the | |
12 | * Internet community. Development is led by Duane Wessels of the | |
e25c139f | 13 | * National Laboratory for Applied Network Research and funded by the |
14 | * National Science Foundation. Squid is Copyrighted (C) 1998 by | |
efd900cb | 15 | * the Regents of the University of California. Please see the |
16 | * COPYRIGHT file for full details. Squid incorporates software | |
17 | * developed and/or copyrighted by other sources. Please see the | |
18 | * 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" |
1df370e3 | 37 | |
38 | #if SQUID_SNMP | |
a97cfa48 | 39 | #include "snmp.h" |
1df370e3 | 40 | #endif |
090089c4 | 41 | |
8813e606 | 42 | static const char *const T_SECOND_STR = "second"; |
43 | static const char *const T_MINUTE_STR = "minute"; | |
44 | static const char *const T_HOUR_STR = "hour"; | |
45 | static const char *const T_DAY_STR = "day"; | |
46 | static const char *const T_WEEK_STR = "week"; | |
47 | static const char *const T_FORTNIGHT_STR = "fortnight"; | |
48 | static const char *const T_MONTH_STR = "month"; | |
49 | static const char *const T_YEAR_STR = "year"; | |
50 | static const char *const T_DECADE_STR = "decade"; | |
aa0a0c7c | 51 | |
9906e724 | 52 | static const char *const B_BYTES_STR = "bytes"; |
53 | static const char *const B_KBYTES_STR = "KB"; | |
54 | static const char *const B_MBYTES_STR = "MB"; | |
55 | static const char *const B_GBYTES_STR = "GB"; | |
56 | ||
4db43fab | 57 | static const char *const list_sep = ", \t\n\r"; |
efd900cb | 58 | static int http_header_first; |
59 | static int http_header_allowed = 0; | |
97474590 | 60 | |
cd748f27 | 61 | static void update_maxobjsize(void); |
f5b8bbc4 | 62 | static void configDoConfigure(void); |
63 | static void parse_refreshpattern(refresh_t **); | |
64 | static int parseTimeUnits(const char *unit); | |
65 | static void parseTimeLine(time_t * tptr, const char *units); | |
59715b38 | 66 | static void parse_ushort(u_short * var); |
f5b8bbc4 | 67 | static void parse_string(char **); |
68 | static void parse_wordlist(wordlist **); | |
69 | static void default_all(void); | |
70 | static void defaults_if_none(void); | |
71 | static int parse_line(char *); | |
72 | static void parseBytesLine(size_t * bptr, const char *units); | |
73 | static size_t parseBytesUnits(const char *unit); | |
f5b8bbc4 | 74 | static void free_all(void); |
f0b19334 | 75 | static void requirePathnameExists(const char *name, const char *path); |
ed7f5615 | 76 | static OBJH dump_config; |
97474590 | 77 | static void dump_http_header(StoreEntry * entry, const char *name, HttpHeaderMask header); |
78 | static void parse_http_header(HttpHeaderMask * header); | |
e3dd531e | 79 | static void free_http_header(HttpHeaderMask * header); |
7e3ce7b9 | 80 | static void parse_sockaddr_in_list(sockaddr_in_list **); |
81 | static void dump_sockaddr_in_list(StoreEntry *, const char *, const sockaddr_in_list *); | |
82 | static void free_sockaddr_in_list(sockaddr_in_list **); | |
83 | static int check_null_sockaddr_in_list(const sockaddr_in_list *); | |
270b86af | 84 | |
0e4e0e7d | 85 | void |
0673c0ba | 86 | self_destruct(void) |
090089c4 | 87 | { |
137ee196 | 88 | fatalf("Bungled %s line %d: %s", |
b8de7ebe | 89 | cfg_filename, config_lineno, config_input_line); |
090089c4 | 90 | } |
91 | ||
8203a132 | 92 | void |
93 | wordlistDestroy(wordlist ** list) | |
0ffd22bc | 94 | { |
95 | wordlist *w = NULL; | |
79d39a72 | 96 | while ((w = *list) != NULL) { |
b5639035 | 97 | *list = w->next; |
0ffd22bc | 98 | safe_free(w->key); |
db1cd23c | 99 | memFree(w, MEM_WORDLIST); |
0ffd22bc | 100 | } |
101 | *list = NULL; | |
102 | } | |
103 | ||
858783c9 | 104 | const char * |
fe4e214f | 105 | wordlistAdd(wordlist ** list, const char *key) |
090089c4 | 106 | { |
c68e9c6b | 107 | while (*list) |
108 | list = &(*list)->next; | |
109 | *list = memAllocate(MEM_WORDLIST); | |
110 | (*list)->key = xstrdup(key); | |
111 | (*list)->next = NULL; | |
858783c9 | 112 | return (*list)->key; |
113 | } | |
114 | ||
115 | void | |
a4b8110e | 116 | wordlistJoin(wordlist ** list, wordlist ** wl) |
858783c9 | 117 | { |
118 | while (*list) | |
119 | list = &(*list)->next; | |
120 | *list = *wl; | |
121 | *wl = NULL; | |
122 | } | |
123 | ||
124 | void | |
a4b8110e | 125 | wordlistAddWl(wordlist ** list, wordlist * wl) |
858783c9 | 126 | { |
127 | while (*list) | |
128 | list = &(*list)->next; | |
a4b8110e | 129 | for (; wl; wl = wl->next, list = &(*list)->next) { |
858783c9 | 130 | *list = memAllocate(MEM_WORDLIST); |
131 | (*list)->key = xstrdup(wl->key); | |
a4b8110e | 132 | (*list)->next = NULL; |
858783c9 | 133 | } |
090089c4 | 134 | } |
135 | ||
137ee196 | 136 | void |
eeb423fb | 137 | wordlistCat(const wordlist * w, MemBuf * mb) |
5da06f20 | 138 | { |
5da06f20 | 139 | while (NULL != w) { |
137ee196 | 140 | memBufPrintf(mb, "%s\n", w->key); |
5da06f20 | 141 | w = w->next; |
142 | } | |
5da06f20 | 143 | } |
144 | ||
6b8e7481 | 145 | wordlist * |
146 | wordlistDup(const wordlist * w) | |
147 | { | |
148 | wordlist *D = NULL; | |
149 | while (NULL != w) { | |
150 | wordlistAdd(&D, w->key); | |
151 | w = w->next; | |
152 | } | |
153 | return D; | |
154 | } | |
155 | ||
8203a132 | 156 | void |
157 | intlistDestroy(intlist ** list) | |
92a6f4b1 | 158 | { |
159 | intlist *w = NULL; | |
160 | intlist *n = NULL; | |
92a6f4b1 | 161 | for (w = *list; w; w = n) { |
162 | n = w->next; | |
db1cd23c | 163 | memFree(w, MEM_INTLIST); |
92a6f4b1 | 164 | } |
165 | *list = NULL; | |
166 | } | |
167 | ||
5db53b8f | 168 | int |
169 | intlistFind(intlist * list, int i) | |
170 | { | |
171 | intlist *w = NULL; | |
172 | for (w = list; w; w = w->next) | |
173 | if (w->i == i) | |
174 | return 1; | |
175 | return 0; | |
176 | } | |
177 | ||
403279e0 | 178 | |
3c5557f9 | 179 | /* |
180 | * Use this #define in all the parse*() functions. Assumes char *token is | |
181 | * defined | |
182 | */ | |
090089c4 | 183 | |
0e4e0e7d | 184 | int |
185 | GetInteger(void) | |
186 | { | |
187 | char *token = strtok(NULL, w_space); | |
188 | int i; | |
189 | if (token == NULL) | |
190 | self_destruct(); | |
191 | if (sscanf(token, "%d", &i) != 1) | |
192 | self_destruct(); | |
193 | return i; | |
194 | } | |
090089c4 | 195 | |
cd748f27 | 196 | static void |
197 | update_maxobjsize(void) | |
198 | { | |
199 | int i; | |
e8dbac8b | 200 | ssize_t ms = -1; |
cd748f27 | 201 | |
202 | for (i = 0; i < Config.cacheSwap.n_configured; i++) { | |
a4b8110e | 203 | if (Config.cacheSwap.swapDirs[i].max_objsize > ms) |
204 | ms = Config.cacheSwap.swapDirs[i].max_objsize; | |
cd748f27 | 205 | } |
206 | store_maxobjsize = ms; | |
207 | } | |
208 | ||
270b86af | 209 | int |
210 | parseConfigFile(const char *file_name) | |
2546fcb3 | 211 | { |
270b86af | 212 | FILE *fp = NULL; |
213 | char *token = NULL; | |
72121e8b | 214 | char *tmp_line; |
e13ee7ad | 215 | int err_count = 0; |
0153d498 | 216 | free_all(); |
217 | default_all(); | |
137ee196 | 218 | if ((fp = fopen(file_name, "r")) == NULL) |
219 | fatalf("Unable to open configuration file: %s: %s", | |
270b86af | 220 | file_name, xstrerror()); |
c4aefe96 | 221 | #if defined(_SQUID_CYGWIN_) |
222 | setmode(fileno(fp), O_TEXT); | |
223 | #endif | |
270b86af | 224 | cfg_filename = file_name; |
225 | if ((token = strrchr(cfg_filename, '/'))) | |
226 | cfg_filename = token + 1; | |
227 | memset(config_input_line, '\0', BUFSIZ); | |
228 | config_lineno = 0; | |
efd900cb | 229 | http_header_first = 0; |
270b86af | 230 | while (fgets(config_input_line, BUFSIZ, fp)) { |
231 | config_lineno++; | |
232 | if ((token = strchr(config_input_line, '\n'))) | |
233 | *token = '\0'; | |
234 | if (config_input_line[0] == '#') | |
235 | continue; | |
236 | if (config_input_line[0] == '\0') | |
237 | continue; | |
238 | debug(3, 5) ("Processing: '%s'\n", config_input_line); | |
72121e8b | 239 | tmp_line = xstrdup(config_input_line); |
270b86af | 240 | if (!parse_line(tmp_line)) { |
241 | debug(3, 0) ("parseConfigFile: line %d unrecognized: '%s'\n", | |
242 | config_lineno, | |
243 | config_input_line); | |
e13ee7ad | 244 | err_count++; |
270b86af | 245 | } |
72121e8b | 246 | safe_free(tmp_line); |
270b86af | 247 | } |
f0b19334 | 248 | fclose(fp); |
249 | defaults_if_none(); | |
250 | configDoConfigure(); | |
22f3fd98 | 251 | cachemgrRegister("config", |
252 | "Current Squid Configuration", | |
253 | dump_config, | |
1da3b90b | 254 | 1, 1); |
e13ee7ad | 255 | return err_count; |
f0b19334 | 256 | } |
270b86af | 257 | |
f0b19334 | 258 | static void |
259 | configDoConfigure(void) | |
260 | { | |
261 | LOCAL_ARRAY(char, buf, BUFSIZ); | |
262 | memset(&Config2, '\0', sizeof(SquidConfig2)); | |
7021844c | 263 | /* init memory as early as possible */ |
264 | memConfigure(); | |
270b86af | 265 | /* Sanity checks */ |
a95856a0 | 266 | if (Config.cacheSwap.swapDirs == NULL) |
267 | fatal("No cache_dir's specified in config file"); | |
9fa8263f | 268 | /* calculate Config.Swap.maxSize */ |
f4e3fa54 | 269 | storeDirConfigure(); |
82e2afd9 | 270 | if (0 == Config.Swap.maxSize) |
271 | /* people might want a zero-sized cache on purpose */ | |
272 | (void) 0; | |
273 | else if (Config.Swap.maxSize < (Config.memMaxSize >> 10)) | |
f0b19334 | 274 | fatal("cache_swap is lower than cache_mem"); |
84f42bac | 275 | if (Config.Announce.period > 0) { |
276 | Config.onoff.announce = 1; | |
277 | } else if (Config.Announce.period < 1) { | |
f1dc9b30 | 278 | Config.Announce.period = 86400 * 365; /* one year */ |
17a0a4ee | 279 | Config.onoff.announce = 0; |
270b86af | 280 | } |
6b53c392 | 281 | #if USE_DNSSERVERS |
f0b19334 | 282 | if (Config.dnsChildren < 1) |
283 | fatal("No dnsservers allocated"); | |
284 | if (Config.dnsChildren > DefaultDnsChildrenMax) { | |
285 | debug(3, 0) ("WARNING: dns_children was set to a bad value: %d\n", | |
270b86af | 286 | Config.dnsChildren); |
f0b19334 | 287 | debug(3, 0) ("Setting it to the maximum (%d).\n", |
288 | DefaultDnsChildrenMax); | |
270b86af | 289 | Config.dnsChildren = DefaultDnsChildrenMax; |
290 | } | |
efd900cb | 291 | #endif |
270b86af | 292 | if (Config.Program.redirect) { |
293 | if (Config.redirectChildren < 1) { | |
294 | Config.redirectChildren = 0; | |
c6d5b87b | 295 | wordlistDestroy(&Config.Program.redirect); |
270b86af | 296 | } else if (Config.redirectChildren > DefaultRedirectChildrenMax) { |
f0b19334 | 297 | debug(3, 0) ("WARNING: redirect_children was set to a bad value: %d\n", |
270b86af | 298 | Config.redirectChildren); |
f0b19334 | 299 | debug(3, 0) ("Setting it to the maximum (%d).\n", DefaultRedirectChildrenMax); |
270b86af | 300 | Config.redirectChildren = DefaultRedirectChildrenMax; |
301 | } | |
fea2e6e0 | 302 | } |
73e67ee0 | 303 | if (Config.Program.authenticate) { |
304 | if (Config.authenticateChildren < 1) { | |
305 | Config.authenticateChildren = 0; | |
6c20b822 | 306 | wordlistDestroy(&Config.Program.authenticate); |
73e67ee0 | 307 | } else if (Config.authenticateChildren > DefaultAuthenticateChildrenMax) { |
308 | debug(3, 0) ("WARNING: authenticate_children was set to a bad value: %d\n", | |
309 | Config.authenticateChildren); | |
310 | debug(3, 0) ("Setting it to the maximum (%d).\n", DefaultAuthenticateChildrenMax); | |
311 | Config.authenticateChildren = DefaultAuthenticateChildrenMax; | |
312 | } | |
313 | } | |
f1dc9b30 | 314 | if (Config.Accel.host) { |
a47b9029 | 315 | snprintf(buf, BUFSIZ, "http://%s:%d", Config.Accel.host, Config.Accel.port); |
316 | Config2.Accel.prefix = xstrdup(buf); | |
317 | Config2.Accel.on = 1; | |
f1dc9b30 | 318 | } |
319 | if (Config.appendDomain) | |
320 | if (*Config.appendDomain != '.') | |
321 | fatal("append_domain must begin with a '.'"); | |
270b86af | 322 | if (Config.errHtmlText == NULL) |
323 | Config.errHtmlText = xstrdup(null_string); | |
324 | storeConfigure(); | |
42b51993 | 325 | if (Config2.Accel.on && !strcmp(Config.Accel.host, "virtual")) { |
270b86af | 326 | vhost_mode = 1; |
42b51993 | 327 | if (Config.Accel.port == 0) |
328 | vport_mode = 1; | |
329 | } | |
7e3ce7b9 | 330 | if (Config.Sockaddr.http == NULL) |
270b86af | 331 | fatal("No http_port specified!"); |
137ee196 | 332 | snprintf(ThisCache, sizeof(ThisCache), "%s:%d (%s)", |
98829f69 | 333 | uniqueHostname(), |
7e3ce7b9 | 334 | (int) ntohs(Config.Sockaddr.http->s.sin_port), |
137ee196 | 335 | full_appname_string); |
38a6c74e | 336 | /* |
337 | * the extra space is for loop detection in client_side.c -- we search | |
338 | * for substrings in the Via header. | |
339 | */ | |
340 | snprintf(ThisCache2, sizeof(ThisCache), " %s:%d (%s)", | |
341 | uniqueHostname(), | |
7e3ce7b9 | 342 | (int) ntohs(Config.Sockaddr.http->s.sin_port), |
38a6c74e | 343 | full_appname_string); |
270b86af | 344 | if (!Config.udpMaxHitObjsz || Config.udpMaxHitObjsz > SQUID_UDP_SO_SNDBUF) |
345 | Config.udpMaxHitObjsz = SQUID_UDP_SO_SNDBUF; | |
346 | if (Config.appendDomain) | |
347 | Config.appendDomainLen = strlen(Config.appendDomain); | |
348 | else | |
349 | Config.appendDomainLen = 0; | |
f1dc9b30 | 350 | safe_free(debug_options) |
351 | debug_options = xstrdup(Config.debugOptions); | |
22c653cd | 352 | if (Config.retry.timeout < 5) |
353 | fatal("minimum_retry_timeout must be at least 5 seconds"); | |
354 | if (Config.retry.maxtries > 10) | |
355 | fatal("maximum_single_addr_tries cannot be larger than 10"); | |
356 | if (Config.retry.maxtries < 1) { | |
22c653cd | 357 | debug(3, 0) ("WARNING: resetting 'maximum_single_addr_tries to 1\n"); |
5210854d | 358 | Config.retry.maxtries = 1; |
359 | } | |
f0b19334 | 360 | requirePathnameExists("MIME Config Table", Config.mimeTablePathname); |
6b53c392 | 361 | #if USE_DNSSERVERS |
f0b19334 | 362 | requirePathnameExists("cache_dns_program", Config.Program.dnsserver); |
efd900cb | 363 | #endif |
a3d0a19d | 364 | #if USE_UNLINKD |
f0b19334 | 365 | requirePathnameExists("unlinkd_program", Config.Program.unlinkd); |
a3d0a19d | 366 | #endif |
f0b19334 | 367 | if (Config.Program.redirect) |
c6d5b87b | 368 | requirePathnameExists("redirect_program", Config.Program.redirect->key); |
73e67ee0 | 369 | if (Config.Program.authenticate) |
6c20b822 | 370 | requirePathnameExists("authenticate_program", Config.Program.authenticate->key); |
f0b19334 | 371 | requirePathnameExists("Icon Directory", Config.icons.directory); |
372 | requirePathnameExists("Error Directory", Config.errorDirectory); | |
9f60cfdf | 373 | #if HTTP_VIOLATIONS |
374 | { | |
49c0f46d | 375 | const refresh_t *R; |
376 | for (R = Config.Refresh; R; R = R->next) { | |
377 | if (!R->flags.override_expire) | |
378 | continue; | |
379 | debug(22, 1) ("WARNING: use of 'override-expire' in 'refresh_pattern' violates HTTP\n"); | |
380 | break; | |
381 | } | |
382 | for (R = Config.Refresh; R; R = R->next) { | |
383 | if (!R->flags.override_lastmod) | |
384 | continue; | |
385 | debug(22, 1) ("WARNING: use of 'override-lastmod' in 'refresh_pattern' violates HTTP\n"); | |
386 | break; | |
387 | } | |
9f60cfdf | 388 | } |
389 | #endif | |
db1cd23c | 390 | if (Config.Wais.relayHost) { |
391 | if (Config.Wais.peer) | |
392 | cbdataFree(Config.Wais.peer); | |
393 | Config.Wais.peer = memAllocate(MEM_PEER); | |
394 | cbdataAdd(Config.Wais.peer, peerDestroy, MEM_PEER); | |
b6a2f15e | 395 | Config.Wais.peer->host = xstrdup(Config.Wais.relayHost); |
db1cd23c | 396 | Config.Wais.peer->http_port = Config.Wais.relayPort; |
397 | } | |
53cb32a9 | 398 | if (aclPurgeMethodInUse(Config.accessList.http)) |
399 | Config2.onoff.enable_purge = 1; | |
d20b1cd0 | 400 | if (NULL != Config.effectiveUser) { |
401 | struct passwd *pwd = getpwnam(Config.effectiveUser); | |
402 | if (NULL == pwd) | |
403 | /* | |
404 | * Andres Kroonmaa <andre@online.ee>: | |
405 | * Some getpwnam() implementations (Solaris?) require | |
406 | * an available FD < 256 for opening a FILE* to the | |
407 | * passwd file. | |
408 | * DW: | |
409 | * This should be safe at startup, but might still fail | |
410 | * during reconfigure. | |
411 | */ | |
412 | fatalf("getpwnam failed to find userid for effective user '%s'", | |
413 | Config.effectiveUser, | |
414 | xstrerror()); | |
415 | Config2.effectiveUserID = pwd->pw_uid; | |
416 | } | |
417 | if (NULL != Config.effectiveGroup) { | |
418 | struct group *grp = getgrnam(Config.effectiveGroup); | |
419 | if (NULL == grp) | |
420 | fatalf("getgrnam failed to find groupid for effective group '%s'", | |
421 | Config.effectiveGroup, | |
422 | xstrerror()); | |
423 | Config2.effectiveGroupID = grp->gr_gid; | |
424 | } | |
56fe752e | 425 | urlExtMethodConfigure(); |
090089c4 | 426 | } |
427 | ||
270b86af | 428 | /* Parse a time specification from the config file. Store the |
f1dc9b30 | 429 | * result in 'tptr', after converting it to 'units' */ |
8203a132 | 430 | static void |
a47b9029 | 431 | parseTimeLine(time_t * tptr, const char *units) |
090089c4 | 432 | { |
433 | char *token; | |
270b86af | 434 | double d; |
f1dc9b30 | 435 | time_t m; |
436 | time_t u; | |
270b86af | 437 | if ((u = parseTimeUnits(units)) == 0) |
3003c0f3 | 438 | self_destruct(); |
270b86af | 439 | if ((token = strtok(NULL, w_space)) == NULL) |
3003c0f3 | 440 | self_destruct(); |
270b86af | 441 | d = atof(token); |
442 | m = u; /* default to 'units' if none specified */ | |
10738561 | 443 | if (0 == d) |
444 | (void) 0; | |
445 | else if ((token = strtok(NULL, w_space)) == NULL) | |
a47b9029 | 446 | debug(3, 0) ("WARNING: No units on '%s', assuming %f %s\n", |
447 | config_input_line, d, units); | |
9e975e4e | 448 | else if ((m = parseTimeUnits(token)) == 0) |
a47b9029 | 449 | self_destruct(); |
f1dc9b30 | 450 | *tptr = m * d / u; |
090089c4 | 451 | } |
452 | ||
270b86af | 453 | static int |
454 | parseTimeUnits(const char *unit) | |
455 | { | |
456 | if (!strncasecmp(unit, T_SECOND_STR, strlen(T_SECOND_STR))) | |
457 | return 1; | |
458 | if (!strncasecmp(unit, T_MINUTE_STR, strlen(T_MINUTE_STR))) | |
459 | return 60; | |
460 | if (!strncasecmp(unit, T_HOUR_STR, strlen(T_HOUR_STR))) | |
461 | return 3600; | |
462 | if (!strncasecmp(unit, T_DAY_STR, strlen(T_DAY_STR))) | |
463 | return 86400; | |
464 | if (!strncasecmp(unit, T_WEEK_STR, strlen(T_WEEK_STR))) | |
465 | return 86400 * 7; | |
466 | if (!strncasecmp(unit, T_FORTNIGHT_STR, strlen(T_FORTNIGHT_STR))) | |
467 | return 86400 * 14; | |
468 | if (!strncasecmp(unit, T_MONTH_STR, strlen(T_MONTH_STR))) | |
469 | return 86400 * 30; | |
470 | if (!strncasecmp(unit, T_YEAR_STR, strlen(T_YEAR_STR))) | |
471 | return 86400 * 365.2522; | |
472 | if (!strncasecmp(unit, T_DECADE_STR, strlen(T_DECADE_STR))) | |
473 | return 86400 * 365.2522 * 10; | |
474 | debug(3, 1) ("parseTimeUnits: unknown time unit '%s'\n", unit); | |
475 | return 0; | |
476 | } | |
477 | ||
9906e724 | 478 | static void |
9e975e4e | 479 | parseBytesLine(size_t * bptr, const char *units) |
9906e724 | 480 | { |
481 | char *token; | |
482 | double d; | |
483 | size_t m; | |
484 | size_t u; | |
485 | if ((u = parseBytesUnits(units)) == 0) | |
486 | self_destruct(); | |
487 | if ((token = strtok(NULL, w_space)) == NULL) | |
488 | self_destruct(); | |
489 | d = atof(token); | |
490 | m = u; /* default to 'units' if none specified */ | |
343f47a3 | 491 | if (0.0 == d) |
10738561 | 492 | (void) 0; |
4860dc1b | 493 | else if ((token = strtok(NULL, w_space)) == NULL) |
9e975e4e | 494 | debug(3, 0) ("WARNING: No units on '%s', assuming %f %s\n", |
495 | config_input_line, d, units); | |
496 | else if ((m = parseBytesUnits(token)) == 0) | |
497 | self_destruct(); | |
9906e724 | 498 | *bptr = m * d / u; |
499 | } | |
500 | ||
501 | static size_t | |
502 | parseBytesUnits(const char *unit) | |
503 | { | |
504 | if (!strncasecmp(unit, B_BYTES_STR, strlen(B_BYTES_STR))) | |
505 | return 1; | |
506 | if (!strncasecmp(unit, B_KBYTES_STR, strlen(B_KBYTES_STR))) | |
a47b9029 | 507 | return 1 << 10; |
9906e724 | 508 | if (!strncasecmp(unit, B_MBYTES_STR, strlen(B_MBYTES_STR))) |
a47b9029 | 509 | return 1 << 20; |
9906e724 | 510 | if (!strncasecmp(unit, B_GBYTES_STR, strlen(B_GBYTES_STR))) |
a47b9029 | 511 | return 1 << 30; |
9906e724 | 512 | debug(3, 1) ("parseBytesUnits: unknown bytes unit '%s'\n", unit); |
513 | return 0; | |
514 | } | |
515 | ||
270b86af | 516 | /***************************************************************************** |
517 | * Max | |
518 | *****************************************************************************/ | |
519 | ||
8203a132 | 520 | static void |
9ef28b60 | 521 | dump_acl(StoreEntry * entry, const char *name, acl * ae) |
090089c4 | 522 | { |
56b63fa1 | 523 | wordlist *w; |
524 | wordlist *v; | |
9ef28b60 | 525 | while (ae != NULL) { |
c68e9c6b | 526 | debug(3, 3) ("dump_acl: %s %s\n", name, ae->name); |
9ef28b60 | 527 | v = w = aclDumpGeneric(ae); |
56b63fa1 | 528 | while (v != NULL) { |
c68e9c6b | 529 | debug(3, 3) ("dump_acl: %s %s %s\n", name, ae->name, v->key); |
16300b58 | 530 | storeAppendPrintf(entry, "%s %s %s %s\n", |
531 | name, | |
9ef28b60 | 532 | ae->name, |
533 | aclTypeToStr(ae->type), | |
16300b58 | 534 | v->key); |
56b63fa1 | 535 | v = v->next; |
536 | } | |
537 | wordlistDestroy(&w); | |
9ef28b60 | 538 | ae = ae->next; |
56b63fa1 | 539 | } |
090089c4 | 540 | } |
541 | ||
8203a132 | 542 | static void |
9ef28b60 | 543 | parse_acl(acl ** ae) |
090089c4 | 544 | { |
9ef28b60 | 545 | aclParseAclLine(ae); |
f1dc9b30 | 546 | } |
547 | ||
548 | static void | |
9ef28b60 | 549 | free_acl(acl ** ae) |
f1dc9b30 | 550 | { |
9ef28b60 | 551 | aclDestroyAcls(ae); |
090089c4 | 552 | } |
553 | ||
8203a132 | 554 | static void |
16300b58 | 555 | dump_acl_access(StoreEntry * entry, const char *name, acl_access * head) |
30a4f2a8 | 556 | { |
56b63fa1 | 557 | acl_list *l; |
558 | while (head != NULL) { | |
505e35db | 559 | storeAppendPrintf(entry, "%s %s", |
0cdcddb9 | 560 | name, |
505e35db | 561 | head->allow ? "Allow" : "Deny"); |
562 | for (l = head->acl_list; l != NULL; l = l->next) { | |
563 | storeAppendPrintf(entry, " %s%s", | |
564 | l->op ? null_string : "!", | |
56b63fa1 | 565 | l->acl->name); |
16300b58 | 566 | } |
505e35db | 567 | storeAppendPrintf(entry, "\n"); |
56b63fa1 | 568 | head = head->next; |
569 | } | |
30a4f2a8 | 570 | } |
090089c4 | 571 | |
8203a132 | 572 | static void |
16300b58 | 573 | parse_acl_access(acl_access ** head) |
090089c4 | 574 | { |
270b86af | 575 | aclParseAccessLine(head); |
090089c4 | 576 | } |
577 | ||
0153d498 | 578 | static void |
16300b58 | 579 | free_acl_access(acl_access ** head) |
0153d498 | 580 | { |
a47b9029 | 581 | aclDestroyAccessList(head); |
0153d498 | 582 | } |
583 | ||
8203a132 | 584 | static void |
a7d59104 | 585 | dump_address(StoreEntry * entry, const char *name, struct in_addr addr) |
270b86af | 586 | { |
f53b06f9 | 587 | storeAppendPrintf(entry, "%s %s\n", name, inet_ntoa(addr)); |
270b86af | 588 | } |
589 | ||
590 | static void | |
591 | parse_address(struct in_addr *addr) | |
090089c4 | 592 | { |
0ee4272b | 593 | const struct hostent *hp; |
270b86af | 594 | char *token = strtok(NULL, w_space); |
595 | ||
30a4f2a8 | 596 | if (token == NULL) |
597 | self_destruct(); | |
429fdbec | 598 | if (safe_inet_addr(token, addr) == 1) |
599 | (void) 0; | |
ceb8994e | 600 | else if ((hp = gethostbyname(token))) /* dont use ipcache */ |
1d73e33a | 601 | *addr = inaddrFromHostent(hp); |
30a4f2a8 | 602 | else |
3003c0f3 | 603 | self_destruct(); |
090089c4 | 604 | } |
605 | ||
0153d498 | 606 | static void |
607 | free_address(struct in_addr *addr) | |
608 | { | |
a47b9029 | 609 | memset(addr, '\0', sizeof(struct in_addr)); |
0153d498 | 610 | } |
611 | ||
59715b38 | 612 | #if DELAY_POOLS |
613 | ||
614 | /* do nothing - free_delay_pool_count is the magic free function. | |
615 | * this is why delay_pool_count isn't just marked TYPE: ushort | |
616 | */ | |
617 | #define free_delay_pool_class(X) | |
618 | #define free_delay_pool_access(X) | |
619 | #define free_delay_pool_rates(X) | |
620 | #define dump_delay_pool_class(X, Y, Z) | |
621 | #define dump_delay_pool_access(X, Y, Z) | |
622 | #define dump_delay_pool_rates(X, Y, Z) | |
623 | ||
624 | static void | |
625 | free_delay_pool_count(delayConfig * cfg) | |
626 | { | |
627 | int i; | |
628 | ||
629 | if (!cfg->pools) | |
630 | return; | |
631 | for (i = 0; i < cfg->pools; i++) { | |
632 | if (cfg->class[i]) { | |
633 | delayFreeDelayPool(i); | |
634 | safe_free(cfg->rates[i]); | |
635 | } | |
636 | aclDestroyAccessList(&cfg->access[i]); | |
637 | } | |
638 | delayFreeDelayData(); | |
639 | xfree(cfg->class); | |
640 | xfree(cfg->rates); | |
641 | xfree(cfg->access); | |
642 | memset(cfg, 0, sizeof(*cfg)); | |
643 | } | |
644 | ||
645 | static void | |
646 | dump_delay_pool_count(StoreEntry * entry, const char *name, delayConfig cfg) | |
647 | { | |
648 | int i; | |
649 | LOCAL_ARRAY(char, nom, 32); | |
650 | ||
651 | if (!cfg.pools) { | |
652 | storeAppendPrintf(entry, "%s 0\n", name); | |
653 | return; | |
654 | } | |
655 | storeAppendPrintf(entry, "%s %d\n", name, cfg.pools); | |
656 | for (i = 0; i < cfg.pools; i++) { | |
657 | storeAppendPrintf(entry, "delay_class %d %d\n", i + 1, cfg.class[i]); | |
658 | snprintf(nom, 32, "delay_access %d", i + 1); | |
659 | dump_acl_access(entry, nom, cfg.access[i]); | |
660 | if (cfg.class[i] >= 1) | |
661 | storeAppendPrintf(entry, "delay_parameters %d %d/%d", i + 1, | |
662 | cfg.rates[i]->aggregate.restore_bps, | |
663 | cfg.rates[i]->aggregate.max_bytes); | |
664 | if (cfg.class[i] >= 3) | |
665 | storeAppendPrintf(entry, " %d/%d", | |
666 | cfg.rates[i]->network.restore_bps, | |
667 | cfg.rates[i]->network.max_bytes); | |
668 | if (cfg.class[i] >= 2) | |
669 | storeAppendPrintf(entry, " %d/%d", | |
670 | cfg.rates[i]->individual.restore_bps, | |
671 | cfg.rates[i]->individual.max_bytes); | |
672 | if (cfg.class[i] >= 1) | |
673 | storeAppendPrintf(entry, "\n"); | |
674 | } | |
675 | } | |
676 | ||
677 | static void | |
678 | parse_delay_pool_count(delayConfig * cfg) | |
679 | { | |
680 | if (cfg->pools) { | |
681 | debug(3, 0) ("parse_delay_pool_count: multiple delay_pools lines, aborting all previous delay_pools config\n"); | |
682 | free_delay_pool_count(cfg); | |
683 | } | |
684 | parse_ushort(&cfg->pools); | |
685 | delayInitDelayData(cfg->pools); | |
686 | cfg->class = xcalloc(cfg->pools, sizeof(u_char)); | |
687 | cfg->rates = xcalloc(cfg->pools, sizeof(delaySpecSet *)); | |
688 | cfg->access = xcalloc(cfg->pools, sizeof(acl_access *)); | |
689 | } | |
690 | ||
691 | static void | |
692 | parse_delay_pool_class(delayConfig * cfg) | |
693 | { | |
694 | ushort pool, class; | |
695 | ||
696 | parse_ushort(&pool); | |
697 | if (pool < 1 || pool > cfg->pools) { | |
698 | debug(3, 0) ("parse_delay_pool_class: Ignoring pool %d not in 1 .. %d\n", pool, cfg->pools); | |
699 | return; | |
700 | } | |
701 | parse_ushort(&class); | |
702 | if (class < 1 || class > 3) { | |
703 | debug(3, 0) ("parse_delay_pool_class: Ignoring pool %d class %d not in 1 .. 3\n", pool, class); | |
704 | return; | |
705 | } | |
706 | pool--; | |
707 | if (cfg->class[pool]) { | |
708 | delayFreeDelayPool(pool); | |
709 | safe_free(cfg->rates[pool]); | |
710 | } | |
711 | cfg->rates[pool] = xmalloc(class * sizeof(delaySpec)); | |
712 | cfg->class[pool] = class; | |
713 | cfg->rates[pool]->aggregate.restore_bps = cfg->rates[pool]->aggregate.max_bytes = -1; | |
714 | if (cfg->class[pool] >= 3) | |
715 | cfg->rates[pool]->network.restore_bps = cfg->rates[pool]->network.max_bytes = -1; | |
716 | if (cfg->class[pool] >= 2) | |
717 | cfg->rates[pool]->individual.restore_bps = cfg->rates[pool]->individual.max_bytes = -1; | |
718 | delayCreateDelayPool(pool, class); | |
719 | } | |
720 | ||
721 | static void | |
722 | parse_delay_pool_rates(delayConfig * cfg) | |
723 | { | |
724 | ushort pool, class; | |
725 | int i; | |
726 | delaySpec *ptr; | |
727 | char *token; | |
728 | ||
729 | parse_ushort(&pool); | |
730 | if (pool < 1 || pool > cfg->pools) { | |
731 | debug(3, 0) ("parse_delay_pool_rates: Ignoring pool %d not in 1 .. %d\n", pool, cfg->pools); | |
732 | return; | |
733 | } | |
734 | pool--; | |
735 | class = cfg->class[pool]; | |
736 | if (class == 0) { | |
737 | debug(3, 0) ("parse_delay_pool_rates: Ignoring pool %d attempt to set rates with class not set\n", pool + 1); | |
738 | return; | |
739 | } | |
740 | ptr = (delaySpec *) cfg->rates[pool]; | |
741 | /* read in "class" sets of restore,max pairs */ | |
742 | while (class--) { | |
743 | token = strtok(NULL, "/"); | |
744 | if (token == NULL) | |
745 | self_destruct(); | |
746 | if (sscanf(token, "%d", &i) != 1) | |
747 | self_destruct(); | |
748 | ptr->restore_bps = i; | |
0e4e0e7d | 749 | i = GetInteger(); |
59715b38 | 750 | ptr->max_bytes = i; |
751 | ptr++; | |
752 | } | |
753 | class = cfg->class[pool]; | |
754 | /* if class is 3, swap around network and individual */ | |
755 | if (class == 3) { | |
756 | delaySpec tmp; | |
757 | ||
758 | tmp = cfg->rates[pool]->individual; | |
759 | cfg->rates[pool]->individual = cfg->rates[pool]->network; | |
760 | cfg->rates[pool]->network = tmp; | |
761 | } | |
762 | /* initialize the delay pools */ | |
763 | delayInitDelayPool(pool, class, cfg->rates[pool]); | |
764 | } | |
765 | ||
766 | static void | |
767 | parse_delay_pool_access(delayConfig * cfg) | |
768 | { | |
769 | ushort pool; | |
770 | ||
771 | parse_ushort(&pool); | |
772 | if (pool < 1 || pool > cfg->pools) { | |
773 | debug(3, 0) ("parse_delay_pool_rates: Ignoring pool %d not in 1 .. %d\n", pool, cfg->pools); | |
774 | return; | |
775 | } | |
776 | aclParseAccessLine(&cfg->access[pool - 1]); | |
777 | } | |
778 | #endif | |
779 | ||
97474590 | 780 | static void |
781 | dump_http_header(StoreEntry * entry, const char *name, HttpHeaderMask header) | |
e3dd531e | 782 | { |
efd900cb | 783 | int i; |
784 | for (i = 0; i < HDR_OTHER; i++) { | |
785 | if (http_header_allowed && !CBIT_TEST(header, i)) | |
786 | storeAppendPrintf(entry, "%s allow %s\n", name, httpHeaderNameById(i)); | |
787 | else if (!http_header_allowed && CBIT_TEST(header, i)) | |
788 | storeAppendPrintf(entry, "%s deny %s\n", name, httpHeaderNameById(i)); | |
789 | } | |
97474590 | 790 | } |
e3dd531e | 791 | |
97474590 | 792 | static void |
793 | parse_http_header(HttpHeaderMask * header) | |
794 | { | |
795 | int allowed, id; | |
796 | char *t = NULL; | |
97474590 | 797 | if ((t = strtok(NULL, w_space)) == NULL) { |
798 | debug(3, 0) ("%s line %d: %s\n", | |
799 | cfg_filename, config_lineno, config_input_line); | |
800 | debug(3, 0) ("parse_http_header: missing 'allow' or 'deny'.\n"); | |
801 | return; | |
802 | } | |
803 | if (!strcmp(t, "allow")) | |
804 | allowed = 1; | |
805 | else if (!strcmp(t, "deny")) | |
806 | allowed = 0; | |
807 | else { | |
808 | debug(3, 0) ("%s line %d: %s\n", | |
809 | cfg_filename, config_lineno, config_input_line); | |
810 | debug(3, 0) ("parse_http_header: expecting 'allow' or 'deny', got '%s'.\n", t); | |
811 | return; | |
812 | } | |
e3dd531e | 813 | if (!http_header_first) { |
97474590 | 814 | http_header_first = 1; |
efd900cb | 815 | if (allowed) { |
816 | http_header_allowed = 1; | |
97474590 | 817 | httpHeaderMaskInit(header, 0xFF); |
efd900cb | 818 | } else { |
819 | http_header_allowed = 0; | |
820 | httpHeaderMaskInit(header, 0); | |
821 | } | |
97474590 | 822 | } |
97474590 | 823 | while ((t = strtok(NULL, w_space))) { |
824 | if ((id = httpHeaderIdByNameDef(t, strlen(t))) == -1) | |
efd900cb | 825 | debug(3, 0) ("parse_http_header: Ignoring unknown header '%s'\n", t); |
826 | else if (allowed) | |
97474590 | 827 | CBIT_CLR(*header, id); |
828 | else | |
829 | CBIT_SET(*header, id); | |
830 | } | |
831 | } | |
e3dd531e | 832 | |
97474590 | 833 | static void |
e3dd531e | 834 | free_http_header(HttpHeaderMask * header) |
835 | { | |
97474590 | 836 | httpHeaderMaskInit(header, 0); |
837 | } | |
838 | ||
e90100aa | 839 | static void |
56b63fa1 | 840 | dump_cachedir(StoreEntry * entry, const char *name, cacheSwap swap) |
e90100aa | 841 | { |
f53b06f9 | 842 | SwapDir *s; |
843 | int i; | |
a7d59104 | 844 | for (i = 0; i < swap.n_configured; i++) { |
845 | s = swap.swapDirs + i; | |
a4b8110e | 846 | s->dump(entry, name, s); |
f53b06f9 | 847 | } |
848 | } | |
849 | ||
850 | static int | |
56b63fa1 | 851 | check_null_cachedir(cacheSwap swap) |
f53b06f9 | 852 | { |
853 | return swap.swapDirs == NULL; | |
e90100aa | 854 | } |
855 | ||
53ad48e6 | 856 | static int |
857 | check_null_string(char *s) | |
858 | { | |
859 | return s == NULL; | |
860 | } | |
861 | ||
0e4e0e7d | 862 | void |
863 | allocate_new_swapdir(cacheSwap * swap) | |
090089c4 | 864 | { |
f1dc9b30 | 865 | if (swap->swapDirs == NULL) { |
866 | swap->n_allocated = 4; | |
867 | swap->swapDirs = xcalloc(swap->n_allocated, sizeof(SwapDir)); | |
868 | } | |
869 | if (swap->n_allocated == swap->n_configured) { | |
0e4e0e7d | 870 | SwapDir *tmp; |
f1dc9b30 | 871 | swap->n_allocated <<= 1; |
872 | tmp = xcalloc(swap->n_allocated, sizeof(SwapDir)); | |
873 | xmemcpy(tmp, swap->swapDirs, swap->n_configured * sizeof(SwapDir)); | |
874 | xfree(swap->swapDirs); | |
875 | swap->swapDirs = tmp; | |
876 | } | |
0e4e0e7d | 877 | } |
878 | ||
cd748f27 | 879 | static int |
880 | find_fstype(char *type) | |
881 | { | |
882 | int i; | |
883 | for (i = 0; storefs_list[i].typestr != NULL; i++) { | |
a4b8110e | 884 | if (strcasecmp(type, storefs_list[i].typestr) == 0) { |
cd748f27 | 885 | return i; |
886 | } | |
887 | } | |
888 | return (-1); | |
889 | } | |
890 | ||
0e4e0e7d | 891 | static void |
892 | parse_cachedir(cacheSwap * swap) | |
893 | { | |
894 | char *type_str; | |
cd748f27 | 895 | char *path_str; |
896 | SwapDir *sd; | |
897 | int i; | |
898 | int fs; | |
e8dbac8b | 899 | ssize_t maxobjsize; |
cd748f27 | 900 | |
0e4e0e7d | 901 | if ((type_str = strtok(NULL, w_space)) == NULL) |
902 | self_destruct(); | |
cd748f27 | 903 | |
e8dbac8b | 904 | maxobjsize = (ssize_t) GetInteger(); |
cd748f27 | 905 | |
906 | if ((path_str = strtok(NULL, w_space)) == NULL) | |
907 | self_destruct(); | |
908 | ||
909 | /* | |
910 | * This bit of code is a little strange. | |
911 | * See, if we find a path and type match for a given line, then | |
912 | * as long as we're reconfiguring, we can just call its reconfigure | |
913 | * function. No harm there. | |
914 | * | |
915 | * Trouble is, if we find a path match, but not a type match, we have | |
916 | * a dilemma - we could gracefully shut down the fs, kill it, and | |
917 | * create a new one of a new type in its place, BUT at this stage the | |
918 | * fs is meant to be the *NEW* one, and so things go very strange. :-) | |
919 | * | |
920 | * So, we'll assume the person isn't going to change the fs type for now, | |
921 | * and XXX later on we will make sure that its picked up. | |
922 | * | |
923 | * (moving around cache_dir lines will be looked at later in a little | |
924 | * more sane detail..) | |
925 | */ | |
926 | ||
927 | for (i = 0; i < swap->n_configured; i++) { | |
a4b8110e | 928 | if (0 == strcasecmp(path_str, swap->swapDirs[i].path)) { |
cd748f27 | 929 | /* This is a little weird, you'll appreciate it later */ |
930 | fs = find_fstype(type_str); | |
931 | if (fs < 0) { | |
a4b8110e | 932 | fatalf("Unknown cache_dir type '%s'\n", type_str); |
cd748f27 | 933 | } |
934 | sd = swap->swapDirs + i; | |
935 | storefs_list[fs].reconfigurefunc(sd, i, path_str); | |
a4b8110e | 936 | sd->max_objsize = maxobjsize; |
937 | update_maxobjsize(); | |
938 | return; | |
cd748f27 | 939 | } |
940 | } | |
941 | ||
942 | fs = find_fstype(type_str); | |
943 | if (fs < 0) { | |
a4b8110e | 944 | /* If we get here, we didn't find a matching cache_dir type */ |
945 | fatalf("Unknown cache_dir type '%s'\n", type_str); | |
0e4e0e7d | 946 | } |
cd748f27 | 947 | allocate_new_swapdir(swap); |
948 | sd = swap->swapDirs + swap->n_configured; | |
949 | storefs_list[fs].parsefunc(sd, swap->n_configured, path_str); | |
950 | /* XXX should we dupe the string here, in case it gets trodden on? */ | |
951 | sd->type = storefs_list[fs].typestr; | |
952 | sd->max_objsize = maxobjsize; | |
90d42c28 | 953 | /* defaults in case fs implementation fails to set these */ |
954 | sd->fs.blksize = 1024; | |
955 | sd->fs.kperblk = 1; | |
cd748f27 | 956 | swap->n_configured++; |
957 | /* Update the max object size */ | |
958 | update_maxobjsize(); | |
752c3b27 | 959 | } |
960 | ||
8203a132 | 961 | static void |
16300b58 | 962 | free_cachedir(cacheSwap * swap) |
f1dc9b30 | 963 | { |
a47b9029 | 964 | SwapDir *s; |
965 | int i; | |
860ee7e3 | 966 | /* DON'T FREE THESE FOR RECONFIGURE */ |
5cd39a10 | 967 | if (reconfiguring) |
860ee7e3 | 968 | return; |
a47b9029 | 969 | for (i = 0; i < swap->n_configured; i++) { |
970 | s = swap->swapDirs + i; | |
cd748f27 | 971 | s->freefs(s); |
a47b9029 | 972 | xfree(s->path); |
a47b9029 | 973 | } |
974 | safe_free(swap->swapDirs); | |
975 | swap->swapDirs = NULL; | |
976 | swap->n_allocated = 0; | |
977 | swap->n_configured = 0; | |
f1dc9b30 | 978 | } |
979 | ||
505e35db | 980 | const char * |
981 | peer_type_str(const peer_t type) | |
982 | { | |
0cdcddb9 | 983 | switch (type) { |
505e35db | 984 | case PEER_PARENT: |
985 | return "parent"; | |
986 | break; | |
987 | case PEER_SIBLING: | |
988 | return "sibling"; | |
989 | break; | |
990 | case PEER_MULTICAST: | |
991 | return "multicast"; | |
992 | break; | |
993 | default: | |
994 | return "unknown"; | |
995 | break; | |
996 | } | |
997 | } | |
998 | ||
f1dc9b30 | 999 | static void |
a7d59104 | 1000 | dump_peer(StoreEntry * entry, const char *name, peer * p) |
98ffb7e4 | 1001 | { |
505e35db | 1002 | domain_ping *d; |
1003 | acl_access *a; | |
1004 | domain_type *t; | |
1005 | LOCAL_ARRAY(char, xname, 128); | |
d41de3c1 | 1006 | while (p != NULL) { |
1007 | storeAppendPrintf(entry, "%s %s %s %d %d", | |
1008 | name, | |
1009 | p->host, | |
1010 | neighborTypeStr(p), | |
1011 | p->http_port, | |
399cabec | 1012 | p->icp.port); |
a369131d | 1013 | dump_peer_options(entry, p); |
b6a2f15e | 1014 | for (d = p->peer_domain; d; d = d->next) { |
505e35db | 1015 | storeAppendPrintf(entry, "cache_peer_domain %s %s%s\n", |
1016 | p->host, | |
1017 | d->do_ping ? null_string : "!", | |
1018 | d->domain); | |
1019 | } | |
1020 | if ((a = p->access)) { | |
1021 | snprintf(xname, 128, "cache_peer_access %s", p->host); | |
1022 | dump_acl_access(entry, xname, p->access); | |
1023 | } | |
1024 | for (t = p->typelist; t; t = t->next) { | |
1025 | storeAppendPrintf(entry, "neighbor_type_domain %s %s %s\n", | |
1026 | p->host, | |
1027 | peer_type_str(t->type), | |
1028 | t->domain); | |
1029 | } | |
d41de3c1 | 1030 | p = p->next; |
1031 | } | |
98ffb7e4 | 1032 | } |
1033 | ||
8203a132 | 1034 | static void |
40a1495e | 1035 | parse_peer(peer ** head) |
7813c6d5 | 1036 | { |
270b86af | 1037 | char *token = NULL; |
40a1495e | 1038 | peer *p; |
7813c6d5 | 1039 | int i; |
e13ee7ad | 1040 | p = memAllocate(MEM_PEER); |
40a1495e | 1041 | p->http_port = CACHE_HTTP_PORT; |
399cabec | 1042 | p->icp.port = CACHE_ICP_PORT; |
40a1495e | 1043 | p->weight = 1; |
dc835977 | 1044 | p->stats.logged_state = PEER_ALIVE; |
e481c2dc | 1045 | if ((token = strtok(NULL, w_space)) == NULL) |
270b86af | 1046 | self_destruct(); |
40a1495e | 1047 | p->host = xstrdup(token); |
e481c2dc | 1048 | if ((token = strtok(NULL, w_space)) == NULL) |
270b86af | 1049 | self_destruct(); |
40a1495e | 1050 | p->type = parseNeighborType(token); |
0e4e0e7d | 1051 | i = GetInteger(); |
40a1495e | 1052 | p->http_port = (u_short) i; |
0e4e0e7d | 1053 | i = GetInteger(); |
399cabec | 1054 | p->icp.port = (u_short) i; |
270b86af | 1055 | while ((token = strtok(NULL, w_space))) { |
1056 | if (!strcasecmp(token, "proxy-only")) { | |
cd196bc8 | 1057 | p->options.proxy_only = 1; |
270b86af | 1058 | } else if (!strcasecmp(token, "no-query")) { |
cd196bc8 | 1059 | p->options.no_query = 1; |
8638fc66 | 1060 | } else if (!strcasecmp(token, "no-digest")) { |
cd196bc8 | 1061 | p->options.no_digest = 1; |
270b86af | 1062 | } else if (!strcasecmp(token, "multicast-responder")) { |
cd196bc8 | 1063 | p->options.mcast_responder = 1; |
270b86af | 1064 | } else if (!strncasecmp(token, "weight=", 7)) { |
40a1495e | 1065 | p->weight = atoi(token + 7); |
0103c4c1 | 1066 | } else if (!strcasecmp(token, "closest-only")) { |
cd196bc8 | 1067 | p->options.closest_only = 1; |
270b86af | 1068 | } else if (!strncasecmp(token, "ttl=", 4)) { |
40a1495e | 1069 | p->mcast.ttl = atoi(token + 4); |
1070 | if (p->mcast.ttl < 0) | |
1071 | p->mcast.ttl = 0; | |
1072 | if (p->mcast.ttl > 128) | |
1073 | p->mcast.ttl = 128; | |
0103c4c1 | 1074 | } else if (!strcasecmp(token, "default")) { |
cd196bc8 | 1075 | p->options.default_parent = 1; |
0103c4c1 | 1076 | } else if (!strcasecmp(token, "round-robin")) { |
cd196bc8 | 1077 | p->options.roundrobin = 1; |
dc9d133b | 1078 | #if USE_HTCP |
0103c4c1 | 1079 | } else if (!strcasecmp(token, "htcp")) { |
cd196bc8 | 1080 | p->options.htcp = 1; |
dc9d133b | 1081 | #endif |
0103c4c1 | 1082 | } else if (!strcasecmp(token, "no-netdb-exchange")) { |
cd196bc8 | 1083 | p->options.no_netdb_exchange = 1; |
afd88fbe | 1084 | #if USE_CARP |
1085 | } else if (!strncasecmp(token, "carp-load-factor=", 17)) { | |
1086 | if (p->type != PEER_PARENT) | |
0cdcddb9 | 1087 | debug(3, 0) ("parse_peer: Ignoring carp-load-factor for non-parent %s/%d\n", p->host, p->http_port); |
1088 | else | |
1089 | p->carp.load_factor = atof(token + 17); | |
95e36d02 | 1090 | #endif |
1091 | #if DELAY_POOLS | |
1092 | } else if (!strcasecmp(token, "no-delay")) { | |
cd196bc8 | 1093 | p->options.no_delay = 1; |
afd88fbe | 1094 | #endif |
c68e9c6b | 1095 | } else if (!strncasecmp(token, "login=", 6)) { |
1096 | p->login = xstrdup(token + 6); | |
3f62decd | 1097 | } else if (!strncasecmp(token, "connect-timeout=", 16)) { |
1098 | p->connect_timeout = atoi(token + 16); | |
7e3ce7b9 | 1099 | #if USE_CACHE_DIGESTS |
1100 | } else if (!strncasecmp(token, "digest-url=", 11)) { | |
1101 | p->digest_url = xstrdup(token + 11); | |
1102 | #endif | |
987de783 | 1103 | } else if (!strcasecmp(token, "allow-miss")) { |
1104 | p->options.allow_miss = 1; | |
c7f9eb6d | 1105 | } else if (!strcasecmp(token, "max-conn=")) { |
1106 | p->max_conn = atoi(token + 9); | |
270b86af | 1107 | } else { |
40a1495e | 1108 | debug(3, 0) ("parse_peer: token='%s'\n", token); |
270b86af | 1109 | self_destruct(); |
1110 | } | |
1111 | } | |
40a1495e | 1112 | if (p->weight < 1) |
1113 | p->weight = 1; | |
399cabec | 1114 | p->icp.version = ICP_VERSION_CURRENT; |
98829f69 | 1115 | p->tcp_up = PEER_TCP_MAGIC_COUNT; |
eb406bb7 | 1116 | p->test_fd = -1; |
afd88fbe | 1117 | #if USE_CARP |
8ee9b49f | 1118 | #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) |
afd88fbe | 1119 | if (p->carp.load_factor) { |
e13ee7ad | 1120 | /* calculate this peers hash for use in CARP */ |
0cdcddb9 | 1121 | p->carp.hash = 0; |
1122 | for (token = p->host; *token != 0; token++) | |
8ee9b49f | 1123 | p->carp.hash += ROTATE_LEFT(p->carp.hash, 19) + (unsigned int) *token; |
d20b1cd0 | 1124 | p->carp.hash += p->carp.hash * 0x62531965; |
8ee9b49f | 1125 | p->carp.hash = ROTATE_LEFT(p->carp.hash, 21); |
afd88fbe | 1126 | } |
1127 | #endif | |
b6a2f15e | 1128 | /* This must preceed peerDigestCreate */ |
1129 | cbdataAdd(p, peerDestroy, MEM_PEER); | |
e13ee7ad | 1130 | #if USE_CACHE_DIGESTS |
1131 | if (!p->options.no_digest) { | |
1132 | p->digest = peerDigestCreate(p); | |
8a6218c6 | 1133 | cbdataLock(p->digest); /* so we know when/if digest disappears */ |
1134 | } | |
e13ee7ad | 1135 | #endif |
0153d498 | 1136 | while (*head != NULL) |
1137 | head = &(*head)->next; | |
1138 | *head = p; | |
40a1495e | 1139 | Config.npeers++; |
82056f1e | 1140 | peerClearRR(p); |
0153d498 | 1141 | } |
1142 | ||
1143 | static void | |
40a1495e | 1144 | free_peer(peer ** P) |
0153d498 | 1145 | { |
40a1495e | 1146 | peer *p; |
79d39a72 | 1147 | while ((p = *P) != NULL) { |
a47b9029 | 1148 | *P = p->next; |
3855c318 | 1149 | #if USE_CACHE_DIGESTS |
1150 | if (p->digest) | |
1151 | cbdataUnlock(p->digest); | |
1152 | p->digest = NULL; | |
1153 | #endif | |
41042c81 | 1154 | cbdataFree(p); |
a47b9029 | 1155 | } |
987c67d1 | 1156 | Config.npeers = 0; |
270b86af | 1157 | } |
1158 | ||
1159 | static void | |
a7d59104 | 1160 | dump_cachemgrpasswd(StoreEntry * entry, const char *name, cachemgr_passwd * list) |
270b86af | 1161 | { |
d41de3c1 | 1162 | wordlist *w; |
1163 | while (list != NULL) { | |
74aa8456 | 1164 | if (strcmp(list->passwd, "none") && strcmp(list->passwd, "disable")) |
1165 | storeAppendPrintf(entry, "%s XXXXXXXXXX", name); | |
1166 | else | |
1167 | storeAppendPrintf(entry, "%s %s", name, list->passwd); | |
d41de3c1 | 1168 | for (w = list->actions; w != NULL; w = w->next) { |
1169 | storeAppendPrintf(entry, " %s", w->key); | |
1170 | } | |
1171 | storeAppendPrintf(entry, "\n"); | |
1172 | list = list->next; | |
1173 | } | |
270b86af | 1174 | } |
1175 | ||
1176 | static void | |
a47b9029 | 1177 | parse_cachemgrpasswd(cachemgr_passwd ** head) |
270b86af | 1178 | { |
1179 | char *passwd = NULL; | |
1180 | wordlist *actions = NULL; | |
22f3fd98 | 1181 | cachemgr_passwd *p; |
1182 | cachemgr_passwd **P; | |
270b86af | 1183 | parse_string(&passwd); |
1184 | parse_wordlist(&actions); | |
22f3fd98 | 1185 | p = xcalloc(1, sizeof(cachemgr_passwd)); |
1186 | p->passwd = passwd; | |
1187 | p->actions = actions; | |
1188 | for (P = head; *P; P = &(*P)->next); | |
1189 | *P = p; | |
270b86af | 1190 | } |
1191 | ||
1192 | static void | |
a47b9029 | 1193 | free_cachemgrpasswd(cachemgr_passwd ** head) |
270b86af | 1194 | { |
a47b9029 | 1195 | cachemgr_passwd *p; |
79d39a72 | 1196 | while ((p = *head) != NULL) { |
a47b9029 | 1197 | *head = p->next; |
1198 | xfree(p->passwd); | |
22f3fd98 | 1199 | wordlistDestroy(&p->actions); |
a47b9029 | 1200 | xfree(p); |
1201 | } | |
270b86af | 1202 | } |
1203 | ||
8203a132 | 1204 | static void |
16300b58 | 1205 | dump_denyinfo(StoreEntry * entry, const char *name, acl_deny_info_list * var) |
270b86af | 1206 | { |
d41de3c1 | 1207 | acl_name_list *a; |
1208 | while (var != NULL) { | |
02922e76 | 1209 | storeAppendPrintf(entry, "%s %s", name, var->err_page_name); |
d41de3c1 | 1210 | for (a = var->acl_list; a != NULL; a = a->next) |
1211 | storeAppendPrintf(entry, " %s", a->name); | |
1212 | storeAppendPrintf(entry, "\n"); | |
1213 | var = var->next; | |
1214 | } | |
270b86af | 1215 | } |
1216 | ||
1217 | static void | |
16300b58 | 1218 | parse_denyinfo(acl_deny_info_list ** var) |
6e40f263 | 1219 | { |
f1dc9b30 | 1220 | aclParseDenyInfoLine(var); |
6e40f263 | 1221 | } |
403279e0 | 1222 | |
1273d501 | 1223 | void |
a47b9029 | 1224 | free_denyinfo(acl_deny_info_list ** list) |
3c5557f9 | 1225 | { |
56b63fa1 | 1226 | acl_deny_info_list *a = NULL; |
1227 | acl_deny_info_list *a_next = NULL; | |
1228 | acl_name_list *l = NULL; | |
1229 | acl_name_list *l_next = NULL; | |
1273d501 | 1230 | for (a = *list; a; a = a_next) { |
a47b9029 | 1231 | for (l = a->acl_list; l; l = l_next) { |
1232 | l_next = l->next; | |
3314e65b | 1233 | memFree(l, MEM_ACL_NAME_LIST); |
eeda4c4d | 1234 | l = NULL; |
a47b9029 | 1235 | } |
1236 | a_next = a->next; | |
eeda4c4d | 1237 | memFree(a, MEM_ACL_DENY_INFO_LIST); |
1238 | a = NULL; | |
1273d501 | 1239 | } |
1240 | *list = NULL; | |
270b86af | 1241 | } |
1242 | ||
1243 | static void | |
505e35db | 1244 | parse_peer_access(void) |
270b86af | 1245 | { |
1246 | char *host = NULL; | |
505e35db | 1247 | peer *p; |
270b86af | 1248 | if (!(host = strtok(NULL, w_space))) |
1249 | self_destruct(); | |
0cdcddb9 | 1250 | if ((p = peerFindByName(host)) == NULL) { |
1251 | debug(15, 0) ("%s, line %d: No cache_peer '%s'\n", | |
1252 | cfg_filename, config_lineno, host); | |
1253 | return; | |
1254 | } | |
505e35db | 1255 | aclParseAccessLine(&p->access); |
270b86af | 1256 | } |
1257 | ||
270b86af | 1258 | static void |
1259 | parse_hostdomain(void) | |
1260 | { | |
1261 | char *host = NULL; | |
1262 | char *domain = NULL; | |
1263 | if (!(host = strtok(NULL, w_space))) | |
1264 | self_destruct(); | |
f1dc9b30 | 1265 | while ((domain = strtok(NULL, list_sep))) { |
1266 | domain_ping *l = NULL; | |
1267 | domain_ping **L = NULL; | |
40a1495e | 1268 | peer *p; |
1269 | if ((p = peerFindByName(host)) == NULL) { | |
43c3424b | 1270 | debug(15, 0) ("%s, line %d: No cache_peer '%s'\n", |
f1dc9b30 | 1271 | cfg_filename, config_lineno, host); |
1272 | continue; | |
1273 | } | |
56b63fa1 | 1274 | l = xcalloc(1, sizeof(domain_ping)); |
f1dc9b30 | 1275 | l->do_ping = 1; |
1276 | if (*domain == '!') { /* check for !.edu */ | |
1277 | l->do_ping = 0; | |
1278 | domain++; | |
1279 | } | |
1280 | l->domain = xstrdup(domain); | |
b6a2f15e | 1281 | for (L = &(p->peer_domain); *L; L = &((*L)->next)); |
f1dc9b30 | 1282 | *L = l; |
1283 | } | |
270b86af | 1284 | } |
1285 | ||
1286 | static void | |
1287 | parse_hostdomaintype(void) | |
1288 | { | |
1289 | char *host = NULL; | |
1290 | char *type = NULL; | |
1291 | char *domain = NULL; | |
1292 | if (!(host = strtok(NULL, w_space))) | |
1293 | self_destruct(); | |
1294 | if (!(type = strtok(NULL, w_space))) | |
1295 | self_destruct(); | |
f1dc9b30 | 1296 | while ((domain = strtok(NULL, list_sep))) { |
1297 | domain_type *l = NULL; | |
1298 | domain_type **L = NULL; | |
40a1495e | 1299 | peer *p; |
1300 | if ((p = peerFindByName(host)) == NULL) { | |
43c3424b | 1301 | debug(15, 0) ("%s, line %d: No cache_peer '%s'\n", |
f1dc9b30 | 1302 | cfg_filename, config_lineno, host); |
1303 | return; | |
1304 | } | |
56b63fa1 | 1305 | l = xcalloc(1, sizeof(domain_type)); |
f1dc9b30 | 1306 | l->type = parseNeighborType(type); |
1307 | l->domain = xstrdup(domain); | |
1308 | for (L = &(p->typelist); *L; L = &((*L)->next)); | |
1309 | *L = l; | |
1310 | } | |
270b86af | 1311 | } |
1312 | ||
7e3ce7b9 | 1313 | #if UNUSED_CODE |
270b86af | 1314 | static void |
a7d59104 | 1315 | dump_ushortlist(StoreEntry * entry, const char *name, ushortlist * u) |
090089c4 | 1316 | { |
270b86af | 1317 | while (u) { |
f53b06f9 | 1318 | storeAppendPrintf(entry, "%s %d\n", name, (int) u->i); |
270b86af | 1319 | u = u->next; |
1320 | } | |
1321 | } | |
090089c4 | 1322 | |
f53b06f9 | 1323 | static int |
1324 | check_null_ushortlist(ushortlist * u) | |
1325 | { | |
1326 | return u == NULL; | |
1327 | } | |
1328 | ||
270b86af | 1329 | static void |
1330 | parse_ushortlist(ushortlist ** P) | |
1331 | { | |
1332 | char *token; | |
1333 | int i; | |
1334 | ushortlist *u; | |
1335 | ushortlist **U; | |
1336 | while ((token = strtok(NULL, w_space))) { | |
1337 | if (sscanf(token, "%d", &i) != 1) | |
1338 | self_destruct(); | |
1339 | if (i < 0) | |
1340 | i = 0; | |
1341 | u = xcalloc(1, sizeof(ushortlist)); | |
1342 | u->i = (u_short) i; | |
1343 | for (U = P; *U; U = &(*U)->next); | |
1344 | *U = u; | |
090089c4 | 1345 | } |
270b86af | 1346 | } |
090089c4 | 1347 | |
0153d498 | 1348 | static void |
a47b9029 | 1349 | free_ushortlist(ushortlist ** P) |
0153d498 | 1350 | { |
a47b9029 | 1351 | ushortlist *u; |
79d39a72 | 1352 | while ((u = *P) != NULL) { |
a47b9029 | 1353 | *P = u->next; |
1354 | xfree(u); | |
1355 | } | |
0153d498 | 1356 | } |
7e3ce7b9 | 1357 | #endif |
0153d498 | 1358 | |
270b86af | 1359 | static void |
a7d59104 | 1360 | dump_int(StoreEntry * entry, const char *name, int var) |
270b86af | 1361 | { |
f53b06f9 | 1362 | storeAppendPrintf(entry, "%s %d\n", name, var); |
270b86af | 1363 | } |
c1c29eb6 | 1364 | |
270b86af | 1365 | static void |
1366 | parse_int(int *var) | |
1367 | { | |
270b86af | 1368 | int i; |
0e4e0e7d | 1369 | i = GetInteger(); |
270b86af | 1370 | *var = i; |
1371 | } | |
090089c4 | 1372 | |
0153d498 | 1373 | static void |
1374 | free_int(int *var) | |
1375 | { | |
a47b9029 | 1376 | *var = 0; |
0153d498 | 1377 | } |
1378 | ||
270b86af | 1379 | static void |
a7d59104 | 1380 | dump_onoff(StoreEntry * entry, const char *name, int var) |
270b86af | 1381 | { |
f53b06f9 | 1382 | storeAppendPrintf(entry, "%s %s\n", name, var ? "on" : "off"); |
270b86af | 1383 | } |
090089c4 | 1384 | |
270b86af | 1385 | static void |
1386 | parse_onoff(int *var) | |
1387 | { | |
1388 | char *token = strtok(NULL, w_space); | |
090089c4 | 1389 | |
270b86af | 1390 | if (token == NULL) |
1391 | self_destruct(); | |
1392 | if (!strcasecmp(token, "on") || !strcasecmp(token, "enable")) | |
1393 | *var = 1; | |
1394 | else | |
1395 | *var = 0; | |
1396 | } | |
e90100aa | 1397 | |
0153d498 | 1398 | #define free_onoff free_int |
f1dc9b30 | 1399 | #define dump_eol dump_string |
1400 | #define free_eol free_string | |
30a4f2a8 | 1401 | |
270b86af | 1402 | static void |
a7d59104 | 1403 | dump_refreshpattern(StoreEntry * entry, const char *name, refresh_t * head) |
270b86af | 1404 | { |
d41de3c1 | 1405 | while (head != NULL) { |
9f60cfdf | 1406 | storeAppendPrintf(entry, "%s%s %s %d %d%% %d\n", |
c3f6d204 | 1407 | name, |
1408 | head->flags.icase ? " -i" : null_string, | |
1409 | head->pattern, | |
1410 | (int) head->min / 60, | |
1411 | (int) (100.0 * head->pct + 0.5), | |
9f60cfdf | 1412 | (int) head->max / 60); |
1413 | #if HTTP_VIOLATIONS | |
1414 | if (head->flags.override_expire) | |
1415 | storeAppendPrintf(entry, " override-expire"); | |
1416 | if (head->flags.override_lastmod) | |
1417 | storeAppendPrintf(entry, " override-lastmod"); | |
1418 | if (head->flags.reload_into_ims) | |
1419 | storeAppendPrintf(entry, " reload-into-ims"); | |
1420 | if (head->flags.ignore_reload) | |
1421 | storeAppendPrintf(entry, " ignore-reload"); | |
1422 | #endif | |
1423 | storeAppendPrintf(entry, "\n"); | |
d41de3c1 | 1424 | head = head->next; |
1425 | } | |
270b86af | 1426 | } |
090089c4 | 1427 | |
270b86af | 1428 | static void |
f1dc9b30 | 1429 | parse_refreshpattern(refresh_t ** head) |
270b86af | 1430 | { |
f1dc9b30 | 1431 | char *token; |
1432 | char *pattern; | |
1433 | time_t min = 0; | |
c3f6d204 | 1434 | double pct = 0.0; |
f1dc9b30 | 1435 | time_t max = 0; |
9f60cfdf | 1436 | #if HTTP_VIOLATIONS |
1dfa1d81 | 1437 | int override_expire = 0; |
1438 | int override_lastmod = 0; | |
cbe3a719 | 1439 | int reload_into_ims = 0; |
1440 | int ignore_reload = 0; | |
9f60cfdf | 1441 | #endif |
f1dc9b30 | 1442 | int i; |
1443 | refresh_t *t; | |
1444 | regex_t comp; | |
1445 | int errcode; | |
1446 | int flags = REG_EXTENDED | REG_NOSUB; | |
1447 | if ((token = strtok(NULL, w_space)) == NULL) | |
1448 | self_destruct(); | |
1449 | if (strcmp(token, "-i") == 0) { | |
1450 | flags |= REG_ICASE; | |
1451 | token = strtok(NULL, w_space); | |
1452 | } else if (strcmp(token, "+i") == 0) { | |
1453 | flags &= ~REG_ICASE; | |
1454 | token = strtok(NULL, w_space); | |
1455 | } | |
1456 | if (token == NULL) | |
1457 | self_destruct(); | |
1458 | pattern = xstrdup(token); | |
0e4e0e7d | 1459 | i = GetInteger(); /* token: min */ |
f1dc9b30 | 1460 | min = (time_t) (i * 60); /* convert minutes to seconds */ |
0e4e0e7d | 1461 | i = GetInteger(); /* token: pct */ |
c3f6d204 | 1462 | pct = (double) i / 100.0; |
0e4e0e7d | 1463 | i = GetInteger(); /* token: max */ |
f1dc9b30 | 1464 | max = (time_t) (i * 60); /* convert minutes to seconds */ |
1dfa1d81 | 1465 | /* Options */ |
1466 | while ((token = strtok(NULL, w_space)) != NULL) { | |
9f60cfdf | 1467 | #if HTTP_VIOLATIONS |
1dfa1d81 | 1468 | if (!strcmp(token, "override-expire")) |
1469 | override_expire = 1; | |
255d6021 | 1470 | else if (!strcmp(token, "override-lastmod")) |
1dfa1d81 | 1471 | override_lastmod = 1; |
cbe3a719 | 1472 | else if (!strcmp(token, "reload-into-ims")) { |
1473 | reload_into_ims = 1; | |
1474 | refresh_nocache_hack = 1; | |
1475 | /* tell client_side.c that this is used */ | |
1476 | } else if (!strcmp(token, "ignore-reload")) { | |
1477 | ignore_reload = 1; | |
1478 | refresh_nocache_hack = 1; | |
1479 | /* tell client_side.c that this is used */ | |
1480 | } else | |
9f60cfdf | 1481 | #endif |
cbe3a719 | 1482 | debug(22, 0) ("redreshAddToList: Unknown option '%s': %s\n", |
1dfa1d81 | 1483 | pattern, token); |
1484 | } | |
f1dc9b30 | 1485 | if ((errcode = regcomp(&comp, pattern, flags)) != 0) { |
1486 | char errbuf[256]; | |
1487 | regerror(errcode, &comp, errbuf, sizeof errbuf); | |
1488 | debug(22, 0) ("%s line %d: %s\n", | |
1489 | cfg_filename, config_lineno, config_input_line); | |
1490 | debug(22, 0) ("refreshAddToList: Invalid regular expression '%s': %s\n", | |
1491 | pattern, errbuf); | |
1492 | return; | |
1493 | } | |
c3f6d204 | 1494 | pct = pct < 0.0 ? 0.0 : pct; |
f1dc9b30 | 1495 | max = max < 0 ? 0 : max; |
1496 | t = xcalloc(1, sizeof(refresh_t)); | |
1497 | t->pattern = (char *) xstrdup(pattern); | |
1498 | t->compiled_pattern = comp; | |
1499 | t->min = min; | |
c3f6d204 | 1500 | t->pct = pct; |
f1dc9b30 | 1501 | t->max = max; |
c3f6d204 | 1502 | if (flags & REG_ICASE) |
1503 | t->flags.icase = 1; | |
9f60cfdf | 1504 | #if HTTP_VIOLATIONS |
1dfa1d81 | 1505 | if (override_expire) |
1506 | t->flags.override_expire = 1; | |
1507 | if (override_lastmod) | |
1508 | t->flags.override_lastmod = 1; | |
cbe3a719 | 1509 | if (reload_into_ims) |
1510 | t->flags.reload_into_ims = 1; | |
1511 | if (ignore_reload) | |
1512 | t->flags.ignore_reload = 1; | |
9f60cfdf | 1513 | #endif |
f1dc9b30 | 1514 | t->next = NULL; |
1515 | while (*head) | |
1516 | head = &(*head)->next; | |
1517 | *head = t; | |
1518 | safe_free(pattern); | |
270b86af | 1519 | } |
090089c4 | 1520 | |
6b53c392 | 1521 | static int |
a4b8110e | 1522 | check_null_refreshpattern(refresh_t * data) |
6b53c392 | 1523 | { |
1524 | return data != NULL; | |
1525 | } | |
1526 | ||
270b86af | 1527 | static void |
a47b9029 | 1528 | free_refreshpattern(refresh_t ** head) |
270b86af | 1529 | { |
f1dc9b30 | 1530 | refresh_t *t; |
79d39a72 | 1531 | while ((t = *head) != NULL) { |
f1dc9b30 | 1532 | *head = t->next; |
1533 | safe_free(t->pattern); | |
1534 | regfree(&t->compiled_pattern); | |
1535 | safe_free(t); | |
1536 | } | |
270b86af | 1537 | } |
12b9e9b1 | 1538 | |
270b86af | 1539 | static void |
a7d59104 | 1540 | dump_string(StoreEntry * entry, const char *name, char *var) |
270b86af | 1541 | { |
f53b06f9 | 1542 | if (var != NULL) |
a7d59104 | 1543 | storeAppendPrintf(entry, "%s %s\n", name, var); |
270b86af | 1544 | } |
98ffb7e4 | 1545 | |
270b86af | 1546 | static void |
0153d498 | 1547 | parse_string(char **var) |
270b86af | 1548 | { |
1549 | char *token = strtok(NULL, w_space); | |
270b86af | 1550 | safe_free(*var); |
1551 | if (token == NULL) | |
1552 | self_destruct(); | |
1553 | *var = xstrdup(token); | |
1554 | } | |
b15e6857 | 1555 | |
0153d498 | 1556 | static void |
1557 | free_string(char **var) | |
1558 | { | |
027acbaf | 1559 | safe_free(*var); |
0153d498 | 1560 | } |
caebbe00 | 1561 | |
270b86af | 1562 | static void |
f1dc9b30 | 1563 | parse_eol(char *volatile *var) |
270b86af | 1564 | { |
1565 | char *token = strtok(NULL, null_string); | |
270b86af | 1566 | safe_free(*var); |
f1dc9b30 | 1567 | if (token == NULL) |
1568 | self_destruct(); | |
270b86af | 1569 | *var = xstrdup(token); |
1570 | } | |
090089c4 | 1571 | |
270b86af | 1572 | static void |
a7d59104 | 1573 | dump_time_t(StoreEntry * entry, const char *name, time_t var) |
090089c4 | 1574 | { |
f53b06f9 | 1575 | storeAppendPrintf(entry, "%s %d seconds\n", name, (int) var); |
090089c4 | 1576 | } |
1577 | ||
270b86af | 1578 | static void |
a47b9029 | 1579 | parse_time_t(time_t * var) |
0ffd22bc | 1580 | { |
f1dc9b30 | 1581 | parseTimeLine(var, T_SECOND_STR); |
0ffd22bc | 1582 | } |
1583 | ||
270b86af | 1584 | static void |
a47b9029 | 1585 | free_time_t(time_t * var) |
270b86af | 1586 | { |
a47b9029 | 1587 | *var = 0; |
270b86af | 1588 | } |
9906e724 | 1589 | |
1590 | static void | |
a7d59104 | 1591 | dump_size_t(StoreEntry * entry, const char *name, size_t var) |
1b635117 | 1592 | { |
f53b06f9 | 1593 | storeAppendPrintf(entry, "%s %d\n", name, (int) var); |
1b635117 | 1594 | } |
1595 | ||
1596 | static void | |
a7d59104 | 1597 | dump_b_size_t(StoreEntry * entry, const char *name, size_t var) |
9906e724 | 1598 | { |
f53b06f9 | 1599 | storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_BYTES_STR); |
9906e724 | 1600 | } |
1601 | ||
1602 | static void | |
a7d59104 | 1603 | dump_kb_size_t(StoreEntry * entry, const char *name, size_t var) |
9906e724 | 1604 | { |
f53b06f9 | 1605 | storeAppendPrintf(entry, "%s %d %s\n", name, (int) var, B_KBYTES_STR); |
9906e724 | 1606 | } |
1607 | ||
1608 | static void | |
a47b9029 | 1609 | parse_size_t(size_t * var) |
1b635117 | 1610 | { |
1b635117 | 1611 | int i; |
0e4e0e7d | 1612 | i = GetInteger(); |
1b635117 | 1613 | *var = (size_t) i; |
1614 | } | |
1615 | ||
1616 | static void | |
1617 | parse_b_size_t(size_t * var) | |
9906e724 | 1618 | { |
1619 | parseBytesLine(var, B_BYTES_STR); | |
1620 | } | |
1621 | ||
1622 | static void | |
a47b9029 | 1623 | parse_kb_size_t(size_t * var) |
9906e724 | 1624 | { |
1625 | parseBytesLine(var, B_KBYTES_STR); | |
1626 | } | |
1627 | ||
1628 | static void | |
a47b9029 | 1629 | free_size_t(size_t * var) |
9906e724 | 1630 | { |
a47b9029 | 1631 | *var = 0; |
9906e724 | 1632 | } |
1633 | ||
1b635117 | 1634 | #define free_b_size_t free_size_t |
9906e724 | 1635 | #define free_kb_size_t free_size_t |
1636 | #define free_mb_size_t free_size_t | |
1637 | #define free_gb_size_t free_size_t | |
090089c4 | 1638 | |
8203a132 | 1639 | static void |
a7d59104 | 1640 | dump_ushort(StoreEntry * entry, const char *name, u_short var) |
090089c4 | 1641 | { |
f53b06f9 | 1642 | storeAppendPrintf(entry, "%s %d\n", name, var); |
270b86af | 1643 | } |
090089c4 | 1644 | |
0153d498 | 1645 | static void |
a47b9029 | 1646 | free_ushort(u_short * u) |
0153d498 | 1647 | { |
1648 | *u = 0; | |
1649 | } | |
1650 | ||
270b86af | 1651 | static void |
1652 | parse_ushort(u_short * var) | |
1653 | { | |
270b86af | 1654 | int i; |
090089c4 | 1655 | |
0e4e0e7d | 1656 | i = GetInteger(); |
270b86af | 1657 | if (i < 0) |
1658 | i = 0; | |
1659 | *var = (u_short) i; | |
090089c4 | 1660 | } |
1661 | ||
270b86af | 1662 | static void |
a7d59104 | 1663 | dump_wordlist(StoreEntry * entry, const char *name, wordlist * list) |
270b86af | 1664 | { |
270b86af | 1665 | while (list != NULL) { |
f53b06f9 | 1666 | storeAppendPrintf(entry, "%s %s\n", name, list->key); |
270b86af | 1667 | list = list->next; |
429fdbec | 1668 | } |
429fdbec | 1669 | } |
1670 | ||
270b86af | 1671 | static void |
1672 | parse_wordlist(wordlist ** list) | |
429fdbec | 1673 | { |
270b86af | 1674 | char *token; |
270b86af | 1675 | while ((token = strtok(NULL, w_space))) |
1676 | wordlistAdd(list, token); | |
429fdbec | 1677 | } |
270b86af | 1678 | |
f8d9f54a | 1679 | static int |
5da06f20 | 1680 | check_null_wordlist(wordlist * w) |
f8d9f54a | 1681 | { |
1682 | return w == NULL; | |
1683 | } | |
1684 | ||
63e9d884 | 1685 | static int |
c6d5b87b | 1686 | check_null_acl_access(acl_access * a) |
63e9d884 | 1687 | { |
1688 | return a == NULL; | |
1689 | } | |
1690 | ||
0153d498 | 1691 | #define free_wordlist wordlistDestroy |
270b86af | 1692 | |
d548ee64 | 1693 | #define free_uri_whitespace free_int |
1694 | ||
1695 | static void | |
1696 | parse_uri_whitespace(int *var) | |
1697 | { | |
1698 | char *token = strtok(NULL, w_space); | |
1699 | if (token == NULL) | |
1700 | self_destruct(); | |
7e3ce7b9 | 1701 | if (!strcasecmp(token, "strip")) |
1702 | *var = URI_WHITESPACE_STRIP; | |
1703 | else if (!strcasecmp(token, "deny")) | |
d548ee64 | 1704 | *var = URI_WHITESPACE_DENY; |
1705 | else if (!strcasecmp(token, "allow")) | |
1706 | *var = URI_WHITESPACE_ALLOW; | |
1707 | else if (!strcasecmp(token, "encode")) | |
1708 | *var = URI_WHITESPACE_ENCODE; | |
1709 | else if (!strcasecmp(token, "chop")) | |
1710 | *var = URI_WHITESPACE_CHOP; | |
1711 | else | |
1712 | self_destruct(); | |
1713 | } | |
1714 | ||
1715 | ||
1716 | static void | |
1717 | dump_uri_whitespace(StoreEntry * entry, const char *name, int var) | |
1718 | { | |
1719 | char *s; | |
1720 | if (var == URI_WHITESPACE_ALLOW) | |
1721 | s = "allow"; | |
1722 | else if (var == URI_WHITESPACE_ENCODE) | |
1723 | s = "encode"; | |
1724 | else if (var == URI_WHITESPACE_CHOP) | |
1725 | s = "chop"; | |
7e3ce7b9 | 1726 | else if (var == URI_WHITESPACE_DENY) |
d548ee64 | 1727 | s = "deny"; |
7e3ce7b9 | 1728 | else |
1729 | s = "strip"; | |
d548ee64 | 1730 | storeAppendPrintf(entry, "%s %s\n", name, s); |
1731 | } | |
1732 | ||
6a566b9c | 1733 | static void |
c1dd71ae | 1734 | free_removalpolicy(RemovalPolicySettings ** settings) |
6a566b9c | 1735 | { |
1736 | if (!*settings) | |
1737 | return; | |
1738 | free_string(&(*settings)->type); | |
1739 | free_wordlist(&(*settings)->args); | |
1740 | xfree(*settings); | |
1741 | *settings = NULL; | |
1742 | } | |
1743 | ||
1744 | static void | |
c1dd71ae | 1745 | parse_removalpolicy(RemovalPolicySettings ** settings) |
6a566b9c | 1746 | { |
1747 | if (*settings) | |
1748 | free_removalpolicy(settings); | |
1749 | *settings = xcalloc(1, sizeof(**settings)); | |
1750 | parse_string(&(*settings)->type); | |
1751 | parse_wordlist(&(*settings)->args); | |
1752 | } | |
1753 | ||
1754 | static void | |
c1dd71ae | 1755 | dump_removalpolicy(StoreEntry * entry, const char *name, RemovalPolicySettings * settings) |
6a566b9c | 1756 | { |
1757 | wordlist *args; | |
1758 | storeAppendPrintf(entry, "%s %s", name, settings->type); | |
1759 | args = settings->args; | |
1760 | while (args) { | |
1761 | storeAppendPrintf(entry, " %s", args->key); | |
1762 | args = args->next; | |
1763 | } | |
be58afb5 | 1764 | storeAppendPrintf(entry, "\n"); |
6a566b9c | 1765 | } |
c1dd71ae | 1766 | |
6a566b9c | 1767 | |
270b86af | 1768 | #include "cf_parser.c" |
f1dc9b30 | 1769 | |
1770 | peer_t | |
1771 | parseNeighborType(const char *s) | |
1772 | { | |
1773 | if (!strcasecmp(s, "parent")) | |
1774 | return PEER_PARENT; | |
1775 | if (!strcasecmp(s, "neighbor")) | |
1776 | return PEER_SIBLING; | |
1777 | if (!strcasecmp(s, "neighbour")) | |
1778 | return PEER_SIBLING; | |
1779 | if (!strcasecmp(s, "sibling")) | |
1780 | return PEER_SIBLING; | |
1781 | if (!strcasecmp(s, "multicast")) | |
1782 | return PEER_MULTICAST; | |
1783 | debug(15, 0) ("WARNING: Unknown neighbor type: %s\n", s); | |
1784 | return PEER_SIBLING; | |
1785 | } | |
f150dd4b | 1786 | |
7e3ce7b9 | 1787 | static void |
1788 | parse_sockaddr_in_list(sockaddr_in_list ** head) | |
1789 | { | |
1790 | char *token; | |
1791 | char *t; | |
efd900cb | 1792 | char *host; |
7e3ce7b9 | 1793 | const struct hostent *hp; |
efd900cb | 1794 | unsigned short port; |
7e3ce7b9 | 1795 | sockaddr_in_list *s; |
1796 | while ((token = strtok(NULL, w_space))) { | |
efd900cb | 1797 | host = NULL; |
1798 | port = 0; | |
7e3ce7b9 | 1799 | if ((t = strchr(token, ':'))) { |
1800 | /* host:port */ | |
1801 | host = token; | |
1802 | *t = '\0'; | |
efd900cb | 1803 | port = (unsigned short) atoi(t + 1); |
1804 | if (0 == port) | |
7e3ce7b9 | 1805 | self_destruct(); |
efd900cb | 1806 | } else if ((port = atoi(token)) > 0) { |
7e3ce7b9 | 1807 | /* port */ |
1808 | } else { | |
1809 | self_destruct(); | |
1810 | } | |
1811 | s = xcalloc(1, sizeof(*s)); | |
efd900cb | 1812 | s->s.sin_port = htons(port); |
7e3ce7b9 | 1813 | if (NULL == host) |
1814 | s->s.sin_addr = any_addr; | |
1815 | else if (1 == safe_inet_addr(host, &s->s.sin_addr)) | |
1816 | (void) 0; | |
efd900cb | 1817 | else if ((hp = gethostbyname(host))) /* dont use ipcache */ |
7e3ce7b9 | 1818 | s->s.sin_addr = inaddrFromHostent(hp); |
1819 | else | |
1820 | self_destruct(); | |
1821 | while (*head) | |
1822 | head = &(*head)->next; | |
1823 | *head = s; | |
1824 | } | |
1825 | } | |
1826 | ||
1827 | static void | |
1828 | dump_sockaddr_in_list(StoreEntry * e, const char *n, const sockaddr_in_list * s) | |
1829 | { | |
1830 | while (s) { | |
1831 | storeAppendPrintf(e, "%s %s:%d\n", | |
1832 | n, | |
1833 | inet_ntoa(s->s.sin_addr), | |
1834 | ntohs(s->s.sin_port)); | |
1835 | s = s->next; | |
1836 | } | |
1837 | } | |
1838 | ||
1839 | static void | |
1840 | free_sockaddr_in_list(sockaddr_in_list ** head) | |
1841 | { | |
1842 | sockaddr_in_list *s; | |
1843 | while ((s = *head) != NULL) { | |
1844 | *head = s->next; | |
1845 | xfree(s); | |
1846 | } | |
1847 | } | |
1848 | ||
1849 | static int | |
1850 | check_null_sockaddr_in_list(const sockaddr_in_list * s) | |
1851 | { | |
1852 | return NULL == s; | |
1853 | } | |
1854 | ||
f150dd4b | 1855 | void |
1856 | configFreeMemory(void) | |
1857 | { | |
23ff6968 | 1858 | free_all(); |
f150dd4b | 1859 | } |
f0b19334 | 1860 | |
1861 | static void | |
1862 | requirePathnameExists(const char *name, const char *path) | |
1863 | { | |
1864 | struct stat sb; | |
f0b19334 | 1865 | assert(path != NULL); |
137ee196 | 1866 | if (stat(path, &sb) < 0) |
1867 | fatalf("%s: %s", path, xstrerror()); | |
f0b19334 | 1868 | } |