]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/Notes.cc
2 * Copyright (C) 1996-2014 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 "HttpReply.h"
17 #include "HttpRequest.h"
18 #include "SquidConfig.h"
27 aclDestroyAclList(&aclList
);
31 Note::addValue(const String
&value
)
33 Value::Pointer v
= new Value(value
);
39 Note::match(HttpRequest
*request
, HttpReply
*reply
, const AccessLogEntry::Pointer
&al
)
42 typedef Values::iterator VLI
;
43 ACLFilledChecklist
ch(NULL
, request
, NULL
);
46 HTTPMSGLOCK(ch
.reply
);
48 for (VLI i
= values
.begin(); i
!= values
.end(); ++i
) {
49 const int ret
= ch
.fastCheck((*i
)->aclList
);
50 debugs(93, 5, HERE
<< "Check for header name: " << key
<< ": " << (*i
)->value
51 <<", HttpRequest: " << request
<< " HttpReply: " << reply
<< " matched: " << ret
);
52 if (ret
== ACCESS_ALLOWED
) {
53 if (al
!= NULL
&& (*i
)->valueFormat
!= NULL
) {
56 (*i
)->valueFormat
->assemble(mb
, al
, 0);
59 return (*i
)->value
.termedBuf();
66 Notes::add(const String
¬eKey
)
68 typedef Notes::NotesList::iterator AMLI
;
69 for (AMLI i
= notes
.begin(); i
!= notes
.end(); ++i
) {
70 if ((*i
)->key
== noteKey
)
74 Note::Pointer note
= new Note(noteKey
);
75 notes
.push_back(note
);
80 Notes::parse(ConfigParser
&parser
)
82 String key
= ConfigParser::NextToken();
83 ConfigParser::EnableMacros();
84 String value
= ConfigParser::NextQuotedToken();
85 ConfigParser::DisableMacros();
86 bool valueWasQuoted
= ConfigParser::LastTokenWasQuoted();
87 Note::Pointer note
= add(key
);
88 Note::Value::Pointer noteValue
= note
->addValue(value
);
93 aclParseAclList(parser
, ¬eValue
->aclList
, label
.termedBuf());
94 if (formattedValues
&& valueWasQuoted
) {
95 noteValue
->valueFormat
= new Format::Format(descr
? descr
: "Notes");
96 noteValue
->valueFormat
->parse(value
.termedBuf());
99 for (int i
= 0; blacklisted
[i
] != NULL
; ++i
) {
100 if (note
->key
.caseCmp(blacklisted
[i
]) == 0) {
101 fatalf("%s:%d: meta key \"%s\" is a reserved %s name",
102 cfg_filename
, config_lineno
, note
->key
.termedBuf(),
112 Notes::dump(StoreEntry
*entry
, const char *key
)
114 typedef Notes::NotesList::iterator AMLI
;
115 for (AMLI m
= notes
.begin(); m
!= notes
.end(); ++m
) {
116 typedef Note::Values::iterator VLI
;
117 for (VLI v
=(*m
)->values
.begin(); v
!= (*m
)->values
.end(); ++v
) {
118 storeAppendPrintf(entry
, "%s " SQUIDSTRINGPH
" %s",
119 key
, SQUIDSTRINGPRINT((*m
)->key
), ConfigParser::QuoteString((*v
)->value
));
120 dump_acl_list(entry
, (*v
)->aclList
);
121 storeAppendPrintf(entry
, "\n");
132 NotePairs::~NotePairs()
134 while (!entries
.empty()) {
135 delete entries
.back();
141 NotePairs::find(const char *noteKey
, const char *sep
) const
145 for (std::vector
<NotePairs::Entry
*>::const_iterator i
= entries
.begin(); i
!= entries
.end(); ++i
) {
146 if ((*i
)->name
.cmp(noteKey
) == 0) {
149 value
.append((*i
)->value
);
152 return value
.size() ? value
.termedBuf() : NULL
;
156 NotePairs::toString(const char *sep
) const
160 for (std::vector
<NotePairs::Entry
*>::const_iterator i
= entries
.begin(); i
!= entries
.end(); ++i
) {
161 value
.append((*i
)->name
);
163 value
.append((*i
)->value
);
166 return value
.size() ? value
.termedBuf() : NULL
;
170 NotePairs::findFirst(const char *noteKey
) const
172 for (std::vector
<NotePairs::Entry
*>::const_iterator i
= entries
.begin(); i
!= entries
.end(); ++i
) {
173 if ((*i
)->name
.cmp(noteKey
) == 0)
174 return (*i
)->value
.termedBuf();
180 NotePairs::add(const char *key
, const char *note
)
182 entries
.push_back(new NotePairs::Entry(key
, note
));
186 NotePairs::remove(const char *key
)
188 std::vector
<NotePairs::Entry
*>::iterator i
= entries
.begin();
189 while (i
!= entries
.end()) {
190 if ((*i
)->name
.cmp(key
) == 0) {
192 i
= entries
.erase(i
);
200 NotePairs::addStrList(const char *key
, const char *values
)
202 String
strValues(values
);
204 const char *pos
= NULL
;
206 while (strListGetItem(&strValues
, ',', &item
, &ilen
, &pos
)) {
208 v
.append(item
, ilen
);
209 entries
.push_back(new NotePairs::Entry(key
, v
.termedBuf()));
214 NotePairs::hasPair(const char *key
, const char *value
) const
216 for (std::vector
<NotePairs::Entry
*>::const_iterator i
= entries
.begin(); i
!= entries
.end(); ++i
) {
217 if ((*i
)->name
.cmp(key
) == 0 && (*i
)->value
.cmp(value
) == 0)
224 NotePairs::append(const NotePairs
*src
)
226 for (std::vector
<NotePairs::Entry
*>::const_iterator i
= src
->entries
.begin(); i
!= src
->entries
.end(); ++i
) {
227 entries
.push_back(new NotePairs::Entry((*i
)->name
.termedBuf(), (*i
)->value
.termedBuf()));
232 NotePairs::appendNewOnly(const NotePairs
*src
)
234 for (std::vector
<NotePairs::Entry
*>::const_iterator i
= src
->entries
.begin(); i
!= src
->entries
.end(); ++i
) {
235 if (!hasPair((*i
)->name
.termedBuf(), (*i
)->value
.termedBuf()))
236 entries
.push_back(new NotePairs::Entry((*i
)->name
.termedBuf(), (*i
)->value
.termedBuf()));
241 NotePairs::replaceOrAdd(const NotePairs
*src
)
243 for (std::vector
<NotePairs::Entry
*>::const_iterator i
= src
->entries
.begin(); i
!= src
->entries
.end(); ++i
) {
244 remove((*i
)->name
.termedBuf());
250 SyncNotes(AccessLogEntry
&ale
, HttpRequest
&request
)
252 // XXX: auth code only has access to HttpRequest being authenticated
253 // so we must handle the case where HttpRequest is set without ALE being set.
257 request
.notes
= new NotePairs
;
258 ale
.notes
= request
.notes
;
260 assert(ale
.notes
== request
.notes
);
266 UpdateRequestNotes(ConnStateData
*csd
, HttpRequest
&request
, NotePairs
const &helperNotes
)
268 // Tag client connection if the helper responded with clt_conn_tag=tag.
269 if (const char *connTag
= helperNotes
.findFirst("clt_conn_tag")) {
271 csd
->connectionTag(connTag
);
274 request
.notes
= new NotePairs
;
275 request
.notes
->replaceOrAdd(&helperNotes
);