]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Use PackableStream for dump_acl (#1573)
authorFrancesco Chemolli <5175948+kinkie@users.noreply.github.com>
Mon, 6 Nov 2023 03:22:38 +0000 (03:22 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Mon, 6 Nov 2023 11:53:36 +0000 (11:53 +0000)
src/acl/Acl.cc
src/acl/Acl.h
src/cache_cf.cc

index f466c6712ee41a26224ad23f31c6367c67bb7745..63c6bff3ecf22c500ab659368f20c773113e4154 100644 (file)
@@ -14,6 +14,7 @@
 #include "acl/Gadgets.h"
 #include "acl/Options.h"
 #include "anyp/PortCfg.h"
+#include "base/IoManip.h"
 #include "cache_cf.h"
 #include "ConfigParser.h"
 #include "debug/Stream.h"
@@ -322,25 +323,14 @@ ACL::parseFlags()
     Acl::ParseFlags(allOptions);
 }
 
-SBufList
-ACL::dumpOptions()
+void
+ACL::dumpWhole(const char * const directiveName, std::ostream &os)
 {
-    SBufList result;
-
-    const auto &myOptions = options();
     // XXX: No lineOptions() call here because we do not remember ACL "line"
     // boundaries and associated "line" options; we cannot report them.
-
-    // optimization: most ACLs do not have myOptions
-    // this check also works around dump_SBufList() adding ' ' after empty items
-    if (!myOptions.empty()) {
-        SBufStream stream;
-        stream << myOptions;
-        const SBuf optionsImage = stream.buf();
-        if (!optionsImage.isEmpty())
-            result.push_back(optionsImage);
-    }
-    return result;
+    os << directiveName << ' ' << name << ' ' << typeString() << options() <<
+        asList(dump()).prefixedBy(" ").delimitedBy(" ") <<
+        '\n';
 }
 
 /* ACL result caching routines */
index d30e0ac7fe20bc4f805172455808767c922aa643..11b59f0b975647cc5c975f0b9f6c4255f2f20298 100644 (file)
@@ -82,7 +82,11 @@ public:
 
     virtual void prepareForUse() {}
 
-    SBufList dumpOptions(); ///< \returns approximate options configuration
+    // TODO: Find a way to make options() and this method constant
+    /// Prints aggregated "acl" (or similar) directive configuration, including
+    /// the given directive name, ACL name, ACL type, and ACL parameters. The
+    /// printed parameters are collected from all same-name "acl" directives.
+    void dumpWhole(const char *directiveName, std::ostream &);
 
     char name[ACL_NAME_SZ];
     char *cfgline;
index 58f7a91df8236a6a31b26540b5356e7162660864..929bf75c378f219162c71791e7ecfc61c7b546a9 100644 (file)
@@ -1490,16 +1490,10 @@ free_SBufList(SBufList *list)
 static void
 dump_acl(StoreEntry * entry, const char *name, ACL * ae)
 {
+    PackableStream os(*entry);
     while (ae != nullptr) {
         debugs(3, 3, "dump_acl: " << name << " " << ae->name);
-        storeAppendPrintf(entry, "%s %s %s ",
-                          name,
-                          ae->name,
-                          ae->typeString());
-        SBufList tail;
-        tail.splice(tail.end(), ae->dumpOptions());
-        tail.splice(tail.end(), ae->dump()); // ACL parameters
-        dump_SBufList(entry, tail);
+        ae->dumpWhole(name, os);
         ae = ae->next;
     }
 }