From fd2c5549483bfdf2dedca8200fb2aaa5dae473be Mon Sep 17 00:00:00 2001 From: wessels <> Date: Thu, 13 Jul 2000 12:13:42 +0000 Subject: [PATCH] DW: - Jens-S. Voeckler submitted this patch for referer header logging. --- src/Makefile.in | 3 +- src/cf.data.pre | 16 +++++++++- src/client_side.cc | 9 ++++-- src/main.cc | 4 ++- src/protos.h | 5 ++- src/referer.cc | 79 ++++++++++++++++++++++++++++++++++++++++++++++ src/structs.h | 5 ++- 7 files changed, 114 insertions(+), 7 deletions(-) create mode 100644 src/referer.cc diff --git a/src/Makefile.in b/src/Makefile.in index 5c890af3ea..41403273a5 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -1,7 +1,7 @@ # # Makefile for the Squid Object Cache server # -# $Id: Makefile.in,v 1.190 2000/06/27 08:35:09 hno Exp $ +# $Id: Makefile.in,v 1.191 2000/07/13 06:13:42 wessels Exp $ # # Uncomment and customize the following to suit your needs: # @@ -150,6 +150,7 @@ OBJS = \ peer_select.o \ pump.o \ redirect.o \ + referer.o \ refresh.o \ repl_modules.o \ send-announce.o \ diff --git a/src/cf.data.pre b/src/cf.data.pre index 1f18fc739e..8064f7719f 100644 --- a/src/cf.data.pre +++ b/src/cf.data.pre @@ -1,6 +1,6 @@ # -# $Id: cf.data.pre,v 1.191 2000/06/26 04:57:16 wessels Exp $ +# $Id: cf.data.pre,v 1.192 2000/07/13 06:13:42 wessels Exp $ # # # SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -833,6 +833,20 @@ DOC_START DOC_END +NAME: referer_log +TYPE: string +LOC: Config.Log.referer +DEFAULT: none +DOC_START + If configured with the "--enable-referer_log" configure + option, Squid will write the Referer field from HTTP + requests to the filename specified here. By default + referer_log is disabled. + +referer_log none +DOC_END + + NAME: pid_filename TYPE: string DEFAULT: @DEFAULT_PID_FILE@ diff --git a/src/client_side.cc b/src/client_side.cc index 2eddd3ae1a..67ffaa2d93 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -1,6 +1,6 @@ /* - * $Id: client_side.cc,v 1.491 2000/07/12 16:20:02 wessels Exp $ + * $Id: client_side.cc,v 1.492 2000/07/13 06:13:42 wessels Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -810,7 +810,7 @@ clientInterpretRequestHeaders(clientHttpRequest * http) request_t *request = http->request; const HttpHeader *req_hdr = &request->header; int no_cache = 0; -#if USE_USERAGENT_LOG +#if defined(USE_USERAGENT_LOG) || defined(USE_REFERER_LOG) const char *str; #endif request->imslen = -1; @@ -868,6 +868,11 @@ clientInterpretRequestHeaders(clientHttpRequest * http) if ((str = httpHeaderGetStr(req_hdr, HDR_USER_AGENT))) logUserAgent(fqdnFromAddr(http->conn->peer.sin_addr), str); #endif +#if USE_REFERER_LOG + if ((str = httpHeaderGetStr(req_hdr, HDR_REFERER))) + logReferer(fqdnFromAddr(http->conn->peer.sin_addr), str, + http->log_uri); +#endif #if FORW_VIA_DB if (httpHeaderHas(req_hdr, HDR_X_FORWARDED_FOR)) { String s = httpHeaderGetList(req_hdr, HDR_X_FORWARDED_FOR); diff --git a/src/main.cc b/src/main.cc index e573f9a6d3..bb31811ac8 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,6 +1,6 @@ /* - * $Id: main.cc,v 1.315 2000/06/27 22:06:03 hno Exp $ + * $Id: main.cc,v 1.316 2000/07/13 06:13:42 wessels Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -390,6 +390,7 @@ mainRotate(void) storeLogRotate(); /* store.log */ accessLogRotate(); /* access.log */ useragentRotateLog(); /* useragent.log */ + refererRotateLog(); /* referer.log */ icmpOpen(); #if USE_DNSSERVERS dnsInit(); @@ -486,6 +487,7 @@ mainInitialize(void) redirectInit(); authenticateInit(); useragentOpenLog(); + refererOpenLog(); httpHeaderInitModule(); /* must go before any header processing (e.g. the one in errorInitialize) */ httpReplyInitModule(); /* must go before accepting replies */ errorInitialize(); diff --git a/src/protos.h b/src/protos.h index 44d712ee04..36915ea711 100644 --- a/src/protos.h +++ b/src/protos.h @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.375 2000/06/27 08:41:30 hno Exp $ + * $Id: protos.h,v 1.376 2000/07/13 06:13:42 wessels Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -1038,6 +1038,9 @@ extern void urlExtMethodConfigure(); extern void useragentOpenLog(void); extern void useragentRotateLog(void); extern void logUserAgent(const char *, const char *); +extern void refererOpenLog(void); +extern void refererRotateLog(void); +extern void logReferer(const char *, const char *, const char *); extern peer_t parseNeighborType(const char *s); extern void errorInitialize(void); diff --git a/src/referer.cc b/src/referer.cc new file mode 100644 index 0000000000..d401b61e8a --- /dev/null +++ b/src/referer.cc @@ -0,0 +1,79 @@ + +/* + * $Id: referer.cc,v 1.1 2000/07/13 06:13:43 wessels Exp $ + * + * DEBUG: section 40 User-Agent and Referer logging + * AUTHOR: Joe Ramey (useragent) + * Jens-S. Vöckler (mod 4 referer) + * + * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from the + * Internet community. Development is led by Duane Wessels of the + * National Laboratory for Applied Network Research and funded by the + * National Science Foundation. Squid is Copyrighted (C) 1998 by + * the Regents of the University of California. Please see the + * COPYRIGHT file for full details. Squid incorporates software + * developed and/or copyrighted by other sources. Please see the + * CREDITS file for full details. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + * + */ + +#include "squid.h" + +#if USE_REFERER_LOG +static Logfile *refererlog = NULL; +#endif + +void +refererOpenLog(void) +{ +#if USE_REFERER_LOG + assert(NULL == refererlog); + if (!Config.Log.referer || (0 == strcmp(Config.Log.referer, "none"))) { + debug(40, 1) ("Referer logging is disabled.\n"); + return; + } + logfileOpen(Config.Log.referer, 0); +#endif +} + +void +refererRotateLog(void) +{ +#if USE_REFERER_LOG + if (NULL == refererlog) + return; + logfileRotate(refererlog); +#endif +} + +void +logReferer(const char *client, const char *referer, const char *uri) +{ +#if USE_REFERER_LOG + if (NULL == refererlog) + return; + logfilePrintf(refererlog, "%9d.%03d %s %s %s\n", + (int) current_time.tv_sec, + (int) current_time.tv_usec / 1000, + client, + referer, + uri ? uri : "-"); +#endif +} diff --git a/src/structs.h b/src/structs.h index 516a5bad93..cccc644c8d 100644 --- a/src/structs.h +++ b/src/structs.h @@ -1,6 +1,6 @@ /* - * $Id: structs.h,v 1.346 2000/06/27 08:41:31 hno Exp $ + * $Id: structs.h,v 1.347 2000/07/13 06:13:43 wessels Exp $ * * * SQUID Internet Object Cache http://squid.nlanr.net/Squid/ @@ -296,6 +296,9 @@ struct _SquidConfig { char *swap; #if USE_USERAGENT_LOG char *useragent; +#endif +#if USE_REFERER_LOG + char *referer; #endif int rotateNumber; } Log; -- 2.47.2