Notes.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2019 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:
100  Values values;
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 
158  NotesList notes;
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:
177  typedef RefCount<Entry> Pointer;
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  typedef std::vector<SBuf> Names;
195 
197  NotePairs &operator=(NotePairs const &) = delete;
198  NotePairs(NotePairs const &) = delete;
199 
201  void append(const NotePairs *src);
202 
206  void replaceOrAddOrAppend(const NotePairs *src, const Names &appendables);
207 
210  void replaceOrAdd(const NotePairs *src);
211 
214  void appendNewOnly(const NotePairs *src);
215 
219  bool find(SBuf &resultNote, const char *noteKey, const char *sep = ",") const;
220 
222  const char *findFirst(const char *noteKey) const;
223 
227  void add(const SBuf &key, const SBuf &value);
228  void add(const char *key, const char *value);
229 
232  void remove(const char *key);
233  void remove(const SBuf &key);
234 
238  void addStrList(const SBuf &key, const SBuf &values, const CharacterSet &delimiters);
239 
241  bool hasPair(const SBuf &key, const SBuf &value) const;
242 
245  const char *toString(const char *sep = "\r\n") const;
246 
248  bool empty() const {return entries.empty();}
249 
250  void clear() { entries.clear(); }
251 
254  const Entries &expandListEntries(const CharacterSet *delimiters) const;
255 
256 private:
257  Entries entries;
258 };
259 
260 #endif
261 
const SBuf & format(const AccessLogEntryPointer &al)
Definition: Notes.cc:49
SBuf toString(const char *sep) const
Definition: Notes.cc:118
SBuf theValue
Definition: Notes.h:65
#define MEMPROXY_CLASS(CLASS)
Value & operator=(const Value &)=delete
Notes(const char *aDescr, const char **metasBlacklist, bool allowFormatted=true)
Definition: Notes.h:116
Definition: SBuf.h:86
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
~Notes()
Definition: Notes.h:118
NotesList::iterator iterator
iterates over the notes list
Definition: Notes.h:113
RefCount< Notes > Pointer
Definition: Notes.h:111
const SBuf & key() const
Definition: Notes.h:90
#define ACLList
Definition: forward.h:45
static struct node * parse(FILE *fp)
Definition: parse.c:995
RefCount< NotePairs > NotePairsPointer
Definition: Notes.h:27
Entry(const SBuf &aKey, const SBuf &aValue)
Definition: Notes.h:179
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
Stores a value for the note.
Definition: Notes.h:41
const SBuf & name() const
Definition: Notes.h:186
std::vector< SBuf > Names
Definition: Notes.h:194
Notes()
Definition: Notes.h:117
void updateNotePairs(NotePairsPointer pairs, const CharacterSet *delimiters, const AccessLogEntryPointer &al)
Definition: Notes.cc:93
NotesList notes
The Note::Pointer objects array list.
Definition: Notes.h:158
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
Used to store a note key/value pair.
Definition: Notes.h:173
::StoreEntry Entry
Definition: forward.h:48
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:250
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
const char * metasBlacklist[]
Definition: Config.cc:31
SBuf theFormattedValue
The expanded value produced by format(), empty for non-quoted values.
Definition: Notes.h:67
std::vector< Note::Pointer > NotesList
Definition: Notes.h:112
Note(const SBuf aKey)
Definition: Notes.h:76
Format::Format * valueFormat
Compiled annotation value format.
Definition: Notes.h:64
Definition: Notes.h:108
NotePairs()
Definition: Notes.h:196
Definition: Notes.h:35
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
const SBuf & value() const
Definition: Notes.h:55
RefCount< Value > Pointer
Definition: Notes.h:44
bool formattedValues
Whether the formatted values are supported.
Definition: Notes.h:161
friend class Note
Definition: Notes.h:45
~Value()
Definition: Notes.cc:28
iterator end()
points to the end of list
Definition: Notes.h:136
RefCount< Note > Pointer
Definition: Notes.h:38
const SBuf & value() const
Definition: Notes.h:187
bool empty() const
Definition: Notes.h:248
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 dump(StoreEntry *entry, const char *key)
Dump the single Note to the given StoreEntry object.
Definition: Notes.cc:107
#define false
Definition: GnuRegex.c:233
bool empty() const
Definition: Notes.h:138
Entries entries
The key/value pair entries.
Definition: Notes.h:257
Method method() const
Definition: Notes.h:54

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors