4 #include "acl/forward.h"
5 #include "base/RefCount.h"
6 #include "CbDataList.h"
7 #include "format/Format.h"
9 #include "SquidString.h"
17 typedef RefCount
<AccessLogEntry
> AccessLogEntryPointer
;
20 * Used to store a note configuration. The notes are custom key:value
21 * pairs ICAP request headers or ECAP options used to pass
22 * custom transaction-state related meta information to squid
23 * internal subsystems or to adaptation services.
25 class Note
: public RefCountable
28 typedef RefCount
<Note
> Pointer
;
29 /// Stores a value for the note.
30 class Value
: public RefCountable
33 typedef RefCount
<Value
> Pointer
;
34 String value
; ///< Configured annotation value, possibly with %macros
35 ACLList
*aclList
; ///< The access list used to determine if this value is valid for a request
36 /// Compiled annotation value format
37 Format::Format
*valueFormat
;
38 explicit Value(const String
&aVal
) : value(aVal
), aclList(NULL
), valueFormat(NULL
) {}
41 typedef std::vector
<Value::Pointer
> Values
;
43 explicit Note(const String
&aKey
): key(aKey
) {}
46 * Adds a value to the note and returns a pointer to the
47 * related Value object.
49 Value::Pointer
addValue(const String
&value
);
52 * Walks through the possible values list of the note and selects
53 * the first value which matches the given HttpRequest and HttpReply
54 * or NULL if none matches.
55 * If an AccessLogEntry given and Value::valueFormat is not null, the
56 * formatted value returned.
58 const char *match(HttpRequest
*request
, HttpReply
*reply
, const AccessLogEntryPointer
&al
);
60 String key
; ///< The note key
61 Values values
; ///< The possible values list for the note
66 * Used to store a notes configuration list.
71 typedef std::vector
<Note::Pointer
> NotesList
;
72 typedef NotesList::iterator iterator
; ///< iterates over the notes list
73 typedef NotesList::const_iterator const_iterator
; ///< iterates over the notes list
75 Notes(const char *aDescr
, const char **metasBlacklist
, bool allowFormatted
= false): descr(aDescr
), blacklisted(metasBlacklist
), formattedValues(allowFormatted
) {}
76 Notes(): descr(NULL
), blacklisted(NULL
) {}
77 ~Notes() { notes
.clear(); }
79 * Parse a notes line and returns a pointer to the
82 Note::Pointer
parse(ConfigParser
&parser
);
84 * Dump the notes list to the given StoreEntry object.
86 void dump(StoreEntry
*entry
, const char *name
);
87 void clean(); /// clean the notes list
89 /// points to the first argument
90 iterator
begin() { return notes
.begin(); }
91 /// points to the end of list
92 iterator
end() { return notes
.end(); }
93 /// return true if the notes list is empty
94 bool empty() { return notes
.empty(); }
96 NotesList notes
; ///< The Note::Pointer objects array list
97 const char *descr
; ///< A short description for notes list
98 const char **blacklisted
; ///< Null terminated list of blacklisted note keys
99 bool formattedValues
; ///< Whether the formatted values are supported
103 * Adds a note to the notes list and returns a pointer to the
104 * related Note object. If the note key already exists in list,
105 * returns a pointer to the existing object.
107 Note::Pointer
add(const String
¬eKey
);
111 * Used to store list of notes
113 class NotePairs
: public RefCountable
116 typedef RefCount
<NotePairs
> Pointer
;
119 * Used to store a note key/value pair.
124 Entry(const char *aKey
, const char *aValue
): name(aKey
), value(aValue
) {}
127 MEMPROXY_CLASS(Entry
);
134 * Append the entries of the src NotePairs list to our list.
136 void append(const NotePairs
*src
);
139 * Append any new entries of the src NotePairs list to our list.
140 * Entries which already exist in the destination set are ignored.
142 void appendNewOnly(const NotePairs
*src
);
145 * Returns a comma separated list of notes with key 'noteKey'.
146 * Use findFirst instead when a unique kv-pair is needed.
148 const char *find(const char *noteKey
) const;
151 * Returns the first note value for this key or an empty string.
153 const char *findFirst(const char *noteKey
) const;
156 * Adds a note key and value to the notes list.
157 * If the key name already exists in list, add the given value to its set
160 void add(const char *key
, const char *value
);
163 * Adds a note key and values strList to the notes list.
164 * If the key name already exists in list, add the new values to its set
167 void addStrList(const char *key
, const char *values
);
170 * Return true if the key/value pair is already stored
172 bool hasPair(const char *key
, const char *value
) const;
175 * Convert NotePairs list to a string consist of "Key: Value"
176 * entries separated by sep string.
178 const char *toString(const char *sep
= "\r\n") const;
181 * True if there are not entries in the list
183 bool empty() const {return entries
.empty();}
185 std::vector
<NotePairs::Entry
*> entries
; ///< The key/value pair entries
188 NotePairs
&operator = (NotePairs
const &); // Not implemented
189 NotePairs(NotePairs
const &); // Not implemented
192 MEMPROXY_CLASS_INLINE(NotePairs::Entry
);
194 class AccessLogEntry
;
196 * Keep in sync HttpRequest and the corresponding AccessLogEntry objects
198 NotePairs
&SyncNotes(AccessLogEntry
&ale
, HttpRequest
&request
);