]>
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 "acl/FilledChecklist.h"
33 #include "acl/Gadgets.h"
34 #include "ConfigParser.h"
35 #include "HttpRequest.h"
36 #include "HttpReply.h"
37 #include "SquidConfig.h"
45 aclDestroyAclList(&aclList
);
49 Note::addValue(const String
&value
)
51 Value::Pointer v
= new Value(value
);
57 Note::match(HttpRequest
*request
, HttpReply
*reply
)
60 typedef Values::iterator VLI
;
61 ACLFilledChecklist
ch(NULL
, request
, NULL
);
64 HTTPMSGLOCK(ch
.reply
);
66 for (VLI i
= values
.begin(); i
!= values
.end(); ++i
) {
67 const int ret
= ch
.fastCheck((*i
)->aclList
);
68 debugs(93, 5, HERE
<< "Check for header name: " << key
<< ": " << (*i
)->value
69 <<", HttpRequest: " << request
<< " HttpReply: " << reply
<< " matched: " << ret
);
70 if (ret
== ACCESS_ALLOWED
)
71 return (*i
)->value
.termedBuf();
77 Notes::find(const String
¬eKey
) const
79 typedef Notes::NotesList::const_iterator AMLI
;
80 for (AMLI i
= notes
.begin(); i
!= notes
.end(); ++i
) {
81 if ((*i
)->key
== noteKey
)
85 return Note::Pointer();
89 Notes::add(const String
¬eKey
, const String
¬eValue
)
91 Note::Pointer key
= add(noteKey
);
92 key
->addValue(noteValue
);
96 Notes::add(const String
¬eKey
)
98 Note::Pointer note
= find(noteKey
);
100 note
= new Note(noteKey
);
101 notes
.push_back(note
);
107 Notes::add(const Notes
&src
)
109 typedef Notes::NotesList::const_iterator AMLI
;
110 typedef Note::Values::iterator VLI
;
112 for (AMLI i
= src
.notes
.begin(); i
!= src
.notes
.end(); ++i
) {
114 // ensure we have a key by that name to fill out values for...
115 // NP: not sharing pointers at the key level since merging other helpers
116 // details later would affect this src objects keys, which is a bad idea.
117 Note::Pointer ourKey
= add((*i
)->key
);
119 // known key names, merge the values lists...
120 for (VLI v
= (*i
)->values
.begin(); v
!= (*i
)->values
.end(); ++v
) {
121 // 2012-11-29: values are read-only and Pointer can safely be shared
122 // for now we share pointers to save memory and gain speed.
123 // If that ever ceases to be true, convert this to a full copy.
124 ourKey
->values
.push_back(*v
);
125 // TODO: prune/skip duplicates ?
131 Notes::parse(ConfigParser
&parser
)
134 ConfigParser::ParseString(&key
);
135 ConfigParser::ParseQuotedString(&value
);
136 Note::Pointer note
= add(key
);
137 Note::Value::Pointer noteValue
= note
->addValue(value
);
138 aclParseAclList(parser
, ¬eValue
->aclList
);
141 for (int i
= 0; blacklisted
[i
] != NULL
; ++i
) {
142 if (note
->key
.caseCmp(blacklisted
[i
]) == 0) {
143 fatalf("%s:%d: meta key \"%s\" is a reserved %s name",
144 cfg_filename
, config_lineno
, note
->key
.termedBuf(),
154 Notes::dump(StoreEntry
*entry
, const char *key
)
156 typedef Notes::NotesList::iterator AMLI
;
157 for (AMLI m
= notes
.begin(); m
!= notes
.end(); ++m
) {
158 typedef Note::Values::iterator VLI
;
159 for (VLI v
=(*m
)->values
.begin(); v
!= (*m
)->values
.end(); ++v
) {
160 storeAppendPrintf(entry
, "%s " SQUIDSTRINGPH
" %s",
161 key
, SQUIDSTRINGPRINT((*m
)->key
), ConfigParser::QuoteString((*v
)->value
));
162 dump_acl_list(entry
, (*v
)->aclList
);
163 storeAppendPrintf(entry
, "\n");