]>
Commit | Line | Data |
---|---|---|
48071869 | 1 | /* |
4ac4a490 | 2 | * Copyright (C) 1996-2017 The Squid Software Foundation and contributors |
48071869 | 3 | * |
bbc27441 AJ |
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. | |
48071869 | 7 | */ |
8 | ||
bbc27441 AJ |
9 | /* DEBUG: section 28 Access Control */ |
10 | ||
582c2af2 | 11 | #include "squid.h" |
3ad63615 | 12 | #include "acl/Checklist.h" |
602d9612 | 13 | #include "acl/ProtocolData.h" |
16c5ad96 | 14 | #include "ConfigParser.h" |
582c2af2 | 15 | #include "Debug.h" |
d295d770 | 16 | #include "wordlist.h" |
48071869 | 17 | |
cd44274b | 18 | ACLProtocolData::ACLProtocolData(ACLProtocolData const &old) |
48071869 | 19 | { |
cd44274b | 20 | assert(old.values.empty()); |
48071869 | 21 | } |
22 | ||
23 | ACLProtocolData::~ACLProtocolData() | |
24 | { | |
cd44274b | 25 | values.clear(); |
48071869 | 26 | } |
27 | ||
28 | bool | |
0c3d3f65 | 29 | ACLProtocolData::match(AnyP::ProtocolType toFind) |
48071869 | 30 | { |
c70b36bd | 31 | for (auto itr = values.begin(); itr != values.end(); ++itr) { |
cd44274b AJ |
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; | |
48071869 | 40 | } |
41 | ||
9b859d6f | 42 | SBufList |
4f8ca96e | 43 | ACLProtocolData::dump() const |
48071869 | 44 | { |
9b859d6f | 45 | SBufList sl; |
cd44274b AJ |
46 | for (std::list<AnyP::ProtocolType>::const_iterator itr = values.begin(); itr != values.end(); ++itr) { |
47 | sl.push_back(SBuf(AnyP::ProtocolType_str[*itr])); | |
48071869 | 48 | } |
49 | ||
9b859d6f | 50 | return sl; |
48071869 | 51 | } |
52 | ||
53 | void | |
54 | ACLProtocolData::parse() | |
55 | { | |
16c5ad96 | 56 | while (char *t = ConfigParser::strtokFile()) { |
9d749b31 AJ |
57 | int p = AnyP::PROTO_NONE; |
58 | for (; p < AnyP::PROTO_UNKNOWN; ++p) { | |
33f05ce5 | 59 | if (strcasecmp(t, AnyP::ProtocolType_str[p]) == 0) { |
cd44274b | 60 | values.push_back(static_cast<AnyP::ProtocolType>(p)); |
0c3d3f65 | 61 | break; |
0c3d3f65 AJ |
62 | } |
63 | } | |
9d749b31 AJ |
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 | } | |
48071869 | 68 | } |
69 | } | |
70 | ||
0c3d3f65 | 71 | ACLData<AnyP::ProtocolType> * |
48071869 | 72 | ACLProtocolData::clone() const |
73 | { | |
74 | /* Splay trees don't clone yet. */ | |
cd44274b | 75 | assert(values.empty()); |
48071869 | 76 | return new ACLProtocolData(*this); |
77 | } | |
f53969cc | 78 |