]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/NoteData.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / acl / NoteData.cc
1 /*
2 * Copyright (C) 1996-2014 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/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
21 ACLNoteData::ACLNoteData() : values(new ACLStringData)
22 {}
23
24 ACLNoteData::~ACLNoteData()
25 {
26 delete values;
27 }
28
29 bool
30 ACLNoteData::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
40 for (std::vector<NotePairs::Entry *>::iterator i = note->entries.begin(); i!= note->entries.end(); ++i) {
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
49 bool
50 ACLNoteData::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
62 SBufList
63 ACLNoteData::dump() const
64 {
65 SBufList sl;
66 sl.push_back(SBuf(name));
67 // temp is needed until c++11 move constructor
68 SBufList temp = values->dump();
69 sl.splice(sl.end(), temp);
70 return sl;
71 }
72
73 void
74 ACLNoteData::parse()
75 {
76 char* t = strtokFile();
77 assert (t != NULL);
78 name = t;
79 values->parse();
80 }
81
82 bool
83 ACLNoteData::empty() const
84 {
85 return name.size() == 0;
86 }
87
88 ACLData<HttpRequest *> *
89 ACLNoteData::clone() const
90 {
91 ACLNoteData * result = new ACLNoteData;
92 result->values = values->clone();
93 result->name = name;
94 return result;
95 }
96