From: Amos Jeffries Date: Thu, 11 Jun 2015 04:51:10 +0000 (-0700) Subject: Convert enum LogTags into class LogTags X-Git-Tag: merge-candidate-3-v1~38^2~18^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9136993377e9decfef076b4fa8b14ee03f4c8a09;p=thirdparty%2Fsquid.git Convert enum LogTags into class LogTags - enum sequence re-typed to LogTags_ot - logTagsIsATcpHit() function converted to method LogTags::isTcpHit() - strings array lookup converted to method LogTags::c_str() - constructors and assignment assure valid values, no more need for external asserts before logging. --- diff --git a/src/AccessLogEntry.h b/src/AccessLogEntry.h index 24a59ac9a0..30f45f1fb7 100644 --- a/src/AccessLogEntry.h +++ b/src/AccessLogEntry.h @@ -63,7 +63,10 @@ public: { public: - HttpDetails() : method(Http::METHOD_NONE), code(0), content_type(NULL), + HttpDetails() : + method(Http::METHOD_NONE), + code(0), + content_type(NULL), timedout(false), aborted(false), clientRequestSz(), @@ -140,7 +143,7 @@ public: CacheDetails() : caddr(), highOffset(0), objectSize(0), - code (LOG_TAG_NONE), + code(LOG_TAG_NONE), rfc931 (NULL), extuser(NULL), #if USE_OPENSSL diff --git a/src/LogTags.cc b/src/LogTags.cc index bb483b25f4..1a3e5f56c8 100644 --- a/src/LogTags.cc +++ b/src/LogTags.cc @@ -10,7 +10,7 @@ #include "LogTags.h" // old deprecated tag strings -const char * LogTags_str[] = { +const char * LogTags::Str_[] = { "TAG_NONE", "TCP_HIT", "TCP_MISS", @@ -36,3 +36,22 @@ const char * LogTags_str[] = { "ICP_QUERY", "TYPE_MAX" }; + +const char * +LogTags::c_str() const +{ + return Str_[oldType]; +} + +bool +LogTags::isTcpHit() const +{ + return + (oldType == LOG_TCP_HIT) || + (oldType == LOG_TCP_IMS_HIT) || + (oldType == LOG_TCP_REFRESH_FAIL_OLD) || + (oldType == LOG_TCP_REFRESH_UNMODIFIED) || + (oldType == LOG_TCP_NEGATIVE_HIT) || + (oldType == LOG_TCP_MEM_HIT) || + (oldType == LOG_TCP_OFFLINE_HIT); +} diff --git a/src/LogTags.h b/src/LogTags.h index ffdad7007a..bc50befbca 100644 --- a/src/LogTags.h +++ b/src/LogTags.h @@ -42,29 +42,34 @@ typedef enum { LOG_UDP_MISS_NOFETCH, LOG_ICP_QUERY, LOG_TYPE_MAX -} LogTags; +} LogTags_ot; -/// list of string representations for LogTags -extern const char *LogTags_str[]; - -/// determine if the log tag code indicates a cache HIT -inline bool logTypeIsATcpHit(LogTags code) +class LogTags { - return - (code == LOG_TCP_HIT) || - (code == LOG_TCP_IMS_HIT) || - (code == LOG_TCP_REFRESH_FAIL_OLD) || - (code == LOG_TCP_REFRESH_UNMODIFIED) || - (code == LOG_TCP_NEGATIVE_HIT) || - (code == LOG_TCP_MEM_HIT) || - (code == LOG_TCP_OFFLINE_HIT); -} +public: + LogTags(LogTags_ot t) : oldType(t) {assert(oldType < LOG_TYPE_MAX);} + LogTags &operator =(const LogTags_ot &t) {assert(t < LOG_TYPE_MAX); oldType = t; return *this;} + + const char *c_str() const; + + /// determine if the log tag code indicates a cache HIT + bool isTcpHit() const; + +private: + /// list of string representations for LogTags_ot + static const char *Str_[]; + +public: // XXX: only until client_db.cc stats are redesigned. + + // deprecated LogTag enum value + LogTags_ot oldType; +}; -/// iterator for LogTags enumeration -inline LogTags &operator++ (LogTags &aLogType) +/// iterator for LogTags_ot enumeration +inline LogTags_ot &operator++ (LogTags_ot &aLogType) { int tmp = (int)aLogType; - aLogType = (LogTags)(++tmp); + aLogType = (LogTags_ot)(++tmp); return aLogType; } diff --git a/src/client_db.cc b/src/client_db.cc index 4946e0108a..87817b3661 100644 --- a/src/client_db.cc +++ b/src/client_db.cc @@ -137,7 +137,7 @@ ClientInfo * clientdbGetInfo(const Ip::Address &addr) } #endif void -clientdbUpdate(const Ip::Address &addr, LogTags ltype, AnyP::ProtocolType p, size_t size) +clientdbUpdate(const Ip::Address &addr, const LogTags <ype, AnyP::ProtocolType p, size_t size) { char key[MAX_IPSTRLEN]; ClientInfo *c; @@ -157,17 +157,17 @@ clientdbUpdate(const Ip::Address &addr, LogTags ltype, AnyP::ProtocolType p, siz if (p == AnyP::PROTO_HTTP) { ++ c->Http.n_requests; - ++ c->Http.result_hist[ltype]; + ++ c->Http.result_hist[ltype.oldType]; kb_incr(&c->Http.kbytes_out, size); - if (logTypeIsATcpHit(ltype)) + if (ltype.isTcpHit()) kb_incr(&c->Http.hit_kbytes_out, size); } else if (p == AnyP::PROTO_ICP) { ++ c->Icp.n_requests; - ++ c->Icp.result_hist[ltype]; + ++ c->Icp.result_hist[ltype.oldType]; kb_incr(&c->Icp.kbytes_out, size); - if (LOG_UDP_HIT == ltype) + if (LOG_UDP_HIT == ltype.oldType) kb_incr(&c->Icp.hit_kbytes_out, size); } @@ -287,7 +287,7 @@ clientdbDump(StoreEntry * sentry) storeAppendPrintf(sentry, " ICP Requests %d\n", c->Icp.n_requests); - for (LogTags l = LOG_TAG_NONE; l < LOG_TYPE_MAX; ++l) { + for (LogTags_ot l = LOG_TAG_NONE; l < LOG_TYPE_MAX; ++l) { if (c->Icp.result_hist[l] == 0) continue; @@ -296,23 +296,23 @@ clientdbDump(StoreEntry * sentry) if (LOG_UDP_HIT == l) icp_hits += c->Icp.result_hist[l]; - storeAppendPrintf(sentry, " %-20.20s %7d %3d%%\n",LogTags_str[l], c->Icp.result_hist[l], Math::intPercent(c->Icp.result_hist[l], c->Icp.n_requests)); + storeAppendPrintf(sentry, " %-20.20s %7d %3d%%\n", LogTags(l).c_str(), c->Icp.result_hist[l], Math::intPercent(c->Icp.result_hist[l], c->Icp.n_requests)); } storeAppendPrintf(sentry, " HTTP Requests %d\n", c->Http.n_requests); - for (LogTags l = LOG_TAG_NONE; l < LOG_TYPE_MAX; ++l) { + for (LogTags_ot l = LOG_TAG_NONE; l < LOG_TYPE_MAX; ++l) { if (c->Http.result_hist[l] == 0) continue; http_total += c->Http.result_hist[l]; - if (logTypeIsATcpHit(l)) + if (LogTags(l).isTcpHit()) http_hits += c->Http.result_hist[l]; storeAppendPrintf(sentry, " %-20.20s %7d %3d%%\n", - LogTags_str[l], + LogTags(l).c_str(), c->Http.result_hist[l], Math::intPercent(c->Http.result_hist[l], c->Http.n_requests)); } @@ -521,8 +521,8 @@ snmp_meshCtblFn(variable_list * Var, snint * ErrP) case MESH_CTBL_HTHITS: aggr = 0; - for (LogTags l = LOG_TAG_NONE; l < LOG_TYPE_MAX; ++l) { - if (logTypeIsATcpHit(l)) + for (LogTags_ot l = LOG_TAG_NONE; l < LOG_TYPE_MAX; ++l) { + if (LogTags(l).isTcpHit()) aggr += c->Http.result_hist[l]; } diff --git a/src/client_db.h b/src/client_db.h index 2b603deb6f..454f90c88a 100644 --- a/src/client_db.h +++ b/src/client_db.h @@ -24,7 +24,7 @@ class Address; class StoreEntry; class ClientInfo; -void clientdbUpdate(const Ip::Address &, LogTags, AnyP::ProtocolType, size_t); +void clientdbUpdate(const Ip::Address &, const LogTags &, AnyP::ProtocolType, size_t); int clientdbCutoffDenied(const Ip::Address &); void clientdbDump(StoreEntry *); void clientdbFreeMemory(void); diff --git a/src/client_side.cc b/src/client_side.cc index c3477fb8df..9fe2f14ca3 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -189,13 +189,13 @@ static IDCB clientIdentDone; static int clientIsContentLengthValid(HttpRequest * r); static int clientIsRequestBodyTooLargeForPolicy(int64_t bodyLength); -static void clientUpdateStatHistCounters(LogTags logType, int svc_time); -static void clientUpdateStatCounters(LogTags logType); +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 &); static void ClientSocketContextPushDeferredIfNeeded(ClientSocketContext::Pointer deferredRequest, ConnStateData * conn); -static void clientUpdateSocketStats(LogTags logType, size_t size); +static void clientUpdateSocketStats(const LogTags &logType, size_t size); char *skipLeadingSpace(char *aString); @@ -387,21 +387,21 @@ clientIdentDone(const char *ident, void *data) #endif void -clientUpdateStatCounters(LogTags logType) +clientUpdateStatCounters(const LogTags &logType) { ++statCounter.client_http.requests; - if (logTypeIsATcpHit(logType)) + if (logType.isTcpHit()) ++statCounter.client_http.hits; - if (logType == LOG_TCP_HIT) + if (logType.oldType == LOG_TCP_HIT) ++statCounter.client_http.disk_hits; - else if (logType == LOG_TCP_MEM_HIT) + else if (logType.oldType == LOG_TCP_MEM_HIT) ++statCounter.client_http.mem_hits; } void -clientUpdateStatHistCounters(LogTags logType, int svc_time) +clientUpdateStatHistCounters(const LogTags &logType, int svc_time) { statCounter.client_http.allSvcTime.count(svc_time); /** @@ -411,7 +411,7 @@ clientUpdateStatHistCounters(LogTags logType, int svc_time) * (we *tried* to validate it, but failed). */ - switch (logType) { + switch (logType.oldType) { case LOG_TCP_REFRESH_UNMODIFIED: statCounter.client_http.nearHitSvcTime.count(svc_time); @@ -567,8 +567,8 @@ prepareLogWithRequestDetails(HttpRequest * request, AccessLogEntry::Pointer &aLo void ClientHttpRequest::logRequest() { - if (!out.size && !logType) - debugs(33, 5, HERE << "logging half-baked transaction: " << log_uri); + if (!out.size && logType.oldType == LOG_TAG_NONE) + debugs(33, 5, "logging half-baked transaction: " << log_uri); al->icp.opcode = ICP_INVALID; al->url = log_uri; @@ -1262,13 +1262,13 @@ ClientSocketContext::buildRangeHeader(HttpReply * rep) /* hits only - upstream CachePeer determines correct behaviour on misses, and client_side_reply determines * hits candidates */ - else if (logTypeIsATcpHit(http->logType) && http->request->header.has(HDR_IF_RANGE) && !clientIfRangeMatch(http, rep)) + else if (http->logType.isTcpHit() && http->request->header.has(HDR_IF_RANGE) && !clientIfRangeMatch(http, rep)) range_err = "If-Range match failed"; else if (!http->request->range->canonize(rep)) range_err = "canonization failed"; else if (http->request->range->isComplex()) range_err = "too complex range header"; - else if (!logTypeIsATcpHit(http->logType) && http->request->range->offsetLimitExceeded(roffLimit)) + else if (!http->logType.isTcpHit() && http->request->range->offsetLimitExceeded(roffLimit)) range_err = "range outside range_offset_limit"; /* get rid of our range specs on error */ @@ -1597,14 +1597,14 @@ ClientSocketContext::keepaliveNextRequest() } void -clientUpdateSocketStats(LogTags logType, size_t size) +clientUpdateSocketStats(const LogTags &logType, size_t size) { if (size == 0) return; kb_incr(&statCounter.client_http.kbytes_out, size); - if (logTypeIsATcpHit(logType)) + if (logType.isTcpHit()) kb_incr(&statCounter.client_http.hit_kbytes_out, size); } diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index b1b7eacd57..fcd73c85d9 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -510,7 +510,7 @@ clientReplyContext::cacheHit(StoreIOBuffer result) /* * Got the headers, now grok them */ - assert(http->logType == LOG_TCP_HIT); + assert(http->logType.oldType == LOG_TCP_HIT); if (strcmp(e->mem_obj->storeId(), http->request->storeId()) != 0) { debugs(33, DBG_IMPORTANT, "clientProcessHit: URL mismatch, '" << e->mem_obj->storeId() << "' != '" << http->request->storeId() << "'"); @@ -655,7 +655,7 @@ clientReplyContext::processMiss() if (http->storeEntry()) { if (EBIT_TEST(http->storeEntry()->flags, ENTRY_SPECIAL)) { debugs(88, DBG_CRITICAL, "clientProcessMiss: miss on a special object (" << url << ")."); - debugs(88, DBG_CRITICAL, "\tlog_type = " << LogTags_str[http->logType]); + debugs(88, DBG_CRITICAL, "\tlog_type = " << http->logType.c_str()); http->storeEntry()->dump(1); } @@ -1306,7 +1306,7 @@ void clientReplyContext::buildReplyHeader() { HttpHeader *hdr = &reply->header; - int is_hit = logTypeIsATcpHit(http->logType); + const bool is_hit = http->logType.isTcpHit(); HttpRequest *request = http->request; #if DONT_FILTER_THESE /* but you might want to if you run Squid as an HTTP accelerator */ @@ -1407,14 +1407,14 @@ clientReplyContext::buildReplyHeader() } // add Warnings required by RFC 2616 if serving a stale hit - if (http->request->flags.staleIfHit && logTypeIsATcpHit(http->logType)) { + if (http->request->flags.staleIfHit && http->logType.isTcpHit()) { hdr->putWarning(110, "Response is stale"); if (http->request->flags.needValidation) hdr->putWarning(111, "Revalidation failed"); } /* Filter unproxyable authentication types */ - if (http->logType != LOG_TCP_DENIED && + if (http->logType.oldType != LOG_TCP_DENIED && hdr->has(HDR_WWW_AUTHENTICATE)) { HttpHeaderPos pos = HttpHeaderInitPos; HttpHeaderEntry *e; @@ -1458,7 +1458,7 @@ clientReplyContext::buildReplyHeader() #if USE_AUTH /* Handle authentication headers */ - if (http->logType == LOG_TCP_DENIED && + if (http->logType.oldType == LOG_TCP_DENIED && ( reply->sline.status() == Http::scProxyAuthenticationRequired || reply->sline.status() == Http::scUnauthorized) ) { @@ -1795,7 +1795,7 @@ clientReplyContext::doGetMoreData() sc->setDelayId(DelayId::DelayClient(http)); #endif - assert(http->logType == LOG_TCP_HIT); + assert(http->logType.oldType == LOG_TCP_HIT); reqofs = 0; /* guarantee nothing has been sent yet! */ assert(http->out.size == 0); @@ -1972,8 +1972,8 @@ clientReplyContext::processReplyAccess () assert(reply); /** Don't block our own responses or HTTP status messages */ - if (http->logType == LOG_TCP_DENIED || - http->logType == LOG_TCP_DENIED_REPLY || + if (http->logType.oldType == LOG_TCP_DENIED || + http->logType.oldType == LOG_TCP_DENIED_REPLY || alwaysAllowResponse(reply->sline.status())) { headers_sz = reply->hdr_sz; processReplyAccessResult(ACCESS_ALLOWED); @@ -2141,7 +2141,7 @@ clientReplyContext::sendMoreData (StoreIOBuffer result) memcpy(buf, result.data, result.length); } - if (reqofs==0 && !logTypeIsATcpHit(http->logType) && Comm::IsConnOpen(conn->clientConnection)) { + if (reqofs==0 && !http->logType.isTcpHit() && Comm::IsConnOpen(conn->clientConnection)) { if (Ip::Qos::TheConfig.isHitTosActive()) { Ip::Qos::doTosLocalMiss(conn->clientConnection, http->request->hier.code); } diff --git a/src/client_side_request.cc b/src/client_side_request.cc index d156d30748..6b37b01fde 100644 --- a/src/client_side_request.cc +++ b/src/client_side_request.cc @@ -274,7 +274,6 @@ ClientHttpRequest::~ClientHttpRequest() /* the ICP check here was erroneous * - StoreEntry::releaseRequest was always called if entry was valid */ - assert(logType < LOG_TYPE_MAX); logRequest(); @@ -1529,7 +1528,7 @@ ClientHttpRequest::httpStart() { PROF_start(httpStart); logType = LOG_TAG_NONE; - debugs(85, 4, LogTags_str[logType] << " for '" << uri << "'"); + debugs(85, 4, logType.c_str() << " for '" << uri << "'"); /* no one should have touched this */ assert(out.offset == 0); diff --git a/src/format/Format.cc b/src/format/Format.cc index 2ef5ef7bf9..7273cb3e5c 100644 --- a/src/format/Format.cc +++ b/src/format/Format.cc @@ -878,11 +878,10 @@ Format::Format::assemble(MemBuf &mb, const AccessLogEntry::Pointer &al, int logS case LFT_SQUID_STATUS: if (al->http.timedout || al->http.aborted) { - snprintf(tmp, sizeof(tmp), "%s%s", LogTags_str[al->cache.code], - al->http.statusSfx()); + snprintf(tmp, sizeof(tmp), "%s%s", al->cache.code.c_str(), al->http.statusSfx()); out = tmp; } else { - out = LogTags_str[al->cache.code]; + out = al->cache.code.c_str(); } break; diff --git a/src/htcp.cc b/src/htcp.cc index 7a762f9745..aa7c96f71e 100644 --- a/src/htcp.cc +++ b/src/htcp.cc @@ -1663,7 +1663,7 @@ static void htcpLogHtcp(Ip::Address &caddr, int opcode, LogTags logcode, const char *url) { AccessLogEntry::Pointer al = new AccessLogEntry; - if (LOG_TAG_NONE == logcode) + if (LOG_TAG_NONE == logcode.oldType) return; if (!Config.onoff.log_udp) return; diff --git a/src/icp_v2.cc b/src/icp_v2.cc index 05273a4f85..603871928a 100644 --- a/src/icp_v2.cc +++ b/src/icp_v2.cc @@ -51,7 +51,7 @@ static void icpIncomingConnectionOpened(const Comm::ConnectionPointer &conn, int errNo); /// \ingroup ServerProtocolICPInternal2 -static void icpLogIcp(const Ip::Address &, LogTags, int, const char *, int); +static void icpLogIcp(const Ip::Address &, const LogTags &, int, const char *, int); /// \ingroup ServerProtocolICPInternal2 static void icpHandleIcpV2(int, Ip::Address &, char *, int); @@ -180,14 +180,14 @@ ICP2State::created(StoreEntry *newEntry) /// \ingroup ServerProtocolICPInternal2 static void -icpLogIcp(const Ip::Address &caddr, LogTags logcode, int len, const char *url, int delay) +icpLogIcp(const Ip::Address &caddr, const LogTags &logcode, int len, const char *url, int delay) { AccessLogEntry::Pointer al = new AccessLogEntry(); - if (LOG_TAG_NONE == logcode) + if (LOG_TAG_NONE == logcode.oldType) return; - if (LOG_ICP_QUERY == logcode) + if (LOG_ICP_QUERY == logcode.oldType) return; clientdbUpdate(caddr, logcode, AnyP::PROTO_ICP, len); diff --git a/src/log/FormatHttpdCombined.cc b/src/log/FormatHttpdCombined.cc index bc5515d938..d57382b2e5 100644 --- a/src/log/FormatHttpdCombined.cc +++ b/src/log/FormatHttpdCombined.cc @@ -64,7 +64,7 @@ Log::Format::HttpdCombined(const AccessLogEntry::Pointer &al, Logfile * logfile) al->http.clientReplySz.messageTotal(), referer, agent, - LogTags_str[al->cache.code], + al->cache.code.c_str(), al->http.statusSfx(), hier_code_str[al->hier.code], (Config.onoff.log_mime_hdrs?"":"\n")); diff --git a/src/log/FormatHttpdCommon.cc b/src/log/FormatHttpdCommon.cc index 865b0b432c..bddb71fc6a 100644 --- a/src/log/FormatHttpdCommon.cc +++ b/src/log/FormatHttpdCommon.cc @@ -49,7 +49,7 @@ Log::Format::HttpdCommon(const AccessLogEntry::Pointer &al, Logfile * logfile) al->http.version.major, al->http.version.minor, al->http.code, al->http.clientReplySz.messageTotal(), - LogTags_str[al->cache.code], + al->cache.code.c_str(), al->http.statusSfx(), hier_code_str[al->hier.code], (Config.onoff.log_mime_hdrs?"":"\n")); diff --git a/src/log/FormatSquidNative.cc b/src/log/FormatSquidNative.cc index 829ee71965..e221643120 100644 --- a/src/log/FormatSquidNative.cc +++ b/src/log/FormatSquidNative.cc @@ -59,7 +59,7 @@ Log::Format::SquidNative(const AccessLogEntry::Pointer &al, Logfile * logfile) (int) current_time.tv_usec / 1000, tvToMsec(al->cache.trTime), clientip, - LogTags_str[al->cache.code], + al->cache.code.c_str(), al->http.statusSfx(), al->http.code, al->http.clientReplySz.messageTotal(), diff --git a/src/stat.cc b/src/stat.cc index e52b9cf06d..cee9b4c700 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -1867,7 +1867,7 @@ statClientRequests(StoreEntry * s) } storeAppendPrintf(s, "uri %s\n", http->uri); - storeAppendPrintf(s, "logType %s\n", LogTags_str[http->logType]); + storeAppendPrintf(s, "logType %s\n", http->logType.c_str()); storeAppendPrintf(s, "out.offset %ld, out.size %lu\n", (long int) http->out.offset, (unsigned long int) http->out.size); storeAppendPrintf(s, "req_sz %ld\n", (long int) http->req_sz); diff --git a/src/tests/stub_client_db.cc b/src/tests/stub_client_db.cc index 1e5142b086..6695b3e324 100644 --- a/src/tests/stub_client_db.cc +++ b/src/tests/stub_client_db.cc @@ -15,7 +15,7 @@ class ClientInfo; void clientdbInit(void) STUB -void clientdbUpdate(const Ip::Address &, LogTags, AnyP::ProtocolType, size_t) STUB +void clientdbUpdate(const Ip::Address &, const LogTags &, AnyP::ProtocolType, size_t) STUB int clientdbCutoffDenied(const Ip::Address &) STUB_RETVAL(-1) void clientdbDump(StoreEntry *) STUB void clientdbFreeMemory(void) STUB