4 #include "acl/forward.h"
5 #include "base/RefCount.h"
6 #include "base/Vector.h"
7 #include "CbDataList.h"
8 #include "format/Format.h"
10 #include "SquidString.h"
19 typedef RefCount
<AccessLogEntry
> AccessLogEntryPointer
;
22 * Used to store a note configuration. The notes are custom key:value
23 * pairs ICAP request headers or ECAP options used to pass
24 * custom transaction-state related meta information to squid
25 * internal subsystems or to adaptation services.
27 class Note
: public RefCountable
30 typedef RefCount
<Note
> Pointer
;
31 /// Stores a value for the note.
32 class Value
: public RefCountable
35 typedef RefCount
<Value
> Pointer
;
36 String value
; ///< Configured annotation value, possibly with %macros
37 ACLList
*aclList
; ///< The access list used to determine if this value is valid for a request
38 /// Compiled annotation value format
39 Format::Format
*valueFormat
;
40 explicit Value(const String
&aVal
) : value(aVal
), aclList(NULL
), valueFormat(NULL
) {}
43 typedef Vector
<Value::Pointer
> Values
;
45 explicit Note(const String
&aKey
): key(aKey
) {}
48 * Adds a value to the note and returns a pointer to the
49 * related Value object.
51 Value::Pointer
addValue(const String
&value
);
54 * Walks through the possible values list of the note and selects
55 * the first value which matches the given HttpRequest and HttpReply
56 * or NULL if none matches.
57 * If an AccessLogEntry given and Value::valueFormat is not null, the
58 * formatted value returned.
60 const char *match(HttpRequest
*request
, HttpReply
*reply
, const AccessLogEntryPointer
&al
);
62 String key
; ///< The note key
63 Values values
; ///< The possible values list for the note
68 * Used to store a notes configuration list.
73 typedef Vector
<Note::Pointer
> NotesList
;
74 typedef NotesList::iterator iterator
; ///< iterates over the notes list
75 typedef NotesList::const_iterator const_iterator
; ///< iterates over the notes list
77 Notes(const char *aDescr
, const char **metasBlacklist
, bool allowFormatted
= false): descr(aDescr
), blacklisted(metasBlacklist
), formattedValues(allowFormatted
) {}
78 Notes(): descr(NULL
), blacklisted(NULL
) {}
79 ~Notes() { notes
.clear(); }
81 * Parse a notes line and returns a pointer to the
84 Note::Pointer
parse(ConfigParser
&parser
);
86 * Dump the notes list to the given StoreEntry object.
88 void dump(StoreEntry
*entry
, const char *name
);
89 void clean(); /// clean the notes list
91 /// points to the first argument
92 iterator
begin() { return notes
.begin(); }
93 /// points to the end of list
94 iterator
end() { return notes
.end(); }
95 /// return true if the notes list is empty
96 bool empty() { return notes
.empty(); }
98 NotesList notes
; ///< The Note::Pointer objects array list
99 const char *descr
; ///< A short description for notes list
100 const char **blacklisted
; ///< Null terminated list of blacklisted note keys
101 bool formattedValues
; ///< Whether the formatted values are supported
105 * Adds a note to the notes list and returns a pointer to the
106 * related Note object. If the note key already exists in list,
107 * returns a pointer to the existing object.
109 Note::Pointer
add(const String
¬eKey
);
113 * Used to store list of notes
115 class NotePairs
: public RefCountable
118 typedef RefCount
<NotePairs
> Pointer
;
121 * Used to store a note key/value pair.
126 Entry(const char *aKey
, const char *aValue
): name(aKey
), value(aValue
) {}
129 MEMPROXY_CLASS(Entry
);
136 * Append the entries of the src NotePairs list to our list.
138 void append(const NotePairs
*src
);
141 * Append any new entries of the src NotePairs list to our list.
142 * Entries which already exist in the destination set are ignored.
144 void appendNewOnly(const NotePairs
*src
);
147 * Returns a comma separated list of notes with key 'noteKey'.
148 * Use findFirst instead when a unique kv-pair is needed.
150 const char *find(const char *noteKey
) const;
153 * Returns the first note value for this key or an empty string.
155 const char *findFirst(const char *noteKey
) const;
158 * Adds a note key and value to the notes list.
159 * If the key name already exists in list, add the given value to its set
162 void add(const char *key
, const char *value
);
165 * Adds a note key and values strList to the notes list.
166 * If the key name already exists in list, add the new values to its set
169 void addStrList(const char *key
, const char *values
);
172 * Return true if the key/value pair is already stored
174 bool hasPair(const char *key
, const char *value
) const;
177 * Convert NotePairs list to a string consist of "Key: Value"
178 * entries separated by sep string.
180 const char *toString(const char *sep
= "\r\n") const;
183 * True if there are not entries in the list
185 bool empty() const {return entries
.empty();}
187 Vector
<NotePairs::Entry
*> entries
; ///< The key/value pair entries
190 NotePairs
&operator = (NotePairs
const &); // Not implemented
191 NotePairs(NotePairs
const &); // Not implemented
194 MEMPROXY_CLASS_INLINE(NotePairs::Entry
);
196 class AccessLogEntry
;
198 * Keep in sync HttpRequest and the corresponding AccessLogEntry objects
200 NotePairs
&SyncNotes(AccessLogEntry
&ale
, HttpRequest
&request
);