]> git.ipfire.org Git - thirdparty/squid.git/blame - src/ACLIntRange.cc
Simple ListIterator template class for iterating over a ListContainer
[thirdparty/squid.git] / src / ACLIntRange.cc
CommitLineData
48071869 1/*
5cda4d56 2 * $Id: ACLIntRange.cc,v 1.5 2005/05/08 09:15:39 serassio Exp $
48071869 3 *
4 * DEBUG: section 28 Access Control
5 * AUTHOR: Robert Collins
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 "ACLIntRange.h"
39
97427e90 40/* explicit instantiation required for some systems */
41
42template cbdata_type List<Range<int> >
43::CBDATA_List;
44
48071869 45void
46ACLIntRange::parse()
47{
48 RangeType **Tail;
49 RangeType *q = NULL;
50 char *t = NULL;
51
52 for (Tail = &ranges; *Tail; Tail = &((*Tail)->next))
53
54 ;
55 while ((t = strtokFile())) {
56 Range<int> temp (0,0);
57 temp.start = atoi(t);
58 t = strchr(t, '-');
59
60 if (t && *(++t))
61 temp.end = atoi(t) + 1;
62 else
63 temp.end = temp.start+1;
64
65 q = new RangeType (temp);
66
67 *(Tail) = q;
68
69 Tail = &q->next;
70 }
71}
72
65092baf 73bool
74ACLIntRange::empty() const
75{
5cda4d56 76 return ranges == NULL;
65092baf 77}
78
48071869 79bool
80ACLIntRange::match(int i)
81{
82 Range<int> const toFind (i, i+1);
83 RangeType *prev;
84 RangeType *data = ranges;
85 prev = NULL;
86
87 while (data) {
88 Range<int> result = data->element.intersection (toFind);
89
90 if (result.size()) {
91 /* matched */
92
93 if (prev != NULL) {
94 /* shift the element just found to the second position
95 * in the list */
96 prev->next = data->next;
97 data->next = ranges->next;
98 ranges->next = data;
99 }
100
101 return true;
102 }
103
104 prev = data;
105 data = data->next;
106 }
107
108 return false;
109}
110
48071869 111ACLData<int> *
112ACLIntRange::clone() const
113{
114 if (ranges)
115 fatal("ACLIntRange::clone: attempt to clone used ACL");
116
117 return new ACLIntRange (*this);
118}
119
120ACLIntRange::~ACLIntRange ()
121{
122 if (ranges)
00d77d6b 123 delete ranges;
48071869 124}
125
126wordlist *
127ACLIntRange::dump ()
128{
129 wordlist *W = NULL;
130 char buf[32];
131 RangeType *data = ranges;
132
133 while (data != NULL) {
134 if (data->element.size() == 1)
135 snprintf(buf, sizeof(buf), "%d", data->element.start);
136 else
137 snprintf(buf, sizeof(buf), "%d-%d", data->element.start, data->element.end);
138
139 wordlistAdd(&W, buf);
140
141 data = data->next;
142 }
143
144 return W;
145}
146