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