]>
Commit | Line | Data |
---|---|---|
48071869 | 1 | /* |
bde978a6 | 2 | * Copyright (C) 1996-2015 The Squid Software Foundation and contributors |
48071869 | 3 | * |
bbc27441 AJ |
4 | * Squid software is distributed under GPLv2+ license and includes |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
48071869 | 7 | */ |
8 | ||
bbc27441 AJ |
9 | /* DEBUG: section 28 Access Control */ |
10 | ||
582c2af2 | 11 | #include "squid.h" |
3ad63615 | 12 | #include "acl/IntRange.h" |
8a01b99e | 13 | #include "cache_cf.h" |
582c2af2 | 14 | #include "Debug.h" |
ed6e9fb9 | 15 | #include "fatal.h" |
0e656b69 | 16 | #include "Parsing.h" |
48071869 | 17 | |
18 | void | |
19 | ACLIntRange::parse() | |
20 | { | |
0e656b69 | 21 | char *a; |
48071869 | 22 | |
0e656b69 | 23 | while ((a = strtokFile())) { |
24 | char *b = strchr(a, '-'); | |
25 | unsigned short port1, port2; | |
5020fbcb | 26 | |
f207fe64 FC |
27 | if (b) { |
28 | *b = '\0'; | |
29 | ++b; | |
30 | } | |
5020fbcb | 31 | |
0e656b69 | 32 | port1 = xatos(a); |
5020fbcb | 33 | |
0e656b69 | 34 | if (b) |
35 | port2 = xatos(b); | |
36 | else | |
37 | port2 = port1; | |
5020fbcb | 38 | |
0e656b69 | 39 | if (port2 >= port1) { |
cd44274b | 40 | RangeType temp(port1, port2+1); |
5020fbcb | 41 | ranges.push_back(temp); |
42 | } else { | |
fa84c01d | 43 | debugs(28, DBG_CRITICAL, "ACLIntRange::parse: Invalid port value"); |
5020fbcb | 44 | self_destruct(); |
45 | } | |
48071869 | 46 | } |
47 | } | |
48 | ||
65092baf | 49 | bool |
50 | ACLIntRange::empty() const | |
51 | { | |
e855eca1 | 52 | return ranges.empty(); |
65092baf | 53 | } |
54 | ||
48071869 | 55 | bool |
56 | ACLIntRange::match(int i) | |
57 | { | |
cd44274b AJ |
58 | RangeType const toFind(i, i+1); |
59 | for (std::list<RangeType>::const_iterator iter = ranges.begin(); iter != ranges.end(); ++iter) { | |
60 | const RangeType & element = *iter; | |
61 | RangeType result = element.intersection(toFind); | |
48071869 | 62 | |
e855eca1 | 63 | if (result.size()) |
48071869 | 64 | return true; |
48071869 | 65 | } |
66 | ||
67 | return false; | |
68 | } | |
69 | ||
48071869 | 70 | ACLData<int> * |
71 | ACLIntRange::clone() const | |
72 | { | |
e855eca1 | 73 | if (!ranges.empty()) |
48071869 | 74 | fatal("ACLIntRange::clone: attempt to clone used ACL"); |
75 | ||
cd44274b | 76 | return new ACLIntRange(*this); |
48071869 | 77 | } |
78 | ||
519bae94 | 79 | ACLIntRange::~ACLIntRange() |
e855eca1 | 80 | {} |
48071869 | 81 | |
8966008b | 82 | SBufList |
4f8ca96e | 83 | ACLIntRange::dump() const |
48071869 | 84 | { |
8966008b | 85 | SBufList sl; |
cd44274b | 86 | for (std::list<RangeType>::const_iterator iter = ranges.begin(); iter != ranges.end(); ++iter) { |
8966008b | 87 | SBuf sb; |
cd44274b | 88 | const RangeType & element = *iter; |
e855eca1 | 89 | |
90 | if (element.size() == 1) | |
8966008b | 91 | sb.Printf("%d", element.start); |
48071869 | 92 | else |
8966008b | 93 | sb.Printf("%d-%d", element.start, element.end-1); |
48071869 | 94 | |
8966008b | 95 | sl.push_back(sb); |
48071869 | 96 | } |
97 | ||
8966008b | 98 | return sl; |
48071869 | 99 | } |
f53969cc | 100 |