]> git.ipfire.org Git - thirdparty/squid.git/blame - src/Notes.cc
Major ACL handling update, including the following changes:
[thirdparty/squid.git] / src / Notes.cc
CommitLineData
b3404bc5
CT
1/*
2 * SQUID Web Proxy Cache http://www.squid-cache.org/
3 * ----------------------------------------------------------
4 *
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.
13 *
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.
18 *
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.
23 *
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.
27 *
28 */
29
30#include "squid.h"
31#include "globals.h"
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"
38#include "Store.h"
cf9f0261 39#include "StrList.h"
b3404bc5
CT
40
41#include <algorithm>
42#include <string>
43
44Note::Value::~Value()
45{
46 aclDestroyAclList(&aclList);
47}
48
49Note::Value::Pointer
50Note::addValue(const String &value)
51{
52 Value::Pointer v = new Value(value);
53 values.push_back(v);
54 return v;
55}
56
57const char *
58Note::match(HttpRequest *request, HttpReply *reply)
59{
60
61 typedef Values::iterator VLI;
62 ACLFilledChecklist ch(NULL, request, NULL);
b248c2a3 63 ch.reply = reply;
b3404bc5 64 if (reply)
b248c2a3 65 HTTPMSGLOCK(ch.reply);
b3404bc5
CT
66
67 for (VLI i = values.begin(); i != values.end(); ++i ) {
68 const int ret= ch.fastCheck((*i)->aclList);
69 debugs(93, 5, HERE << "Check for header name: " << key << ": " << (*i)->value
70 <<", HttpRequest: " << request << " HttpReply: " << reply << " matched: " << ret);
71 if (ret == ACCESS_ALLOWED)
72 return (*i)->value.termedBuf();
73 }
74 return NULL;
75}
76
77Note::Pointer
cf9f0261 78Notes::add(const String &noteKey)
b3404bc5 79{
cf9f0261 80 typedef Notes::NotesList::iterator AMLI;
b3404bc5
CT
81 for (AMLI i = notes.begin(); i != notes.end(); ++i) {
82 if ((*i)->key == noteKey)
83 return (*i);
84 }
85
cf9f0261
CT
86 Note::Pointer note = new Note(noteKey);
87 notes.push_back(note);
b3404bc5
CT
88 return note;
89}
90
91Note::Pointer
92Notes::parse(ConfigParser &parser)
93{
94 String key, value;
95 ConfigParser::ParseString(&key);
96 ConfigParser::ParseQuotedString(&value);
97 Note::Pointer note = add(key);
98 Note::Value::Pointer noteValue = note->addValue(value);
6f58d7d7
AR
99
100 String label(key);
101 label.append('=');
102 label.append(value);
103 aclParseAclList(parser, &noteValue->aclList, label.termedBuf());
b3404bc5
CT
104
105 if (blacklisted) {
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(),
110 descr ? descr : "");
111 }
112 }
113 }
114
115 return note;
116}
117
118void
119Notes::dump(StoreEntry *entry, const char *key)
120{
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");
129 }
130 }
131}
132
133void
134Notes::clean()
135{
136 notes.clean();
137}
cf9f0261
CT
138
139const char *
140NotePairs::find(const char *noteKey) const
141{
142 static String value;
143 value.clean();
144 for (Vector<NotePairs::Entry *>::const_iterator i = entries.begin(); i != entries.end(); ++i) {
145 if ((*i)->name.cmp(noteKey) == 0) {
146 if (value.size())
147 value.append(", ");
148 value.append(ConfigParser::QuoteString((*i)->value));
149 }
150 }
151 return value.size() ? value.termedBuf() : NULL;
152}
153
154const char *
155NotePairs::toString(const char *sep) const
156{
157 static String value;
158 value.clean();
159 for (Vector<NotePairs::Entry *>::const_iterator i = entries.begin(); i != entries.end(); ++i) {
160 value.append((*i)->name);
161 value.append(": ");
162 value.append(ConfigParser::QuoteString((*i)->value));
163 value.append(sep);
164 }
165 return value.size() ? value.termedBuf() : NULL;
166}
167
168const char *
169NotePairs::findFirst(const char *noteKey) const
170{
171 for (Vector<NotePairs::Entry *>::const_iterator i = entries.begin(); i != entries.end(); ++i) {
172 if ((*i)->name.cmp(noteKey) == 0)
173 return (*i)->value.termedBuf();
174 }
175 return NULL;
176}
177
178void
179NotePairs::add(const char *key, const char *note)
180{
181 entries.push_back(new NotePairs::Entry(key, note));
182}
183
184void
185NotePairs::addStrList(const char *key, const char *values)
186{
187 String strValues(values);
188 const char *item;
189 const char *pos = NULL;
190 int ilen = 0;
191 while(strListGetItem(&strValues, ',', &item, &ilen, &pos)) {
192 String v;
193 v.append(item, ilen);
194 entries.push_back(new NotePairs::Entry(key, v.termedBuf()));
195 }
196}
197
198bool
199NotePairs::hasPair(const char *key, const char *value) const
200{
201 for (Vector<NotePairs::Entry *>::const_iterator i = entries.begin(); i != entries.end(); ++i) {
202 if ((*i)->name.cmp(key) == 0 || (*i)->value.cmp(value) == 0)
203 return true;
204 }
205 return false;
206}
207
208void
209NotePairs::append(const NotePairs *src)
210{
211 for (Vector<NotePairs::Entry *>::const_iterator i = src->entries.begin(); i != src->entries.end(); ++i) {
212 entries.push_back(new NotePairs::Entry((*i)->name.termedBuf(), (*i)->value.termedBuf()));
213 }
214}