Squid Web Cache master
Loading...
Searching...
No Matches
SplayInserter.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2025 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#ifndef SQUID_SRC_ACL_SPLAYINSERTER_H
10#define SQUID_SRC_ACL_SPLAYINSERTER_H
11
12#include "acl/Acl.h"
13#include "debug/Stream.h"
14#include "globals.h"
15#include "splay.h"
16
17namespace Acl {
18
21template <class DataValue>
23{
24public:
25 using Value = DataValue;
26
32 static void Merge(Splay<Value> &, Value &&);
33
34private:
37
48 static int Compare(const Value &a, const Value &b);
49
53 static bool IsSubset(const Value &a, const Value &b);
54
58 static Value MakeCombinedValue(const Value &a, const Value &b);
59
61 static void DestroyValue(Value v) { delete v; }
62};
63
64} // namespace Acl
65
66template <class DataValue>
67void
69{
70 const auto comparator = &SplayInserter<Value>::Compare;
71 while (const auto oldItemPointer = storage.insert(newItem, comparator)) {
72 const auto oldItem = *oldItemPointer;
73
74 if (IsSubset(newItem, oldItem)) {
75 debugs(28, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: Ignoring " << newItem << " because it is already covered by " << oldItem <<
76 Debug::Extra << "advice: Remove value " << newItem << " from the ACL");
77 DestroyValue(newItem);
78 return;
79 }
80
81 if (IsSubset(oldItem, newItem)) {
82 debugs(28, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: Ignoring earlier " << oldItem << " because it is covered by " << newItem <<
83 Debug::Extra << "advice: Remove value " << oldItem << " from the ACL");
84 storage.remove(oldItem, comparator);
85 DestroyValue(oldItem);
86 continue; // still need to insert newItem (and it may conflict with other old items)
87 }
88
89 const auto combinedItem = MakeCombinedValue(oldItem, newItem);
90 debugs(28, DBG_PARSE_NOTE(DBG_IMPORTANT), "WARNING: Merging overlapping " << newItem << " and " << oldItem << " into " << combinedItem <<
91 Debug::Extra << "advice: Replace values " << newItem << " and " << oldItem << " with " << combinedItem << " in the ACL");
92 DestroyValue(newItem);
93 newItem = combinedItem;
94 storage.remove(oldItem, comparator);
95 DestroyValue(oldItem);
96 continue; // still need to insert updated newItem (and it may conflict with other old items)
97 }
98}
99
100#endif /* SQUID_SRC_ACL_SPLAYINSERTER_H */
101
static Value MakeCombinedValue(const Value &a, const Value &b)
static void DestroyValue(Value v)
A Splay::SPLAYFREE-like function that destroys parsed ACL parameter values.
static int Compare(const Value &a, const Value &b)
static bool IsSubset(const Value &a, const Value &b)
static void Merge(Splay< Value > &, Value &&)
static std::ostream & Extra(std::ostream &)
Definition debug.cc:1316
Definition splay.h:50
void remove(Value const &, SPLAYCMP *compare)
Definition splay.h:336
const Value * insert(const Value &, SPLAYCMP *)
Definition splay.h:320
#define DBG_PARSE_NOTE(x)
Definition Stream.h:42
#define DBG_IMPORTANT
Definition Stream.h:38
#define debugs(SECTION, LEVEL, CONTENT)
Definition Stream.h:192
Definition Acl.cc:33