Notes.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 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
21class HttpRequest;
22class HttpReply;
23class AccessLogEntry;
24class NotePairs;
25
28
35class Note: public RefCountable
36{
37public:
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() override;
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,
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
98private:
101};
102
103class ConfigParser;
104
108class Notes : public RefCountable
109{
110public:
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() override { 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);
145private:
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
173{
174public:
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
261private:
263};
264
265#endif
266
#define RefCountable
The locking interface for use on Reference-Counted classes.
Definition: Lock.h:66
RefCount< NotePairs > NotePairsPointer
Definition: Notes.h:27
RefCount< AccessLogEntry > AccessLogEntryPointer
Definition: Notes.h:26
#define ACLList
Definition: forward.h:46
optimized set of C chars, with quick membership test and merge support
Definition: CharacterSet.h:18
Used to store a note key/value pair.
Definition: Notes.h:179
Entry(const char *aKey, const char *aValue)
Definition: Notes.h:186
const SBuf & value() const
Definition: Notes.h:192
SBuf theValue
Definition: Notes.h:196
SBuf theName
Definition: Notes.h:195
Entry(const SBuf &aKey, const SBuf &aValue)
Definition: Notes.h:184
Entry & operator=(const Entry &)=delete
const SBuf & name() const
Definition: Notes.h:191
RefCount< Entry > Pointer
Definition: Notes.h:182
Entry(const Entry &)=delete
void appendNewOnly(const NotePairs *src)
Definition: Notes.cc:381
void append(const NotePairs *src)
Append the entries of the src NotePairs list to our list.
Definition: Notes.cc:374
bool empty() const
Definition: Notes.h:253
void clear()
Definition: Notes.h:255
std::vector< SBuf > Names
Definition: Notes.h:199
std::vector< Entry::Pointer > Entries
The key/value pair entries.
Definition: Notes.h:198
bool find(SBuf &resultNote, const char *noteKey, const char *sep=",") const
Definition: Notes.cc:272
NotePairs(NotePairs const &)=delete
void add(const SBuf &key, const SBuf &value)
Definition: Notes.cc:312
void remove(const char *key)
Definition: Notes.cc:318
void replaceOrAdd(const NotePairs *src)
Definition: Notes.cc:400
RefCount< NotePairs > Pointer
Definition: Notes.h:175
bool hasPair(const SBuf &key, const SBuf &value) const
Definition: Notes.cc:365
const Entries & expandListEntries(const CharacterSet *delimiters) const
Definition: Notes.cc:346
const char * findFirst(const char *noteKey) const
Definition: Notes.cc:297
void addStrList(const SBuf &key, const SBuf &values, const CharacterSet &delimiters)
Definition: Notes.cc:359
Entries entries
The key/value pair entries.
Definition: Notes.h:262
NotePairs()
Definition: Notes.h:201
NotePairs & operator=(NotePairs const &)=delete
const char * toString(const char *sep="\r\n") const
Definition: Notes.cc:286
void replaceOrAddOrAppend(const NotePairs *src, const Names &appendables)
Definition: Notes.cc:390
Stores a value for the note.
Definition: Notes.h:42
RefCount< Value > Pointer
Definition: Notes.h:44
Method method() const
Definition: Notes.h:54
@ mhReplace
Definition: Notes.h:47
@ mhAppend
Definition: Notes.h:47
SBuf theFormattedValue
The expanded value produced by format(), empty for non-quoted values.
Definition: Notes.h:67
~Value() override
Definition: Notes.cc:29
SBuf theValue
Definition: Notes.h:65
Format::Format * valueFormat
Compiled annotation value format.
Definition: Notes.h:64
Value(const Value &)=delete
ACLList * aclList
The access list used to determine if this value is valid for a request.
Definition: Notes.h:57
Value(const char *aVal, const bool quoted, const char *descr, const Method method=mhReplace)
Definition: Notes.cc:35
const SBuf & value() const
Definition: Notes.h:55
const SBuf & format(const AccessLogEntryPointer &al)
Definition: Notes.cc:50
Value & operator=(const Value &)=delete
Method theMethod
Definition: Notes.h:71
Definition: Notes.h:36
Value::Pointer addValue(const char *value, const bool quoted, const char *descr, const Value::Method m=Value::mhAppend)
Definition: Notes.cc:63
Note(const char *aKey, const size_t keyLen)
Definition: Notes.h:75
bool match(HttpRequest *request, HttpReply *reply, const AccessLogEntryPointer &al, SBuf &matched)
Definition: Notes.cc:70
Values values
The possible values list for the note.
Definition: Notes.h:100
Note(const SBuf aKey)
Definition: Notes.h:76
void dump(StoreEntry *entry, const char *key)
Dump the single Note to the given StoreEntry object.
Definition: Notes.cc:108
Note(const Note &)=delete
SBuf theKey
The note key.
Definition: Notes.h:99
Note & operator=(const Note &)=delete
const SBuf & key() const
Definition: Notes.h:90
std::vector< Value::Pointer > Values
Definition: Notes.h:73
RefCount< Note > Pointer
Definition: Notes.h:38
void updateNotePairs(NotePairsPointer pairs, const CharacterSet *delimiters, const AccessLogEntryPointer &al)
Definition: Notes.cc:94
SBuf toString(const char *sep) const
Definition: Notes.cc:119
Definition: Notes.h:109
Note::Pointer find(const SBuf &noteKey)
Definition: Notes.cc:168
NotesList::const_iterator const_iterator
iterates over the notes list
Definition: Notes.h:115
Note::Pointer parse(ConfigParser &parser)
Parses a notes line and returns a pointer to the parsed Note object.
Definition: Notes.cc:202
void clean()
clean the notes list
Definition: Notes.h:132
Notes()=default
const char * toString(const char *sep="\r\n") const
Definition: Notes.cc:262
bool empty() const
Definition: Notes.h:139
std::vector< SBuf > Keys
unordered annotation names
Definition: Notes.h:112
Note::Pointer add(const SBuf &noteKey)
Definition: Notes.cc:159
iterator begin()
points to the first argument
Definition: Notes.h:135
void updateNotePairs(NotePairsPointer pairs, const CharacterSet *delimiters, const AccessLogEntryPointer &al)
Definition: Notes.cc:248
const char * descr
identifies note source in error messages
Definition: Notes.h:161
iterator end()
points to the end of list
Definition: Notes.h:137
Notes & operator=(const Notes &)=delete
std::vector< Note::Pointer > NotesList
Definition: Notes.h:113
NotesList::iterator iterator
iterates over the notes list
Definition: Notes.h:114
void dump(StoreEntry *entry, const char *name)
Dump the notes list to the given StoreEntry object.
Definition: Notes.cc:255
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 notes
The Note::Pointer objects array list.
Definition: Notes.h:160
bool formattedValues
whether to expand quoted logformat codes
Definition: Notes.h:164
static const Notes::Keys & ReservedKeys()
always prohibited key names
Definition: Notes.cc:129
~Notes() override
Definition: Notes.h:119
Notes(const Notes &)=delete
RefCount< Notes > Pointer
Definition: Notes.h:111
void validateKey(const SBuf &key) const
Definition: Notes.cc:184
void parseKvPair()
Parses an annotate line with "key=value" or "key+=value" formats.
Definition: Notes.cc:223
Keys reservedKeys
a list of additional prohibited key names
Definition: Notes.h:163
Definition: SBuf.h:94

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors