]> git.ipfire.org Git - thirdparty/squid.git/blame - src/acl/ProtocolData.cc
Simplify appending SBuf to String (#2108)
[thirdparty/squid.git] / src / acl / ProtocolData.cc
CommitLineData
48071869 1/*
1f7b830e 2 * Copyright (C) 1996-2025 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"
675b8408 15#include "debug/Stream.h"
d295d770 16#include "wordlist.h"
48071869 17
48071869 18ACLProtocolData::~ACLProtocolData()
19{
cd44274b 20 values.clear();
48071869 21}
22
23bool
0c3d3f65 24ACLProtocolData::match(AnyP::ProtocolType toFind)
48071869 25{
c70b36bd 26 for (auto itr = values.begin(); itr != values.end(); ++itr) {
cd44274b
AJ
27 if (*itr == toFind) {
28 // tune the list for LRU ordering
29 values.erase(itr);
30 values.push_front(toFind);
31 return true;
32 }
33 }
34 return false;
48071869 35}
36
9b859d6f 37SBufList
4f8ca96e 38ACLProtocolData::dump() const
48071869 39{
9b859d6f 40 SBufList sl;
cd44274b
AJ
41 for (std::list<AnyP::ProtocolType>::const_iterator itr = values.begin(); itr != values.end(); ++itr) {
42 sl.push_back(SBuf(AnyP::ProtocolType_str[*itr]));
48071869 43 }
44
9b859d6f 45 return sl;
48071869 46}
47
48void
49ACLProtocolData::parse()
50{
16c5ad96 51 while (char *t = ConfigParser::strtokFile()) {
9d749b31
AJ
52 int p = AnyP::PROTO_NONE;
53 for (; p < AnyP::PROTO_UNKNOWN; ++p) {
33f05ce5 54 if (strcasecmp(t, AnyP::ProtocolType_str[p]) == 0) {
cd44274b 55 values.push_back(static_cast<AnyP::ProtocolType>(p));
0c3d3f65 56 break;
0c3d3f65
AJ
57 }
58 }
9d749b31 59 if (p == AnyP::PROTO_UNKNOWN) {
b5818136 60 debugs(28, DBG_IMPORTANT, "WARNING: Ignoring unknown protocol '" << t << "' in the ACL");
9d749b31
AJ
61 // XXX: store the text pattern of this protocol name for live comparisons
62 }
48071869 63 }
64}
65