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 "CbDataList.h"
15 #include "format/Format.h"
17 #include "SquidString.h"
25 typedef RefCount
<AccessLogEntry
> AccessLogEntryPointer
;
28 * Used to store a note configuration. The notes are custom key:value
29 * pairs ICAP request headers or ECAP options used to pass
30 * custom transaction-state related meta information to squid
31 * internal subsystems or to adaptation services.
33 class Note
: public RefCountable
36 typedef RefCount
<Note
> Pointer
;
37 /// Stores a value for the note.
38 class Value
: public RefCountable
41 typedef RefCount
<Value
> Pointer
;
42 String value
; ///< Configured annotation value, possibly with %macros
43 ACLList
*aclList
; ///< The access list used to determine if this value is valid for a request
44 /// Compiled annotation value format
45 Format::Format
*valueFormat
;
46 explicit Value(const String
&aVal
) : value(aVal
), aclList(NULL
), valueFormat(NULL
) {}
49 typedef std::vector
<Value::Pointer
> Values
;
51 explicit Note(const String
&aKey
): key(aKey
) {}
54 * Adds a value to the note and returns a pointer to the
55 * related Value object.
57 Value::Pointer
addValue(const String
&value
);
60 * Walks through the possible values list of the note and selects
61 * the first value which matches the given HttpRequest and HttpReply
62 * or NULL if none matches.
63 * If an AccessLogEntry given and Value::valueFormat is not null, the
64 * formatted value returned.
66 const char *match(HttpRequest
*request
, HttpReply
*reply
, const AccessLogEntryPointer
&al
);
68 String key
; ///< The note key
69 Values values
; ///< The possible values list for the note
74 * Used to store a notes configuration list.
79 typedef std::vector
<Note::Pointer
> NotesList
;
80 typedef NotesList::iterator iterator
; ///< iterates over the notes list
81 typedef NotesList::const_iterator const_iterator
; ///< iterates over the notes list
83 Notes(const char *aDescr
, const char **metasBlacklist
, bool allowFormatted
= false): descr(aDescr
), blacklisted(metasBlacklist
), formattedValues(allowFormatted
) {}
84 Notes(): descr(NULL
), blacklisted(NULL
) {}
85 ~Notes() { notes
.clear(); }
87 * Parse a notes line and returns a pointer to the
90 Note::Pointer
parse(ConfigParser
&parser
);
92 * Dump the notes list to the given StoreEntry object.
94 void dump(StoreEntry
*entry
, const char *name
);
95 void clean(); /// clean the notes list
97 /// points to the first argument
98 iterator
begin() { return notes
.begin(); }
99 /// points to the end of list
100 iterator
end() { return notes
.end(); }
101 /// return true if the notes list is empty
102 bool empty() { return notes
.empty(); }
104 NotesList notes
; ///< The Note::Pointer objects array list
105 const char *descr
; ///< A short description for notes list
106 const char **blacklisted
; ///< Null terminated list of blacklisted note keys
107 bool formattedValues
; ///< Whether the formatted values are supported
111 * Adds a note to the notes list and returns a pointer to the
112 * related Note object. If the note key already exists in list,
113 * returns a pointer to the existing object.
115 Note::Pointer
add(const String
¬eKey
);
119 * Used to store list of notes
121 class NotePairs
: public RefCountable
124 typedef RefCount
<NotePairs
> Pointer
;
127 * Used to store a note key/value pair.
132 Entry(const char *aKey
, const char *aValue
): name(aKey
), value(aValue
) {}
135 MEMPROXY_CLASS(Entry
);
142 * Append the entries of the src NotePairs list to our list.
144 void append(const NotePairs
*src
);
147 * Replace existing list entries with the src NotePairs entries.
148 * Entries which do not exist in the destination set are added.
150 void replaceOrAdd(const NotePairs
*src
);
153 * Append any new entries of the src NotePairs list to our list.
154 * Entries which already exist in the destination set are ignored.
156 void appendNewOnly(const NotePairs
*src
);
159 * Returns a comma separated list of notes with key 'noteKey'.
160 * Use findFirst instead when a unique kv-pair is needed.
162 const char *find(const char *noteKey
, const char *sep
= ",") const;
165 * Returns the first note value for this key or an empty string.
167 const char *findFirst(const char *noteKey
) const;
170 * Adds a note key and value to the notes list.
171 * If the key name already exists in list, add the given value to its set
174 void add(const char *key
, const char *value
);
177 * Remove all notes with a given key.
179 void remove(const char *key
);
182 * Adds a note key and values strList to the notes list.
183 * If the key name already exists in list, add the new values to its set
186 void addStrList(const char *key
, const char *values
);
189 * Return true if the key/value pair is already stored
191 bool hasPair(const char *key
, const char *value
) const;
194 * Convert NotePairs list to a string consist of "Key: Value"
195 * entries separated by sep string.
197 const char *toString(const char *sep
= "\r\n") const;
200 * True if there are not entries in the list
202 bool empty() const {return entries
.empty();}
204 std::vector
<NotePairs::Entry
*> entries
; ///< The key/value pair entries
207 NotePairs
&operator = (NotePairs
const &); // Not implemented
208 NotePairs(NotePairs
const &); // Not implemented
211 MEMPROXY_CLASS_INLINE(NotePairs::Entry
);
213 class AccessLogEntry
;
215 * Keep in sync HttpRequest and the corresponding AccessLogEntry objects
217 NotePairs
&SyncNotes(AccessLogEntry
&ale
, HttpRequest
&request
);
221 * Updates ConnStateData ids and HttpRequest notes from helpers received notes.
223 void UpdateRequestNotes(ConnStateData
*csd
, HttpRequest
&request
, NotePairs
const ¬es
);