]>
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.
32 #include "AccessLogEntry.h"
33 #include "acl/FilledChecklist.h"
34 #include "acl/Gadgets.h"
35 #include "ConfigParser.h"
36 #include "HttpRequest.h"
37 #include "HttpReply.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
)
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 return (*i
)->value
.termedBuf();
79 Notes::add(const String
¬eKey
)
81 typedef Notes::NotesList::iterator AMLI
;
82 for (AMLI i
= notes
.begin(); i
!= notes
.end(); ++i
) {
83 if ((*i
)->key
== noteKey
)
87 Note::Pointer note
= new Note(noteKey
);
88 notes
.push_back(note
);
93 Notes::parse(ConfigParser
&parser
)
96 ConfigParser::ParseString(&key
);
97 ConfigParser::ParseQuotedString(&value
);
98 Note::Pointer note
= add(key
);
99 Note::Value::Pointer noteValue
= note
->addValue(value
);
100 aclParseAclList(parser
, ¬eValue
->aclList
);
103 for (int i
= 0; blacklisted
[i
] != NULL
; ++i
) {
104 if (note
->key
.caseCmp(blacklisted
[i
]) == 0) {
105 fatalf("%s:%d: meta key \"%s\" is a reserved %s name",
106 cfg_filename
, config_lineno
, note
->key
.termedBuf(),
116 Notes::dump(StoreEntry
*entry
, const char *key
)
118 typedef Notes::NotesList::iterator AMLI
;
119 for (AMLI m
= notes
.begin(); m
!= notes
.end(); ++m
) {
120 typedef Note::Values::iterator VLI
;
121 for (VLI v
=(*m
)->values
.begin(); v
!= (*m
)->values
.end(); ++v
) {
122 storeAppendPrintf(entry
, "%s " SQUIDSTRINGPH
" %s",
123 key
, SQUIDSTRINGPRINT((*m
)->key
), ConfigParser::QuoteString((*v
)->value
));
124 dump_acl_list(entry
, (*v
)->aclList
);
125 storeAppendPrintf(entry
, "\n");
136 NotePairs::~NotePairs()
138 while (!entries
.empty())
139 delete entries
.pop_back();
143 NotePairs::find(const char *noteKey
) const
147 for (Vector
<NotePairs::Entry
*>::const_iterator i
= entries
.begin(); i
!= entries
.end(); ++i
) {
148 if ((*i
)->name
.cmp(noteKey
) == 0) {
151 value
.append(ConfigParser::QuoteString((*i
)->value
));
154 return value
.size() ? value
.termedBuf() : NULL
;
158 NotePairs::toString(const char *sep
) const
162 for (Vector
<NotePairs::Entry
*>::const_iterator i
= entries
.begin(); i
!= entries
.end(); ++i
) {
163 value
.append((*i
)->name
);
165 value
.append(ConfigParser::QuoteString((*i
)->value
));
168 return value
.size() ? value
.termedBuf() : NULL
;
172 NotePairs::findFirst(const char *noteKey
) const
174 for (Vector
<NotePairs::Entry
*>::const_iterator i
= entries
.begin(); i
!= entries
.end(); ++i
) {
175 if ((*i
)->name
.cmp(noteKey
) == 0)
176 return (*i
)->value
.termedBuf();
182 NotePairs::add(const char *key
, const char *note
)
184 entries
.push_back(new NotePairs::Entry(key
, note
));
188 NotePairs::addStrList(const char *key
, const char *values
)
190 String
strValues(values
);
192 const char *pos
= NULL
;
194 while (strListGetItem(&strValues
, ',', &item
, &ilen
, &pos
)) {
196 v
.append(item
, ilen
);
197 entries
.push_back(new NotePairs::Entry(key
, v
.termedBuf()));
202 NotePairs::hasPair(const char *key
, const char *value
) const
204 for (Vector
<NotePairs::Entry
*>::const_iterator i
= entries
.begin(); i
!= entries
.end(); ++i
) {
205 if ((*i
)->name
.cmp(key
) == 0 || (*i
)->value
.cmp(value
) == 0)
212 NotePairs::append(const NotePairs
*src
)
214 for (Vector
<NotePairs::Entry
*>::const_iterator i
= src
->entries
.begin(); i
!= src
->entries
.end(); ++i
) {
215 entries
.push_back(new NotePairs::Entry((*i
)->name
.termedBuf(), (*i
)->value
.termedBuf()));
220 SyncNotes(AccessLogEntry
&ale
, HttpRequest
&request
)
223 assert(!request
.notes
);
224 ale
.notes
= request
.notes
= new NotePairs
;
226 assert(ale
.notes
== request
.notes
);