]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ACLTimeData.cc
Complain during parsing if https_port version is not in (1..4)
[thirdparty/squid.git] / src / ACLTimeData.cc
CommitLineData
5dee515e 1/*
4b0f5de8 2 * $Id: ACLTimeData.cc,v 1.9 2005/05/06 01:57:55 hno Exp $
5dee515e 3 *
4 * DEBUG: section 28 Access Control
5 * AUTHOR: Duane Wessels
6 *
7 * SQUID Web Proxy Cache http://www.squid-cache.org/
8 * ----------------------------------------------------------
9 *
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.
18 *
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.
23 *
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.
28 *
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.
32 *
33 *
34 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
35 */
36
37#include "squid.h"
38#include "ACLTimeData.h"
39#include "authenticate.h"
40#include "ACLChecklist.h"
41
5dee515e 42ACLTimeData::ACLTimeData () : weekbits (0), start (0), stop (0), next (NULL) {}
62e76326 43
44ACLTimeData::ACLTimeData(ACLTimeData const &old) : weekbits(old.weekbits), start (old.start), stop (old.stop), next (NULL)
5dee515e 45{
46 if (old.next)
62e76326 47 next = (ACLTimeData *)old.next->clone();
5dee515e 48}
49
50ACLTimeData&
51ACLTimeData::operator=(ACLTimeData const &old)
52{
53 weekbits = old.weekbits;
54 start = old.start;
55 stop = old.stop;
56 next = NULL;
62e76326 57
5dee515e 58 if (old.next)
62e76326 59 next = (ACLTimeData *)old.next->clone();
60
5dee515e 61 return *this;
62}
63
64ACLTimeData::~ACLTimeData()
65{
66 if (next)
00d77d6b 67 delete next;
62e76326 68}
5dee515e 69
70bool
71ACLTimeData::match(time_t when)
72{
73 static time_t last_when = 0;
62e76326 74
5dee515e 75 static struct tm tm;
76 time_t t;
62e76326 77
5dee515e 78 if (when != last_when) {
62e76326 79 last_when = when;
80
81 xmemcpy(&tm, localtime(&when), sizeof(struct tm));
5dee515e 82 }
62e76326 83
5dee515e 84 t = (time_t) (tm.tm_hour * 60 + tm.tm_min);
85 ACLTimeData *data = this;
62e76326 86
5dee515e 87 while (data) {
62e76326 88 debug(28, 3) ("aclMatchTime: checking %d in %d-%d, weekbits=%x\n",
89 (int) t, (int) data->start, (int) data->stop, data->weekbits);
5dee515e 90
62e76326 91 if (t >= data->start && t <= data->stop && (data->weekbits & (1 << tm.tm_wday)))
92 return 1;
93
94 data = data->next;
5dee515e 95 }
62e76326 96
5dee515e 97 return 0;
98}
99
100wordlist *
101ACLTimeData::dump()
102{
103 wordlist *W = NULL;
104 char buf[128];
105 ACLTimeData *t = this;
62e76326 106
5dee515e 107 while (t != NULL) {
62e76326 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);
118 t = t->next;
5dee515e 119 }
62e76326 120
5dee515e 121 return W;
122}
123
124void
125ACLTimeData::parse()
126{
127 ACLTimeData **Tail;
3f7580f9 128 long weekbits = 0;
62e76326 129
130 for (Tail = &next; *Tail; Tail = &((*Tail)->next))
131
132 ;
5dee515e 133 ACLTimeData *q = NULL;
62e76326 134
5dee515e 135 int h1, m1, h2, m2;
62e76326 136
5dee515e 137 char *t = NULL;
62e76326 138
5dee515e 139 while ((t = strtokFile())) {
62e76326 140 if (*t < '0' || *t > '9') {
141 /* assume its day-of-week spec */
142
143 while (*t) {
144 switch (*t++) {
145
146 case 'S':
3f7580f9 147 weekbits |= ACL_SUNDAY;
62e76326 148 break;
149
150 case 'M':
3f7580f9 151 weekbits |= ACL_MONDAY;
62e76326 152 break;
153
154 case 'T':
3f7580f9 155 weekbits |= ACL_TUESDAY;
62e76326 156 break;
157
158 case 'W':
3f7580f9 159 weekbits |= ACL_WEDNESDAY;
62e76326 160 break;
161
162 case 'H':
3f7580f9 163 weekbits |= ACL_THURSDAY;
62e76326 164 break;
165
166 case 'F':
3f7580f9 167 weekbits |= ACL_FRIDAY;
62e76326 168 break;
169
170 case 'A':
3f7580f9 171 weekbits |= ACL_SATURDAY;
62e76326 172 break;
173
174 case 'D':
3f7580f9 175 weekbits |= ACL_WEEKDAYS;
62e76326 176 break;
177
178 case '-':
179 /* ignore placeholder */
180 break;
181
182 default:
183 debug(28, 0) ("%s line %d: %s\n",
184 cfg_filename, config_lineno, config_input_line);
185 debug(28, 0) ("aclParseTimeSpec: Bad Day '%c'\n", *t);
186 break;
187 }
188 }
189 } else {
190 /* assume its time-of-day spec */
191
192 if (sscanf(t, "%d:%d-%d:%d", &h1, &m1, &h2, &m2) < 4) {
4b0f5de8 193 debug(28, 0) ("aclParseTimeSpec: Bad time range '%s'\n", t);
194 self_destruct();
62e76326 195
196 if (q != this)
00d77d6b 197 delete q;
62e76326 198
199 return;
200 }
201
3f7580f9 202 if ((weekbits == 0) && (start == 0) && (stop == 0))
203 q = this;
204 else
205 q = new ACLTimeData;
206
62e76326 207 q->start = h1 * 60 + m1;
3f7580f9 208
62e76326 209 q->stop = h2 * 60 + m2;
210
3f7580f9 211 q->weekbits = weekbits;
212
213 weekbits = 0;
214
62e76326 215 if (q->start > q->stop) {
4b0f5de8 216 debug(28, 0) ("aclParseTimeSpec: Reversed time range\n");
217 self_destruct();
62e76326 218
219 if (q != this)
00d77d6b 220 delete q;
62e76326 221
222 return;
223 }
3f7580f9 224
225 if (q->weekbits == 0)
226 q->weekbits = ACL_ALLWEEK;
227
228 if (q != this) {
229 *(Tail) = q;
230 Tail = &q->next;
231 }
62e76326 232 }
5dee515e 233 }
62e76326 234
3f7580f9 235 if (weekbits) {
236
237 if ((weekbits == 0) && (start == 0) && (stop == 0))
238 q = this;
239 else
240 q = new ACLTimeData;
241
242 q->start = 0 * 60 + 0;
62e76326 243
3f7580f9 244 q->stop = 24 * 60 + 0;
62e76326 245
3f7580f9 246 q->weekbits = weekbits;
247
248 if (q != this) {
249 *(Tail) = q;
250 Tail = &q->next;
251 }
252 }
5dee515e 253}
254
255
256ACLData<time_t> *
257ACLTimeData::clone() const
258{
259 return new ACLTimeData(*this);
260}