]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/TimeData.cc
4 * DEBUG: section 28 Access Control
5 * AUTHOR: Duane Wessels
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
10 * Squid is the result of efforts by numerous individuals from
11 * the Internet community; see the CONTRIBUTORS file for full
12 * details. Many organizations have provided support for Squid's
13 * development; see the SPONSORS file for full details. Squid is
14 * Copyrighted (C) 2001 by the Regents of the University of
15 * California; see the COPYRIGHT file for full details. Squid
16 * incorporates software developed and/or copyrighted by other
17 * sources; see the CREDITS file for full details.
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
34 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
38 #include "acl/TimeData.h"
39 #include "acl/Checklist.h"
45 ACLTimeData::ACLTimeData () : weekbits (0), start (0), stop (0), next (NULL
) {}
47 ACLTimeData::ACLTimeData(ACLTimeData
const &old
) : weekbits(old
.weekbits
), start (old
.start
), stop (old
.stop
), next (NULL
)
50 next
= (ACLTimeData
*)old
.next
->clone();
54 ACLTimeData::operator=(ACLTimeData
const &old
)
56 weekbits
= old
.weekbits
;
62 next
= (ACLTimeData
*)old
.next
->clone();
67 ACLTimeData::~ACLTimeData()
74 ACLTimeData::match(time_t when
)
76 static time_t last_when
= 0;
81 if (when
!= last_when
) {
83 memcpy(&tm
, localtime(&when
), sizeof(struct tm
));
86 t
= (time_t) (tm
.tm_hour
* 60 + tm
.tm_min
);
87 ACLTimeData
*data
= this;
90 debugs(28, 3, "aclMatchTime: checking " << t
<< " in " <<
91 data
->start
<< "-" << data
->stop
<< ", weekbits=" <<
92 std::hex
<< data
->weekbits
);
94 if (t
>= data
->start
&& t
<= data
->stop
&& (data
->weekbits
& (1 << tm
.tm_wday
)))
108 ACLTimeData
*t
= this;
111 snprintf(buf
, sizeof(buf
), "%c%c%c%c%c%c%c %02d:%02d-%02d:%02d",
112 t
->weekbits
& ACL_SUNDAY
? 'S' : '-',
113 t
->weekbits
& ACL_MONDAY
? 'M' : '-',
114 t
->weekbits
& ACL_TUESDAY
? 'T' : '-',
115 t
->weekbits
& ACL_WEDNESDAY
? 'W' : '-',
116 t
->weekbits
& ACL_THURSDAY
? 'H' : '-',
117 t
->weekbits
& ACL_FRIDAY
? 'F' : '-',
118 t
->weekbits
& ACL_SATURDAY
? 'A' : '-',
119 t
->start
/ 60, t
->start
% 60, t
->stop
/ 60, t
->stop
% 60);
120 wordlistAdd(&W
, buf
);
131 long parsed_weekbits
= 0;
133 for (Tail
= &next
; *Tail
; Tail
= &((*Tail
)->next
));
134 ACLTimeData
*q
= NULL
;
140 while ((t
= strtokFile())) {
141 if (*t
< '0' || *t
> '9') {
142 /* assume its day-of-week spec */
148 parsed_weekbits
|= ACL_SUNDAY
;
152 parsed_weekbits
|= ACL_MONDAY
;
156 parsed_weekbits
|= ACL_TUESDAY
;
160 parsed_weekbits
|= ACL_WEDNESDAY
;
164 parsed_weekbits
|= ACL_THURSDAY
;
168 parsed_weekbits
|= ACL_FRIDAY
;
172 parsed_weekbits
|= ACL_SATURDAY
;
176 parsed_weekbits
|= ACL_WEEKDAYS
;
180 /* ignore placeholder */
184 debugs(28, DBG_CRITICAL
, "" << cfg_filename
<< " line " << config_lineno
<<
185 ": " << config_input_line
);
186 debugs(28, DBG_CRITICAL
, "aclParseTimeSpec: Bad Day '" << *t
<< "'" );
191 /* assume its time-of-day spec */
193 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)))) {
194 debugs(28, DBG_CRITICAL
, "aclParseTimeSpec: Bad time range '" << t
<< "'");
203 if ((parsed_weekbits
== 0) && (start
== 0) && (stop
== 0))
208 q
->start
= h1
* 60 + m1
;
210 q
->stop
= h2
* 60 + m2
;
212 q
->weekbits
= parsed_weekbits
;
216 if (q
->start
> q
->stop
) {
217 debugs(28, DBG_CRITICAL
, "aclParseTimeSpec: Reversed time range");
226 if (q
->weekbits
== 0)
227 q
->weekbits
= ACL_ALLWEEK
;
236 if (parsed_weekbits
) {
240 q
->start
= 0 * 60 + 0;
242 q
->stop
= 24 * 60 + 0;
244 q
->weekbits
= parsed_weekbits
;
252 ACLTimeData::empty() const
258 ACLTimeData::clone() const
260 return new ACLTimeData(*this);