]> git.ipfire.org Git - thirdparty/squid.git/blob - src/Notes.cc
Merged from trunk
[thirdparty/squid.git] / src / Notes.cc
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"
39
40 #include <algorithm>
41 #include <string>
42
43 Note::Value::~Value()
44 {
45 aclDestroyAclList(&aclList);
46 }
47
48 Note::Value::Pointer
49 Note::addValue(const String &value)
50 {
51 Value::Pointer v = new Value(value);
52 values.push_back(v);
53 return v;
54 }
55
56 const char *
57 Note::match(HttpRequest *request, HttpReply *reply)
58 {
59
60 typedef Values::iterator VLI;
61 ACLFilledChecklist ch(NULL, request, NULL);
62 if (reply)
63 ch.reply = HTTPMSGLOCK(reply);
64
65 for (VLI i = values.begin(); i != values.end(); ++i ) {
66 const int ret= ch.fastCheck((*i)->aclList);
67 debugs(93, 5, HERE << "Check for header name: " << key << ": " << (*i)->value
68 <<", HttpRequest: " << request << " HttpReply: " << reply << " matched: " << ret);
69 if (ret == ACCESS_ALLOWED)
70 return (*i)->value.termedBuf();
71 }
72 return NULL;
73 }
74
75 Note::Pointer
76 Notes::findByName(const String &noteKey) const
77 {
78 typedef Notes::NotesList::const_iterator AMLI;
79 for (AMLI i = notes.begin(); i != notes.end(); ++i) {
80 if ((*i)->key == noteKey)
81 return (*i);
82 }
83
84 return Note::Pointer();
85 }
86
87 void
88 Notes::add(const String &noteKey, const String &noteValue)
89 {
90 Note::Pointer key = add(noteKey);
91 key->addValue(noteValue);
92 }
93
94 Note::Pointer
95 Notes::add(const String &noteKey)
96 {
97 Note::Pointer note = findByName(noteKey);
98 if (note == NULL) {
99 note = new Note(noteKey);
100 notes.push_back(note);
101 }
102 return note;
103 }
104
105 Note::Pointer
106 Notes::parse(ConfigParser &parser)
107 {
108 String key, value;
109 ConfigParser::ParseString(&key);
110 ConfigParser::ParseQuotedString(&value);
111 Note::Pointer note = add(key);
112 Note::Value::Pointer noteValue = note->addValue(value);
113 aclParseAclList(parser, &noteValue->aclList);
114
115 if (blacklisted) {
116 for (int i = 0; blacklisted[i] != NULL; ++i) {
117 if (note->key.caseCmp(blacklisted[i]) == 0) {
118 fatalf("%s:%d: meta key \"%s\" is a reserved %s name",
119 cfg_filename, config_lineno, note->key.termedBuf(),
120 descr ? descr : "");
121 }
122 }
123 }
124
125 return note;
126 }
127
128 void
129 Notes::dump(StoreEntry *entry, const char *key)
130 {
131 typedef Notes::NotesList::iterator AMLI;
132 for (AMLI m = notes.begin(); m != notes.end(); ++m) {
133 typedef Note::Values::iterator VLI;
134 for (VLI v =(*m)->values.begin(); v != (*m)->values.end(); ++v ) {
135 storeAppendPrintf(entry, "%s " SQUIDSTRINGPH " %s",
136 key, SQUIDSTRINGPRINT((*m)->key), ConfigParser::QuoteString((*v)->value));
137 dump_acl_list(entry, (*v)->aclList);
138 storeAppendPrintf(entry, "\n");
139 }
140 }
141 }
142
143 void
144 Notes::clean()
145 {
146 notes.clean();
147 }