2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
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.
12 #include "acl/forward.h"
13 #include "base/RefCount.h"
14 #include "format/Format.h"
15 #include "mem/forward.h"
16 #include "SquidString.h"
23 typedef RefCount
<AccessLogEntry
> AccessLogEntryPointer
;
26 * Used to store a note configuration. The notes are custom key:value
27 * pairs ICAP request headers or ECAP options used to pass
28 * custom transaction-state related meta information to squid
29 * internal subsystems or to adaptation services.
31 class Note
: public RefCountable
34 typedef RefCount
<Note
> Pointer
;
35 /// Stores a value for the note.
36 class Value
: public RefCountable
39 typedef RefCount
<Value
> Pointer
;
40 String value
; ///< Configured annotation value, possibly with %macros
41 ACLList
*aclList
; ///< The access list used to determine if this value is valid for a request
42 /// Compiled annotation value format
43 Format::Format
*valueFormat
;
44 explicit Value(const String
&aVal
) : value(aVal
), aclList(NULL
), valueFormat(NULL
) {}
47 typedef std::vector
<Value::Pointer
> Values
;
49 explicit Note(const String
&aKey
): key(aKey
) {}
52 * Adds a value to the note and returns a pointer to the
53 * related Value object.
55 Value::Pointer
addValue(const String
&value
);
58 * Walks through the possible values list of the note and selects
59 * the first value which matches the given HttpRequest and HttpReply
60 * or NULL if none matches.
61 * If an AccessLogEntry given and Value::valueFormat is not null, the
62 * formatted value returned.
64 const char *match(HttpRequest
*request
, HttpReply
*reply
, const AccessLogEntryPointer
&al
);
66 String key
; ///< The note key
67 Values values
; ///< The possible values list for the note
72 * Used to store a notes configuration list.
77 typedef std::vector
<Note::Pointer
> NotesList
;
78 typedef NotesList::iterator iterator
; ///< iterates over the notes list
79 typedef NotesList::const_iterator const_iterator
; ///< iterates over the notes list
81 Notes(const char *aDescr
, const char **metasBlacklist
, bool allowFormatted
= false): descr(aDescr
), blacklisted(metasBlacklist
), formattedValues(allowFormatted
) {}
82 Notes(): descr(NULL
), blacklisted(NULL
), formattedValues(false) {}
83 ~Notes() { notes
.clear(); }
85 * Parse a notes line and returns a pointer to the
88 Note::Pointer
parse(ConfigParser
&parser
);
90 * Dump the notes list to the given StoreEntry object.
92 void dump(StoreEntry
*entry
, const char *name
);
93 void clean(); /// clean the notes list
95 /// points to the first argument
96 iterator
begin() { return notes
.begin(); }
97 /// points to the end of list
98 iterator
end() { return notes
.end(); }
99 /// return true if the notes list is empty
100 bool empty() { return notes
.empty(); }
102 NotesList notes
; ///< The Note::Pointer objects array list
103 const char *descr
; ///< A short description for notes list
104 const char **blacklisted
; ///< Null terminated list of blacklisted note keys
105 bool formattedValues
; ///< Whether the formatted values are supported
109 * Adds a note to the notes list and returns a pointer to the
110 * related Note object. If the note key already exists in list,
111 * returns a pointer to the existing object.
113 Note::Pointer
add(const String
¬eKey
);
117 * Used to store list of notes
119 class NotePairs
: public RefCountable
122 typedef RefCount
<NotePairs
> Pointer
;
125 * Used to store a note key/value pair.
129 MEMPROXY_CLASS(Entry
);
131 Entry(const char *aKey
, const char *aValue
): name(aKey
), value(aValue
) {}
140 * Append the entries of the src NotePairs list to our list.
142 void append(const NotePairs
*src
);
145 * Replace existing list entries with the src NotePairs entries.
146 * Entries which do not exist in the destination set are added.
148 void replaceOrAdd(const NotePairs
*src
);
151 * Append any new entries of the src NotePairs list to our list.
152 * Entries which already exist in the destination set are ignored.
154 void appendNewOnly(const NotePairs
*src
);
157 * Returns a comma separated list of notes with key 'noteKey'.
158 * Use findFirst instead when a unique kv-pair is needed.
160 const char *find(const char *noteKey
, const char *sep
= ",") const;
163 * Returns the first note value for this key or an empty string.
165 const char *findFirst(const char *noteKey
) const;
168 * Adds a note key and value to the notes list.
169 * If the key name already exists in list, add the given value to its set
172 void add(const char *key
, const char *value
);
175 * Remove all notes with a given key.
177 void remove(const char *key
);
180 * Adds a note key and values strList to the notes list.
181 * If the key name already exists in list, add the new values to its set
184 void addStrList(const char *key
, const char *values
);
187 * Return true if the key/value pair is already stored
189 bool hasPair(const char *key
, const char *value
) const;
192 * Convert NotePairs list to a string consist of "Key: Value"
193 * entries separated by sep string.
195 const char *toString(const char *sep
= "\r\n") const;
198 * True if there are not entries in the list
200 bool empty() const {return entries
.empty();}
202 std::vector
<NotePairs::Entry
*> entries
; ///< The key/value pair entries
205 NotePairs
&operator = (NotePairs
const &); // Not implemented
206 NotePairs(NotePairs
const &); // Not implemented
209 class AccessLogEntry
;
211 * Keep in sync HttpRequest and the corresponding AccessLogEntry objects
213 NotePairs
&SyncNotes(AccessLogEntry
&ale
, HttpRequest
&request
);
217 * Updates ConnStateData ids and HttpRequest notes from helpers received notes.
219 void UpdateRequestNotes(ConnStateData
*csd
, HttpRequest
&request
, NotePairs
const ¬es
);