]>
Commit | Line | Data |
---|---|---|
48071869 | 1 | /* |
2 | * $Id: ACLIntRange.cc,v 1.1 2003/02/25 12:16:55 robertc Exp $ | |
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 | ||
40 | void | |
41 | ACLIntRange::parse() | |
42 | { | |
43 | RangeType **Tail; | |
44 | RangeType *q = NULL; | |
45 | char *t = NULL; | |
46 | ||
47 | for (Tail = &ranges; *Tail; Tail = &((*Tail)->next)) | |
48 | ||
49 | ; | |
50 | while ((t = strtokFile())) { | |
51 | Range<int> temp (0,0); | |
52 | temp.start = atoi(t); | |
53 | t = strchr(t, '-'); | |
54 | ||
55 | if (t && *(++t)) | |
56 | temp.end = atoi(t) + 1; | |
57 | else | |
58 | temp.end = temp.start+1; | |
59 | ||
60 | q = new RangeType (temp); | |
61 | ||
62 | *(Tail) = q; | |
63 | ||
64 | Tail = &q->next; | |
65 | } | |
66 | } | |
67 | ||
68 | bool | |
69 | ACLIntRange::match(int i) | |
70 | { | |
71 | Range<int> const toFind (i, i+1); | |
72 | RangeType *prev; | |
73 | RangeType *data = ranges; | |
74 | prev = NULL; | |
75 | ||
76 | while (data) { | |
77 | Range<int> result = data->element.intersection (toFind); | |
78 | ||
79 | if (result.size()) { | |
80 | /* matched */ | |
81 | ||
82 | if (prev != NULL) { | |
83 | /* shift the element just found to the second position | |
84 | * in the list */ | |
85 | prev->next = data->next; | |
86 | data->next = ranges->next; | |
87 | ranges->next = data; | |
88 | } | |
89 | ||
90 | return true; | |
91 | } | |
92 | ||
93 | prev = data; | |
94 | data = data->next; | |
95 | } | |
96 | ||
97 | return false; | |
98 | } | |
99 | ||
100 | void | |
101 | ACLIntRange::deleteSelf() const | |
102 | { | |
103 | delete this; | |
104 | } | |
105 | ||
106 | ACLData<int> * | |
107 | ACLIntRange::clone() const | |
108 | { | |
109 | if (ranges) | |
110 | fatal("ACLIntRange::clone: attempt to clone used ACL"); | |
111 | ||
112 | return new ACLIntRange (*this); | |
113 | } | |
114 | ||
115 | ACLIntRange::~ACLIntRange () | |
116 | { | |
117 | if (ranges) | |
118 | ranges->deleteSelf(); | |
119 | } | |
120 | ||
121 | wordlist * | |
122 | ACLIntRange::dump () | |
123 | { | |
124 | wordlist *W = NULL; | |
125 | char buf[32]; | |
126 | RangeType *data = ranges; | |
127 | ||
128 | while (data != NULL) { | |
129 | if (data->element.size() == 1) | |
130 | snprintf(buf, sizeof(buf), "%d", data->element.start); | |
131 | else | |
132 | snprintf(buf, sizeof(buf), "%d-%d", data->element.start, data->element.end); | |
133 | ||
134 | wordlistAdd(&W, buf); | |
135 | ||
136 | data = data->next; | |
137 | } | |
138 | ||
139 | return W; | |
140 | } | |
141 |