]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/Notes.h
Fix and improve annotation reporting (#1516)
[thirdparty/squid.git] / src / Notes.h
index 0c6229e23dbe92db3a404a513da639206f59749d..18cd9f71ca21640b548b27c455852979259084bd 100644 (file)
 
 #include "acl/forward.h"
 #include "base/RefCount.h"
+#include "sbuf/forward.h"
 #include "format/Format.h"
 #include "mem/forward.h"
 #include "SquidString.h"
 
+#include <iosfwd>
 #include <string>
 #include <vector>
 
@@ -89,11 +91,13 @@ public:
     bool match(HttpRequest *request, HttpReply *reply, const AccessLogEntryPointer &al, SBuf &matched);
     const SBuf &key() const { return theKey; }
     void updateNotePairs(NotePairsPointer pairs, const CharacterSet *delimiters, const AccessLogEntryPointer &al);
-    /// Dump the single Note to the given StoreEntry object.
-    void dump(StoreEntry *entry, const char *key);
-    /// For the key and all its Values compile a string of
-    /// "Key: Value" pairs separated by sep string.
-    SBuf toString(const char *sep) const;
+
+    /// Prints key and value(s) using a "note" directive format (including directive name).
+    void printAsNoteDirective(StoreEntry *, const char *directiveName) const;
+
+    /// Prints using "annotate_transaction acl parameter" format, one key=value
+    /// or key+=value parameter per stored value.
+    void printAsAnnotationAclParameters(std::ostream &) const;
 
 private:
     SBuf theKey; ///< The note key
@@ -126,8 +130,9 @@ public:
     /// Parses an annotate line with "key=value" or "key+=value" formats.
     void parseKvPair();
 
-    /// Dump the notes list to the given StoreEntry object.
-    void dump(StoreEntry *entry, const char *name);
+    /// Prints notes using "note" squid.conf directive format, one directive per stored note.
+    void printAsNoteDirectives(StoreEntry *, const char *directiveName) const;
+
     /// clean the notes list
     void clean() { notes.clear(); }
 
@@ -137,9 +142,11 @@ public:
     iterator end() { return notes.end(); }
     /// \returns true if the notes list is empty
     bool empty() const { return notes.empty(); }
-    /// Convert Notes list to a string consist of "Key: Value"
-    /// entries separated by sep string.
-    const char *toString(const char *sep = "\r\n") const;
+
+    /// print notes using "annotate_transaction acl parameters" format, one
+    /// key=value parameter per note
+    void printAsAnnotationAclParameters(std::ostream &) const;
+
     void updateNotePairs(NotePairsPointer pairs, const CharacterSet *delimiters,
                          const AccessLogEntryPointer &al);
 private:
@@ -245,9 +252,9 @@ public:
     /// \returns true if the key/value pair is already stored
     bool hasPair(const SBuf &key, const SBuf &value) const;
 
-    /// Convert NotePairs list to a string consist of "Key: Value"
-    /// entries separated by sep string.
-    const char *toString(const char *sep = "\r\n") const;
+    /// Reports all entries (if any), printing exactly four items for each:
+    /// entry name, nameValueSeparator, entry value, and entry terminator.
+    void print(std::ostream &os, const char *nameValueSeparator, const char *entryTerminator) const;
 
     /// \returns true if there are not entries in the list
     bool empty() const {return entries.empty();}