From: Francesco Chemolli <5175948+kinkie@users.noreply.github.com> Date: Mon, 6 Nov 2023 03:22:38 +0000 (+0000) Subject: Use PackableStream for dump_acl (#1573) X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=36dcfef6b367132a2b00264357dd2a62224c8177;p=thirdparty%2Fsquid.git Use PackableStream for dump_acl (#1573) --- diff --git a/src/acl/Acl.cc b/src/acl/Acl.cc index f466c6712e..63c6bff3ec 100644 --- a/src/acl/Acl.cc +++ b/src/acl/Acl.cc @@ -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 */ diff --git a/src/acl/Acl.h b/src/acl/Acl.h index d30e0ac7fe..11b59f0b97 100644 --- a/src/acl/Acl.h +++ b/src/acl/Acl.h @@ -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; diff --git a/src/cache_cf.cc b/src/cache_cf.cc index 58f7a91df8..929bf75c37 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -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; } }