Notes.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2021 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<SBuf> Keys;
113  typedef std::vector<Note::Pointer> NotesList;
114  typedef NotesList::iterator iterator;
115  typedef NotesList::const_iterator const_iterator;
116 
117  explicit Notes(const char *aDescr, const Keys *extraReservedKeys = nullptr, bool allowFormatted = true);
118  Notes() = default;
119  ~Notes() { notes.clear(); }
120  Notes(const Notes&) = delete;
121  Notes &operator=(const Notes&) = delete;
122 
125 
127  void parseKvPair();
128 
130  void dump(StoreEntry *entry, const char *name);
132  void clean() { notes.clear(); }
133 
135  iterator begin() { return notes.begin(); }
137  iterator end() { return notes.end(); }
139  bool empty() const { return notes.empty(); }
142  const char *toString(const char *sep = "\r\n") const;
143  void updateNotePairs(NotePairsPointer pairs, const CharacterSet *delimiters,
144  const AccessLogEntryPointer &al);
145 private:
147  void banReservedKey(const SBuf &key, const Keys &banned) const;
148 
151  void validateKey(const SBuf &key) const;
152 
157  Note::Pointer add(const SBuf &noteKey);
158  Note::Pointer find(const SBuf &noteKey);
159 
161  const char *descr = nullptr;
162 
164  bool formattedValues = false;
165 
166  static const Notes::Keys &ReservedKeys();
167 };
168 
172 class NotePairs: public RefCountable
173 {
174 public:
176 
178  class Entry : public RefCountable
179  {
181  public:
183 
184  Entry(const SBuf &aKey, const SBuf &aValue)
185  : theName(aKey), theValue(aValue) {}
186  Entry(const char *aKey, const char *aValue)
187  : theName(aKey), theValue(aValue) {}
188  Entry(const Entry &) = delete;
189  Entry &operator=(const Entry &) = delete;
190 
191  const SBuf &name() const { return theName; }
192  const SBuf &value() const { return theValue; }
193 
194  private:
197  };
198  typedef std::vector<Entry::Pointer> Entries;
199  typedef std::vector<SBuf> Names;
200 
202  NotePairs &operator=(NotePairs const &) = delete;
203  NotePairs(NotePairs const &) = delete;
204 
206  void append(const NotePairs *src);
207 
211  void replaceOrAddOrAppend(const NotePairs *src, const Names &appendables);
212 
215  void replaceOrAdd(const NotePairs *src);
216 
219  void appendNewOnly(const NotePairs *src);
220 
224  bool find(SBuf &resultNote, const char *noteKey, const char *sep = ",") const;
225 
227  const char *findFirst(const char *noteKey) const;
228 
232  void add(const SBuf &key, const SBuf &value);
233  void add(const char *key, const char *value);
234 
237  void remove(const char *key);
238  void remove(const SBuf &key);
239 
243  void addStrList(const SBuf &key, const SBuf &values, const CharacterSet &delimiters);
244 
246  bool hasPair(const SBuf &key, const SBuf &value) const;
247 
250  const char *toString(const char *sep = "\r\n") const;
251 
253  bool empty() const {return entries.empty();}
254 
255  void clear() { entries.clear(); }
256 
259  const Entries &expandListEntries(const CharacterSet *delimiters) const;
260 
261 private:
263 };
264 
265 #endif
266 
void appendNewOnly(const NotePairs *src)
Definition: Notes.cc:381
void replaceOrAdd(const NotePairs *src)
Definition: Notes.cc:400
NotesList::iterator iterator
iterates over the notes list
Definition: Notes.h:114
ACLList * aclList
The access list used to determine if this value is valid for a request.
Definition: Notes.h:57
SBuf theFormattedValue
The expanded value produced by format(), empty for non-quoted values.
Definition: Notes.h:67
const SBuf & name() const
Definition: Notes.h:191
void parseKvPair()
Parses an annotate line with "key=value" or "key+=value" formats.
Definition: Notes.cc:223
Entry(const Entry &)=delete
void validateKey(const SBuf &key) const
Definition: Notes.cc:184
std::vector< Note::Pointer > NotesList
Definition: Notes.h:113
Notes(const Notes &)=delete
const char * findFirst(const char *noteKey) const
Definition: Notes.cc:297
const char * descr
identifies note source in error messages
Definition: Notes.h:161
Method method() const
Definition: Notes.h:54
RefCount< Entry > Pointer
Definition: Notes.h:180
void dump(StoreEntry *entry, const char *name)
Dump the notes list to the given StoreEntry object.
Definition: Notes.cc:255
Note & operator=(const Note &)=delete
Entry(const SBuf &aKey, const SBuf &aValue)
Definition: Notes.h:184
SBuf toString(const char *sep) const
Definition: Notes.cc:119
Note(const SBuf aKey)
Definition: Notes.h:76
Entry & operator=(const Entry &)=delete
Value(const char *aVal, const bool quoted, const char *descr, const Method method=mhReplace)
Definition: Notes.cc:35
Note::Pointer parse(ConfigParser &parser)
Parses a notes line and returns a pointer to the parsed Note object.
Definition: Notes.cc:202
Values values
The possible values list for the note.
Definition: Notes.h:100
NotesList notes
The Note::Pointer objects array list.
Definition: Notes.h:160
Definition: SBuf.h:87
const char * toString(const char *sep="\r\n") const
Definition: Notes.cc:262
void dump(StoreEntry *entry, const char *key)
Dump the single Note to the given StoreEntry object.
Definition: Notes.cc:108
NotePairs & operator=(NotePairs const &)=delete
SBuf theKey
The note key.
Definition: Notes.h:99
const char * toString(const char *sep="\r\n") const
Definition: Notes.cc:286
#define ACLList
Definition: forward.h:46
const SBuf & value() const
Definition: Notes.h:55
std::vector< Value::Pointer > Values
Definition: Notes.h:73
bool empty() const
Definition: Notes.h:253
Note(const char *aKey, const size_t keyLen)
Definition: Notes.h:75
std::vector< SBuf > Names
Definition: Notes.h:199
bool empty() const
Definition: Notes.h:139
RefCount< Value > Pointer
Definition: Notes.h:44
Used to store a note key/value pair.
Definition: Notes.h:179
~Value()
Definition: Notes.cc:29
@ mhAppend
Definition: Notes.h:47
Definition: Notes.h:109
RefCount< Notes > Pointer
Definition: Notes.h:111
@ mhReplace
Definition: Notes.h:47
void updateNotePairs(NotePairsPointer pairs, const CharacterSet *delimiters, const AccessLogEntryPointer &al)
Definition: Notes.cc:248
Note::Pointer find(const SBuf &noteKey)
Definition: Notes.cc:168
std::vector< SBuf > Keys
unordered annotation names
Definition: Notes.h:112
const SBuf & key() const
Definition: Notes.h:90
bool find(SBuf &resultNote, const char *noteKey, const char *sep=",") const
Definition: Notes.cc:272
Entries entries
The key/value pair entries.
Definition: Notes.h:262
~Notes()
Definition: Notes.h:119
Method theMethod
Definition: Notes.h:71
static const Notes::Keys & ReservedKeys()
always prohibited key names
Definition: Notes.cc:129
Format::Format * valueFormat
Compiled annotation value format.
Definition: Notes.h:64
const Entries & expandListEntries(const CharacterSet *delimiters) const
Definition: Notes.cc:346
iterator end()
points to the end of list
Definition: Notes.h:137
NotePairs()
Definition: Notes.h:201
void addStrList(const SBuf &key, const SBuf &values, const CharacterSet &delimiters)
Definition: Notes.cc:359
void updateNotePairs(NotePairsPointer pairs, const CharacterSet *delimiters, const AccessLogEntryPointer &al)
Definition: Notes.cc:94
Notes()=default
SBuf theValue
Definition: Notes.h:65
iterator begin()
points to the first argument
Definition: Notes.h:135
Stores a value for the note.
Definition: Notes.h:42
Note::Pointer add(const SBuf &noteKey)
Definition: Notes.cc:159
Value::Pointer addValue(const char *value, const bool quoted, const char *descr, const Value::Method m=Value::mhAppend)
Definition: Notes.cc:63
Entry(const char *aKey, const char *aValue)
Definition: Notes.h:186
Notes & operator=(const Notes &)=delete
void clear()
Definition: Notes.h:255
void append(const NotePairs *src)
Append the entries of the src NotePairs list to our list.
Definition: Notes.cc:374
Keys reservedKeys
a list of additional prohibited key names
Definition: Notes.h:163
SBuf theName
Definition: Notes.h:195
bool hasPair(const SBuf &key, const SBuf &value) const
Definition: Notes.cc:365
#define MEMPROXY_CLASS(CLASS)
RefCount< NotePairs > NotePairsPointer
Definition: Notes.h:27
const SBuf & value() const
Definition: Notes.h:192
bool match(HttpRequest *request, HttpReply *reply, const AccessLogEntryPointer &al, SBuf &matched)
Definition: Notes.cc:70
void remove(const char *key)
Definition: Notes.cc:318
RefCount< AccessLogEntry > AccessLogEntryPointer
Definition: Notes.h:24
void add(const SBuf &key, const SBuf &value)
Definition: Notes.cc:312
RefCount< NotePairs > Pointer
Definition: Notes.h:175
optimized set of C chars, with quick membership test and merge support
Definition: CharacterSet.h:18
Value(const Value &)=delete
void clean()
clean the notes list
Definition: Notes.h:132
std::vector< Entry::Pointer > Entries
The key/value pair entries.
Definition: Notes.h:198
Definition: Notes.h:36
Note(const Note &)=delete
NotePairs(NotePairs const &)=delete
struct _request * request(char *urlin)
Definition: tcp-banger2.c:291
RefCount< Note > Pointer
Definition: Notes.h:38
void banReservedKey(const SBuf &key, const Keys &banned) const
Makes sure the given key is not on the given list of banned names.
Definition: Notes.cc:177
NotesList::const_iterator const_iterator
iterates over the notes list
Definition: Notes.h:115
const SBuf & format(const AccessLogEntryPointer &al)
Definition: Notes.cc:50
bool formattedValues
whether to expand quoted logformat codes
Definition: Notes.h:164
SBuf theValue
Definition: Notes.h:196
void replaceOrAddOrAppend(const NotePairs *src, const Names &appendables)
Definition: Notes.cc:390
Value & operator=(const Value &)=delete

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors