]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/ProtocolData.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / acl / ProtocolData.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/ProtocolData.h"
14 #include "cache_cf.h"
15 #include "Debug.h"
16 #include "wordlist.h"
17
18 ACLProtocolData::ACLProtocolData(ACLProtocolData const &old)
19 {
20 assert(old.values.empty());
21 }
22
23 ACLProtocolData::~ACLProtocolData()
24 {
25 values.clear();
26 }
27
28 bool
29 ACLProtocolData::match(AnyP::ProtocolType toFind)
30 {
31 for (auto itr = values.begin(); itr != values.end(); ++itr) {
32 if (*itr == toFind) {
33 // tune the list for LRU ordering
34 values.erase(itr);
35 values.push_front(toFind);
36 return true;
37 }
38 }
39 return false;
40 }
41
42 SBufList
43 ACLProtocolData::dump() const
44 {
45 SBufList sl;
46 for (std::list<AnyP::ProtocolType>::const_iterator itr = values.begin(); itr != values.end(); ++itr) {
47 sl.push_back(SBuf(AnyP::ProtocolType_str[*itr]));
48 }
49
50 return sl;
51 }
52
53 void
54 ACLProtocolData::parse()
55 {
56 while (char *t = strtokFile()) {
57 int p = AnyP::PROTO_NONE;
58 for (; p < AnyP::PROTO_UNKNOWN; ++p) {
59 if (strcasecmp(t, AnyP::ProtocolType_str[p]) == 0) {
60 values.push_back(static_cast<AnyP::ProtocolType>(p));
61 break;
62 }
63 }
64 if (p == AnyP::PROTO_UNKNOWN) {
65 debugs(28, DBG_IMPORTANT, "WARNING: Ignoring unknown protocol '" << t << "' in the ACL named '" << AclMatchedName << "'");
66 // XXX: store the text pattern of this protocol name for live comparisons
67 }
68 }
69 }
70
71 ACLData<AnyP::ProtocolType> *
72 ACLProtocolData::clone() const
73 {
74 /* Splay trees don't clone yet. */
75 assert(values.empty());
76 return new ACLProtocolData(*this);
77 }
78