]>
Commit | Line | Data |
---|---|---|
bbc27441 | 1 | /* |
bde978a6 | 2 | * Copyright (C) 1996-2015 The Squid Software Foundation and contributors |
bbc27441 AJ |
3 | * |
4 | * Squid software is distributed under GPLv2+ license and includes | |
5 | * contributions from numerous individuals and organizations. | |
6 | * Please see the COPYING and CONTRIBUTORS files for details. | |
7 | */ | |
8 | ||
b3404bc5 CT |
9 | #ifndef SQUID_NOTES_H |
10 | #define SQUID_NOTES_H | |
11 | ||
6f58d7d7 | 12 | #include "acl/forward.h" |
cf9f0261 | 13 | #include "base/RefCount.h" |
af0ded40 | 14 | #include "format/Format.h" |
ed6e9fb9 | 15 | #include "mem/forward.h" |
cf9f0261 | 16 | #include "SquidString.h" |
b3404bc5 CT |
17 | #include "typedefs.h" |
18 | ||
b3404bc5 | 19 | #include <string> |
81481ec0 | 20 | #include <vector> |
b3404bc5 | 21 | |
b3404bc5 CT |
22 | class HttpRequest; |
23 | class HttpReply; | |
af0ded40 | 24 | typedef RefCount<AccessLogEntry> AccessLogEntryPointer; |
b3404bc5 CT |
25 | |
26 | /** | |
cf9f0261 CT |
27 | * Used to store a note configuration. The notes are custom key:value |
28 | * pairs ICAP request headers or ECAP options used to pass | |
b3404bc5 | 29 | * custom transaction-state related meta information to squid |
cf9f0261 | 30 | * internal subsystems or to adaptation services. |
b3404bc5 CT |
31 | */ |
32 | class Note: public RefCountable | |
33 | { | |
34 | public: | |
35 | typedef RefCount<Note> Pointer; | |
36 | /// Stores a value for the note. | |
37 | class Value: public RefCountable | |
38 | { | |
39 | public: | |
40 | typedef RefCount<Value> Pointer; | |
af0ded40 | 41 | String value; ///< Configured annotation value, possibly with %macros |
b3404bc5 | 42 | ACLList *aclList; ///< The access list used to determine if this value is valid for a request |
af0ded40 CT |
43 | /// Compiled annotation value format |
44 | Format::Format *valueFormat; | |
45 | explicit Value(const String &aVal) : value(aVal), aclList(NULL), valueFormat(NULL) {} | |
b3404bc5 CT |
46 | ~Value(); |
47 | }; | |
81481ec0 | 48 | typedef std::vector<Value::Pointer> Values; |
b3404bc5 CT |
49 | |
50 | explicit Note(const String &aKey): key(aKey) {} | |
51 | ||
52 | /** | |
53 | * Adds a value to the note and returns a pointer to the | |
54 | * related Value object. | |
55 | */ | |
56 | Value::Pointer addValue(const String &value); | |
57 | ||
58 | /** | |
59 | * Walks through the possible values list of the note and selects | |
60 | * the first value which matches the given HttpRequest and HttpReply | |
61 | * or NULL if none matches. | |
af0ded40 CT |
62 | * If an AccessLogEntry given and Value::valueFormat is not null, the |
63 | * formatted value returned. | |
b3404bc5 | 64 | */ |
af0ded40 | 65 | const char *match(HttpRequest *request, HttpReply *reply, const AccessLogEntryPointer &al); |
fd7f26ea | 66 | |
b3404bc5 CT |
67 | String key; ///< The note key |
68 | Values values; ///< The possible values list for the note | |
69 | }; | |
70 | ||
71 | class ConfigParser; | |
72 | /** | |
cf9f0261 | 73 | * Used to store a notes configuration list. |
b3404bc5 | 74 | */ |
ffb82151 A |
75 | class Notes |
76 | { | |
b3404bc5 | 77 | public: |
81481ec0 | 78 | typedef std::vector<Note::Pointer> NotesList; |
b3404bc5 | 79 | typedef NotesList::iterator iterator; ///< iterates over the notes list |
bc600349 | 80 | typedef NotesList::const_iterator const_iterator; ///< iterates over the notes list |
b3404bc5 | 81 | |
af0ded40 | 82 | Notes(const char *aDescr, const char **metasBlacklist, bool allowFormatted = false): descr(aDescr), blacklisted(metasBlacklist), formattedValues(allowFormatted) {} |
4579a6d0 | 83 | Notes(): descr(NULL), blacklisted(NULL), formattedValues(false) {} |
c33a88ca | 84 | ~Notes() { notes.clear(); } |
b3404bc5 CT |
85 | /** |
86 | * Parse a notes line and returns a pointer to the | |
87 | * parsed Note object. | |
88 | */ | |
89 | Note::Pointer parse(ConfigParser &parser); | |
90 | /** | |
91 | * Dump the notes list to the given StoreEntry object. | |
92 | */ | |
93 | void dump(StoreEntry *entry, const char *name); | |
94 | void clean(); /// clean the notes list | |
95 | ||
96 | /// points to the first argument | |
97 | iterator begin() { return notes.begin(); } | |
98 | /// points to the end of list | |
99 | iterator end() { return notes.end(); } | |
100 | /// return true if the notes list is empty | |
101 | bool empty() { return notes.empty(); } | |
102 | ||
103 | NotesList notes; ///< The Note::Pointer objects array list | |
104 | const char *descr; ///< A short description for notes list | |
105 | const char **blacklisted; ///< Null terminated list of blacklisted note keys | |
af0ded40 | 106 | bool formattedValues; ///< Whether the formatted values are supported |
fd7f26ea | 107 | |
b3404bc5 CT |
108 | private: |
109 | /** | |
110 | * Adds a note to the notes list and returns a pointer to the | |
111 | * related Note object. If the note key already exists in list, | |
112 | * returns a pointer to the existing object. | |
113 | */ | |
114 | Note::Pointer add(const String ¬eKey); | |
115 | }; | |
116 | ||
cf9f0261 CT |
117 | /** |
118 | * Used to store list of notes | |
119 | */ | |
120 | class NotePairs: public RefCountable | |
ffb82151 | 121 | { |
b3404bc5 | 122 | public: |
cf9f0261 CT |
123 | typedef RefCount<NotePairs> Pointer; |
124 | ||
125 | /** | |
126 | * Used to store a note key/value pair. | |
127 | */ | |
7e6ef752 A |
128 | class Entry |
129 | { | |
741c2986 | 130 | MEMPROXY_CLASS(Entry); |
cf9f0261 | 131 | public: |
7e6ef752 | 132 | Entry(const char *aKey, const char *aValue): name(aKey), value(aValue) {} |
cf9f0261 CT |
133 | String name; |
134 | String value; | |
cf9f0261 CT |
135 | }; |
136 | ||
d74740bd | 137 | NotePairs() {} |
b670cb6a | 138 | ~NotePairs(); |
cf9f0261 CT |
139 | |
140 | /** | |
141 | * Append the entries of the src NotePairs list to our list. | |
142 | */ | |
143 | void append(const NotePairs *src); | |
144 | ||
457857fe CT |
145 | /** |
146 | * Replace existing list entries with the src NotePairs entries. | |
147 | * Entries which do not exist in the destination set are added. | |
148 | */ | |
149 | void replaceOrAdd(const NotePairs *src); | |
150 | ||
71e7400c AJ |
151 | /** |
152 | * Append any new entries of the src NotePairs list to our list. | |
153 | * Entries which already exist in the destination set are ignored. | |
154 | */ | |
155 | void appendNewOnly(const NotePairs *src); | |
156 | ||
cf9f0261 CT |
157 | /** |
158 | * Returns a comma separated list of notes with key 'noteKey'. | |
159 | * Use findFirst instead when a unique kv-pair is needed. | |
160 | */ | |
c7bcf010 | 161 | const char *find(const char *noteKey, const char *sep = ",") const; |
cf9f0261 CT |
162 | |
163 | /** | |
164 | * Returns the first note value for this key or an empty string. | |
165 | */ | |
166 | const char *findFirst(const char *noteKey) const; | |
167 | ||
168 | /** | |
169 | * Adds a note key and value to the notes list. | |
170 | * If the key name already exists in list, add the given value to its set | |
171 | * of values. | |
172 | */ | |
173 | void add(const char *key, const char *value); | |
174 | ||
457857fe CT |
175 | /** |
176 | * Remove all notes with a given key. | |
177 | */ | |
178 | void remove(const char *key); | |
179 | ||
cf9f0261 CT |
180 | /** |
181 | * Adds a note key and values strList to the notes list. | |
182 | * If the key name already exists in list, add the new values to its set | |
183 | * of values. | |
184 | */ | |
185 | void addStrList(const char *key, const char *values); | |
186 | ||
187 | /** | |
188 | * Return true if the key/value pair is already stored | |
189 | */ | |
190 | bool hasPair(const char *key, const char *value) const; | |
191 | ||
192 | /** | |
193 | * Convert NotePairs list to a string consist of "Key: Value" | |
194 | * entries separated by sep string. | |
195 | */ | |
196 | const char *toString(const char *sep = "\r\n") const; | |
197 | ||
198 | /** | |
199 | * True if there are not entries in the list | |
200 | */ | |
201 | bool empty() const {return entries.empty();} | |
202 | ||
f53969cc | 203 | std::vector<NotePairs::Entry *> entries; ///< The key/value pair entries |
95c0dbfc CT |
204 | |
205 | private: | |
206 | NotePairs &operator = (NotePairs const &); // Not implemented | |
207 | NotePairs(NotePairs const &); // Not implemented | |
b3404bc5 CT |
208 | }; |
209 | ||
f4f55a21 CT |
210 | class AccessLogEntry; |
211 | /** | |
212 | * Keep in sync HttpRequest and the corresponding AccessLogEntry objects | |
213 | */ | |
214 | NotePairs &SyncNotes(AccessLogEntry &ale, HttpRequest &request); | |
215 | ||
457857fe CT |
216 | class ConnStateData; |
217 | /** | |
218 | * Updates ConnStateData ids and HttpRequest notes from helpers received notes. | |
219 | */ | |
220 | void UpdateRequestNotes(ConnStateData *csd, HttpRequest &request, NotePairs const ¬es); | |
b3404bc5 | 221 | #endif |
f53969cc | 222 |