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