]>
Commit | Line | Data |
---|---|---|
48071869 | 1 | /* |
262a0e14 | 2 | * $Id$ |
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. | |
26ac0430 | 23 | * |
48071869 | 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. | |
26ac0430 | 28 | * |
48071869 | 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 | ||
582c2af2 | 37 | #include "squid.h" |
3ad63615 | 38 | #include "acl/IntRange.h" |
582c2af2 | 39 | #include "Debug.h" |
d295d770 | 40 | #include "wordlist.h" |
0e656b69 | 41 | #include "Parsing.h" |
582c2af2 | 42 | #include "protos.h" |
48071869 | 43 | |
97427e90 | 44 | /* explicit instantiation required for some systems */ |
d85b8894 | 45 | /** \cond AUTODOCS-IGNORE */ |
2236466c | 46 | template cbdata_type CbDataList< Range<int> >::CBDATA_CbDataList; |
d85b8894 | 47 | /** \endcond */ |
97427e90 | 48 | |
48071869 | 49 | void |
50 | ACLIntRange::parse() | |
51 | { | |
0e656b69 | 52 | char *a; |
48071869 | 53 | |
0e656b69 | 54 | while ((a = strtokFile())) { |
55 | char *b = strchr(a, '-'); | |
56 | unsigned short port1, port2; | |
5020fbcb | 57 | |
f207fe64 FC |
58 | if (b) { |
59 | *b = '\0'; | |
60 | ++b; | |
61 | } | |
5020fbcb | 62 | |
0e656b69 | 63 | port1 = xatos(a); |
5020fbcb | 64 | |
0e656b69 | 65 | if (b) |
66 | port2 = xatos(b); | |
67 | else | |
68 | port2 = port1; | |
5020fbcb | 69 | |
0e656b69 | 70 | if (port2 >= port1) { |
71 | RangeType temp (0,0); | |
72 | temp.start = port1; | |
73 | temp.end = port2+1; | |
5020fbcb | 74 | ranges.push_back(temp); |
75 | } else { | |
fa84c01d | 76 | debugs(28, DBG_CRITICAL, "ACLIntRange::parse: Invalid port value"); |
5020fbcb | 77 | self_destruct(); |
78 | } | |
48071869 | 79 | } |
80 | } | |
81 | ||
65092baf | 82 | bool |
83 | ACLIntRange::empty() const | |
84 | { | |
e855eca1 | 85 | return ranges.empty(); |
65092baf | 86 | } |
87 | ||
48071869 | 88 | bool |
89 | ACLIntRange::match(int i) | |
90 | { | |
e855eca1 | 91 | RangeType const toFind (i, i+1); |
2236466c | 92 | CbDataListIterator<RangeType> iter(ranges); |
48071869 | 93 | |
e855eca1 | 94 | while (!iter.end()) { |
95 | const RangeType & element = iter.next(); | |
96 | RangeType result = element.intersection (toFind); | |
48071869 | 97 | |
e855eca1 | 98 | if (result.size()) |
48071869 | 99 | return true; |
48071869 | 100 | } |
101 | ||
102 | return false; | |
103 | } | |
104 | ||
48071869 | 105 | ACLData<int> * |
106 | ACLIntRange::clone() const | |
107 | { | |
e855eca1 | 108 | if (!ranges.empty()) |
48071869 | 109 | fatal("ACLIntRange::clone: attempt to clone used ACL"); |
110 | ||
111 | return new ACLIntRange (*this); | |
112 | } | |
113 | ||
114 | ACLIntRange::~ACLIntRange () | |
e855eca1 | 115 | {} |
48071869 | 116 | |
117 | wordlist * | |
118 | ACLIntRange::dump () | |
119 | { | |
120 | wordlist *W = NULL; | |
121 | char buf[32]; | |
2236466c | 122 | CbDataListIterator<RangeType> iter(ranges); |
48071869 | 123 | |
e855eca1 | 124 | while (!iter.end()) { |
125 | const RangeType & element = iter.next(); | |
126 | ||
127 | if (element.size() == 1) | |
128 | snprintf(buf, sizeof(buf), "%d", element.start); | |
48071869 | 129 | else |
5020fbcb | 130 | snprintf(buf, sizeof(buf), "%d-%d", element.start, element.end-1); |
48071869 | 131 | |
132 | wordlistAdd(&W, buf); | |
48071869 | 133 | } |
134 | ||
135 | return W; | |
136 | } | |
137 |