From: wessels <> Date: Sat, 14 Sep 1996 02:22:58 +0000 (+0000) Subject: From: Ron Gomes X-Git-Tag: SQUID_3_0_PRE1~5810 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e43efe5014b6ddaa9152b50bd6b6fa517d6624ce;p=thirdparty%2Fsquid.git From: Ron Gomes I'm sending you our Squid changes that Mark Kennedy discussed with you, for optionally logging the full set of MIME request and reply headers on every transaction. There are two sets of context diffs, one set for 1.1.10 and the other for 1.1.alpha12. We'd love it if you bought these changes back; we think the log information can be of great value and we'd love not to have to keep retrofitting these changes into every release. We've been running with this code essentially unchanged for several weeks and it seems to be pretty stable. Code follows in two separate mail messages. --- diff --git a/src/Makefile.in b/src/Makefile.in index 07dc8452e4..c492173f2f 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.37 1996/09/12 04:49:43 wessels Exp $ +# $Id: Makefile.in,v 1.38 1996/09/13 20:22:58 wessels Exp $ # # Uncomment and customize the following to suit your needs: # @@ -9,7 +9,8 @@ HOST_OPT = # -DCACHEMGR_HOSTNAME="getfullhostname()" AIO_OPT = # -DUSE_ASYNC_IO=1 AIO_LIBS = # @AIO_LIBS@ AUTH_OPT = # -DUSE_PROXY_AUTH=1 -DEFINES = $(HOST_OPT) $(AIO_OPT) $(AUTH_OPT) +LOG_HDRS_OPT = # -DLOG_FULL_HEADERS=1 +DEFINES = $(HOST_OPT) $(AIO_OPT) $(AUTH_OPT) $(LOG_HDRS_OPT) prefix = @prefix@ exec_prefix = @exec_prefix@ diff --git a/src/cache_cf.cc b/src/cache_cf.cc index 71cb5066e7..7a072ec9db 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -1,5 +1,5 @@ /* - * $Id: cache_cf.cc,v 1.84 1996/09/11 22:39:01 wessels Exp $ + * $Id: cache_cf.cc,v 1.85 1996/09/13 20:22:59 wessels Exp $ * * DEBUG: section 3 Configuration File Parsing * AUTHOR: Harvest Derived @@ -168,6 +168,9 @@ struct SquidConfig Config; #define DefaultAccelWithProxy 0 /* default off */ #define DefaultSourcePing 0 /* default off */ #define DefaultCommonLogFormat 0 /* default off */ +#ifdef LOG_FULL_HEADERS +#define DefaultLogMimeHdrs 0 /* default off */ +#endif /* LOG_FULL_HEADERS */ #define DefaultIdentLookup 0 /* default off */ #define DefaultQuickAbortMin -1 /* default off */ #define DefaultQuickAbortPct 0 /* default off */ @@ -1225,6 +1228,11 @@ int parseConfigFile(file_name) else if (!strcmp(token, "emulate_httpd_log")) parseOnOff(&Config.commonLogFormat); +#ifdef LOG_FULL_HEADERS + else if (!strcmp(token, "log_mime_hdrs")) + parseOnOff(&Config.logMimeHdrs); + +#endif /* LOG_FULL_HEADERS */ else if (!strcmp(token, "ident_lookup")) parseOnOff(&Config.identLookup); @@ -1462,6 +1470,9 @@ static void configSetFactoryDefaults() Config.quickAbort.pct = DefaultQuickAbortPct; Config.quickAbort.max = DefaultQuickAbortMax; Config.commonLogFormat = DefaultCommonLogFormat; +#ifdef LOG_FULL_HEADERS + Config.logMimeHdrs = DefaultLogMimeHdrs; +#endif /* LOG_FULL_HEADERS */ Config.debugOptions = safe_xstrdup(DefaultDebugOptions); Config.neighborTimeout = DefaultNeighborTimeout; Config.stallDelay = DefaultStallDelay; diff --git a/src/stat.cc b/src/stat.cc index 27924e5ec2..0fdf11f42b 100644 --- a/src/stat.cc +++ b/src/stat.cc @@ -1,5 +1,5 @@ /* - * $Id: stat.cc,v 1.62 1996/09/12 16:59:57 wessels Exp $ + * $Id: stat.cc,v 1.63 1996/09/13 20:23:03 wessels Exp $ * * DEBUG: section 18 Cache Manager Statistics * AUTHOR: Harvest Derived @@ -900,8 +900,91 @@ void parameter_get(obj, sentry) storeAppendPrintf(sentry, close_bracket); } +#ifdef LOG_FULL_HEADERS +/* Table of char to hex string conversions */ +#endif /* LOG_FULL_HEADERS */ +#ifndef LOG_FULL_HEADERS void log_append(obj, url, caddr, size, action, method, http_code, msec, ident, hierData) +#else +static char c2x[] = +{ + "000102030405060708090a0b0c0d0e0f" + "101112131415161718191a1b1c1d1e1f" + "202122232425262728292a2b2c2d2e2f" + "303132333435363738393a3b3c3d3e3f" + "404142434445464748494a4b4c4d4e4f" + "505152535455565758595a5b5c5d5e5f" + "606162636465666768696a6b6c6d6e6f" + "707172737475767778797a7b7c7d7e7f" + "808182838485868788898a8b8c8d8e8f" + "909192939495969798999a9b9c9d9e9f" + "a0a1a2a3a4a5a6a7a8a9aaabacadaeaf" + "b0b1b2b3b4b5b6b7b8b9babbbcbdbebf" + "c0c1c2c3c4c5c6c7c8c9cacbcccdcecf" + "d0d1d2d3d4d5d6d7d8d9dadbdcdddedf" + "e0e1e2e3e4e5e6e7e8e9eaebecedeeef" + "f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff" +}; + +/* log_quote -- URL-style encoding on MIME headers. */ + +char *log_quote(header) + char *header; +{ + int c, i; + char *buf, *buf_cursor; + + if (header == NULL) { + buf = xcalloc(1, 1); + *buf = '\0'; + return buf; + } + + buf = xcalloc((strlen(header) * 3) + 1, 1); + buf_cursor = buf; + + /* + * We escape: \x00-\x1F"#%;<>?{}|\\\\^~`\[\]\x7F-\xFF + * which is the default escape list for the CPAN Perl5 URI module + * modulo the inclusion of space (x40) to make the raw logs a bit + * more readable. + */ + while ((c = *header++)) { + if (c <= 0x1F + || c >= 0x7F + || c == '"' + || c == '#' + || c == '%' + || c == ';' + || c == '<' + || c == '>' + || c == '?' + || c == '{' + || c == '}' + || c == '|' + || c == '\\' + || c == '^' + || c == '~' + || c == '`' + || c == '[' + || c == ']') { + *buf_cursor++ = '%'; + i = c*2; + *buf_cursor++ = c2x[i]; + *buf_cursor++ = c2x[i+1]; + } else { + *buf_cursor++ = c; + } + } + + *buf_cursor = '\0'; + return buf; +} + + +void log_append(obj, url, caddr, size, action, method, http_code, msec, ident, hierData, request_hdr, reply_hdr) +#endif /* LOG_FULL_HEADERS */ cacheinfo *obj; char *url; struct in_addr caddr; @@ -912,8 +995,16 @@ void log_append(obj, url, caddr, size, action, method, http_code, msec, ident, h int msec; char *ident; struct _hierarchyLogData *hierData; +#ifdef LOG_FULL_HEADERS + char *request_hdr; + char *reply_hdr; +#endif /* LOG_FULL_HEADERS */ { +#ifndef LOG_FULL_HEADERS LOCAL_ARRAY(char, tmp, 6000); /* MAX_URL is 4096 */ +#else + LOCAL_ARRAY(char, tmp, 10000); /* MAX_URL is 4096 */ +#endif /* LOG_FULL_HEADERS */ int x; char *client = NULL; hier_code hier_code = HIER_NONE; @@ -963,6 +1054,22 @@ void log_append(obj, url, caddr, size, action, method, http_code, msec, ident, h hier_timeout ? "TIMEOUT_" : "", hier_strings[hier_code], hier_host); +#ifdef LOG_FULL_HEADERS + + if (Config.logMimeHdrs) { + int msize = strlen(tmp); + char *ereq = log_quote(request_hdr); + char *erep = log_quote(reply_hdr); + + if (msize + strlen(ereq) + strlen(erep) + 7 <= sizeof(tmp)) + sprintf(tmp+msize-1, " [%s] [%s]\n", ereq, erep); + else + debug(18, 1, "log_append: Long headers not logged.\n"); + safe_free(ereq); + safe_free(erep); + } + +#endif /* LOG_FULL_HEADERS */ x = file_write(obj->logfile_fd, xstrdup(tmp), strlen(tmp),