]>
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 "ConfigParser.h"
36 #include "HttpReply.h"
37 #include "HttpRequest.h"
38 #include "SquidConfig.h"
47 aclDestroyAclList(&aclList
);
51 Note::addValue(const String
&value
)
53 Value::Pointer v
= new Value(value
);
59 Note::match(HttpRequest
*request
, HttpReply
*reply
, const AccessLogEntry::Pointer
&al
)
62 typedef Values::iterator VLI
;
63 ACLFilledChecklist
ch(NULL
, request
, NULL
);
66 HTTPMSGLOCK(ch
.reply
);
68 for (VLI i
= values
.begin(); i
!= values
.end(); ++i
) {
69 const int ret
= ch
.fastCheck((*i
)->aclList
);
70 debugs(93, 5, HERE
<< "Check for header name: " << key
<< ": " << (*i
)->value
71 <<", HttpRequest: " << request
<< " HttpReply: " << reply
<< " matched: " << ret
);
72 if (ret
== ACCESS_ALLOWED
) {
73 if (al
!= NULL
&& (*i
)->valueFormat
!= NULL
) {
76 (*i
)->valueFormat
->assemble(mb
, al
, 0);
79 return (*i
)->value
.termedBuf();
86 Notes::add(const String
¬eKey
)
88 typedef Notes::NotesList::iterator AMLI
;
89 for (AMLI i
= notes
.begin(); i
!= notes
.end(); ++i
) {
90 if ((*i
)->key
== noteKey
)
94 Note::Pointer note
= new Note(noteKey
);
95 notes
.push_back(note
);
100 Notes::parse(ConfigParser
&parser
)
102 String key
= ConfigParser::NextToken();
103 ConfigParser::EnableMacros();
104 String value
= ConfigParser::NextQuotedToken();
105 ConfigParser::DisableMacros();
106 bool valueWasQuoted
= ConfigParser::LastTokenWasQuoted();
107 Note::Pointer note
= add(key
);
108 Note::Value::Pointer noteValue
= note
->addValue(value
);
113 aclParseAclList(parser
, ¬eValue
->aclList
, label
.termedBuf());
114 if (formattedValues
&& valueWasQuoted
) {
115 noteValue
->valueFormat
= new Format::Format(descr
? descr
: "Notes");
116 noteValue
->valueFormat
->parse(value
.termedBuf());
119 for (int i
= 0; blacklisted
[i
] != NULL
; ++i
) {
120 if (note
->key
.caseCmp(blacklisted
[i
]) == 0) {
121 fatalf("%s:%d: meta key \"%s\" is a reserved %s name",
122 cfg_filename
, config_lineno
, note
->key
.termedBuf(),
132 Notes::dump(StoreEntry
*entry
, const char *key
)
134 typedef Notes::NotesList::iterator AMLI
;
135 for (AMLI m
= notes
.begin(); m
!= notes
.end(); ++m
) {
136 typedef Note::Values::iterator VLI
;
137 for (VLI v
=(*m
)->values
.begin(); v
!= (*m
)->values
.end(); ++v
) {
138 storeAppendPrintf(entry
, "%s " SQUIDSTRINGPH
" %s",
139 key
, SQUIDSTRINGPRINT((*m
)->key
), ConfigParser::QuoteString((*v
)->value
));
140 dump_acl_list(entry
, (*v
)->aclList
);
141 storeAppendPrintf(entry
, "\n");
152 NotePairs::~NotePairs()
154 while (!entries
.empty()) {
155 delete entries
.back();
161 NotePairs::find(const char *noteKey
) const
165 for (std::vector
<NotePairs::Entry
*>::const_iterator i
= entries
.begin(); i
!= entries
.end(); ++i
) {
166 if ((*i
)->name
.cmp(noteKey
) == 0) {
169 value
.append(ConfigParser::QuoteString((*i
)->value
));
172 return value
.size() ? value
.termedBuf() : NULL
;
176 NotePairs::toString(const char *sep
) const
180 for (std::vector
<NotePairs::Entry
*>::const_iterator i
= entries
.begin(); i
!= entries
.end(); ++i
) {
181 value
.append((*i
)->name
);
183 value
.append(ConfigParser::QuoteString((*i
)->value
));
186 return value
.size() ? value
.termedBuf() : NULL
;
190 NotePairs::findFirst(const char *noteKey
) const
192 for (std::vector
<NotePairs::Entry
*>::const_iterator i
= entries
.begin(); i
!= entries
.end(); ++i
) {
193 if ((*i
)->name
.cmp(noteKey
) == 0)
194 return (*i
)->value
.termedBuf();
200 NotePairs::add(const char *key
, const char *note
)
202 entries
.push_back(new NotePairs::Entry(key
, note
));
206 NotePairs::addStrList(const char *key
, const char *values
)
208 String
strValues(values
);
210 const char *pos
= NULL
;
212 while (strListGetItem(&strValues
, ',', &item
, &ilen
, &pos
)) {
214 v
.append(item
, ilen
);
215 entries
.push_back(new NotePairs::Entry(key
, v
.termedBuf()));
220 NotePairs::hasPair(const char *key
, const char *value
) const
222 for (std::vector
<NotePairs::Entry
*>::const_iterator i
= entries
.begin(); i
!= entries
.end(); ++i
) {
223 if ((*i
)->name
.cmp(key
) == 0 && (*i
)->value
.cmp(value
) == 0)
230 NotePairs::append(const NotePairs
*src
)
232 for (std::vector
<NotePairs::Entry
*>::const_iterator i
= src
->entries
.begin(); i
!= src
->entries
.end(); ++i
) {
233 entries
.push_back(new NotePairs::Entry((*i
)->name
.termedBuf(), (*i
)->value
.termedBuf()));
238 NotePairs::appendNewOnly(const NotePairs
*src
)
240 for (std::vector
<NotePairs::Entry
*>::const_iterator i
= src
->entries
.begin(); i
!= src
->entries
.end(); ++i
) {
241 if (!hasPair((*i
)->name
.termedBuf(), (*i
)->value
.termedBuf()))
242 entries
.push_back(new NotePairs::Entry((*i
)->name
.termedBuf(), (*i
)->value
.termedBuf()));
247 SyncNotes(AccessLogEntry
&ale
, HttpRequest
&request
)
249 // XXX: auth code only has access to HttpRequest being authenticated
250 // so we must handle the case where HttpRequest is set without ALE being set.
254 request
.notes
= new NotePairs
;
255 ale
.notes
= request
.notes
;
257 assert(ale
.notes
== request
.notes
);