4 #include "base/Vector.h"
5 #include "base/RefCount.h"
6 #include "CbDataList.h"
8 #include "SquidString.h"
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
; ///< a note value
35 ACLList
*aclList
; ///< The access list used to determine if this value is valid for a request
36 explicit Value(const String
&aVal
) : value(aVal
), aclList(NULL
) {}
39 typedef Vector
<Value::Pointer
> Values
;
41 explicit Note(const String
&aKey
): key(aKey
) {}
44 * Adds a value to the note and returns a pointer to the
45 * related Value object.
47 Value::Pointer
addValue(const String
&value
);
50 * Walks through the possible values list of the note and selects
51 * the first value which matches the given HttpRequest and HttpReply
52 * or NULL if none matches.
54 const char *match(HttpRequest
*request
, HttpReply
*reply
);
56 String key
; ///< The note key
57 Values values
; ///< The possible values list for the note
62 * Used to store a notes configuration list.
67 typedef Vector
<Note::Pointer
> NotesList
;
68 typedef NotesList::iterator iterator
; ///< iterates over the notes list
69 typedef NotesList::const_iterator const_iterator
; ///< iterates over the notes list
71 Notes(const char *aDescr
, const char **metasBlacklist
): descr(aDescr
), blacklisted(metasBlacklist
) {}
72 Notes(): descr(NULL
), blacklisted(NULL
) {}
73 ~Notes() { notes
.clean(); }
75 * Parse a notes line and returns a pointer to the
78 Note::Pointer
parse(ConfigParser
&parser
);
80 * Dump the notes list to the given StoreEntry object.
82 void dump(StoreEntry
*entry
, const char *name
);
83 void clean(); /// clean the notes list
85 /// points to the first argument
86 iterator
begin() { return notes
.begin(); }
87 /// points to the end of list
88 iterator
end() { return notes
.end(); }
89 /// return true if the notes list is empty
90 bool empty() { return notes
.empty(); }
92 NotesList notes
; ///< The Note::Pointer objects array list
93 const char *descr
; ///< A short description for notes list
94 const char **blacklisted
; ///< Null terminated list of blacklisted note keys
98 * Adds a note to the notes list and returns a pointer to the
99 * related Note object. If the note key already exists in list,
100 * returns a pointer to the existing object.
102 Note::Pointer
add(const String
¬eKey
);
106 * Used to store list of notes
108 class NotePairs
: public RefCountable
111 typedef RefCount
<NotePairs
> Pointer
;
114 * Used to store a note key/value pair.
119 Entry(const char *aKey
, const char *aValue
): name(aKey
), value(aValue
) {}
122 MEMPROXY_CLASS(Entry
);
128 * Append the entries of the src NotePairs list to our list.
130 void append(const NotePairs
*src
);
133 * Returns a comma separated list of notes with key 'noteKey'.
134 * Use findFirst instead when a unique kv-pair is needed.
136 const char *find(const char *noteKey
) const;
139 * Returns the first note value for this key or an empty string.
141 const char *findFirst(const char *noteKey
) const;
144 * Adds a note key and value to the notes list.
145 * If the key name already exists in list, add the given value to its set
148 void add(const char *key
, const char *value
);
151 * Adds a note key and values strList to the notes list.
152 * If the key name already exists in list, add the new values to its set
155 void addStrList(const char *key
, const char *values
);
158 * Return true if the key/value pair is already stored
160 bool hasPair(const char *key
, const char *value
) const;
163 * Convert NotePairs list to a string consist of "Key: Value"
164 * entries separated by sep string.
166 const char *toString(const char *sep
= "\r\n") const;
169 * True if there are not entries in the list
171 bool empty() const {return entries
.empty();}
173 Vector
<NotePairs::Entry
*> entries
; ///< The key/value pair entries
176 MEMPROXY_CLASS_INLINE(NotePairs::Entry
);