]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/HierCodeData.cc
Source Format Enforcement (#963)
[thirdparty/squid.git] / src / acl / HierCodeData.cc
1 /*
2 * Copyright (C) 1996-2022 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 #include "squid.h"
10 #include "acl/Checklist.h"
11 #include "acl/HierCodeData.h"
12 #include "ConfigParser.h"
13 #include "fatal.h"
14 #include "hier_code.h"
15
16 ACLHierCodeData::ACLHierCodeData()
17 {
18 // initialize mask to NULL
19 memset(values, 0, sizeof(values));
20 }
21
22 ACLHierCodeData::~ACLHierCodeData()
23 { }
24
25 bool
26 ACLHierCodeData::match(hier_code toFind)
27 {
28 return values[toFind];
29 }
30
31 SBufList
32 ACLHierCodeData::dump() const
33 {
34 SBufList sl;
35
36 for (hier_code iter=HIER_NONE; iter<HIER_MAX; ++iter) {
37 if (!values[iter]) continue;
38 sl.push_back(SBuf(hier_code_str[iter]));
39 }
40
41 return sl;
42 }
43
44 void
45 ACLHierCodeData::parse()
46 {
47 char *t = NULL;
48
49 while ((t = ConfigParser::strtokFile())) {
50 for (hier_code iter = HIER_NONE; iter <= HIER_MAX; ++iter) {
51 if (iter == HIER_MAX) {
52 fatalf("ERROR: No such hier_code '%s'",t);
53 return;
54 }
55 if (strcmp(hier_code_str[iter],t) == 0) {
56 values[iter] = true;
57 break; // back to while-loop
58 }
59 }
60 }
61 }
62
63 bool
64 ACLHierCodeData::empty() const
65 {
66 for (hier_code iter = HIER_NONE; iter <= HIER_MAX; ++iter) {
67 if (values[iter]) return false; // not empty.
68 }
69 return true;
70 }
71