]> git.ipfire.org Git - thirdparty/squid.git/blame - src/acl/IntRange.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / acl / IntRange.cc
CommitLineData
48071869 1/*
4ac4a490 2 * Copyright (C) 1996-2017 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"
16c5ad96 14#include "ConfigParser.h"
582c2af2 15#include "Debug.h"
ed6e9fb9 16#include "fatal.h"
0e656b69 17#include "Parsing.h"
48071869 18
19void
20ACLIntRange::parse()
21{
16c5ad96 22 while (char *a = ConfigParser::strtokFile()) {
0e656b69 23 char *b = strchr(a, '-');
24 unsigned short port1, port2;
5020fbcb 25
f207fe64
FC
26 if (b) {
27 *b = '\0';
28 ++b;
29 }
5020fbcb 30
0e656b69 31 port1 = xatos(a);
5020fbcb 32
0e656b69 33 if (b)
34 port2 = xatos(b);
35 else
36 port2 = port1;
5020fbcb 37
0e656b69 38 if (port2 >= port1) {
cd44274b 39 RangeType temp(port1, port2+1);
5020fbcb 40 ranges.push_back(temp);
41 } else {
fa84c01d 42 debugs(28, DBG_CRITICAL, "ACLIntRange::parse: Invalid port value");
5020fbcb 43 self_destruct();
44 }
48071869 45 }
46}
47
65092baf 48bool
49ACLIntRange::empty() const
50{
e855eca1 51 return ranges.empty();
65092baf 52}
53
48071869 54bool
55ACLIntRange::match(int i)
56{
cd44274b
AJ
57 RangeType const toFind(i, i+1);
58 for (std::list<RangeType>::const_iterator iter = ranges.begin(); iter != ranges.end(); ++iter) {
59 const RangeType & element = *iter;
60 RangeType result = element.intersection(toFind);
48071869 61
e855eca1 62 if (result.size())
48071869 63 return true;
48071869 64 }
65
66 return false;
67}
68
48071869 69ACLData<int> *
70ACLIntRange::clone() const
71{
e855eca1 72 if (!ranges.empty())
48071869 73 fatal("ACLIntRange::clone: attempt to clone used ACL");
74
cd44274b 75 return new ACLIntRange(*this);
48071869 76}
77
519bae94 78ACLIntRange::~ACLIntRange()
e855eca1 79{}
48071869 80
8966008b 81SBufList
4f8ca96e 82ACLIntRange::dump() const
48071869 83{
8966008b 84 SBufList sl;
cd44274b 85 for (std::list<RangeType>::const_iterator iter = ranges.begin(); iter != ranges.end(); ++iter) {
8966008b 86 SBuf sb;
cd44274b 87 const RangeType & element = *iter;
e855eca1 88
89 if (element.size() == 1)
8966008b 90 sb.Printf("%d", element.start);
48071869 91 else
8966008b 92 sb.Printf("%d-%d", element.start, element.end-1);
48071869 93
8966008b 94 sl.push_back(sb);
48071869 95 }
96
8966008b 97 return sl;
48071869 98}
f53969cc 99