Notes.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
3  *
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.
7  */
8 
9 #ifndef SQUID_NOTES_H
10 #define SQUID_NOTES_H
11 
12 #include "acl/forward.h"
13 #include "base/RefCount.h"
14 #include "format/Format.h"
15 #include "mem/forward.h"
16 #include "SquidString.h"
17 
18 #include <string>
19 #include <vector>
20 
21 class HttpRequest;
22 class HttpReply;
23 class AccessLogEntry;
24 class NotePairs;
25 
28 
35 class Note: public RefCountable
36 {
37 public:
39 
41  class Value: public RefCountable
42  {
43  public:
45  friend class Note;
46 
48 
49  Value(const char *aVal, const bool quoted, const char *descr, const Method method = mhReplace);
50  ~Value();
51  Value(const Value&) = delete;
52  Value &operator=(const Value&) = delete;
53 
54  Method method() const { return theMethod; }
55  const SBuf &value() const { return theValue; }
56 
58 
59  private:
62  const SBuf &format(const AccessLogEntryPointer &al);
63 
72  };
73  typedef std::vector<Value::Pointer> Values;
74 
75  Note(const char *aKey, const size_t keyLen): theKey(aKey, keyLen) {}
76  explicit Note(const SBuf aKey): theKey(aKey) {}
77  Note(const Note&) = delete;
78  Note &operator=(const Note&) = delete;
79 
82  Value::Pointer addValue(const char *value, const bool quoted, const char *descr,
83  const Value::Method m = Value::mhAppend);
84 
89  bool match(HttpRequest *request, HttpReply *reply, const AccessLogEntryPointer &al, SBuf &matched);
90  const SBuf &key() const { return theKey; }
91  void updateNotePairs(NotePairsPointer pairs, const CharacterSet *delimiters, const AccessLogEntryPointer &al);
93  void dump(StoreEntry *entry, const char *key);
96  SBuf toString(const char *sep) const;
97 
98 private:
101 };
102 
103 class ConfigParser;
104 
108 class Notes : public RefCountable
109 {
110 public:
112  typedef std::vector<Note::Pointer> NotesList;
113  typedef NotesList::iterator iterator;
114  typedef NotesList::const_iterator const_iterator;
115 
116  Notes(const char *aDescr, const char **metasBlacklist, bool allowFormatted = true): descr(aDescr), blacklisted(metasBlacklist), formattedValues(allowFormatted) {}
117  Notes(): descr(nullptr), blacklisted(nullptr), formattedValues(false) {}
118  ~Notes() { notes.clear(); }
119  Notes(const Notes&) = delete;
120  Notes &operator=(const Notes&) = delete;
121 
124 
126  void parseKvPair();
127 
129  void dump(StoreEntry *entry, const char *name);
131  void clean() { notes.clear(); }
132 
134  iterator begin() { return notes.begin(); }
136  iterator end() { return notes.end(); }
138  bool empty() const { return notes.empty(); }
141  const char *toString(const char *sep = "\r\n") const;
142  void updateNotePairs(NotePairsPointer pairs, const CharacterSet *delimiters,
143  const AccessLogEntryPointer &al);
144 private:
145 
149  void validateKey(const SBuf &key) const;
150 
155  Note::Pointer add(const SBuf &noteKey);
156  Note::Pointer find(const SBuf &noteKey);
157 
159  const char *descr;
160  const char **blacklisted;
162 };
163 
167 class NotePairs: public RefCountable
168 {
169 public:
171 
173  class Entry : public RefCountable
174  {
176  public:
178 
179  Entry(const SBuf &aKey, const SBuf &aValue)
180  : theName(aKey), theValue(aValue) {}
181  Entry(const char *aKey, const char *aValue)
182  : theName(aKey), theValue(aValue) {}
183  Entry(const Entry &) = delete;
184  Entry &operator=(const Entry &) = delete;
185 
186  const SBuf &name() const { return theName; }
187  const SBuf &value() const { return theValue; }
188 
189  private:
192  };
193  typedef std::vector<Entry::Pointer> Entries;
194 
196  NotePairs &operator=(NotePairs const &) = delete;
197  NotePairs(NotePairs const &) = delete;
198 
200  void append(const NotePairs *src);
201 
204  void replaceOrAdd(const NotePairs *src);
205 
208  void appendNewOnly(const NotePairs *src);
209 
213  bool find(SBuf &resultNote, const char *noteKey, const char *sep = ",") const;
214 
216  const char *findFirst(const char *noteKey) const;
217 
221  void add(const SBuf &key, const SBuf &value);
222  void add(const char *key, const char *value);
223 
226  void remove(const char *key);
227  void remove(const SBuf &key);
228 
232  void addStrList(const SBuf &key, const SBuf &values, const CharacterSet &delimiters);
233 
235  bool hasPair(const SBuf &key, const SBuf &value) const;
236 
239  const char *toString(const char *sep = "\r\n") const;
240 
242  bool empty() const {return entries.empty();}
243 
244  void clear() { entries.clear(); }
245 
248  const Entries &expandListEntries(const CharacterSet *delimiters) const;
249 
250 private:
252 };
253 
254 #endif
255 
NotePairs & operator=(NotePairs const &)=delete
const SBuf & format(const AccessLogEntryPointer &al)
Definition: Notes.cc:49
Note & operator=(const Note &)=delete
const SBuf & name() const
Definition: Notes.h:186
SBuf theValue
Definition: Notes.h:65
Value & operator=(const Value &)=delete
Note::Pointer add(const SBuf &noteKey)
Definition: Notes.cc:126
Notes(const char *aDescr, const char **metasBlacklist, bool allowFormatted=true)
Definition: Notes.h:116
Definition: SBuf.h:87
iterator begin()
points to the first argument
Definition: Notes.h:134
std::vector< Value::Pointer > Values
Definition: Notes.h:73
Note(const char *aKey, const size_t keyLen)
Definition: Notes.h:75
struct _request * request(char *urlin)
Definition: tcp-banger2.c:291
void add(const SBuf &key, const SBuf &value)
Definition: Notes.cc:278
~Notes()
Definition: Notes.h:118
NotesList::iterator iterator
iterates over the notes list
Definition: Notes.h:113
RefCount< Notes > Pointer
Definition: Notes.h:111
#define ACLList
Definition: forward.h:45
RefCount< NotePairs > NotePairsPointer
Definition: Notes.h:27
Entry(const SBuf &aKey, const SBuf &aValue)
Definition: Notes.h:179
const Entries & expandListEntries(const CharacterSet *delimiters) const
Definition: Notes.cc:312
void appendNewOnly(const NotePairs *src)
Definition: Notes.cc:347
Entry(const char *aKey, const char *aValue)
Definition: Notes.h:181
bool match(HttpRequest *request, HttpReply *reply, const AccessLogEntryPointer &al, SBuf &matched)
Definition: Notes.cc:69
void replaceOrAdd(const NotePairs *src)
Definition: Notes.cc:356
Stores a value for the note.
Definition: Notes.h:41
RefCount< Entry > Pointer
Definition: Notes.h:177
Notes()
Definition: Notes.h:117
void updateNotePairs(NotePairsPointer pairs, const CharacterSet *delimiters, const AccessLogEntryPointer &al)
Definition: Notes.cc:91
Notes & operator=(const Notes &)=delete
NotesList notes
The Note::Pointer objects array list.
Definition: Notes.h:158
const char * toString(const char *sep="\r\n") const
Definition: Notes.cc:228
void addStrList(const SBuf &key, const SBuf &values, const CharacterSet &delimiters)
Definition: Notes.cc:325
std::vector< Entry::Pointer > Entries
The key/value pair entries.
Definition: Notes.h:193
NotesList::const_iterator const_iterator
iterates over the notes list
Definition: Notes.h:114
const char ** blacklisted
Null terminated list of blacklisted note keys.
Definition: Notes.h:160
bool empty() const
Definition: Notes.h:242
Used to store a note key/value pair.
Definition: Notes.h:173
ACLList * aclList
The access list used to determine if this value is valid for a request.
Definition: Notes.h:57
void clean()
clean the notes list
Definition: Notes.h:131
Method theMethod
Definition: Notes.h:71
void clear()
Definition: Notes.h:244
SBuf theValue
Definition: Notes.h:191
Value::Pointer addValue(const char *value, const bool quoted, const char *descr, const Value::Method m=Value::mhAppend)
Definition: Notes.cc:62
Values values
The possible values list for the note.
Definition: Notes.h:100
optimized set of C chars, with quick membership test and merge support
Definition: CharacterSet.h:17
RefCount< AccessLogEntry > AccessLogEntryPointer
Definition: Notes.h:24
void validateKey(const SBuf &key) const
Definition: Notes.cc:144
bool find(SBuf &resultNote, const char *noteKey, const char *sep=",") const
Definition: Notes.cc:238
const char * metasBlacklist[]
Definition: Config.cc:31
SBuf theFormattedValue
The expanded value produced by format(), empty for non-quoted values.
Definition: Notes.h:67
bool empty() const
Definition: Notes.h:138
std::vector< Note::Pointer > NotesList
Definition: Notes.h:112
Note::Pointer parse(ConfigParser &parser)
Parses a notes line and returns a pointer to the parsed Note object.
Definition: Notes.cc:168
Note(const SBuf aKey)
Definition: Notes.h:76
Format::Format * valueFormat
Compiled annotation value format.
Definition: Notes.h:64
SBuf toString(const char *sep) const
Definition: Notes.cc:116
Definition: Notes.h:108
NotePairs()
Definition: Notes.h:195
const SBuf & value() const
Definition: Notes.h:55
Definition: Notes.h:35
void updateNotePairs(NotePairsPointer pairs, const CharacterSet *delimiters, const AccessLogEntryPointer &al)
Definition: Notes.cc:214
RefCount< NotePairs > Pointer
Definition: Notes.h:170
Value(const char *aVal, const bool quoted, const char *descr, const Method method=mhReplace)
Definition: Notes.cc:34
void parseKvPair()
Parses an annotate line with "key=value" or "key+=value" formats.
Definition: Notes.cc:189
bool hasPair(const SBuf &key, const SBuf &value) const
Definition: Notes.cc:331
RefCount< Value > Pointer
Definition: Notes.h:44
void const cache_key * key
const SBuf & key() const
Definition: Notes.h:90
bool formattedValues
Whether the formatted values are supported.
Definition: Notes.h:161
const SBuf & value() const
Definition: Notes.h:187
~Value()
Definition: Notes.cc:28
iterator end()
points to the end of list
Definition: Notes.h:136
void dump(StoreEntry *entry, const char *name)
Dump the notes list to the given StoreEntry object.
Definition: Notes.cc:221
RefCount< Note > Pointer
Definition: Notes.h:38
const char * findFirst(const char *noteKey) const
Definition: Notes.cc:263
Note::Pointer find(const SBuf &noteKey)
Definition: Notes.cc:135
const char * toString(const char *sep="\r\n") const
Definition: Notes.cc:252
SBuf theName
Definition: Notes.h:190
const char * descr
A short description for notes list.
Definition: Notes.h:159
SBuf theKey
The note key.
Definition: Notes.h:99
void append(const NotePairs *src)
Append the entries of the src NotePairs list to our list.
Definition: Notes.cc:340
void dump(StoreEntry *entry, const char *key)
Dump the single Note to the given StoreEntry object.
Definition: Notes.cc:105
Method method() const
Definition: Notes.h:54
#define false
Definition: GnuRegex.c:233
Entry & operator=(const Entry &)=delete
Entries entries
The key/value pair entries.
Definition: Notes.h:251

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors