2 * Copyright (C) 1996-2014 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"
16 #include "SquidString.h"
24 typedef RefCount
<AccessLogEntry
> AccessLogEntryPointer
;
27 * Used to store a note configuration. The notes are custom key:value
28 * pairs ICAP request headers or ECAP options used to pass
29 * custom transaction-state related meta information to squid
30 * internal subsystems or to adaptation services.
32 class Note
: public RefCountable
35 typedef RefCount
<Note
> Pointer
;
36 /// Stores a value for the note.
37 class Value
: public RefCountable
40 typedef RefCount
<Value
> Pointer
;
41 String value
; ///< Configured annotation value, possibly with %macros
42 ACLList
*aclList
; ///< The access list used to determine if this value is valid for a request
43 /// Compiled annotation value format
44 Format::Format
*valueFormat
;
45 explicit Value(const String
&aVal
) : value(aVal
), aclList(NULL
), valueFormat(NULL
) {}
48 typedef std::vector
<Value::Pointer
> Values
;
50 explicit Note(const String
&aKey
): key(aKey
) {}
53 * Adds a value to the note and returns a pointer to the
54 * related Value object.
56 Value::Pointer
addValue(const String
&value
);
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.
62 * If an AccessLogEntry given and Value::valueFormat is not null, the
63 * formatted value returned.
65 const char *match(HttpRequest
*request
, HttpReply
*reply
, const AccessLogEntryPointer
&al
);
67 String key
; ///< The note key
68 Values values
; ///< The possible values list for the note
73 * Used to store a notes configuration list.
78 typedef std::vector
<Note::Pointer
> NotesList
;
79 typedef NotesList::iterator iterator
; ///< iterates over the notes list
80 typedef NotesList::const_iterator const_iterator
; ///< iterates over the notes list
82 Notes(const char *aDescr
, const char **metasBlacklist
, bool allowFormatted
= false): descr(aDescr
), blacklisted(metasBlacklist
), formattedValues(allowFormatted
) {}
83 Notes(): descr(NULL
), blacklisted(NULL
), formattedValues(false) {}
84 ~Notes() { notes
.clear(); }
86 * Parse a notes line and returns a pointer to the
89 Note::Pointer
parse(ConfigParser
&parser
);
91 * Dump the notes list to the given StoreEntry object.
93 void dump(StoreEntry
*entry
, const char *name
);
94 void clean(); /// clean the notes list
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(); }
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
106 bool formattedValues
; ///< Whether the formatted values are supported
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.
114 Note::Pointer
add(const String
¬eKey
);
118 * Used to store list of notes
120 class NotePairs
: public RefCountable
123 typedef RefCount
<NotePairs
> Pointer
;
126 * Used to store a note key/value pair.
130 MEMPROXY_CLASS(Entry
);
132 Entry(const char *aKey
, const char *aValue
): name(aKey
), value(aValue
) {}
141 * Append the entries of the src NotePairs list to our list.
143 void append(const NotePairs
*src
);
146 * Replace existing list entries with the src NotePairs entries.
147 * Entries which do not exist in the destination set are added.
149 void replaceOrAdd(const NotePairs
*src
);
152 * Append any new entries of the src NotePairs list to our list.
153 * Entries which already exist in the destination set are ignored.
155 void appendNewOnly(const NotePairs
*src
);
158 * Returns a comma separated list of notes with key 'noteKey'.
159 * Use findFirst instead when a unique kv-pair is needed.
161 const char *find(const char *noteKey
, const char *sep
= ",") const;
164 * Returns the first note value for this key or an empty string.
166 const char *findFirst(const char *noteKey
) const;
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
173 void add(const char *key
, const char *value
);
176 * Remove all notes with a given key.
178 void remove(const char *key
);
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
185 void addStrList(const char *key
, const char *values
);
188 * Return true if the key/value pair is already stored
190 bool hasPair(const char *key
, const char *value
) const;
193 * Convert NotePairs list to a string consist of "Key: Value"
194 * entries separated by sep string.
196 const char *toString(const char *sep
= "\r\n") const;
199 * True if there are not entries in the list
201 bool empty() const {return entries
.empty();}
203 std::vector
<NotePairs::Entry
*> entries
; ///< The key/value pair entries
206 NotePairs
&operator = (NotePairs
const &); // Not implemented
207 NotePairs(NotePairs
const &); // Not implemented
210 class AccessLogEntry
;
212 * Keep in sync HttpRequest and the corresponding AccessLogEntry objects
214 NotePairs
&SyncNotes(AccessLogEntry
&ale
, HttpRequest
&request
);
218 * Updates ConnStateData ids and HttpRequest notes from helpers received notes.
220 void UpdateRequestNotes(ConnStateData
*csd
, HttpRequest
&request
, NotePairs
const ¬es
);