]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/refresh.cc
3 * $Id: refresh.cc,v 1.1 1996/10/27 08:40:23 wessels Exp $
5 * DEBUG: section 22 Refresh Calculation
6 * AUTHOR: Harvest Derived
8 * SQUID Internet Object Cache http://www.nlanr.net/Squid/
9 * --------------------------------------------------------
11 * Squid is the result of efforts by numerous individuals from the
12 * Internet community. Development is led by Duane Wessels of the
13 * National Laboratory for Applied Network Research and funded by
14 * the National Science Foundation.
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 #ifndef USE_POSIX_REGEX
33 #define USE_POSIX_REGEX /* put before includes; always use POSIX */
44 #define REFRESH_DEFAULT_MIN 0
45 #define REFRESH_DEFAULT_PCT 20
46 #define REFRESH_DEFAULT_MAX 259200
48 typedef struct _refresh_t
{
50 regex_t compiled_pattern
;
54 struct _refresh_t
*next
;
57 static refresh_t
*Refresh_tbl
= NULL
;
58 static refresh_t
*Refresh_tail
= NULL
;
61 refreshFreeList(refresh_t
* t
)
65 for (; t
; t
= tnext
) {
67 safe_free(t
->pattern
);
68 regfree(&t
->compiled_pattern
);
74 refreshFreeMemory(void)
76 refreshFreeList(Refresh_tbl
);
77 Refresh_tail
= Refresh_tbl
= NULL
;
81 refreshAddToList(char *pattern
, int opts
, time_t min
, int pct
, time_t max
)
85 int flags
= REG_EXTENDED
;
86 if (opts
& REFRESH_ICASE
)
88 if (regcomp(&comp
, pattern
, flags
) != REG_NOERROR
) {
89 debug(22, 0, "refreshAddToList: Invalid regular expression: %s\n",
93 pct
= pct
< 0 ? 0 : pct
;
94 max
= max
< 0 ? 0 : max
;
95 t
= xcalloc(1, sizeof(refresh_t
));
96 t
->pattern
= (char *) xstrdup(pattern
);
97 t
->compiled_pattern
= comp
;
105 Refresh_tail
->next
= t
;
111 * return 1 if its time to revalidate this entry, 0 otherwise
114 refreshCheck(StoreEntry
* entry
, request_t
* request_unused
)
117 time_t min
= REFRESH_DEFAULT_MIN
;
118 int pct
= REFRESH_DEFAULT_PCT
;
119 time_t max
= REFRESH_DEFAULT_MAX
;
123 debug(22,1,"refreshCheck: '%s'\n", entry
->url
);
124 for (R
= Refresh_tbl
; R
; R
= R
->next
) {
125 if (regexec(&(R
->compiled_pattern
), entry
->url
, 0, 0, 0) != 0)
130 pattern
= R
->pattern
;
133 debug(22, 1, "refreshCheck: Matched '%s %d %d%% %d'\n",
134 pattern
, (int) min
, pct
, (int) max
);
135 age
= squid_curtime
- entry
->timestamp
;
136 debug(22,1,"refreshCheck: age = %d\n", (int) age
);
138 debug(22,1,"refreshCheck: NO: age < min\n");
141 if (-1 < entry
->expires
&& entry
->expires
<= squid_curtime
) {
142 debug(22,1,"refreshCheck: YES: expires <= curtime\n");
146 debug(22,1,"refreshCheck: YES: age > max\n");
149 if (entry
->timestamp
<= entry
->lastmod
) {
150 debug(22,1,"refreshCheck: YES: lastvalid <= lastmod\n");
153 factor
= 100 * age
/ (entry
->timestamp
- entry
->lastmod
);
154 debug(22,1,"refreshCheck: factor = %d\n", factor
);
156 debug(22,1,"refreshCheck: YES: factor > pc\n");