]>
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
)
95 String key
= ConfigParser::NextToken();
96 String value
= ConfigParser::NextToken();
97 Note::Pointer note
= add(key
);
98 Note::Value::Pointer noteValue
= note
->addValue(value
);
103 aclParseAclList(parser
, ¬eValue
->aclList
, label
.termedBuf());
106 for (int i
= 0; blacklisted
[i
] != NULL
; ++i
) {
107 if (note
->key
.caseCmp(blacklisted
[i
]) == 0) {
108 fatalf("%s:%d: meta key \"%s\" is a reserved %s name",
109 cfg_filename
, config_lineno
, note
->key
.termedBuf(),
119 Notes::dump(StoreEntry
*entry
, const char *key
)
121 typedef Notes::NotesList::iterator AMLI
;
122 for (AMLI m
= notes
.begin(); m
!= notes
.end(); ++m
) {
123 typedef Note::Values::iterator VLI
;
124 for (VLI v
=(*m
)->values
.begin(); v
!= (*m
)->values
.end(); ++v
) {
125 storeAppendPrintf(entry
, "%s " SQUIDSTRINGPH
" %s",
126 key
, SQUIDSTRINGPRINT((*m
)->key
), ConfigParser::QuoteString((*v
)->value
));
127 dump_acl_list(entry
, (*v
)->aclList
);
128 storeAppendPrintf(entry
, "\n");
139 NotePairs::~NotePairs()
141 while (!entries
.empty())
142 delete entries
.pop_back();
146 NotePairs::find(const char *noteKey
) const
150 for (Vector
<NotePairs::Entry
*>::const_iterator i
= entries
.begin(); i
!= entries
.end(); ++i
) {
151 if ((*i
)->name
.cmp(noteKey
) == 0) {
154 value
.append(ConfigParser::QuoteString((*i
)->value
));
157 return value
.size() ? value
.termedBuf() : NULL
;
161 NotePairs::toString(const char *sep
) const
165 for (Vector
<NotePairs::Entry
*>::const_iterator i
= entries
.begin(); i
!= entries
.end(); ++i
) {
166 value
.append((*i
)->name
);
168 value
.append(ConfigParser::QuoteString((*i
)->value
));
171 return value
.size() ? value
.termedBuf() : NULL
;
175 NotePairs::findFirst(const char *noteKey
) const
177 for (Vector
<NotePairs::Entry
*>::const_iterator i
= entries
.begin(); i
!= entries
.end(); ++i
) {
178 if ((*i
)->name
.cmp(noteKey
) == 0)
179 return (*i
)->value
.termedBuf();
185 NotePairs::add(const char *key
, const char *note
)
187 entries
.push_back(new NotePairs::Entry(key
, note
));
191 NotePairs::addStrList(const char *key
, const char *values
)
193 String
strValues(values
);
195 const char *pos
= NULL
;
197 while (strListGetItem(&strValues
, ',', &item
, &ilen
, &pos
)) {
199 v
.append(item
, ilen
);
200 entries
.push_back(new NotePairs::Entry(key
, v
.termedBuf()));
205 NotePairs::hasPair(const char *key
, const char *value
) const
207 for (Vector
<NotePairs::Entry
*>::const_iterator i
= entries
.begin(); i
!= entries
.end(); ++i
) {
208 if ((*i
)->name
.cmp(key
) == 0 || (*i
)->value
.cmp(value
) == 0)
215 NotePairs::append(const NotePairs
*src
)
217 for (Vector
<NotePairs::Entry
*>::const_iterator i
= src
->entries
.begin(); i
!= src
->entries
.end(); ++i
) {
218 entries
.push_back(new NotePairs::Entry((*i
)->name
.termedBuf(), (*i
)->value
.termedBuf()));
223 SyncNotes(AccessLogEntry
&ale
, HttpRequest
&request
)
226 assert(!request
.notes
);
227 ale
.notes
= request
.notes
= new NotePairs
;
229 assert(ale
.notes
== request
.notes
);