]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/ACLTimeData.cc
2 * $Id: ACLTimeData.cc,v 1.15 2007/04/30 16:56:09 wessels Exp $
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 "ACLTimeData.h"
39 #include "authenticate.h"
40 #include "ACLChecklist.h"
43 ACLTimeData::ACLTimeData () : weekbits (0), start (0), stop (0), next (NULL
) {}
45 ACLTimeData::ACLTimeData(ACLTimeData
const &old
) : weekbits(old
.weekbits
), start (old
.start
), stop (old
.stop
), next (NULL
)
48 next
= (ACLTimeData
*)old
.next
->clone();
52 ACLTimeData::operator=(ACLTimeData
const &old
)
54 weekbits
= old
.weekbits
;
60 next
= (ACLTimeData
*)old
.next
->clone();
65 ACLTimeData::~ACLTimeData()
72 ACLTimeData::match(time_t when
)
74 static time_t last_when
= 0;
79 if (when
!= last_when
) {
82 xmemcpy(&tm
, localtime(&when
), sizeof(struct tm
));
85 t
= (time_t) (tm
.tm_hour
* 60 + tm
.tm_min
);
86 ACLTimeData
*data
= this;
89 debugs(28, 3, "aclMatchTime: checking " << t
<< " in " <<
90 data
->start
<< "-" << data
->stop
<< ", weekbits=" <<
91 std::hex
<< data
->weekbits
);
93 if (t
>= data
->start
&& t
<= data
->stop
&& (data
->weekbits
& (1 << tm
.tm_wday
)))
107 ACLTimeData
*t
= this;
110 snprintf(buf
, sizeof(buf
), "%c%c%c%c%c%c%c %02d:%02d-%02d:%02d",
111 t
->weekbits
& ACL_SUNDAY
? 'S' : '-',
112 t
->weekbits
& ACL_MONDAY
? 'M' : '-',
113 t
->weekbits
& ACL_TUESDAY
? 'T' : '-',
114 t
->weekbits
& ACL_WEDNESDAY
? 'W' : '-',
115 t
->weekbits
& ACL_THURSDAY
? 'H' : '-',
116 t
->weekbits
& ACL_FRIDAY
? 'F' : '-',
117 t
->weekbits
& ACL_SATURDAY
? 'A' : '-',
118 t
->start
/ 60, t
->start
% 60, t
->stop
/ 60, t
->stop
% 60);
119 wordlistAdd(&W
, buf
);
132 for (Tail
= &next
; *Tail
; Tail
= &((*Tail
)->next
))
135 ACLTimeData
*q
= NULL
;
141 while ((t
= strtokFile())) {
142 if (*t
< '0' || *t
> '9') {
143 /* assume its day-of-week spec */
149 weekbits
|= ACL_SUNDAY
;
153 weekbits
|= ACL_MONDAY
;
157 weekbits
|= ACL_TUESDAY
;
161 weekbits
|= ACL_WEDNESDAY
;
165 weekbits
|= ACL_THURSDAY
;
169 weekbits
|= ACL_FRIDAY
;
173 weekbits
|= ACL_SATURDAY
;
177 weekbits
|= ACL_WEEKDAYS
;
181 /* ignore placeholder */
185 debugs(28, 0, "" << cfg_filename
<< " line " << config_lineno
<<
186 ": " << config_input_line
);
187 debugs(28, 0, "aclParseTimeSpec: Bad Day '" << *t
<< "'" );
192 /* assume its time-of-day spec */
194 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)))) {
195 debugs(28, 0, "aclParseTimeSpec: Bad time range '" << t
<< "'");
204 if ((weekbits
== 0) && (start
== 0) && (stop
== 0))
209 q
->start
= h1
* 60 + m1
;
211 q
->stop
= h2
* 60 + m2
;
213 q
->weekbits
= weekbits
;
217 if (q
->start
> q
->stop
) {
218 debugs(28, 0, "aclParseTimeSpec: Reversed time range");
227 if (q
->weekbits
== 0)
228 q
->weekbits
= ACL_ALLWEEK
;
239 if ((weekbits
== 0) && (start
== 0) && (stop
== 0))
244 q
->start
= 0 * 60 + 0;
246 q
->stop
= 24 * 60 + 0;
248 q
->weekbits
= weekbits
;
258 ACLTimeData::empty() const
264 ACLTimeData::clone() const
266 return new ACLTimeData(*this);