]> git.ipfire.org Git - thirdparty/squid.git/blame - src/acl/NoteData.cc
Remove dst ACL dependency on HTTP request message existence
[thirdparty/squid.git] / src / acl / NoteData.cc
CommitLineData
bbc27441 1/*
bde978a6 2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
bbc27441
AJ
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
39baccc8
CT
9#include "squid.h"
10#include "acl/Acl.h"
11#include "acl/Checklist.h"
12#include "acl/NoteData.h"
13#include "acl/StringData.h"
14#include "cache_cf.h"
15#include "ConfigParser.h"
16#include "Debug.h"
17#include "HttpRequest.h"
18#include "Notes.h"
19#include "wordlist.h"
20
21ACLNoteData::ACLNoteData() : values(new ACLStringData)
22{}
23
24ACLNoteData::~ACLNoteData()
25{
26 delete values;
27}
28
29bool
30ACLNoteData::matchNotes(NotePairs *note)
31{
32 if (note == NULL)
33 return false;
34
35 debugs(28, 3, "Checking " << name);
36
37 if (values->empty())
38 return (note->findFirst(name.termedBuf()) != NULL);
39
81481ec0 40 for (std::vector<NotePairs::Entry *>::iterator i = note->entries.begin(); i!= note->entries.end(); ++i) {
39baccc8
CT
41 if ((*i)->name.cmp(name.termedBuf()) == 0) {
42 if (values->match((*i)->value.termedBuf()))
43 return true;
44 }
45 }
46 return false;
47}
48
49bool
50ACLNoteData::match(HttpRequest *request)
51{
52 if (request->notes != NULL && matchNotes(request->notes.getRaw()))
53 return true;
54#if USE_ADAPTATION
55 const Adaptation::History::Pointer ah = request->adaptLogHistory();
56 if (ah != NULL && ah->metaHeaders != NULL && matchNotes(ah->metaHeaders.getRaw()))
57 return true;
58#endif
59 return false;
60}
61
9b859d6f 62SBufList
4f8ca96e 63ACLNoteData::dump() const
39baccc8 64{
9b859d6f
FC
65 SBufList sl;
66 sl.push_back(SBuf(name));
7d75c222
FC
67 // temp is needed until c++11 move constructor
68 SBufList temp = values->dump();
69 sl.splice(sl.end(), temp);
9b859d6f 70 return sl;
39baccc8
CT
71}
72
73void
74ACLNoteData::parse()
75{
76 char* t = strtokFile();
77 assert (t != NULL);
78 name = t;
79 values->parse();
80}
81
82bool
83ACLNoteData::empty() const
84{
a1377698 85 return name.size() == 0;
39baccc8
CT
86}
87
88ACLData<HttpRequest *> *
89ACLNoteData::clone() const
90{
91 ACLNoteData * result = new ACLNoteData;
92 result->values = values->clone();
93 result->name = name;
94 return result;
95}
f53969cc 96