]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/Note.cc
4b96ad7c7bfda630e41fd46636ea11a7831883fa
[thirdparty/squid.git] / src / acl / Note.cc
1 /*
2 * Copyright (C) 1996-2016 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/Checklist.h"
11 #include "acl/HttpHeaderData.h"
12 #include "acl/Note.h"
13 #include "acl/NoteData.h"
14 #include "HttpRequest.h"
15 #include "Notes.h"
16 #include "parser/Tokenizer.h"
17 #include "sbuf/StringConvert.h"
18
19 int
20 ACLNoteStrategy::match(ACLData<MatchType> * &data, ACLFilledChecklist *checklist, ACLFlags &flags)
21 {
22 if (const auto request = checklist->request) {
23 if (request->notes != NULL && matchNotes(data, request->notes.getRaw(), flags.delimiters()))
24 return 1;
25 #if USE_ADAPTATION
26 const Adaptation::History::Pointer ah = request->adaptLogHistory();
27 if (ah != NULL && ah->metaHeaders != NULL && matchNotes(data, ah->metaHeaders.getRaw(), flags.delimiters()))
28 return 1;
29 #endif
30 }
31 return 0;
32 }
33
34 bool
35 ACLNoteStrategy::matchNotes(ACLData<MatchType> *noteData, const NotePairs *note, const CharacterSet *delimiters) const
36 {
37 for (auto &entry: note->entries) {
38 if (delimiters) {
39 NotePairs::Entry e(entry->name.termedBuf(), "");
40 Parser::Tokenizer t(StringToSBuf(entry->value));
41 SBuf s;
42 while (t.token(s, *delimiters)) {
43 e.value = s.c_str();
44 if (noteData->match(&e))
45 return true;
46 }
47 s = t.remaining();
48 e.value = s.c_str();
49 if (noteData->match(&e))
50 return true;
51 }
52 if (noteData->match(entry))
53 return true;
54 }
55 return false;
56 }
57
58 ACLNoteStrategy *
59 ACLNoteStrategy::Instance()
60 {
61 return &Instance_;
62 }
63
64 ACLNoteStrategy ACLNoteStrategy::Instance_;
65