]> git.ipfire.org Git - thirdparty/squid.git/blame - src/acl/IntRange.cc
Docs: Copyright updates for 2018 (#114)
[thirdparty/squid.git] / src / acl / IntRange.cc
CommitLineData
48071869 1/*
5b74111a 2 * Copyright (C) 1996-2018 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 57 RangeType const toFind(i, i+1);
40ab1857 58 for (const auto &element : ranges) {
cd44274b 59 RangeType result = element.intersection(toFind);
e855eca1 60 if (result.size())
48071869 61 return true;
48071869 62 }
63
64 return false;
65}
66
48071869 67ACLData<int> *
68ACLIntRange::clone() const
69{
e855eca1 70 if (!ranges.empty())
48071869 71 fatal("ACLIntRange::clone: attempt to clone used ACL");
72
cd44274b 73 return new ACLIntRange(*this);
48071869 74}
75
519bae94 76ACLIntRange::~ACLIntRange()
e855eca1 77{}
48071869 78
8966008b 79SBufList
4f8ca96e 80ACLIntRange::dump() const
48071869 81{
8966008b 82 SBufList sl;
40ab1857 83 for (const auto &element : ranges) {
8966008b 84 SBuf sb;
e855eca1 85
86 if (element.size() == 1)
8966008b 87 sb.Printf("%d", element.start);
48071869 88 else
8966008b 89 sb.Printf("%d-%d", element.start, element.end-1);
48071869 90
8966008b 91 sl.push_back(sb);
48071869 92 }
93
8966008b 94 return sl;
48071869 95}
f53969cc 96