]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/Notes.cc
2 * SQUID Web Proxy Cache http://www.squid-cache.org/
3 * ----------------------------------------------------------
5 * Squid is the result of efforts by numerous individuals from
6 * the Internet community; see the CONTRIBUTORS file for full
7 * details. Many organizations have provided support for Squid's
8 * development; see the SPONSORS file for full details. Squid is
9 * Copyrighted (C) 2001 by the Regents of the University of
10 * California; see the COPYRIGHT file for full details. Squid
11 * incorporates software developed and/or copyrighted by other
12 * sources; see the CREDITS file for full details.
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
31 #include "AccessLogEntry.h"
32 #include "acl/FilledChecklist.h"
33 #include "acl/Gadgets.h"
34 #include "client_side.h"
35 #include "ConfigParser.h"
37 #include "HttpReply.h"
38 #include "HttpRequest.h"
39 #include "SquidConfig.h"
48 aclDestroyAclList(&aclList
);
52 Note::addValue(const String
&value
)
54 Value::Pointer v
= new Value(value
);
60 Note::match(HttpRequest
*request
, HttpReply
*reply
, const AccessLogEntry::Pointer
&al
)
63 typedef Values::iterator VLI
;
64 ACLFilledChecklist
ch(NULL
, request
, NULL
);
67 HTTPMSGLOCK(ch
.reply
);
69 for (VLI i
= values
.begin(); i
!= values
.end(); ++i
) {
70 const int ret
= ch
.fastCheck((*i
)->aclList
);
71 debugs(93, 5, HERE
<< "Check for header name: " << key
<< ": " << (*i
)->value
72 <<", HttpRequest: " << request
<< " HttpReply: " << reply
<< " matched: " << ret
);
73 if (ret
== ACCESS_ALLOWED
) {
74 if (al
!= NULL
&& (*i
)->valueFormat
!= NULL
) {
77 (*i
)->valueFormat
->assemble(mb
, al
, 0);
80 return (*i
)->value
.termedBuf();
87 Notes::add(const String
¬eKey
)
89 typedef Notes::NotesList::iterator AMLI
;
90 for (AMLI i
= notes
.begin(); i
!= notes
.end(); ++i
) {
91 if ((*i
)->key
== noteKey
)
95 Note::Pointer note
= new Note(noteKey
);
96 notes
.push_back(note
);
101 Notes::parse(ConfigParser
&parser
)
103 String key
= ConfigParser::NextToken();
104 ConfigParser::EnableMacros();
105 String value
= ConfigParser::NextQuotedToken();
106 ConfigParser::DisableMacros();
107 bool valueWasQuoted
= ConfigParser::LastTokenWasQuoted();
108 Note::Pointer note
= add(key
);
109 Note::Value::Pointer noteValue
= note
->addValue(value
);
114 aclParseAclList(parser
, ¬eValue
->aclList
, label
.termedBuf());
115 if (formattedValues
&& valueWasQuoted
) {
116 noteValue
->valueFormat
= new Format::Format(descr
? descr
: "Notes");
117 noteValue
->valueFormat
->parse(value
.termedBuf());
120 for (int i
= 0; blacklisted
[i
] != NULL
; ++i
) {
121 if (note
->key
.caseCmp(blacklisted
[i
]) == 0) {
122 fatalf("%s:%d: meta key \"%s\" is a reserved %s name",
123 cfg_filename
, config_lineno
, note
->key
.termedBuf(),
133 Notes::dump(StoreEntry
*entry
, const char *key
)
135 typedef Notes::NotesList::iterator AMLI
;
136 for (AMLI m
= notes
.begin(); m
!= notes
.end(); ++m
) {
137 typedef Note::Values::iterator VLI
;
138 for (VLI v
=(*m
)->values
.begin(); v
!= (*m
)->values
.end(); ++v
) {
139 storeAppendPrintf(entry
, "%s " SQUIDSTRINGPH
" %s",
140 key
, SQUIDSTRINGPRINT((*m
)->key
), ConfigParser::QuoteString((*v
)->value
));
141 dump_acl_list(entry
, (*v
)->aclList
);
142 storeAppendPrintf(entry
, "\n");
153 NotePairs::~NotePairs()
155 while (!entries
.empty()) {
156 delete entries
.back();
162 NotePairs::find(const char *noteKey
, const char *sep
) const
166 for (std::vector
<NotePairs::Entry
*>::const_iterator i
= entries
.begin(); i
!= entries
.end(); ++i
) {
167 if ((*i
)->name
.cmp(noteKey
) == 0) {
170 value
.append((*i
)->value
);
173 return value
.size() ? value
.termedBuf() : NULL
;
177 NotePairs::toString(const char *sep
) const
181 for (std::vector
<NotePairs::Entry
*>::const_iterator i
= entries
.begin(); i
!= entries
.end(); ++i
) {
182 value
.append((*i
)->name
);
184 value
.append((*i
)->value
);
187 return value
.size() ? value
.termedBuf() : NULL
;
191 NotePairs::findFirst(const char *noteKey
) const
193 for (std::vector
<NotePairs::Entry
*>::const_iterator i
= entries
.begin(); i
!= entries
.end(); ++i
) {
194 if ((*i
)->name
.cmp(noteKey
) == 0)
195 return (*i
)->value
.termedBuf();
201 NotePairs::add(const char *key
, const char *note
)
203 entries
.push_back(new NotePairs::Entry(key
, note
));
207 NotePairs::remove(const char *key
)
209 std::vector
<NotePairs::Entry
*>::iterator i
= entries
.begin();
210 while (i
!= entries
.end()) {
211 if ((*i
)->name
.cmp(key
) == 0) {
213 i
= entries
.erase(i
);
221 NotePairs::addStrList(const char *key
, const char *values
)
223 String
strValues(values
);
225 const char *pos
= NULL
;
227 while (strListGetItem(&strValues
, ',', &item
, &ilen
, &pos
)) {
229 v
.append(item
, ilen
);
230 entries
.push_back(new NotePairs::Entry(key
, v
.termedBuf()));
235 NotePairs::hasPair(const char *key
, const char *value
) const
237 for (std::vector
<NotePairs::Entry
*>::const_iterator i
= entries
.begin(); i
!= entries
.end(); ++i
) {
238 if ((*i
)->name
.cmp(key
) == 0 && (*i
)->value
.cmp(value
) == 0)
245 NotePairs::append(const NotePairs
*src
)
247 for (std::vector
<NotePairs::Entry
*>::const_iterator i
= src
->entries
.begin(); i
!= src
->entries
.end(); ++i
) {
248 entries
.push_back(new NotePairs::Entry((*i
)->name
.termedBuf(), (*i
)->value
.termedBuf()));
253 NotePairs::appendNewOnly(const NotePairs
*src
)
255 for (std::vector
<NotePairs::Entry
*>::const_iterator i
= src
->entries
.begin(); i
!= src
->entries
.end(); ++i
) {
256 if (!hasPair((*i
)->name
.termedBuf(), (*i
)->value
.termedBuf()))
257 entries
.push_back(new NotePairs::Entry((*i
)->name
.termedBuf(), (*i
)->value
.termedBuf()));
262 NotePairs::replaceOrAdd(const NotePairs
*src
)
264 for (std::vector
<NotePairs::Entry
*>::const_iterator i
= src
->entries
.begin(); i
!= src
->entries
.end(); ++i
) {
265 remove((*i
)->name
.termedBuf());
271 SyncNotes(AccessLogEntry
&ale
, HttpRequest
&request
)
273 // XXX: auth code only has access to HttpRequest being authenticated
274 // so we must handle the case where HttpRequest is set without ALE being set.
278 request
.notes
= new NotePairs
;
279 ale
.notes
= request
.notes
;
281 assert(ale
.notes
== request
.notes
);
287 UpdateRequestNotes(ConnStateData
*csd
, HttpRequest
&request
, NotePairs
const &helperNotes
)
289 // Tag client connection if the helper responded with clt_conn_tag=tag.
290 if (const char *connTag
= helperNotes
.findFirst("clt_conn_tag")) {
292 csd
->connectionTag(connTag
);
295 request
.notes
= new NotePairs
;
296 request
.notes
->replaceOrAdd(&helperNotes
);