/*
- * $Id: access_log.cc,v 1.23 1998/02/24 21:17:01 wessels Exp $
+ * $Id: access_log.cc,v 1.24 1998/03/31 03:57:14 wessels Exp $
*
* DEBUG: section 46 Access Log
* AUTHOR: Duane Wessels
"LOG_TYPE_MAX"
};
-#define MAX_LINELEN (4096)
+#if FORW_VIA_DB
+typedef struct {
+ char *key;
+ void *next;
+ int n;
+} fvdb_entry;
+static hash_table *via_table = NULL;
+static hash_table *forw_table = NULL;
+static void fvdbInit(void);
+static void fvdbDumpTable(StoreEntry *e, hash_table *hash);
+static void fvdbCount(hash_table *hash, const char *key);
+static OBJH fvdbDumpVia;
+static OBJH fvdbDumpForw;
+static FREE fvdbFreeEntry;
+static void fvdbClear(void);
+#endif
static int LogfileStatus = LOG_DISABLE;
static int LogfileFD = -1;
LOCAL_ARRAY(char, to, MAXPATHLEN);
char *fname = NULL;
struct stat sb;
+#if FORW_VIA_DB
+ fvdbClear();
+#endif
if ((fname = LogfileName) == NULL)
return;
#ifdef S_ISREG
{
assert(sizeof(log_tags) == (LOG_TYPE_MAX + 1) * sizeof(char *));
accessLogOpen(Config.Log.access);
+#if FORW_VIA_DB
+ fvdbInit();
+#endif
}
const char *
}
return buf;
}
+
+
+#if FORW_VIA_DB
+
+static void
+fvdbInit(void)
+{
+ via_table = hash_create((HASHCMP *) strcmp, 977, hash4);
+ forw_table = hash_create((HASHCMP *) strcmp, 977, hash4);
+ cachemgrRegister("via_headers", "Via Request Headers", fvdbDumpVia, 0);
+ cachemgrRegister("forw_headers", "X-Forwarded-For Request Headers",
+ fvdbDumpForw, 0);
+}
+
+static void
+fvdbCount(hash_table *hash, const char *key)
+{
+ fvdb_entry *fv;
+ if (NULL == hash)
+ return;
+ fv = hash_lookup(hash, key);
+ if (NULL == fv) {
+ fv = xcalloc(1, sizeof(fvdb_entry));
+ fv->key = xstrdup(key);
+ hash_join(hash, (hash_link *) fv);
+ }
+ fv->n++;
+}
+
+void
+fvdbCountVia(const char *key)
+{
+ fvdbCount(via_table, key);
+}
+
+void
+fvdbCountForw(const char *key)
+{
+ fvdbCount(forw_table, key);
+}
+
+static void
+fvdbDumpTable(StoreEntry *e, hash_table *hash)
+{
+ hash_link *h;
+ fvdb_entry *fv;
+ if (hash == NULL)
+ return;
+ for (h = hash_first(hash); h != NULL; h = hash_next(hash)) {
+ fv = (fvdb_entry *) h;
+ storeAppendPrintf(e, "%9d %s\n", fv->n, fv->key);
+ }
+}
+
+static void
+fvdbDumpVia(StoreEntry *e)
+{
+ fvdbDumpTable(e, via_table);
+}
+
+static void
+fvdbDumpForw(StoreEntry *e)
+{
+ fvdbDumpTable(e, forw_table);
+}
+
+static
+void fvdbFreeEntry(void *data)
+{
+ fvdb_entry *fv = data;
+ xfree(fv->key);
+ xfree(fv);
+}
+
+static void
+fvdbClear(void)
+{
+ hashFreeItems(via_table, fvdbFreeEntry);
+ hashFreeItems(forw_table, fvdbFreeEntry);
+}
+
+#endif
/*
- * $Id: client_side.cc,v 1.239 1998/03/30 06:56:24 rousskov Exp $
+ * $Id: client_side.cc,v 1.240 1998/03/31 03:57:15 wessels Exp $
*
* DEBUG: section 33 Client-side Routines
* AUTHOR: Duane Wessels
if (!strcasecmp(t, "Keep-Alive"))
EBIT_SET(request->flags, REQ_PROXY_KEEPALIVE);
}
- if ((t = mime_get_header(request_hdr, "Via")))
+ if ((t = mime_get_header(request_hdr, "Via"))) {
if (strstr(t, ThisCache)) {
if (!http->accel) {
debug(33, 1) ("WARNING: Forwarding loop detected for '%s'\n",
}
EBIT_SET(request->flags, REQ_LOOPDETECT);
}
+#if FORW_VIA_DB
+ fvdbCountVia(t);
+#endif
+ }
#if USE_USERAGENT_LOG
if ((t = mime_get_header(request_hdr, "User-Agent")))
logUserAgent(fqdnFromAddr(http->conn->peer.sin_addr), t);
+#endif
+#if FORW_VIA_DB
+ if ((t = mime_get_header(request_hdr, "X-Forwarded-For")))
+ fvdbCountForw(t);
#endif
request->max_age = -1;
if ((t = mime_get_header(request_hdr, "Cache-control"))) {
}
NHttpSockets = 0;
}
+