]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Author: Mark Nottingham <mnot@pobox.com>
authorAmos Jeffries <squid3@treenet.co.nz>
Sat, 9 May 2009 14:06:48 +0000 (02:06 +1200)
committerAmos Jeffries <squid3@treenet.co.nz>
Sat, 9 May 2009 14:06:48 +0000 (02:06 +1200)
Bug 2627: HTCP Logging

src/AccessLogEntry.h
src/access_log.cc
src/htcp.cc
src/structs.h

index 3719223fe0954547d5adaad884307681044c469b..ef571b758c7552997224f5f3f242728913701d54 100644 (file)
@@ -69,6 +69,13 @@ public:
         icp_opcode opcode;
     } icp;
 
+    class HtcpDetails {
+    public:
+        HtcpDetails() : opcode(NULL) {};
+
+        const char *opcode;
+    } htcp;
+
     class CacheDetails
     {
 
index 7ff76f26af93e3cf37566b52b68b502f5e6e3511..9b7525e2cf9e0edd37f445a23e3534d3944fdf31 100644 (file)
@@ -1403,6 +1403,8 @@ accessLogLog(AccessLogEntry * al, ACLChecklist * checklist)
 
     if (al->icp.opcode)
         al->_private.method_str = icp_opcode_str[al->icp.opcode];
+    else if (al->htcp.opcode)
+        al->_private.method_str = al->htcp.opcode;
     else
         al->_private.method_str = RequestMethodStr(al->http.method);
 
index 8e16c6716fd1e50f2add2c0c566b17d1ec0557ab..c28412bd5d9410352ed38b999ad20948970e1875 100644 (file)
@@ -45,6 +45,7 @@
 #include "MemBuf.h"
 #include "http.h"
 #include "icmp/net_db.h"
+#include "AccessLogEntry.h"
 
 typedef struct _Countstr Countstr;
 
@@ -252,6 +253,7 @@ static void htcpFreeDetail(htcpDetail * s);
 
 static void htcpHandleMsg(char *buf, int sz, IpAddress &from);
 
+static void htcpLogHtcp(IpAddress &, int, log_type, const char *);
 static void htcpHandleMon(htcpDataHeader *, char *buf, int sz, IpAddress &from);
 
 static void htcpHandleNop(htcpDataHeader *, char *buf, int sz, IpAddress &from);
@@ -259,6 +261,7 @@ static void htcpHandleNop(htcpDataHeader *, char *buf, int sz, IpAddress &from);
 static void htcpHandleSet(htcpDataHeader *, char *buf, int sz, IpAddress &from);
 
 static void htcpHandleTst(htcpDataHeader *, char *buf, int sz, IpAddress &from);
+
 static void htcpRecv(int fd, void *data);
 
 static void htcpSend(const char *buf, int len, IpAddress &to);
@@ -1184,23 +1187,26 @@ htcpHandleTstRequest(htcpDataHeader * dhdr, char *buf, int sz, IpAddress &from)
     /* s is a new object */
     s = htcpUnpackSpecifier(buf, sz);
 
-    s->setFrom (from);
+    s->setFrom(from);
 
-    s->setDataHeader (dhdr);
+    s->setDataHeader(dhdr);
 
     if (NULL == s) {
         debugs(31, 2, "htcpHandleTstRequest: htcpUnpackSpecifier failed");
+        htcpLogHtcp(from, dhdr->opcode, LOG_UDP_INVALID, dash_str);
         return;
     }
 
     if (!s->request) {
         debugs(31, 2, "htcpHandleTstRequest: failed to parse request");
+        htcpLogHtcp(from, dhdr->opcode, LOG_UDP_INVALID, dash_str);
         htcpFreeSpecifier(s);
         return;
     }
 
     if (!htcpAccessCheck(Config.accessList.htcp, s, from)) {
         debugs(31, 2, "htcpHandleTstRequest: Access denied");
+        htcpLogHtcp(from, dhdr->opcode, LOG_UDP_DENIED, s->uri);
         htcpFreeSpecifier(s);
         return;
     }
@@ -1213,10 +1219,13 @@ htcpHandleTstRequest(htcpDataHeader * dhdr, char *buf, int sz, IpAddress &from)
 void
 htcpSpecifier::checkedHit(StoreEntry *e)
 {
-    if (e)
+    if (e) {
         htcpTstReply(dhdr, e, this, from);             /* hit */
-    else
+        htcpLogHtcp(from, dhdr->opcode, LOG_UDP_HIT, uri);
+    } else {
         htcpTstReply(dhdr, NULL, NULL, from);  /* cache miss */
+        htcpLogHtcp(from, dhdr->opcode, LOG_UDP_MISS, uri);
+    }
 
     htcpFreeSpecifier(this);
 }
@@ -1236,7 +1245,6 @@ htcpHandleSet(htcpDataHeader * hdr, char *buf, int sz, IpAddress &from)
 }
 
 static void
-
 htcpHandleClr(htcpDataHeader * hdr, char *buf, int sz, IpAddress &from)
 {
     htcpSpecifier *s;
@@ -1250,6 +1258,7 @@ htcpHandleClr(htcpDataHeader * hdr, char *buf, int sz, IpAddress &from)
 
     if (sz == 0) {
         debugs(31, 4, "htcpHandleClr: nothing to do");
+        htcpLogHtcp(from, hdr->opcode, LOG_UDP_INVALID, dash_str);
         return;
     }
 
@@ -1257,11 +1266,13 @@ htcpHandleClr(htcpDataHeader * hdr, char *buf, int sz, IpAddress &from)
 
     if (NULL == s) {
         debugs(31, 3, "htcpHandleClr: htcpUnpackSpecifier failed");
+        htcpLogHtcp(from, hdr->opcode, LOG_UDP_INVALID, dash_str);
         return;
     }
 
     if (!htcpAccessCheck(Config.accessList.htcp_clr, s, from)) {
         debugs(31, 2, "htcpHandleClr: Access denied");
+        htcpLogHtcp(from, hdr->opcode, LOG_UDP_DENIED, s->uri);
         htcpFreeSpecifier(s);
         return;
     }
@@ -1277,10 +1288,12 @@ htcpHandleClr(htcpDataHeader * hdr, char *buf, int sz, IpAddress &from)
 
     case 1:
         htcpClrReply(hdr, 1, from);    /* hit */
+        htcpLogHtcp(from, hdr->opcode, LOG_UDP_HIT, s->uri);
         break;
 
     case 0:
         htcpClrReply(hdr, 0, from);    /* miss */
+        htcpLogHtcp(from, hdr->opcode, LOG_UDP_MISS, s->uri);
         break;
 
     default:
@@ -1689,3 +1702,19 @@ htcpSocketClose(void)
         htcpOutSocket = -1;
     }
 }
+
+static void
+htcpLogHtcp(IpAddress &caddr, int opcode, log_type logcode, const char *url)
+{
+    AccessLogEntry al;
+    if (LOG_TAG_NONE == logcode)
+       return;
+    if (!Config.onoff.log_udp)
+       return;
+    al.htcp.opcode = htcpOpcodeStr[opcode];
+    al.url = url;
+    al.cache.caddr = caddr;
+    al.cache.code = logcode;
+    al.cache.msec = 0;
+    accessLogLog(&al, NULL);
+}
index e679e8f72ebc1a4a99f3882790017fd124dd3a7a..e81dfdcfe46cbbf6224525f8ed501f0815262916 100644 (file)
@@ -837,8 +837,8 @@ struct peer {
         int counts[ICP_END+1];
         u_short port;
     } icp;
-#if USE_HTCP
 
+#if USE_HTCP
     struct {
         double version;
         int counts[2];