From: Eduard Bagdasaryan Date: Tue, 28 Sep 2021 15:59:43 +0000 (+0000) Subject: Improved const-correctness of ALE-driven APIs (#904) X-Git-Tag: SQUID_6_0_1~286 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=63ed9e8e330a376f9b9f7c776d74b083b704f4c4;p=thirdparty%2Fsquid.git Improved const-correctness of ALE-driven APIs (#904) Also made ClientHttpRequest::al constant. This work actually started with changing this data member, to make some ALE-related hack safer. That change required the API fixes. We have since got rid of the hack, but all these const-correctness changes are valuable on their own. No functionality changes. --- diff --git a/src/AccessLogEntry.h b/src/AccessLogEntry.h index 9f63104846..d4b9cb9061 100644 --- a/src/AccessLogEntry.h +++ b/src/AccessLogEntry.h @@ -276,8 +276,8 @@ class ACLChecklist; class StoreEntry; /* Should be in 'AccessLog.h' as the driver */ -void accessLogLogTo(CustomLog* log, AccessLogEntry::Pointer &al, ACLChecklist* checklist = NULL); -void accessLogLog(AccessLogEntry::Pointer &, ACLChecklist * checklist); +void accessLogLogTo(CustomLog *, const AccessLogEntryPointer &, ACLChecklist *checklist = nullptr); +void accessLogLog(const AccessLogEntryPointer &, ACLChecklist *); void accessLogRotate(void); void accessLogClose(void); void accessLogInit(void); diff --git a/src/adaptation/AccessCheck.cc b/src/adaptation/AccessCheck.cc index bb1947f878..505a24315d 100644 --- a/src/adaptation/AccessCheck.cc +++ b/src/adaptation/AccessCheck.cc @@ -29,7 +29,7 @@ cbdata_type Adaptation::AccessCheck::CBDATA_AccessCheck = CBDATA_UNKNOWN; bool Adaptation::AccessCheck::Start(Method method, VectPoint vp, HttpRequest *req, HttpReply *rep, - AccessLogEntry::Pointer &al, Adaptation::Initiator *initiator) + const AccessLogEntryPointer &al, Adaptation::Initiator *initiator) { if (Config::Enabled) { diff --git a/src/adaptation/AccessCheck.h b/src/adaptation/AccessCheck.h index 872650a8e5..aa57ec03d3 100644 --- a/src/adaptation/AccessCheck.h +++ b/src/adaptation/AccessCheck.h @@ -9,13 +9,13 @@ #ifndef SQUID_ADAPTATION__ACCESS_CHECK_H #define SQUID_ADAPTATION__ACCESS_CHECK_H -#include "AccessLogEntry.h" #include "acl/Acl.h" #include "adaptation/Elements.h" #include "adaptation/forward.h" #include "adaptation/Initiator.h" #include "adaptation/ServiceFilter.h" #include "base/AsyncJob.h" +#include "log/forward.h" class HttpRequest; class HttpReply; @@ -36,7 +36,7 @@ public: // use this to start async ACL checks; returns true if started static bool Start(Method method, VectPoint vp, HttpRequest *req, - HttpReply *rep, AccessLogEntry::Pointer &al, Adaptation::Initiator *initiator); + HttpReply *, const AccessLogEntryPointer &, Adaptation::Initiator *); protected: // use Start to start adaptation checks diff --git a/src/adaptation/Iterator.cc b/src/adaptation/Iterator.cc index c1a2b1d367..b223363634 100644 --- a/src/adaptation/Iterator.cc +++ b/src/adaptation/Iterator.cc @@ -21,7 +21,7 @@ Adaptation::Iterator::Iterator( Http::Message *aMsg, HttpRequest *aCause, - AccessLogEntry::Pointer &alp, + const AccessLogEntryPointer &alp, const ServiceGroupPointer &aGroup): AsyncJob("Iterator"), Adaptation::Initiate("Iterator"), diff --git a/src/adaptation/Iterator.h b/src/adaptation/Iterator.h index 9c2be5764c..2f8f410a0d 100644 --- a/src/adaptation/Iterator.h +++ b/src/adaptation/Iterator.h @@ -9,11 +9,11 @@ #ifndef SQUID_ADAPTATION__ITERATOR_H #define SQUID_ADAPTATION__ITERATOR_H -#include "AccessLogEntry.h" #include "adaptation/Initiate.h" #include "adaptation/Initiator.h" #include "adaptation/ServiceGroups.h" #include "http/forward.h" +#include "log/forward.h" namespace Adaptation { @@ -34,7 +34,7 @@ class Iterator: public Initiate, public Initiator public: Iterator(Http::Message *virginHeader, HttpRequest *virginCause, - AccessLogEntry::Pointer &alp, + const AccessLogEntryPointer &, const Adaptation::ServiceGroupPointer &aGroup); virtual ~Iterator(); @@ -67,7 +67,7 @@ protected: ServicePlan thePlan; ///< which services to use and in what order Http::Message *theMsg; ///< the message being adapted (virgin for each step) HttpRequest *theCause; ///< the cause of the original virgin message - AccessLogEntry::Pointer al; ///< info for the future access.log entry + AccessLogEntryPointer al; ///< info for the future access.log entry CbcPointer theLauncher; ///< current transaction launcher int iterations; ///< number of steps initiated bool adapted; ///< whether the virgin message has been replaced diff --git a/src/adaptation/icap/ModXact.cc b/src/adaptation/icap/ModXact.cc index 3fd49c312a..e16314c889 100644 --- a/src/adaptation/icap/ModXact.cc +++ b/src/adaptation/icap/ModXact.cc @@ -1311,7 +1311,7 @@ void Adaptation::Icap::ModXact::swanSong() Adaptation::Icap::Xaction::swanSong(); } -void prepareLogWithRequestDetails(HttpRequest *, AccessLogEntry::Pointer &); +void prepareLogWithRequestDetails(HttpRequest *, const AccessLogEntryPointer &); void Adaptation::Icap::ModXact::finalizeLogInfo() { diff --git a/src/client_side.cc b/src/client_side.cc index a23efb19e4..512796b1ea 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -186,7 +186,7 @@ static void clientUpdateStatHistCounters(const LogTags &logType, int svc_time); static void clientUpdateStatCounters(const LogTags &logType); static void clientUpdateHierCounters(HierarchyLogEntry *); static bool clientPingHasFinished(ping_data const *aPing); -void prepareLogWithRequestDetails(HttpRequest *, AccessLogEntry::Pointer &); +void prepareLogWithRequestDetails(HttpRequest *, const AccessLogEntryPointer &); static void ClientSocketContextPushDeferredIfNeeded(Http::StreamPointer deferredRequest, ConnStateData * conn); char *skipLeadingSpace(char *aString); @@ -325,7 +325,7 @@ ClientHttpRequest::updateCounters() } void -prepareLogWithRequestDetails(HttpRequest * request, AccessLogEntry::Pointer &aLogEntry) +prepareLogWithRequestDetails(HttpRequest *request, const AccessLogEntryPointer &aLogEntry) { assert(request); assert(aLogEntry != NULL); diff --git a/src/client_side_request.cc b/src/client_side_request.cc index 866d78db9c..aba646de19 100644 --- a/src/client_side_request.cc +++ b/src/client_side_request.cc @@ -151,6 +151,7 @@ ClientHttpRequest::ClientHttpRequest(ConnStateData * aConn) : uri(NULL), log_uri(NULL), req_sz(0), + al(new AccessLogEntry()), calloutContext(NULL), maxReplyBodySize_(0), entry_(NULL), @@ -164,7 +165,6 @@ ClientHttpRequest::ClientHttpRequest(ConnStateData * aConn) : , request_satisfaction_offset(0) #endif { - al = new AccessLogEntry; CodeContext::Reset(al); al->cache.start_time = current_time; if (aConn) { diff --git a/src/client_side_request.h b/src/client_side_request.h index 55a2c63b5a..fe8551b299 100644 --- a/src/client_side_request.h +++ b/src/client_side_request.h @@ -9,12 +9,12 @@ #ifndef SQUID_CLIENTSIDEREQUEST_H #define SQUID_CLIENTSIDEREQUEST_H -#include "AccessLogEntry.h" #include "acl/forward.h" #include "client_side.h" #include "clientStream.h" #include "http/forward.h" #include "HttpHeaderRange.h" +#include "log/forward.h" #include "LogTags.h" #include "Store.h" @@ -123,7 +123,7 @@ public: // NP: still an enum so each stage altering it must take care when replacing it. LogTags logType; - AccessLogEntry::Pointer al; ///< access.log entry + const AccessLogEntryPointer al; ///< access.log entry struct Flags { Flags() : accel(false), internal(false), done_copying(false) {} diff --git a/src/esi/Esi.cc b/src/esi/Esi.cc index c67ac79c70..091ce3c3c5 100644 --- a/src/esi/Esi.cc +++ b/src/esi/Esi.cc @@ -37,6 +37,7 @@ #include "HttpReply.h" #include "HttpRequest.h" #include "ip/Address.h" +#include "log/forward.h" #include "MemBuf.h" #include "profiler/Profiler.h" #include "SquidConfig.h" @@ -1412,7 +1413,7 @@ ESIContext::freeResources () /* don't touch incoming, it's a pointer into buffered anyway */ } -ErrorState *clientBuildError(err_type, Http::StatusCode, char const *, const ConnStateData *, HttpRequest *, const AccessLogEntry::Pointer &); +ErrorState *clientBuildError(err_type, Http::StatusCode, char const *, const ConnStateData *, HttpRequest *, const AccessLogEntryPointer &); /* This can ONLY be used before we have sent *any* data to the client */ void diff --git a/src/log/access_log.cc b/src/log/access_log.cc index 9e72c95893..8b811da318 100644 --- a/src/log/access_log.cc +++ b/src/log/access_log.cc @@ -75,7 +75,7 @@ static void fvdbRegisterWithCacheManager(); int LogfileStatus = LOG_DISABLE; void -accessLogLogTo(CustomLog* log, AccessLogEntry::Pointer &al, ACLChecklist * checklist) +accessLogLogTo(CustomLog *log, const AccessLogEntryPointer &al, ACLChecklist *checklist) { if (al->url.isEmpty()) @@ -145,7 +145,7 @@ accessLogLogTo(CustomLog* log, AccessLogEntry::Pointer &al, ACLChecklist * check } void -accessLogLog(AccessLogEntry::Pointer &al, ACLChecklist * checklist) +accessLogLog(const AccessLogEntryPointer &al, ACLChecklist *checklist) { if (LogfileStatus != LOG_ENABLE) return; diff --git a/src/stat.cc b/src/stat.cc index 497b9734e9..b537396caf 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -9,6 +9,7 @@ /* DEBUG: section 18 Cache Manager Statistics */ #include "squid.h" +#include "AccessLogEntry.h" #include "CacheDigest.h" #include "CachePeer.h" #include "client_side.h" diff --git a/src/tests/stub_liblog.cc b/src/tests/stub_liblog.cc index b4a0b16813..25f4a4bbaa 100644 --- a/src/tests/stub_liblog.cc +++ b/src/tests/stub_liblog.cc @@ -23,8 +23,8 @@ SBuf AccessLogEntry::getLogMethod() const STUB_RETVAL(SBuf()) AccessLogEntry::SslDetails::SslDetails() {STUB} #endif */ -void accessLogLogTo(CustomLog *, AccessLogEntry::Pointer &, ACLChecklist *) STUB -void accessLogLog(AccessLogEntry::Pointer &, ACLChecklist *) STUB +void accessLogLogTo(CustomLog *, const AccessLogEntry::Pointer &, ACLChecklist *) STUB +void accessLogLog(const AccessLogEntry::Pointer &, ACLChecklist *) STUB void accessLogRotate(void) STUB void accessLogClose(void) STUB void accessLogInit(void) STUB