]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/HierCodeData.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / acl / HierCodeData.cc
1 /*
2 * Copyright (C) 1996-2015 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 "cache_cf.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(ACLHierCodeData const &old)
23 {
24 memcpy(values, old.values, sizeof(values) );
25 }
26
27 ACLHierCodeData::~ACLHierCodeData()
28 { }
29
30 bool
31 ACLHierCodeData::match(hier_code toFind)
32 {
33 return values[toFind];
34 }
35
36 SBufList
37 ACLHierCodeData::dump() const
38 {
39 SBufList sl;
40
41 for (hier_code iter=HIER_NONE; iter<HIER_MAX; ++iter) {
42 if (!values[iter]) continue;
43 sl.push_back(SBuf(hier_code_str[iter]));
44 }
45
46 return sl;
47 }
48
49 void
50 ACLHierCodeData::parse()
51 {
52 char *t = NULL;
53
54 while ((t = strtokFile())) {
55 for (hier_code iter = HIER_NONE; iter <= HIER_MAX; ++iter) {
56 if (iter == HIER_MAX) {
57 fatalf("ERROR: No such hier_code '%s'",t);
58 return;
59 }
60 if (strcmp(hier_code_str[iter],t) == 0) {
61 values[iter] = true;
62 break; // back to while-loop
63 }
64 }
65 }
66 }
67
68 bool
69 ACLHierCodeData::empty() const
70 {
71 for (hier_code iter = HIER_NONE; iter <= HIER_MAX; ++iter) {
72 if (values[iter]) return false; // not empty.
73 }
74 return true;
75 }
76
77 ACLData<hier_code> *
78 ACLHierCodeData::clone() const
79 {
80 return new ACLHierCodeData(*this);
81 }
82