IntRange.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3  *
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.
7  */
8 
9 /* DEBUG: section 28 Access Control */
10 
11 #include "squid.h"
12 #include "acl/IntRange.h"
13 #include "cache_cf.h"
14 #include "ConfigParser.h"
15 #include "Debug.h"
16 #include "fatal.h"
17 #include "Parsing.h"
18 
19 void
21 {
22  while (char *a = ConfigParser::strtokFile()) {
23  char *b = strchr(a, '-');
24  unsigned short port1, port2;
25 
26  if (b) {
27  *b = '\0';
28  ++b;
29  }
30 
31  port1 = xatos(a);
32 
33  if (b)
34  port2 = xatos(b);
35  else
36  port2 = port1;
37 
38  if (port2 >= port1) {
39  RangeType temp(port1, port2+1);
40  ranges.push_back(temp);
41  } else {
42  debugs(28, DBG_CRITICAL, "ACLIntRange::parse: Invalid port value");
43  self_destruct();
44  }
45  }
46 }
47 
48 bool
50 {
51  return ranges.empty();
52 }
53 
54 bool
56 {
57  RangeType const toFind(i, i+1);
58  for (const auto &element : ranges) {
59  RangeType result = element.intersection(toFind);
60  if (result.size())
61  return true;
62  }
63 
64  return false;
65 }
66 
69 {
70  if (!ranges.empty())
71  fatal("ACLIntRange::clone: attempt to clone used ACL");
72 
73  return new ACLIntRange(*this);
74 }
75 
77 {}
78 
81 {
82  SBufList sl;
83  for (const auto &element : ranges) {
84  SBuf sb;
85 
86  if (element.size() == 1)
87  sb.Printf("%d", element.start);
88  else
89  sb.Printf("%d-%d", element.start, element.end-1);
90 
91  sl.push_back(sb);
92  }
93 
94  return sl;
95 }
96 
Definition: SBuf.h:87
void self_destruct(void)
Definition: cache_cf.cc:255
virtual ~ACLIntRange()
Definition: IntRange.cc:76
int i
Definition: membanger.c:49
std::list< RangeType > ranges
Definition: IntRange.h:32
ACLIntRange()
Definition: IntRange.h:21
Definition: Range.h:18
static struct stat sb
Definition: squidclient.cc:75
#define DBG_CRITICAL
Definition: Debug.h:44
S size() const
Definition: Range.h:61
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Debug.h:123
SBuf & Printf(const char *fmt,...)
Definition: SBuf.cc:236
virtual bool empty() const
Definition: IntRange.cc:49
void fatal(const char *message)
Definition: fatal.cc:39
unsigned short xatos(const char *token)
Definition: Parsing.cc:108
Range intersection(Range const &) const
Definition: Range.h:46
virtual bool match(int)
Definition: IntRange.cc:55
virtual SBufList dump() const
Definition: IntRange.cc:80
std::list< SBuf > SBufList
Definition: forward.h:26
static char * strtokFile()
Definition: ConfigParser.cc:82
int a
Definition: membanger.c:50
virtual ACLData< int > * clone() const
Definition: IntRange.cc:68
virtual void parse()
Definition: IntRange.cc:20

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors