~clint-fewbar/ubuntu/precise/squid3/ignore-sighup-early

« back to all changes in this revision

Viewing changes to src/ACLTimeData.cc

  • Committer: Bazaar Package Importer
  • Author(s): Luigi Gangitano
  • Date: 2010-05-04 11:15:49 UTC
  • mfrom: (1.3.1 upstream)
  • mto: (20.3.1 squeeze) (21.2.1 sid)
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: james.westby@ubuntu.com-20100504111549-1apjh2g5sndki4te
Tags: upstream-3.1.3
ImportĀ upstreamĀ versionĀ 3.1.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * $Id: ACLTimeData.cc,v 1.15 2007/04/30 16:56:09 wessels Exp $
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
 
#include "wordlist.h"
42
 
 
43
 
ACLTimeData::ACLTimeData () : weekbits (0), start (0), stop (0), next (NULL) {}
44
 
 
45
 
ACLTimeData::ACLTimeData(ACLTimeData const &old) : weekbits(old.weekbits), start (old.start), stop (old.stop), next (NULL)
46
 
{
47
 
    if (old.next)
48
 
        next = (ACLTimeData *)old.next->clone();
49
 
}
50
 
 
51
 
ACLTimeData&
52
 
ACLTimeData::operator=(ACLTimeData const &old)
53
 
{
54
 
    weekbits = old.weekbits;
55
 
    start = old.start;
56
 
    stop = old.stop;
57
 
    next = NULL;
58
 
 
59
 
    if (old.next)
60
 
        next = (ACLTimeData *)old.next->clone();
61
 
 
62
 
    return *this;
63
 
}
64
 
 
65
 
ACLTimeData::~ACLTimeData()
66
 
{
67
 
    if (next)
68
 
        delete next;
69
 
}
70
 
 
71
 
bool
72
 
ACLTimeData::match(time_t when)
73
 
{
74
 
    static time_t last_when = 0;
75
 
 
76
 
    static struct tm tm;
77
 
    time_t t;
78
 
 
79
 
    if (when != last_when) {
80
 
        last_when = when;
81
 
 
82
 
        xmemcpy(&tm, localtime(&when), sizeof(struct tm));
83
 
    }
84
 
 
85
 
    t = (time_t) (tm.tm_hour * 60 + tm.tm_min);
86
 
    ACLTimeData *data = this;
87
 
 
88
 
    while (data) {
89
 
        debugs(28, 3, "aclMatchTime: checking " << t  << " in " <<
90
 
               data->start  << "-" << data->stop  << ", weekbits=" <<
91
 
               std::hex << data->weekbits);
92
 
 
93
 
        if (t >= data->start && t <= data->stop && (data->weekbits & (1 << tm.tm_wday)))
94
 
            return 1;
95
 
 
96
 
        data = data->next;
97
 
    }
98
 
 
99
 
    return 0;
100
 
}
101
 
 
102
 
wordlist *
103
 
ACLTimeData::dump()
104
 
{
105
 
    wordlist *W = NULL;
106
 
    char buf[128];
107
 
    ACLTimeData *t = this;
108
 
 
109
 
    while (t != NULL) {
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);
120
 
        t = t->next;
121
 
    }
122
 
 
123
 
    return W;
124
 
}
125
 
 
126
 
void
127
 
ACLTimeData::parse()
128
 
{
129
 
    ACLTimeData **Tail;
130
 
    long weekbits = 0;
131
 
 
132
 
    for (Tail = &next; *Tail; Tail = &((*Tail)->next))
133
 
 
134
 
        ;
135
 
    ACLTimeData *q = NULL;
136
 
 
137
 
    int h1, m1, h2, m2;
138
 
 
139
 
    char *t = NULL;
140
 
 
141
 
    while ((t = strtokFile())) {
142
 
        if (*t < '0' || *t > '9') {
143
 
            /* assume its day-of-week spec */
144
 
 
145
 
            while (*t) {
146
 
                switch (*t++) {
147
 
 
148
 
                case 'S':
149
 
                    weekbits |= ACL_SUNDAY;
150
 
                    break;
151
 
 
152
 
                case 'M':
153
 
                    weekbits |= ACL_MONDAY;
154
 
                    break;
155
 
 
156
 
                case 'T':
157
 
                    weekbits |= ACL_TUESDAY;
158
 
                    break;
159
 
 
160
 
                case 'W':
161
 
                    weekbits |= ACL_WEDNESDAY;
162
 
                    break;
163
 
 
164
 
                case 'H':
165
 
                    weekbits |= ACL_THURSDAY;
166
 
                    break;
167
 
 
168
 
                case 'F':
169
 
                    weekbits |= ACL_FRIDAY;
170
 
                    break;
171
 
 
172
 
                case 'A':
173
 
                    weekbits |= ACL_SATURDAY;
174
 
                    break;
175
 
 
176
 
                case 'D':
177
 
                    weekbits |= ACL_WEEKDAYS;
178
 
                    break;
179
 
 
180
 
                case '-':
181
 
                    /* ignore placeholder */
182
 
                    break;
183
 
 
184
 
                default:
185
 
                    debugs(28, 0, "" << cfg_filename << " line " << config_lineno <<
186
 
                           ": " << config_input_line);
187
 
                    debugs(28, 0, "aclParseTimeSpec: Bad Day '" << *t << "'" );
188
 
                    break;
189
 
                }
190
 
            }
191
 
        } else {
192
 
            /* assume its time-of-day spec */
193
 
 
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 << "'");
196
 
                self_destruct();
197
 
 
198
 
                if (q != this)
199
 
                    delete q;
200
 
 
201
 
                return;
202
 
            }
203
 
 
204
 
            if ((weekbits == 0) && (start == 0) && (stop == 0))
205
 
                q = this;
206
 
            else
207
 
                q = new ACLTimeData;
208
 
 
209
 
            q->start = h1 * 60 + m1;
210
 
 
211
 
            q->stop = h2 * 60 + m2;
212
 
 
213
 
            q->weekbits = weekbits;
214
 
 
215
 
            weekbits = 0;
216
 
 
217
 
            if (q->start > q->stop) {
218
 
                debugs(28, 0, "aclParseTimeSpec: Reversed time range");
219
 
                self_destruct();
220
 
 
221
 
                if (q != this)
222
 
                    delete q;
223
 
 
224
 
                return;
225
 
            }
226
 
 
227
 
            if (q->weekbits == 0)
228
 
                q->weekbits = ACL_ALLWEEK;
229
 
 
230
 
            if (q != this) {
231
 
                *(Tail) = q;
232
 
                Tail = &q->next;
233
 
            }
234
 
        }
235
 
    }
236
 
 
237
 
    if (weekbits) {
238
 
 
239
 
        if ((weekbits == 0) && (start == 0) && (stop == 0))
240
 
            q = this;
241
 
        else
242
 
            q = new ACLTimeData;
243
 
 
244
 
        q->start = 0 * 60 + 0;
245
 
 
246
 
        q->stop =  24 * 60 + 0;
247
 
 
248
 
        q->weekbits = weekbits;
249
 
 
250
 
        if (q != this) {
251
 
            *(Tail) = q;
252
 
            Tail = &q->next;
253
 
        }
254
 
    }
255
 
}
256
 
 
257
 
bool
258
 
ACLTimeData::empty() const
259
 
{
260
 
    return false;
261
 
}
262
 
 
263
 
ACLData<time_t> *
264
 
ACLTimeData::clone() const
265
 
{
266
 
    return new ACLTimeData(*this);
267
 
}