]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
added x-forwarded-for and via header database
authorwessels <>
Tue, 31 Mar 1998 10:57:14 +0000 (10:57 +0000)
committerwessels <>
Tue, 31 Mar 1998 10:57:14 +0000 (10:57 +0000)
src/access_log.cc
src/client_side.cc
src/protos.h

index 1379ee536868f9e74d1c19636b05c2dc9515fe20..9940a8af1dd40f7d6c3b2fd6ecc9e2c83c8e7ba8 100644 (file)
@@ -1,7 +1,7 @@
 
 
 /*
- * $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
@@ -61,7 +61,22 @@ const char *log_tags[] =
     "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;
@@ -260,6 +275,9 @@ accessLogRotate(void)
     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
@@ -316,6 +334,9 @@ accessLogInit(void)
 {
     assert(sizeof(log_tags) == (LOG_TYPE_MAX + 1) * sizeof(char *));
     accessLogOpen(Config.Log.access);
+#if FORW_VIA_DB
+    fvdbInit();
+#endif
 }
 
 const char *
@@ -331,3 +352,85 @@ accessLogTime(time_t t)
     }
     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  
index 27818278af39f45763fd685923843154f72a4ec0..4f329f4cb46c7161cc9b2dcb7d3b1f8c3f8425d2 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $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
@@ -653,7 +653,7 @@ clientParseRequestHeaders(clientHttpRequest * http)
        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",
@@ -662,9 +662,17 @@ clientParseRequestHeaders(clientHttpRequest * http)
            }
            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"))) {
@@ -2195,3 +2203,4 @@ clientHttpConnectionsClose(void)
     }
     NHttpSockets = 0;
 }
+
index 02a6fdc01d9dbba99ebe5516fe93a1eeb86c0dcc..7a1ba448eb2587e31f58633490a24d52c2483200 100644 (file)
@@ -6,6 +6,10 @@ extern void accessLogClose(void);
 extern void accessLogInit(void);
 extern const char *accessLogTime(time_t);
 extern void hierarchyNote(HierarchyLogEntry *, hier_code, icp_ping_data *, const char *);
+#if FORW_VIA_DB
+extern void fvdbCountVia(const char *key);
+extern void fvdbCountForw(const char *key);
+#endif
 
 extern aclCheck_t *aclChecklistCreate(const struct _acl_access *,
     request_t *,