]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/Notes.cc
f6ba7cc4c9f3cd31fe88b1c69014aba451b86cb2
2 * Copyright (C) 1996-2016 The Squid Software Foundation and contributors
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.
10 #include "AccessLogEntry.h"
11 #include "acl/FilledChecklist.h"
12 #include "acl/Gadgets.h"
13 #include "client_side.h"
14 #include "ConfigParser.h"
16 #include "http/Stream.h"
17 #include "HttpReply.h"
18 #include "HttpRequest.h"
19 #include "SquidConfig.h"
28 aclDestroyAclList(&aclList
);
32 Note::addValue(const String
&value
)
34 Value::Pointer v
= new Value(value
);
40 Note::match(HttpRequest
*request
, HttpReply
*reply
, const AccessLogEntry::Pointer
&al
)
43 typedef Values::iterator VLI
;
44 ACLFilledChecklist
ch(NULL
, request
, NULL
);
47 HTTPMSGLOCK(ch
.reply
);
49 for (VLI i
= values
.begin(); i
!= values
.end(); ++i
) {
50 const int ret
= ch
.fastCheck((*i
)->aclList
);
51 debugs(93, 5, HERE
<< "Check for header name: " << key
<< ": " << (*i
)->value
52 <<", HttpRequest: " << request
<< " HttpReply: " << reply
<< " matched: " << ret
);
53 if (ret
== ACCESS_ALLOWED
) {
54 if (al
!= NULL
&& (*i
)->valueFormat
!= NULL
) {
57 (*i
)->valueFormat
->assemble(mb
, al
, 0);
60 return (*i
)->value
.termedBuf();
67 Notes::add(const String
¬eKey
)
69 typedef Notes::NotesList::iterator AMLI
;
70 for (AMLI i
= notes
.begin(); i
!= notes
.end(); ++i
) {
71 if ((*i
)->key
== noteKey
)
75 Note::Pointer note
= new Note(noteKey
);
76 notes
.push_back(note
);
81 Notes::parse(ConfigParser
&parser
)
83 String key
= ConfigParser::NextToken();
84 ConfigParser::EnableMacros();
85 String value
= ConfigParser::NextQuotedToken();
86 ConfigParser::DisableMacros();
87 bool valueWasQuoted
= ConfigParser::LastTokenWasQuoted();
88 Note::Pointer note
= add(key
);
89 Note::Value::Pointer noteValue
= note
->addValue(value
);
94 aclParseAclList(parser
, ¬eValue
->aclList
, label
.termedBuf());
95 if (formattedValues
&& valueWasQuoted
) {
96 noteValue
->valueFormat
= new Format::Format(descr
? descr
: "Notes");
97 noteValue
->valueFormat
->parse(value
.termedBuf());
100 for (int i
= 0; blacklisted
[i
] != NULL
; ++i
) {
101 if (note
->key
.caseCmp(blacklisted
[i
]) == 0) {
102 fatalf("%s:%d: meta key \"%s\" is a reserved %s name",
103 cfg_filename
, config_lineno
, note
->key
.termedBuf(),
113 Notes::dump(StoreEntry
*entry
, const char *key
)
115 typedef Notes::NotesList::iterator AMLI
;
116 for (AMLI m
= notes
.begin(); m
!= notes
.end(); ++m
) {
117 typedef Note::Values::iterator VLI
;
118 for (VLI v
=(*m
)->values
.begin(); v
!= (*m
)->values
.end(); ++v
) {
119 storeAppendPrintf(entry
, "%s " SQUIDSTRINGPH
" %s",
120 key
, SQUIDSTRINGPRINT((*m
)->key
), ConfigParser::QuoteString((*v
)->value
));
121 dump_acl_list(entry
, (*v
)->aclList
);
122 storeAppendPrintf(entry
, "\n");
133 NotePairs::~NotePairs()
135 while (!entries
.empty()) {
136 delete entries
.back();
142 NotePairs::find(const char *noteKey
, const char *sep
) const
146 for (std::vector
<NotePairs::Entry
*>::const_iterator i
= entries
.begin(); i
!= entries
.end(); ++i
) {
147 if ((*i
)->name
.cmp(noteKey
) == 0) {
150 value
.append((*i
)->value
);
153 return value
.size() ? value
.termedBuf() : NULL
;
157 NotePairs::toString(const char *sep
) const
161 for (std::vector
<NotePairs::Entry
*>::const_iterator i
= entries
.begin(); i
!= entries
.end(); ++i
) {
162 value
.append((*i
)->name
);
164 value
.append((*i
)->value
);
167 return value
.size() ? value
.termedBuf() : NULL
;
171 NotePairs::findFirst(const char *noteKey
) const
173 for (std::vector
<NotePairs::Entry
*>::const_iterator i
= entries
.begin(); i
!= entries
.end(); ++i
) {
174 if ((*i
)->name
.cmp(noteKey
) == 0)
175 return (*i
)->value
.termedBuf();
181 NotePairs::add(const char *key
, const char *note
)
183 entries
.push_back(new NotePairs::Entry(key
, note
));
187 NotePairs::remove(const char *key
)
189 std::vector
<NotePairs::Entry
*>::iterator i
= entries
.begin();
190 while (i
!= entries
.end()) {
191 if ((*i
)->name
.cmp(key
) == 0) {
193 i
= entries
.erase(i
);
201 NotePairs::addStrList(const char *key
, const char *values
)
203 String
strValues(values
);
205 const char *pos
= NULL
;
207 while (strListGetItem(&strValues
, ',', &item
, &ilen
, &pos
)) {
209 v
.append(item
, ilen
);
210 entries
.push_back(new NotePairs::Entry(key
, v
.termedBuf()));
215 NotePairs::hasPair(const char *key
, const char *value
) const
217 for (std::vector
<NotePairs::Entry
*>::const_iterator i
= entries
.begin(); i
!= entries
.end(); ++i
) {
218 if ((*i
)->name
.cmp(key
) == 0 && (*i
)->value
.cmp(value
) == 0)
225 NotePairs::append(const NotePairs
*src
)
227 for (std::vector
<NotePairs::Entry
*>::const_iterator i
= src
->entries
.begin(); i
!= src
->entries
.end(); ++i
) {
228 entries
.push_back(new NotePairs::Entry((*i
)->name
.termedBuf(), (*i
)->value
.termedBuf()));
233 NotePairs::appendNewOnly(const NotePairs
*src
)
235 for (std::vector
<NotePairs::Entry
*>::const_iterator i
= src
->entries
.begin(); i
!= src
->entries
.end(); ++i
) {
236 if (!hasPair((*i
)->name
.termedBuf(), (*i
)->value
.termedBuf()))
237 entries
.push_back(new NotePairs::Entry((*i
)->name
.termedBuf(), (*i
)->value
.termedBuf()));
242 NotePairs::replaceOrAdd(const NotePairs
*src
)
244 for (std::vector
<NotePairs::Entry
*>::const_iterator i
= src
->entries
.begin(); i
!= src
->entries
.end(); ++i
) {
245 remove((*i
)->name
.termedBuf());
251 SyncNotes(AccessLogEntry
&ale
, HttpRequest
&request
)
253 // XXX: auth code only has access to HttpRequest being authenticated
254 // so we must handle the case where HttpRequest is set without ALE being set.
258 request
.notes
= new NotePairs
;
259 ale
.notes
= request
.notes
;
261 assert(ale
.notes
== request
.notes
);
267 UpdateRequestNotes(ConnStateData
*csd
, HttpRequest
&request
, NotePairs
const &helperNotes
)
269 // Tag client connection if the helper responded with clt_conn_tag=tag.
270 if (const char *connTag
= helperNotes
.findFirst("clt_conn_tag")) {
272 csd
->connectionTag(connTag
);
275 request
.notes
= new NotePairs
;
276 request
.notes
->replaceOrAdd(&helperNotes
);