]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/TimeData.cc
2 * DEBUG: section 28 Access Control
3 * AUTHOR: Duane Wessels
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
32 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
36 #include "acl/Checklist.h"
37 #include "acl/TimeData.h"
42 ACLTimeData::ACLTimeData () : weekbits (0), start (0), stop (0), next (NULL
) {}
44 ACLTimeData::ACLTimeData(ACLTimeData
const &old
) : weekbits(old
.weekbits
), start (old
.start
), stop (old
.stop
), next (NULL
)
47 next
= (ACLTimeData
*)old
.next
->clone();
51 ACLTimeData::operator=(ACLTimeData
const &old
)
53 weekbits
= old
.weekbits
;
59 next
= (ACLTimeData
*)old
.next
->clone();
64 ACLTimeData::~ACLTimeData()
71 ACLTimeData::match(time_t when
)
73 static time_t last_when
= 0;
78 if (when
!= last_when
) {
80 memcpy(&tm
, localtime(&when
), sizeof(struct tm
));
83 t
= (time_t) (tm
.tm_hour
* 60 + tm
.tm_min
);
84 ACLTimeData
*data
= this;
87 debugs(28, 3, "aclMatchTime: checking " << t
<< " in " <<
88 data
->start
<< "-" << data
->stop
<< ", weekbits=" <<
89 std::hex
<< data
->weekbits
);
91 if (t
>= data
->start
&& t
<= data
->stop
&& (data
->weekbits
& (1 << tm
.tm_wday
)))
105 ACLTimeData
*t
= this;
108 snprintf(buf
, sizeof(buf
), "%c%c%c%c%c%c%c %02d:%02d-%02d:%02d",
109 t
->weekbits
& ACL_SUNDAY
? 'S' : '-',
110 t
->weekbits
& ACL_MONDAY
? 'M' : '-',
111 t
->weekbits
& ACL_TUESDAY
? 'T' : '-',
112 t
->weekbits
& ACL_WEDNESDAY
? 'W' : '-',
113 t
->weekbits
& ACL_THURSDAY
? 'H' : '-',
114 t
->weekbits
& ACL_FRIDAY
? 'F' : '-',
115 t
->weekbits
& ACL_SATURDAY
? 'A' : '-',
116 t
->start
/ 60, t
->start
% 60, t
->stop
/ 60, t
->stop
% 60);
117 wordlistAdd(&W
, buf
);
128 long parsed_weekbits
= 0;
130 for (Tail
= &next
; *Tail
; Tail
= &((*Tail
)->next
));
131 ACLTimeData
*q
= NULL
;
137 while ((t
= strtokFile())) {
138 if (*t
< '0' || *t
> '9') {
139 /* assume its day-of-week spec */
145 parsed_weekbits
|= ACL_SUNDAY
;
149 parsed_weekbits
|= ACL_MONDAY
;
153 parsed_weekbits
|= ACL_TUESDAY
;
157 parsed_weekbits
|= ACL_WEDNESDAY
;
161 parsed_weekbits
|= ACL_THURSDAY
;
165 parsed_weekbits
|= ACL_FRIDAY
;
169 parsed_weekbits
|= ACL_SATURDAY
;
173 parsed_weekbits
|= ACL_WEEKDAYS
;
177 /* ignore placeholder */
181 debugs(28, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<<
182 ": " << config_input_line
);
183 debugs(28, DBG_CRITICAL
, "aclParseTimeSpec: Bad Day '" << *t
<< "'" );
188 /* assume its time-of-day spec */
190 if ((sscanf(t
, "%d:%d-%d:%d", &h1
, &m1
, &h2
, &m2
) < 4) || (!((h1
>= 0 && h1
< 24) && ((h2
>= 0 && h2
< 24) || (h2
== 24 && m2
== 0)) && (m1
>= 0 && m1
< 60) && (m2
>= 0 && m2
< 60)))) {
191 debugs(28, DBG_CRITICAL
, "aclParseTimeSpec: Bad time range '" << t
<< "'");
200 if ((parsed_weekbits
== 0) && (start
== 0) && (stop
== 0))
205 q
->start
= h1
* 60 + m1
;
207 q
->stop
= h2
* 60 + m2
;
209 q
->weekbits
= parsed_weekbits
;
213 if (q
->start
> q
->stop
) {
214 debugs(28, DBG_CRITICAL
, "aclParseTimeSpec: Reversed time range");
223 if (q
->weekbits
== 0)
224 q
->weekbits
= ACL_ALLWEEK
;
233 if (parsed_weekbits
) {
237 q
->start
= 0 * 60 + 0;
239 q
->stop
= 24 * 60 + 0;
241 q
->weekbits
= parsed_weekbits
;
249 ACLTimeData::empty() const
255 ACLTimeData::clone() const
257 return new ACLTimeData(*this);