]> git.ipfire.org Git - thirdparty/squid.git/blame - src/acl/IntRange.cc
Interim. Remove useless wordlist.h and SBufList.h includes, more SBufList conversions
[thirdparty/squid.git] / src / acl / IntRange.cc
CommitLineData
48071869 1/*
48071869 2 * DEBUG: section 28 Access Control
3 * AUTHOR: Robert Collins
4 *
5 * SQUID Web Proxy Cache http://www.squid-cache.org/
6 * ----------------------------------------------------------
7 *
8 * Squid is the result of efforts by numerous individuals from
9 * the Internet community; see the CONTRIBUTORS file for full
10 * details. Many organizations have provided support for Squid's
11 * development; see the SPONSORS file for full details. Squid is
12 * Copyrighted (C) 2001 by the Regents of the University of
13 * California; see the COPYRIGHT file for full details. Squid
14 * incorporates software developed and/or copyrighted by other
15 * sources; see the CREDITS file for full details.
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
26ac0430 21 *
48071869 22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26ac0430 26 *
48071869 27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
30 *
31 *
32 * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
33 */
34
582c2af2 35#include "squid.h"
3ad63615 36#include "acl/IntRange.h"
8a01b99e 37#include "cache_cf.h"
582c2af2 38#include "Debug.h"
0e656b69 39#include "Parsing.h"
48071869 40
97427e90 41/* explicit instantiation required for some systems */
d6d0eb11 42/** \cond AUTODOCS_IGNORE */
2236466c 43template cbdata_type CbDataList< Range<int> >::CBDATA_CbDataList;
d85b8894 44/** \endcond */
97427e90 45
48071869 46void
47ACLIntRange::parse()
48{
0e656b69 49 char *a;
48071869 50
0e656b69 51 while ((a = strtokFile())) {
52 char *b = strchr(a, '-');
53 unsigned short port1, port2;
5020fbcb 54
f207fe64
FC
55 if (b) {
56 *b = '\0';
57 ++b;
58 }
5020fbcb 59
0e656b69 60 port1 = xatos(a);
5020fbcb 61
0e656b69 62 if (b)
63 port2 = xatos(b);
64 else
65 port2 = port1;
5020fbcb 66
0e656b69 67 if (port2 >= port1) {
68 RangeType temp (0,0);
69 temp.start = port1;
70 temp.end = port2+1;
5020fbcb 71 ranges.push_back(temp);
72 } else {
fa84c01d 73 debugs(28, DBG_CRITICAL, "ACLIntRange::parse: Invalid port value");
5020fbcb 74 self_destruct();
75 }
48071869 76 }
77}
78
65092baf 79bool
80ACLIntRange::empty() const
81{
e855eca1 82 return ranges.empty();
65092baf 83}
84
48071869 85bool
86ACLIntRange::match(int i)
87{
e855eca1 88 RangeType const toFind (i, i+1);
2236466c 89 CbDataListIterator<RangeType> iter(ranges);
48071869 90
e855eca1 91 while (!iter.end()) {
92 const RangeType & element = iter.next();
93 RangeType result = element.intersection (toFind);
48071869 94
e855eca1 95 if (result.size())
48071869 96 return true;
48071869 97 }
98
99 return false;
100}
101
48071869 102ACLData<int> *
103ACLIntRange::clone() const
104{
e855eca1 105 if (!ranges.empty())
48071869 106 fatal("ACLIntRange::clone: attempt to clone used ACL");
107
108 return new ACLIntRange (*this);
109}
110
111ACLIntRange::~ACLIntRange ()
e855eca1 112{}
48071869 113
8966008b 114SBufList
48071869 115ACLIntRange::dump ()
116{
8966008b 117 SBufList sl;
2236466c 118 CbDataListIterator<RangeType> iter(ranges);
48071869 119
e855eca1 120 while (!iter.end()) {
8966008b 121 SBuf sb;
e855eca1 122 const RangeType & element = iter.next();
123
124 if (element.size() == 1)
8966008b 125 sb.Printf("%d", element.start);
48071869 126 else
8966008b 127 sb.Printf("%d-%d", element.start, element.end-1);
48071869 128
8966008b 129 sl.push_back(sb);
48071869 130 }
131
8966008b 132 return sl;
48071869 133}
134