From c3609322cd4b14f77726de33e7b815c40f904bcf Mon Sep 17 00:00:00 2001 From: wessels <> Date: Sat, 25 Mar 2000 11:58:39 +0000 Subject: [PATCH] DW: - binary HTTP header logging. Gives better stats than 'headers' from cachemgr. --- src/access_log.cc | 67 +++++++++++++++++++++++++++++++++++++++++++++- src/client_side.cc | 8 +++++- src/http.cc | 5 +++- src/protos.h | 5 +++- 4 files changed, 81 insertions(+), 4 deletions(-) diff --git a/src/access_log.cc b/src/access_log.cc index c187a347a9..fc2255d9f4 100644 --- a/src/access_log.cc +++ b/src/access_log.cc @@ -1,7 +1,7 @@ /* - * $Id: access_log.cc,v 1.55 2000/03/14 23:07:51 wessels Exp $ + * $Id: access_log.cc,v 1.56 2000/03/25 04:58:39 wessels Exp $ * * DEBUG: section 46 Access Log * AUTHOR: Duane Wessels @@ -41,6 +41,9 @@ static char *log_quote(const char *header); static void accessLogSquid(AccessLogEntry * al); static void accessLogCommon(AccessLogEntry * al); static Logfile *logfile = NULL; +#if HEADERS_LOG +static Logfile *headerslog = NULL; +#endif #if MULTICAST_MISS_STREAM static int mcast_miss_fd = -1; @@ -298,6 +301,9 @@ accessLogRotate(void) if (NULL == logfile) return; logfileRotate(logfile); +#if HEADERS_LOG + logfileRotate(headerslog); +#endif } void @@ -305,6 +311,10 @@ accessLogClose(void) { logfileClose(logfile); logfile = NULL; +#if HEADERS_LOG + logfileClose(headerslog); + headerslog = NULL; +#endif } void @@ -323,6 +333,10 @@ accessLogInit(void) assert(sizeof(log_tags) == (LOG_TYPE_MAX + 1) * sizeof(char *)); logfile = logfileOpen(Config.Log.access, MAX_URL << 1); LogfileStatus = LOG_ENABLE; +#if HEADERS_LOG + headerslog = logfileOpen("/usr/local/squid/logs/headers.log", 512); + assert(NULL != headerslog); +#endif #if FORW_VIA_DB fvdbInit(); #endif @@ -488,3 +502,54 @@ mcast_encode(unsigned int *ibuf, size_t isize, const unsigned int *key) } #endif + +#if HEADERS_LOG +void +headersLog(int cs, int pq, method_t m, void *data) +{ + HttpReply *rep; + request_t *req; + unsigned short magic = 0; + unsigned char M = (unsigned char) m; + unsigned short S; + char *hmask; + int ccmask = 0; + if (0 == pq) { + /* reply */ + rep = data; + req = NULL; + magic = 0x0050; + hmask = rep->header.mask; + if (rep->cache_control) + ccmask = rep->cache_control->mask; + } else { + /* request */ + req = data; + rep = NULL; + magic = 0x0051; + hmask = req->header.mask; + if (req->cache_control) + ccmask = req->cache_control->mask; + } + if (0 == cs) { + /* client */ + magic |= 0x4300; + } else { + /* server */ + magic |= 0x5300; + } + magic = htons(magic); + ccmask = htonl(ccmask); + if (0 == pq) + S = (unsigned short) rep->sline.status; + else + S = (unsigned short) HTTP_STATUS_NONE; + logfileWrite(headerslog, &magic, sizeof(magic)); + logfileWrite(headerslog, &M, sizeof(M)); + logfileWrite(headerslog, &S, sizeof(S)); + logfileWrite(headerslog, hmask, sizeof(HttpHeaderMask)); + logfileWrite(headerslog, &ccmask, sizeof(int)); + logfileFlush(headerslog); +} + +#endif diff --git a/src/client_side.cc b/src/client_side.cc index 3dd0d73ea5..effce9f334 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -1,6 +1,6 @@ /* - * $Id: client_side.cc,v 1.471 2000/03/06 16:23:29 wessels Exp $ + * $Id: client_side.cc,v 1.472 2000/03/25 04:58:39 wessels Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -1699,6 +1699,9 @@ clientSendMoreData(void *data, char *buf, ssize_t size) http->out.offset += rep->hdr_sz; check_size += rep->hdr_sz; httpReplyDestroy(rep); +#if HEADERS_LOG + headersLog(0, 0, http->request->method, rep); +#endif rep = NULL; } else { memBufDefInit(&mb); @@ -2511,6 +2514,9 @@ clientReadRequest(int fd, void *data) break; } } +#if HEADERS_LOG + headersLog(0, 1, request->method, request); +#endif clientAccessCheck(http); continue; /* while offset > 0 */ } else if (parser_return_code == 0) { diff --git a/src/http.cc b/src/http.cc index 571ac13dc8..2272a0db7d 100644 --- a/src/http.cc +++ b/src/http.cc @@ -1,6 +1,6 @@ /* - * $Id: http.cc,v 1.356 2000/03/06 16:23:32 wessels Exp $ + * $Id: http.cc,v 1.357 2000/03/25 04:58:39 wessels Exp $ * * DEBUG: section 11 Hypertext Transfer Protocol (HTTP) * AUTHOR: Harvest Derived @@ -393,6 +393,9 @@ httpProcessReplyHeader(HttpStateData * httpState, const char *buf, int size) httpState->request->host, skew); } ctx_exit(ctx); +#if HEADERS_LOG + headersLog(1, 0, httpState->request->method, reply); +#endif } static int diff --git a/src/protos.h b/src/protos.h index 121c2beb9b..8d5f28053d 100644 --- a/src/protos.h +++ b/src/protos.h @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.357 2000/03/14 23:11:05 wessels Exp $ + * $Id: protos.h,v 1.358 2000/03/25 04:58:40 wessels Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -41,6 +41,9 @@ extern void hierarchyNote(HierarchyLogEntry *, hier_code, const char *); extern void fvdbCountVia(const char *key); extern void fvdbCountForw(const char *key); #endif +#if HEADERS_LOG +extern void headersLog(int cs, int pq, method_t m, void *data); +#endif extern aclCheck_t *aclChecklistCreate(const struct _acl_access *, request_t *, -- 2.39.5