]> git.ipfire.org Git - thirdparty/squid.git/blame - src/Notes.cc
Polish: convert ACLFilledChecklist to CBDATA_CLASS2
[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);
99 aclParseAclList(parser, &noteValue->aclList);
100
101 if (blacklisted) {
102 for (int i = 0; blacklisted[i] != NULL; ++i) {
103 if (note->key.caseCmp(blacklisted[i]) == 0) {
104 fatalf("%s:%d: meta key \"%s\" is a reserved %s name",
105 cfg_filename, config_lineno, note->key.termedBuf(),
106 descr ? descr : "");
107 }
108 }
109 }
110
111 return note;
112}
113
114void
115Notes::dump(StoreEntry *entry, const char *key)
116{
117 typedef Notes::NotesList::iterator AMLI;
118 for (AMLI m = notes.begin(); m != notes.end(); ++m) {
119 typedef Note::Values::iterator VLI;
120 for (VLI v =(*m)->values.begin(); v != (*m)->values.end(); ++v ) {
121 storeAppendPrintf(entry, "%s " SQUIDSTRINGPH " %s",
122 key, SQUIDSTRINGPRINT((*m)->key), ConfigParser::QuoteString((*v)->value));
123 dump_acl_list(entry, (*v)->aclList);
124 storeAppendPrintf(entry, "\n");
125 }
126 }
127}
128
129void
130Notes::clean()
131{
132 notes.clean();
133}
cf9f0261
CT
134
135const char *
136NotePairs::find(const char *noteKey) const
137{
138 static String value;
139 value.clean();
140 for (Vector<NotePairs::Entry *>::const_iterator i = entries.begin(); i != entries.end(); ++i) {
141 if ((*i)->name.cmp(noteKey) == 0) {
142 if (value.size())
143 value.append(", ");
144 value.append(ConfigParser::QuoteString((*i)->value));
145 }
146 }
147 return value.size() ? value.termedBuf() : NULL;
148}
149
150const char *
151NotePairs::toString(const char *sep) const
152{
7e6ef752 153 static String value;
cf9f0261
CT
154 value.clean();
155 for (Vector<NotePairs::Entry *>::const_iterator i = entries.begin(); i != entries.end(); ++i) {
156 value.append((*i)->name);
157 value.append(": ");
158 value.append(ConfigParser::QuoteString((*i)->value));
159 value.append(sep);
160 }
161 return value.size() ? value.termedBuf() : NULL;
162}
163
164const char *
165NotePairs::findFirst(const char *noteKey) const
166{
167 for (Vector<NotePairs::Entry *>::const_iterator i = entries.begin(); i != entries.end(); ++i) {
168 if ((*i)->name.cmp(noteKey) == 0)
169 return (*i)->value.termedBuf();
170 }
171 return NULL;
172}
173
174void
175NotePairs::add(const char *key, const char *note)
176{
177 entries.push_back(new NotePairs::Entry(key, note));
178}
179
180void
181NotePairs::addStrList(const char *key, const char *values)
182{
183 String strValues(values);
184 const char *item;
185 const char *pos = NULL;
186 int ilen = 0;
7e6ef752 187 while (strListGetItem(&strValues, ',', &item, &ilen, &pos)) {
cf9f0261
CT
188 String v;
189 v.append(item, ilen);
190 entries.push_back(new NotePairs::Entry(key, v.termedBuf()));
191 }
192}
193
194bool
195NotePairs::hasPair(const char *key, const char *value) const
196{
197 for (Vector<NotePairs::Entry *>::const_iterator i = entries.begin(); i != entries.end(); ++i) {
198 if ((*i)->name.cmp(key) == 0 || (*i)->value.cmp(value) == 0)
199 return true;
200 }
201 return false;
202}
203
204void
205NotePairs::append(const NotePairs *src)
206{
207 for (Vector<NotePairs::Entry *>::const_iterator i = src->entries.begin(); i != src->entries.end(); ++i) {
208 entries.push_back(new NotePairs::Entry((*i)->name.termedBuf(), (*i)->value.termedBuf()));
209 }
210}