From 41ebd3975f9f230c1c9eb8ec25358c9da985762d Mon Sep 17 00:00:00 2001 From: Christos Tsantilas Date: Tue, 17 Jul 2012 17:11:24 +0300 Subject: [PATCH] Convert AccessLogEntry class to RefCountable The AccessLogEntry objects currently are only members of the ClientHttpRequest objects. There are cases where we need to access AccessLogEntry from server side objects to retrieve already stored informations for the client request and use it in server side code with format/* interface (eg use Format::Format::assemble inside http.cc) This patch convert AccessLogEntry class to RefCountable to allow link it with other than the ClientHttpRequest objects. This is a Measurement Factory project. --- src/AccessLogEntry.cc | 23 +++++++++++ src/AccessLogEntry.h | 16 +++++--- src/adaptation/icap/ModXact.cc | 4 +- src/adaptation/icap/Xaction.cc | 7 ++-- src/adaptation/icap/Xaction.h | 3 +- src/adaptation/icap/icap_log.cc | 2 +- src/adaptation/icap/icap_log.h | 5 ++- src/client_side.cc | 70 ++++++++++++++++----------------- src/client_side_reply.cc | 12 +++--- src/client_side_request.cc | 11 +++--- src/client_side_request.h | 2 +- src/format/Format.cc | 2 +- src/format/Format.h | 4 +- src/htcp.cc | 14 +++---- src/icp_v2.cc | 16 ++++---- src/log/FormatHttpdCombined.cc | 4 +- src/log/FormatHttpdCommon.cc | 2 +- src/log/FormatSquidCustom.cc | 2 +- src/log/FormatSquidIcap.cc | 2 +- src/log/FormatSquidNative.cc | 2 +- src/log/FormatSquidReferer.cc | 4 +- src/log/FormatSquidUseragent.cc | 4 +- src/log/Formats.h | 17 ++++---- src/log/access_log.cc | 28 +------------ 24 files changed, 134 insertions(+), 122 deletions(-) diff --git a/src/AccessLogEntry.cc b/src/AccessLogEntry.cc index d2dca0cfe5..31ea406864 100644 --- a/src/AccessLogEntry.cc +++ b/src/AccessLogEntry.cc @@ -17,3 +17,26 @@ AccessLogEntry::getLogClientIp(char *buf, size_t bufsz) const else cache.caddr.NtoA(buf, bufsz); } + +AccessLogEntry::~AccessLogEntry() +{ + safe_free(headers.request); + +#if ICAP_CLIENT + safe_free(adapt.last_meta); +#endif + + safe_free(headers.reply); + safe_free(cache.authuser); + + safe_free(headers.adapted_request); + HTTPMSGUNLOCK(adapted_request); + + HTTPMSGUNLOCK(reply); + HTTPMSGUNLOCK(request); +#if ICAP_CLIENT + HTTPMSGUNLOCK(icap.reply); + HTTPMSGUNLOCK(icap.request); +#endif + cbdataReferenceDone(cache.port); +} diff --git a/src/AccessLogEntry.h b/src/AccessLogEntry.h index 4e9fc88770..d3f3f0fe2c 100644 --- a/src/AccessLogEntry.h +++ b/src/AccessLogEntry.h @@ -40,17 +40,21 @@ #if ICAP_CLIENT #include "adaptation/icap/Elements.h" #endif +#include "RefCount.h" /* forward decls */ class HttpReply; class HttpRequest; -class AccessLogEntry +class AccessLogEntry: public RefCountable { public: + typedef RefCount Pointer; + AccessLogEntry() : url(NULL), tcpClient(), reply(NULL), request(NULL), adapted_request(NULL) {} + ~AccessLogEntry(); /// Fetch the client IP log string into the given buffer. /// Knows about several alternate locations of the IP @@ -131,10 +135,11 @@ public: msec(0), rfc931 (NULL), authuser (NULL), - extuser(NULL) + extuser(NULL), #if USE_SSL - ,ssluser(NULL) + ssluser(NULL), #endif + port(NULL) {; } @@ -254,12 +259,11 @@ class ACLChecklist; class StoreEntry; /* Should be in 'AccessLog.h' as the driver */ -extern void accessLogLogTo(customlog* log, AccessLogEntry* al, ACLChecklist* checklist = NULL); -extern void accessLogLog(AccessLogEntry *, ACLChecklist * checklist); +extern void accessLogLogTo(customlog* log, AccessLogEntry::Pointer &al, ACLChecklist* checklist = NULL); +extern void accessLogLog(AccessLogEntry::Pointer &, ACLChecklist * checklist); extern void accessLogRotate(void); extern void accessLogClose(void); extern void accessLogInit(void); -extern void accessLogFreeMemory(AccessLogEntry * aLogEntry); extern const char *accessLogTime(time_t); #endif /* SQUID_HTTPACCESSLOGENTRY_H */ diff --git a/src/adaptation/icap/ModXact.cc b/src/adaptation/icap/ModXact.cc index 8891606579..13596d3780 100644 --- a/src/adaptation/icap/ModXact.cc +++ b/src/adaptation/icap/ModXact.cc @@ -1249,7 +1249,7 @@ void Adaptation::Icap::ModXact::swanSong() Adaptation::Icap::Xaction::swanSong(); } -void prepareLogWithRequestDetails(HttpRequest *, AccessLogEntry *); +void prepareLogWithRequestDetails(HttpRequest *, AccessLogEntry::Pointer &); void Adaptation::Icap::ModXact::finalizeLogInfo() { @@ -1313,7 +1313,7 @@ void Adaptation::Icap::ModXact::finalizeLogInfo() packerClean(&p); mb.clean(); } - prepareLogWithRequestDetails(request_, &al); + prepareLogWithRequestDetails(request_, alep); Xaction::finalizeLogInfo(); } diff --git a/src/adaptation/icap/Xaction.cc b/src/adaptation/icap/Xaction.cc index 1fa5d57ab5..21e9cee53c 100644 --- a/src/adaptation/icap/Xaction.cc +++ b/src/adaptation/icap/Xaction.cc @@ -40,7 +40,9 @@ Adaptation::Icap::Xaction::Xaction(const char *aTypeName, Adaptation::Icap::Serv isRetriable(true), isRepeatable(true), ignoreLastWrite(false), - connector(NULL), reader(NULL), writer(NULL), closer(NULL) + connector(NULL), reader(NULL), writer(NULL), closer(NULL), + alep(new AccessLogEntry), + al(*alep) { debugs(93,3, typeName << " constructed, this=" << this << " [icapx" << id << ']'); // we should not call virtual status() here @@ -540,9 +542,8 @@ void Adaptation::Icap::Xaction::maybeLog() ACLChecklist *checklist = new ACLFilledChecklist(::Config.accessList.icap, al.request, dash_str); if (!::Config.accessList.icap || checklist->fastCheck() == ACCESS_ALLOWED) { finalizeLogInfo(); - icapLogLog(&al, checklist); + icapLogLog(alep, checklist); } - accessLogFreeMemory(&al); delete checklist; } } diff --git a/src/adaptation/icap/Xaction.h b/src/adaptation/icap/Xaction.h index c46fb8f95f..66d2bd21c4 100644 --- a/src/adaptation/icap/Xaction.h +++ b/src/adaptation/icap/Xaction.h @@ -180,7 +180,8 @@ protected: AsyncCall::Pointer writer; AsyncCall::Pointer closer; - AccessLogEntry al; + AccessLogEntry::Pointer alep; ///< icap.log entry + AccessLogEntry &al; ///< short for *alep timeval icap_tr_start; /*time when the ICAP transaction was created */ timeval icap_tio_start; /*time when the first ICAP request byte was scheduled for sending*/ diff --git a/src/adaptation/icap/icap_log.cc b/src/adaptation/icap/icap_log.cc index db21709491..88119bd3b8 100644 --- a/src/adaptation/icap/icap_log.cc +++ b/src/adaptation/icap/icap_log.cc @@ -44,7 +44,7 @@ icapLogRotate() } } -void icapLogLog(AccessLogEntry *al, ACLChecklist * checklist) +void icapLogLog(AccessLogEntry::Pointer &al, ACLChecklist * checklist) { if (IcapLogfileStatus == LOG_ENABLE) accessLogLogTo(Config.Log.icaplogs, al, checklist); diff --git a/src/adaptation/icap/icap_log.h b/src/adaptation/icap/icap_log.h index bf577ab399..1e981c6bd6 100644 --- a/src/adaptation/icap/icap_log.h +++ b/src/adaptation/icap/icap_log.h @@ -1,13 +1,16 @@ #ifndef ICAP_LOG_H_ #define ICAP_LOG_H_ +#include "RefCount.h" + +typedef RefCount AccessLogEntryPointer; class AccessLogEntry; class ACLChecklist; void icapLogClose(); void icapLogOpen(); void icapLogRotate(); -void icapLogLog(AccessLogEntry *al, ACLChecklist * checklist); +void icapLogLog(AccessLogEntryPointer &al, ACLChecklist * checklist); extern int IcapLogfileStatus; diff --git a/src/client_side.cc b/src/client_side.cc index 76c3014a2c..3a81b3a013 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -214,7 +214,7 @@ static void clientUpdateStatHistCounters(log_type logType, int svc_time); static void clientUpdateStatCounters(log_type logType); static void clientUpdateHierCounters(HierarchyLogEntry *); static bool clientPingHasFinished(ping_data const *aPing); -void prepareLogWithRequestDetails(HttpRequest *, AccessLogEntry *); +void prepareLogWithRequestDetails(HttpRequest *, AccessLogEntry::Pointer &); #ifndef PURIFY static bool connIsUsable(ConnStateData * conn); #endif @@ -548,10 +548,10 @@ ClientHttpRequest::updateCounters() } void -prepareLogWithRequestDetails(HttpRequest * request, AccessLogEntry * aLogEntry) +prepareLogWithRequestDetails(HttpRequest * request, AccessLogEntry::Pointer &aLogEntry) { assert(request); - assert(aLogEntry); + assert(aLogEntry != NULL); if (Config.onoff.log_mime_hdrs) { Packer p; @@ -622,47 +622,47 @@ ClientHttpRequest::logRequest() if (!out.size && !logType) debugs(33, 5, HERE << "logging half-baked transaction: " << log_uri); - al.icp.opcode = ICP_INVALID; - al.url = log_uri; - debugs(33, 9, "clientLogRequest: al.url='" << al.url << "'"); + al->icp.opcode = ICP_INVALID; + al->url = log_uri; + debugs(33, 9, "clientLogRequest: al.url='" << al->url << "'"); - if (al.reply) { - al.http.code = al.reply->sline.status; - al.http.content_type = al.reply->content_type.termedBuf(); + if (al->reply) { + al->http.code = al->reply->sline.status; + al->http.content_type = al->reply->content_type.termedBuf(); } else if (loggingEntry() && loggingEntry()->mem_obj) { - al.http.code = loggingEntry()->mem_obj->getReply()->sline.status; - al.http.content_type = loggingEntry()->mem_obj->getReply()->content_type.termedBuf(); + al->http.code = loggingEntry()->mem_obj->getReply()->sline.status; + al->http.content_type = loggingEntry()->mem_obj->getReply()->content_type.termedBuf(); } - debugs(33, 9, "clientLogRequest: http.code='" << al.http.code << "'"); + debugs(33, 9, "clientLogRequest: http.code='" << al->http.code << "'"); if (loggingEntry() && loggingEntry()->mem_obj) - al.cache.objectSize = loggingEntry()->contentLen(); + al->cache.objectSize = loggingEntry()->contentLen(); - al.cache.caddr.SetNoAddr(); + al->cache.caddr.SetNoAddr(); if (getConn() != NULL) { - al.cache.caddr = getConn()->log_addr; - al.cache.port = cbdataReference(getConn()->port); + al->cache.caddr = getConn()->log_addr; + al->cache.port = cbdataReference(getConn()->port); } - al.cache.requestSize = req_sz; - al.cache.requestHeadersSize = req_sz; + al->cache.requestSize = req_sz; + al->cache.requestHeadersSize = req_sz; - al.cache.replySize = out.size; - al.cache.replyHeadersSize = out.headers_sz; + al->cache.replySize = out.size; + al->cache.replyHeadersSize = out.headers_sz; - al.cache.highOffset = out.offset; + al->cache.highOffset = out.offset; - al.cache.code = logType; + al->cache.code = logType; - al.cache.msec = tvSubMsec(start_time, current_time); + al->cache.msec = tvSubMsec(start_time, current_time); if (request) - prepareLogWithRequestDetails(request, &al); + prepareLogWithRequestDetails(request, al); if (getConn() != NULL && getConn()->clientConnection != NULL && getConn()->clientConnection->rfc931[0]) - al.cache.rfc931 = getConn()->clientConnection->rfc931; + al->cache.rfc931 = getConn()->clientConnection->rfc931; #if USE_SSL && 0 @@ -670,19 +670,19 @@ ClientHttpRequest::logRequest() * to snarf the ssl details some place earlier.. */ if (getConn() != NULL) - al.cache.ssluser = sslGetUserEmail(fd_table[getConn()->fd].ssl); + al->cache.ssluser = sslGetUserEmail(fd_table[getConn()->fd].ssl); #endif ACLFilledChecklist *checklist = clientAclChecklistCreate(Config.accessList.log, this); - if (al.reply) - checklist->reply = HTTPMSGLOCK(al.reply); + if (al->reply) + checklist->reply = HTTPMSGLOCK(al->reply); if (!Config.accessList.log || checklist->fastCheck() == ACCESS_ALLOWED) { if (request) - al.adapted_request = HTTPMSGLOCK(request); - accessLogLog(&al, checklist); + al->adapted_request = HTTPMSGLOCK(request); + accessLogLog(al, checklist); updateCounters(); if (getConn() != NULL && getConn()->clientConnection != NULL) @@ -690,8 +690,6 @@ ClientHttpRequest::logRequest() } delete checklist; - - accessLogFreeMemory(&al); } void @@ -1441,7 +1439,7 @@ clientSocketRecipient(clientStreamNode * node, ClientHttpRequest * http, context->sendBody(rep, receivedData); else { assert(rep); - http->al.reply = HTTPMSGLOCK(rep); + http->al->reply = HTTPMSGLOCK(rep); context->sendStartOfMessage(rep, receivedData); } @@ -1787,9 +1785,9 @@ ClientSocketContext::noteIoError(const int xerrno) { if (http) { if (xerrno == ETIMEDOUT) - http->al.http.timedout = true; + http->al->http.timedout = true; else // even if xerrno is zero (which means read abort/eof) - http->al.http.aborted = true; + http->al->http.aborted = true; } } @@ -3141,7 +3139,7 @@ clientLifetimeTimeout(const CommTimeoutCbParams &io) ClientHttpRequest *http = static_cast(io.data); debugs(33, DBG_IMPORTANT, "WARNING: Closing client connection due to lifetime timeout"); debugs(33, DBG_IMPORTANT, "\t" << http->uri); - http->al.http.timedout = true; + http->al->http.timedout = true; if (Comm::IsConnOpen(io.conn)) io.conn->close(); } diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index 4d0af98f34..69754bd439 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -117,7 +117,7 @@ clientReplyContext::setReplyToError( /* prevent confusion over whether we default to persistent or not */ http->request->flags.proxy_keepalive = 0; - http->al.http.code = errstate->httpStatus; + http->al->http.code = errstate->httpStatus; createStoreEntry(method, request_flags()); #if USE_AUTH @@ -633,7 +633,7 @@ clientReplyContext::processMiss() /// Deny loops for accelerator and interceptor. TODO: deny in all modes? if (r->flags.loopdetect && (http->flags.accel || http->flags.intercepted)) { - http->al.http.code = HTTP_FORBIDDEN; + http->al->http.code = HTTP_FORBIDDEN; err = clientBuildError(ERR_ACCESS_DENIED, HTTP_FORBIDDEN, NULL, http->getConn()->clientConnection->remote, http->request); createStoreEntry(r->method, request_flags()); errorAppendEntry(http->storeEntry(), err); @@ -677,7 +677,7 @@ clientReplyContext::processOnlyIfCachedMiss() { debugs(88, 4, "clientProcessOnlyIfCachedMiss: '" << RequestMethodStr(http->request->method) << " " << http->uri << "'"); - http->al.http.code = HTTP_GATEWAY_TIMEOUT; + http->al->http.code = HTTP_GATEWAY_TIMEOUT; ErrorState *err = clientBuildError(ERR_ONLY_IF_CACHED_MISS, HTTP_GATEWAY_TIMEOUT, NULL, http->getConn()->clientConnection->remote, http->request); removeClientStoreReference(&sc, http); @@ -2122,9 +2122,9 @@ clientReplyContext::sendMoreData (StoreIOBuffer result) size_t k; if ((k = headersEnd(buf, reqofs))) { - safe_free(http->al.headers.reply); - http->al.headers.reply = (char *)xcalloc(k + 1, 1); - xstrncpy(http->al.headers.reply, buf, k); + safe_free(http->al->headers.reply); + http->al->headers.reply = (char *)xcalloc(k + 1, 1); + xstrncpy(http->al->headers.reply, buf, k); } } diff --git a/src/client_side_request.cc b/src/client_side_request.cc index 7c738f45d1..1eacb96b80 100644 --- a/src/client_side_request.cc +++ b/src/client_side_request.cc @@ -176,7 +176,8 @@ ClientHttpRequest::ClientHttpRequest(ConnStateData * aConn) : { start_time = current_time; setConn(aConn); - al.tcpClient = clientConnection = aConn->clientConnection; + al = new AccessLogEntry; + al->tcpClient = clientConnection = aConn->clientConnection; dlinkAdd(this, &active, &ClientActiveRequests); #if USE_ADAPTATION request_satisfaction_mode = false; @@ -280,7 +281,7 @@ ClientHttpRequest::~ClientHttpRequest() loggingEntry(NULL); if (request) - checkFailureRatio(request->errType, al.hier.code); + checkFailureRatio(request->errType, al->hier.code); freeResources(); @@ -1333,7 +1334,7 @@ ClientHttpRequest::processRequest() #endif logType = LOG_TCP_MISS; getConn()->stopReading(); // tunnels read for themselves - tunnelStart(this, &out.size, &al.http.code); + tunnelStart(this, &out.size, &al->http.code); return; } @@ -1492,8 +1493,8 @@ ClientHttpRequest::doCallouts() assert(calloutContext); /*Save the original request for logging purposes*/ - if (!calloutContext->http->al.request) - calloutContext->http->al.request = HTTPMSGLOCK(request); + if (!calloutContext->http->al->request) + calloutContext->http->al->request = HTTPMSGLOCK(request); // CVE-2009-0801: verify the Host: header is consistent with other known details. if (!calloutContext->host_header_verify_done) { diff --git a/src/client_side_request.h b/src/client_side_request.h index 5e84030a9f..d55c173cf9 100644 --- a/src/client_side_request.h +++ b/src/client_side_request.h @@ -116,7 +116,7 @@ public: log_type logType; struct timeval start_time; - AccessLogEntry al; + AccessLogEntry::Pointer al; ///< access.log entry struct { unsigned int accel:1; diff --git a/src/format/Format.cc b/src/format/Format.cc index 18348e8148..018442eaa3 100644 --- a/src/format/Format.cc +++ b/src/format/Format.cc @@ -290,7 +290,7 @@ log_quoted_string(const char *str, char *out) } void -Format::Format::assemble(MemBuf &mb, AccessLogEntry *al, int logSequenceNumber) const +Format::Format::assemble(MemBuf &mb, const AccessLogEntryPointer &al, int logSequenceNumber) const { char tmp[1024]; String sb; diff --git a/src/format/Format.h b/src/format/Format.h index 3c177569f1..9ac18baacb 100644 --- a/src/format/Format.h +++ b/src/format/Format.h @@ -1,6 +1,7 @@ #ifndef _SQUID_FORMAT_FORMAT_H #define _SQUID_FORMAT_FORMAT_H +#include "RefCount.h" /* * Squid configuration allows users to define custom formats in * several components. @@ -14,6 +15,7 @@ */ class AccessLogEntry; +typedef RefCount AccessLogEntryPointer; class MemBuf; class StoreEntry; @@ -36,7 +38,7 @@ public: bool parse(char *def); /// assemble the state information into a formatted line. - void assemble(MemBuf &mb, AccessLogEntry *al, int logSequenceNumber) const; + void assemble(MemBuf &mb, const AccessLogEntryPointer &al, int logSequenceNumber) const; /// dump this whole list of formats into the provided StoreEntry void dump(StoreEntry * entry, const char *name); diff --git a/src/htcp.cc b/src/htcp.cc index cbdb03cc1d..c4e0b08a58 100644 --- a/src/htcp.cc +++ b/src/htcp.cc @@ -1717,15 +1717,15 @@ htcpClosePorts(void) static void htcpLogHtcp(Ip::Address &caddr, int opcode, log_type logcode, const char *url) { - AccessLogEntry al; + AccessLogEntry::Pointer al = new AccessLogEntry; if (LOG_TAG_NONE == logcode) return; if (!Config.onoff.log_udp) return; - al.htcp.opcode = htcpOpcodeStr[opcode]; - al.url = url; - al.cache.caddr = caddr; - al.cache.code = logcode; - al.cache.msec = 0; - accessLogLog(&al, NULL); + al->htcp.opcode = htcpOpcodeStr[opcode]; + al->url = url; + al->cache.caddr = caddr; + al->cache.code = logcode; + al->cache.msec = 0; + accessLogLog(al, NULL); } diff --git a/src/icp_v2.cc b/src/icp_v2.cc index 9b64c2acb3..6e78ebcc0b 100644 --- a/src/icp_v2.cc +++ b/src/icp_v2.cc @@ -186,7 +186,7 @@ ICP2State::created(StoreEntry *newEntry) static void icpLogIcp(const Ip::Address &caddr, log_type logcode, int len, const char *url, int delay) { - AccessLogEntry al; + AccessLogEntry::Pointer al = new AccessLogEntry(); if (LOG_TAG_NONE == logcode) return; @@ -199,19 +199,19 @@ icpLogIcp(const Ip::Address &caddr, log_type logcode, int len, const char *url, if (!Config.onoff.log_udp) return; - al.icp.opcode = ICP_QUERY; + al->icp.opcode = ICP_QUERY; - al.url = url; + al->url = url; - al.cache.caddr = caddr; + al->cache.caddr = caddr; - al.cache.replySize = len; + al->cache.replySize = len; - al.cache.code = logcode; + al->cache.code = logcode; - al.cache.msec = delay; + al->cache.msec = delay; - accessLogLog(&al, NULL); + accessLogLog(al, NULL); } /// \ingroup ServerProtocolICPInternal2 diff --git a/src/log/FormatHttpdCombined.cc b/src/log/FormatHttpdCombined.cc index 4980462d9d..b3aae86344 100644 --- a/src/log/FormatHttpdCombined.cc +++ b/src/log/FormatHttpdCombined.cc @@ -42,7 +42,7 @@ #include "SquidTime.h" void -Log::Format::HttpdCombined(AccessLogEntry * al, Logfile * logfile) +Log::Format::HttpdCombined(const AccessLogEntry::Pointer &al, Logfile * logfile) { const char *user_ident = ::Format::QuoteUrlEncodeUsername(al->cache.rfc931); @@ -51,7 +51,7 @@ Log::Format::HttpdCombined(AccessLogEntry * al, Logfile * logfile) const char *referer = NULL; const char *agent = NULL; - if (al && al->request) { + if (al->request) { referer = al->request->header.getStr(HDR_REFERER); agent = al->request->header.getStr(HDR_USER_AGENT); } diff --git a/src/log/FormatHttpdCommon.cc b/src/log/FormatHttpdCommon.cc index bcb5d74d39..612afc6533 100644 --- a/src/log/FormatHttpdCommon.cc +++ b/src/log/FormatHttpdCommon.cc @@ -41,7 +41,7 @@ #include "SquidTime.h" void -Log::Format::HttpdCommon(AccessLogEntry * al, Logfile * logfile) +Log::Format::HttpdCommon(const AccessLogEntry::Pointer &al, Logfile * logfile) { const char *user_auth = ::Format::QuoteUrlEncodeUsername(al->cache.authuser); const char *user_ident = ::Format::QuoteUrlEncodeUsername(al->cache.rfc931); diff --git a/src/log/FormatSquidCustom.cc b/src/log/FormatSquidCustom.cc index 6cf2427d33..af49911717 100644 --- a/src/log/FormatSquidCustom.cc +++ b/src/log/FormatSquidCustom.cc @@ -39,7 +39,7 @@ #include "MemBuf.h" void -Log::Format::SquidCustom(AccessLogEntry * al, customlog * log) +Log::Format::SquidCustom(const AccessLogEntry::Pointer &al, customlog * log) { static MemBuf mb; mb.reset(); diff --git a/src/log/FormatSquidIcap.cc b/src/log/FormatSquidIcap.cc index ffa9223c0f..15b8104e05 100644 --- a/src/log/FormatSquidIcap.cc +++ b/src/log/FormatSquidIcap.cc @@ -44,7 +44,7 @@ #include "SquidTime.h" void -Log::Format::SquidIcap(AccessLogEntry * al, Logfile * logfile) +Log::Format::SquidIcap(const AccessLogEntry::Pointer &al, Logfile * logfile) { const char *client = NULL; const char *user = NULL; diff --git a/src/log/FormatSquidNative.cc b/src/log/FormatSquidNative.cc index c5b059da0d..4cde4eca2d 100644 --- a/src/log/FormatSquidNative.cc +++ b/src/log/FormatSquidNative.cc @@ -41,7 +41,7 @@ #include "SquidTime.h" void -Log::Format::SquidNative(AccessLogEntry * al, Logfile * logfile) +Log::Format::SquidNative(const AccessLogEntry::Pointer &al, Logfile * logfile) { char hierHost[MAX_IPSTRLEN]; diff --git a/src/log/FormatSquidReferer.cc b/src/log/FormatSquidReferer.cc index 0c7236d2a4..20f56e92a9 100644 --- a/src/log/FormatSquidReferer.cc +++ b/src/log/FormatSquidReferer.cc @@ -41,10 +41,10 @@ #include "SquidTime.h" void -Log::Format::SquidReferer(AccessLogEntry *al, Logfile *logfile) +Log::Format::SquidReferer(const AccessLogEntry::Pointer &al, Logfile *logfile) { const char *referer = NULL; - if (al && al->request) + if (al->request) referer = al->request->header.getStr(HDR_REFERER); if (!referer || *referer == '\0') diff --git a/src/log/FormatSquidUseragent.cc b/src/log/FormatSquidUseragent.cc index bfe3245e87..3dd595d36e 100644 --- a/src/log/FormatSquidUseragent.cc +++ b/src/log/FormatSquidUseragent.cc @@ -41,11 +41,11 @@ #include "SquidTime.h" void -Log::Format::SquidUserAgent(AccessLogEntry * al, Logfile * logfile) +Log::Format::SquidUserAgent(const AccessLogEntry::Pointer &al, Logfile * logfile) { const char *agent = NULL; - if (al && al->request) + if (al->request) agent = al->request->header.getStr(HDR_USER_AGENT); if (!agent || *agent == '\0') diff --git a/src/log/Formats.h b/src/log/Formats.h index 97ac52c48f..8d60a08622 100644 --- a/src/log/Formats.h +++ b/src/log/Formats.h @@ -1,6 +1,9 @@ #ifndef _SQUID_LOG_FORMATS_H #define _SQUID_LOG_FORMATS_H +#include "RefCount.h" + +typedef RefCount AccessLogEntryPointer; class AccessLogEntry; class Logfile; @@ -25,25 +28,25 @@ typedef enum { } log_type; /// Native Squid Format Display -void SquidNative(AccessLogEntry * al, Logfile * logfile); +void SquidNative(const AccessLogEntryPointer &al, Logfile * logfile); /// Display log details in Squid ICAP format. -void SquidIcap(AccessLogEntry * al, Logfile * logfile); +void SquidIcap(const AccessLogEntryPointer &al, Logfile * logfile); /// Display log details in useragent format. -void SquidUserAgent(AccessLogEntry * al, Logfile * logfile); +void SquidUserAgent(const AccessLogEntryPointer &al, Logfile * logfile); /// Display log details in Squid old refererlog format. -void SquidReferer(AccessLogEntry * al, Logfile * logfile); +void SquidReferer(const AccessLogEntryPointer &al, Logfile * logfile); /// Log with a local custom format -void SquidCustom(AccessLogEntry * al, customlog * log); +void SquidCustom(const AccessLogEntryPointer &al, customlog * log); /// Log with Apache httpd common format -void HttpdCommon(AccessLogEntry * al, Logfile * logfile); +void HttpdCommon(const AccessLogEntryPointer &al, Logfile * logfile); /// Log with Apache httpd combined format -void HttpdCombined(AccessLogEntry * al, Logfile * logfile); +void HttpdCombined(const AccessLogEntryPointer &al, Logfile * logfile); }; // namespace Format }; // namespace Log diff --git a/src/log/access_log.cc b/src/log/access_log.cc index 88265626fa..0a5a11049b 100644 --- a/src/log/access_log.cc +++ b/src/log/access_log.cc @@ -91,7 +91,7 @@ static void fvdbRegisterWithCacheManager(); int LogfileStatus = LOG_DISABLE; void -accessLogLogTo(customlog* log, AccessLogEntry * al, ACLChecklist * checklist) +accessLogLogTo(customlog* log, AccessLogEntry::Pointer &al, ACLChecklist * checklist) { if (al->url == NULL) @@ -167,7 +167,7 @@ accessLogLogTo(customlog* log, AccessLogEntry * al, ACLChecklist * checklist) } void -accessLogLog(AccessLogEntry * al, ACLChecklist * checklist) +accessLogLog(AccessLogEntry::Pointer &al, ACLChecklist * checklist) { if (LogfileStatus != LOG_ENABLE) return; @@ -575,30 +575,6 @@ headersLog(int cs, int pq, const HttpRequestMethod& method, void *data) #endif -void -accessLogFreeMemory(AccessLogEntry * aLogEntry) -{ - safe_free(aLogEntry->headers.request); - -#if ICAP_CLIENT - safe_free(aLogEntry->adapt.last_meta); -#endif - - safe_free(aLogEntry->headers.reply); - safe_free(aLogEntry->cache.authuser); - - safe_free(aLogEntry->headers.adapted_request); - HTTPMSGUNLOCK(aLogEntry->adapted_request); - - HTTPMSGUNLOCK(aLogEntry->reply); - HTTPMSGUNLOCK(aLogEntry->request); -#if ICAP_CLIENT - HTTPMSGUNLOCK(aLogEntry->icap.reply); - HTTPMSGUNLOCK(aLogEntry->icap.request); -#endif - cbdataReferenceDone(aLogEntry->cache.port); -} - int logTypeIsATcpHit(log_type code) { -- 2.47.2