]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/StringData.cc
Interim: removed needless spacing and c++ guards, started fixing DelayTagged accessin...
[thirdparty/squid.git] / src / acl / StringData.cc
1 /*
2 * Copyright (C) 1996-2014 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/Checklist.h"
13 #include "acl/StringData.h"
14 #include "cache_cf.h"
15 #include "Debug.h"
16
17 ACLStringData::ACLStringData() : values (NULL)
18 {}
19
20 ACLStringData::ACLStringData(ACLStringData const &old) : values (NULL)
21 {
22 assert (!old.values);
23 }
24
25 template<class T>
26 inline void
27 xRefFree(T &thing)
28 {
29 xfree (thing);
30 }
31
32 ACLStringData::~ACLStringData()
33 {
34 if (values) {
35 values->destroy(xRefFree);
36 delete values;
37 }
38 }
39
40 static int
41 splaystrcmp (char * const &l, char * const &r)
42 {
43 return strcmp (l,r);
44 }
45
46 void
47 ACLStringData::insert(const char *value)
48 {
49 values->insert(xstrdup(value), splaystrcmp);
50 }
51
52 bool
53 ACLStringData::match(char const *toFind)
54 {
55 if (!values || !toFind)
56 return 0;
57
58 debugs(28, 3, "aclMatchStringList: checking '" << toFind << "'");
59
60 char * const * result = values->find(const_cast<char *>(toFind), splaystrcmp);
61
62 debugs(28, 3, "aclMatchStringList: '" << toFind << "' " << (result ? "found" : "NOT found"));
63
64 return (result != NULL);
65 }
66
67 // visitor functor to collect the contents of the Arp Acl
68 struct StringDataAclDumpVisitor {
69 SBufList contents;
70 void operator() (char * const& node_data) {
71 contents.push_back(SBuf(node_data));
72 }
73 };
74
75 SBufList
76 ACLStringData::dump() const
77 {
78 StringDataAclDumpVisitor visitor;
79 values->visit(visitor);
80 return visitor.contents;
81 }
82
83 void
84 ACLStringData::parse()
85 {
86 char *t;
87
88 while ((t = strtokFile()))
89 values->insert(xstrdup(t), splaystrcmp);
90 }
91
92 bool
93 ACLStringData::empty() const
94 {
95 return values->empty();
96 }
97
98 ACLData<char const *> *
99 ACLStringData::clone() const
100 {
101 /* Splay trees don't clone yet. */
102 assert (!values);
103 return new ACLStringData(*this);
104 }
105