]> git.ipfire.org Git - thirdparty/squid.git/blob - src/acl/NoteData.cc
Merge from trunk rev.13907
[thirdparty/squid.git] / src / acl / NoteData.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/Acl.h"
11 #include "acl/Checklist.h"
12 #include "acl/NoteData.h"
13 #include "acl/StringData.h"
14 #include "ConfigParser.h"
15 #include "Debug.h"
16 #include "HttpRequest.h"
17 #include "Notes.h"
18 #include "wordlist.h"
19
20 ACLNoteData::ACLNoteData() : values(new ACLStringData)
21 {}
22
23 ACLNoteData::~ACLNoteData()
24 {
25 delete values;
26 }
27
28 bool
29 ACLNoteData::matchNotes(NotePairs *note)
30 {
31 if (note == NULL)
32 return false;
33
34 debugs(28, 3, "Checking " << name);
35
36 if (values->empty())
37 return (note->findFirst(name.termedBuf()) != NULL);
38
39 for (std::vector<NotePairs::Entry *>::iterator i = note->entries.begin(); i!= note->entries.end(); ++i) {
40 if ((*i)->name.cmp(name.termedBuf()) == 0) {
41 if (values->match((*i)->value.termedBuf()))
42 return true;
43 }
44 }
45 return false;
46 }
47
48 bool
49 ACLNoteData::match(HttpRequest *request)
50 {
51 if (request->notes != NULL && matchNotes(request->notes.getRaw()))
52 return true;
53 #if USE_ADAPTATION
54 const Adaptation::History::Pointer ah = request->adaptLogHistory();
55 if (ah != NULL && ah->metaHeaders != NULL && matchNotes(ah->metaHeaders.getRaw()))
56 return true;
57 #endif
58 return false;
59 }
60
61 SBufList
62 ACLNoteData::dump() const
63 {
64 SBufList sl;
65 sl.push_back(SBuf(name));
66 #if __cplusplus >= 201103L
67 sl.splice(sl.end(), values->dump());
68 #else
69 // temp is needed until c++11 move constructor
70 SBufList temp = values->dump();
71 sl.splice(sl.end(), temp);
72 #endif
73 return sl;
74 }
75
76 void
77 ACLNoteData::parse()
78 {
79 char* t = ConfigParser::strtokFile();
80 assert (t != NULL);
81 name = t;
82 values->parse();
83 }
84
85 bool
86 ACLNoteData::empty() const
87 {
88 return name.size() == 0;
89 }
90
91 ACLData<HttpRequest *> *
92 ACLNoteData::clone() const
93 {
94 ACLNoteData * result = new ACLNoteData;
95 result->values = values->clone();
96 result->name = name;
97 return result;
98 }
99