]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
From: Ron Gomes <rrg@ny.ubs.com>
authorwessels <>
Sat, 14 Sep 1996 02:22:58 +0000 (02:22 +0000)
committerwessels <>
Sat, 14 Sep 1996 02:22:58 +0000 (02:22 +0000)
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.

src/Makefile.in
src/cache_cf.cc
src/stat.cc

index 07dc8452e4a90438e3cc543ae81989d81af72e3b..c492173f2f8fc25eb8bd70e644ce5dfc2dc5fbef 100644 (file)
@@ -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@
index 71cb5066e72b0c7b7a7ca41b379dd0025159f4c6..7a072ec9db313d61923ad9d2dd57e5ab447c116e 100644 (file)
@@ -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;
index 27924e5ec2ee008e0558db8acd29d4db01308f7a..0fdf11f42b4a8e98031f9cdd9ed00f3aa48284fe 100644 (file)
@@ -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),