]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/Note.cc
Maintenance: Removed most NULLs using modernize-use-nullptr (#1075)
[thirdparty/squid.git] / src / acl / Note.cc
1 /*
2 * Copyright (C) 1996-2022 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 #include "squid.h"
10 #include "acl/FilledChecklist.h"
11 #include "acl/HttpHeaderData.h"
12 #include "acl/Note.h"
13 #include "acl/NoteData.h"
14 #include "HttpRequest.h"
15
16 /* Acl::AnnotationStrategy */
17
18 const Acl::Options &
19 Acl::AnnotationStrategy::options()
20 {
21 static const Acl::CharacterSetOption Delimiters("-m");
22 static const Acl::Options MyOptions = { &Delimiters };
23 Delimiters.linkWith(&delimiters);
24 return MyOptions;
25 }
26
27 /* ACLNoteStrategy */
28
29 int
30 ACLNoteStrategy::match(ACLData<MatchType> * &data, ACLFilledChecklist *checklist)
31 {
32 if (const auto request = checklist->request) {
33 if (request->hasNotes() && matchNotes(data, request->notes().getRaw()))
34 return 1;
35 #if USE_ADAPTATION
36 const Adaptation::History::Pointer ah = request->adaptLogHistory();
37 if (ah != nullptr && ah->metaHeaders != nullptr && matchNotes(data, ah->metaHeaders.getRaw()))
38 return 1;
39 #endif
40 }
41 return 0;
42 }
43
44 bool
45 ACLNoteStrategy::matchNotes(ACLData<MatchType> *noteData, const NotePairs *note) const
46 {
47 const NotePairs::Entries &entries = note->expandListEntries(&delimiters.value);
48 for (auto e: entries)
49 if (noteData->match(e.getRaw()))
50 return true;
51 return false;
52 }
53