]> git.ipfire.org Git - thirdparty/squid.git/blame - src/acl/StringData.cc
Simplify appending SBuf to String (#2108)
[thirdparty/squid.git] / src / acl / StringData.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/StringData.h"
16c5ad96 14#include "ConfigParser.h"
675b8408 15#include "debug/Stream.h"
48071869 16
00352183
AR
17void
18ACLStringData::insert(const char *value)
19{
56a821c4 20 stringValues.insert(SBuf(value));
00352183
AR
21}
22
48071869 23bool
76ee67ac 24ACLStringData::match(const SBuf &tf)
48071869 25{
5370d361 26 if (stringValues.empty())
48071869 27 return 0;
28
56a821c4 29 debugs(28, 3, "aclMatchStringList: checking '" << tf << "'");
48071869 30
56a821c4
FC
31 bool found = (stringValues.find(tf) != stringValues.end());
32 debugs(28, 3, "aclMatchStringList: '" << tf << "' " << (found ? "found" : "NOT found"));
48071869 33
56a821c4 34 return found;
48071869 35}
36
76ee67ac
CT
37// XXX: performance regression due to SBuf(char*) data-copies.
38bool
39ACLStringData::match(char const *toFind)
40{
5370d361
AR
41 if (!toFind) {
42 // TODO: Check whether we can Assure(toFind) instead.
43 debugs(28, 3, "not matching a nil c-string");
44 return false;
45 }
76ee67ac
CT
46 return match(SBuf(toFind));
47}
48
8966008b 49SBufList
4f8ca96e 50ACLStringData::dump() const
48071869 51{
56a821c4
FC
52 SBufList sl;
53 sl.insert(sl.end(), stringValues.begin(), stringValues.end());
54 return sl;
48071869 55}
56
57void
58ACLStringData::parse()
59{
16c5ad96 60 while (const char *t = ConfigParser::strtokFile())
56a821c4 61 stringValues.insert(SBuf(t));
48071869 62}
63
65092baf 64bool
65ACLStringData::empty() const
66{
56a821c4 67 return stringValues.empty();
65092baf 68}
69