--------------------- PatchSet 5279 Date: 2002/10/07 15:33:27 Author: rbcollins Branch: rbcollins_cxxtest Tag: (none) Log: extract method on icp sending code Members: src/icp_v2.cc:1.1.2.3->1.1.2.4 src/icp_v3.cc:1.1.2.5->1.1.2.6 src/protos.h:1.63.2.10->1.63.2.11 Index: squid/src/icp_v2.cc =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/icp_v2.cc,v retrieving revision 1.1.2.3 retrieving revision 1.1.2.4 diff -u -r1.1.2.3 -r1.1.2.4 --- squid/src/icp_v2.cc 7 Oct 2002 15:09:28 -0000 1.1.2.3 +++ squid/src/icp_v2.cc 7 Oct 2002 15:33:27 -0000 1.1.2.4 @@ -1,6 +1,6 @@ /* - * $Id: icp_v2.cc,v 1.1.2.3 2002/10/07 15:09:28 rbcollins Exp $ + * $Id: icp_v2.cc,v 1.1.2.4 2002/10/07 15:33:27 rbcollins Exp $ * * DEBUG: section 12 Internet Cache Protocol * AUTHOR: Duane Wessels @@ -201,21 +201,42 @@ { /* if store is rebuilding, return a UDP_HIT, but not a MISS */ if (store_dirs_rebuilding && opt_reload_hit_only) { - icp_common_t *reply = (icp_common_t *) icpCreateMessage(ICP_MISS_NOFETCH, flags, url, reqnum, pad); - icpUdpSend(fd, from, reply, LOG_UDP_MISS_NOFETCH, 0); + icpReallyCreateAndSend (ICP_MISS_NOFETCH, flags, url, reqnum, pad, fd, from); return 1; } else if (hit_only_mode_until > squid_curtime) { - icp_common_t *reply = (icp_common_t *) icpCreateMessage(ICP_MISS_NOFETCH, flags, url, reqnum, pad); - icpUdpSend(fd, from, reply, LOG_UDP_MISS_NOFETCH, 0); + icpReallyCreateAndSend (ICP_MISS_NOFETCH, flags, url, reqnum, pad, fd, from); return 1; } return 0; } +log_type +icpLogFromICPCode(icp_opcode opcode) +{ + if (opcode == ICP_ERR) + return LOG_UDP_INVALID; + if (opcode == ICP_DENIED) + return LOG_UDP_DENIED; + if (opcode == ICP_HIT) + return LOG_UDP_HIT; + if (opcode == ICP_MISS) + return LOG_UDP_MISS; + if (opcode == ICP_MISS_NOFETCH) + return LOG_UDP_MISS_NOFETCH; + fatal("expected ICP opcode\n"); + return LOG_UDP_INVALID; +} + +void +icpReallyCreateAndSend(icp_opcode opcode, int flags, char const *url, int reqnum, int pad, int fd, const struct sockaddr_in *from) +{ + icp_common_t *reply = (icp_common_t *) icpCreateMessage(opcode, flags, url, reqnum, pad); + icpUdpSend(fd, from, reply, icpLogFromICPCode(opcode), 0); +} + static void doV2Query(int fd, struct sockaddr_in from, char *buf, icp_common_t header) { - icp_common_t *reply; request_t *icp_request = NULL; aclCheck_t checklist; int allow = 0; @@ -227,13 +248,11 @@ char *url = buf + sizeof(icp_common_t) + sizeof(u_int32_t); if (strpbrk(url, w_space)) { url = rfc1738_escape(url); - reply = (icp_common_t *) icpCreateMessage(ICP_ERR, 0, url, header.reqnum, 0); - icpUdpSend(fd, &from, reply, LOG_UDP_INVALID, 0); + icpReallyCreateAndSend(ICP_ERR, 0, url, header.reqnum, 0, fd, &from); return; } if ((icp_request = urlParse(METHOD_GET, url)) == NULL) { - reply = (icp_common_t *) icpCreateMessage(ICP_ERR, 0, url, header.reqnum, 0); - icpUdpSend(fd, &from, reply, LOG_UDP_INVALID, 0); + icpReallyCreateAndSend(ICP_ERR, 0, url, header.reqnum, 0, fd, &from); return; } memset(&checklist, '\0', sizeof(checklist)); @@ -251,8 +270,7 @@ */ clientdbUpdate(from.sin_addr, LOG_UDP_DENIED, PROTO_ICP, 0); } else { - reply = (icp_common_t *) icpCreateMessage(ICP_DENIED, 0, url, header.reqnum, 0); - icpUdpSend(fd, &from, reply, LOG_UDP_DENIED, 0); + icpReallyCreateAndSend(ICP_DENIED, 0, url, header.reqnum, 0, fd, &from); } requestDestroy(icp_request); return; @@ -268,8 +286,7 @@ StoreEntry *entry = storeGetPublic(url, METHOD_GET); debug(12, 5) ("icpHandleIcpV2: OPCODE %s\n", icp_opcode_str[header.opcode]); if (icpCheckUdpHit(entry, icp_request)) { - reply = (icp_common_t *) icpCreateMessage(ICP_HIT, flags, url, header.reqnum, src_rtt); - icpUdpSend(fd, &from, reply, LOG_UDP_HIT, 0); + icpReallyCreateAndSend(ICP_HIT, flags, url, header.reqnum, src_rtt, fd, &from); requestDestroy(icp_request); return; } @@ -278,13 +295,10 @@ netdbPingSite(icp_request->host); } if (!icpCreateAndSend(fd, &from, flags, url, header.reqnum, src_rtt)) { - if (Config.onoff.test_reachability && rtt == 0) { - reply = (icp_common_t *) icpCreateMessage(ICP_MISS_NOFETCH, flags, url, header.reqnum, src_rtt); - icpUdpSend(fd, &from, reply, LOG_UDP_MISS_NOFETCH, 0); - } else { - reply = (icp_common_t *) icpCreateMessage(ICP_MISS, flags, url, header.reqnum, src_rtt); - icpUdpSend(fd, &from, reply, LOG_UDP_MISS, 0); - } + if (Config.onoff.test_reachability && rtt == 0) + icpReallyCreateAndSend(ICP_MISS_NOFETCH, flags, url, header.reqnum, src_rtt, fd, &from); + else + icpReallyCreateAndSend(ICP_MISS, flags, url, header.reqnum, src_rtt, fd, &from); } requestDestroy(icp_request); } @@ -313,7 +327,7 @@ switch (header.opcode) { case ICP_QUERY: /* We have a valid packet */ - doV2Query (fd, from, buf, header); + doV2Query(fd, from, buf, header); break; case ICP_HIT: Index: squid/src/icp_v3.cc =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/icp_v3.cc,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -u -r1.1.2.5 -r1.1.2.6 --- squid/src/icp_v3.cc 7 Oct 2002 15:09:28 -0000 1.1.2.5 +++ squid/src/icp_v3.cc 7 Oct 2002 15:33:28 -0000 1.1.2.6 @@ -1,6 +1,6 @@ /* - * $Id: icp_v3.cc,v 1.1.2.5 2002/10/07 15:09:28 rbcollins Exp $ + * $Id: icp_v3.cc,v 1.1.2.6 2002/10/07 15:33:28 rbcollins Exp $ * * DEBUG: section 12 Internet Cache Protocol * AUTHOR: Duane Wessels @@ -52,7 +52,6 @@ static void doV3Query(int fd, struct sockaddr_in from, char *buf, icp_common_t header) { - icp_common_t *reply; request_t *icp_request = NULL; aclCheck_t checklist; int allow = 0; @@ -60,13 +59,11 @@ char *url = buf + sizeof(icp_common_t) + sizeof(u_int32_t); if (strpbrk(url, w_space)) { url = rfc1738_escape(url); - reply = (icp_common_t *) icpCreateMessage(ICP_ERR, 0, url, header.reqnum, 0); - icpUdpSend(fd, &from, reply, LOG_UDP_INVALID, 0); + icpReallyCreateAndSend (ICP_ERR,0,url,header.reqnum,0,fd,&from); return; } if ((icp_request = urlParse(METHOD_GET, url)) == NULL) { - reply = (icp_common_t *) icpCreateMessage(ICP_ERR, 0, url, header.reqnum, 0); - icpUdpSend(fd, &from, reply, LOG_UDP_INVALID, 0); + icpReallyCreateAndSend (ICP_ERR,0,url,header.reqnum,0,fd,&from); return; } memset(&checklist, '\0', sizeof(checklist)); @@ -84,8 +81,7 @@ */ clientdbUpdate(from.sin_addr, LOG_UDP_DENIED, PROTO_ICP, 0); } else { - reply = (icp_common_t *) icpCreateMessage(ICP_DENIED, 0, url, header.reqnum, 0); - icpUdpSend(fd, &from, reply, LOG_UDP_DENIED, 0); + icpReallyCreateAndSend (ICP_DENIED, 0, url, header.reqnum,0,fd,&from); } requestDestroy(icp_request); return; @@ -114,11 +110,9 @@ debug(12, 5) ("icpHandleIcpV3: OPCODE %s\n", icp_opcode_str[header.opcode]); if (icpCheckUdpHit(entry, request)) { - icp_common_t *reply = (icp_common_t *) icpCreateMessage(ICP_HIT, 0, url, header.reqnum, 0); - icpUdpSend(fd, &from, reply, LOG_UDP_HIT, 0); + icpReallyCreateAndSend (ICP_HIT, 0, url, header.reqnum, 0, fd, &from); } else if (!icpCreateAndSend(fd, &from, 0, url, header.reqnum,0)) { - icp_common_t *reply = (icp_common_t *) icpCreateMessage(ICP_MISS, 0, url, header.reqnum, 0); - icpUdpSend(fd, &from, reply, LOG_UDP_MISS, 0); + icpReallyCreateAndSend (ICP_MISS, 0, url, header.reqnum, 0, fd, &from); } delete this; } Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.63.2.10 retrieving revision 1.63.2.11 diff -u -r1.63.2.10 -r1.63.2.11 --- squid/src/protos.h 7 Oct 2002 15:09:28 -0000 1.63.2.10 +++ squid/src/protos.h 7 Oct 2002 15:33:28 -0000 1.63.2.11 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.63.2.10 2002/10/07 15:09:28 rbcollins Exp $ + * $Id: protos.h,v 1.63.2.11 2002/10/07 15:33:28 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -536,6 +536,7 @@ const char *url, int reqnum, int pad); +SQUIDCEXTERN void icpReallyCreateAndSend (icp_opcode, int flags, char const *url, int reqnum, int pad, int fd, const struct sockaddr_in *from); SQUIDCEXTERN int icpCreateAndSend(int fd, const struct sockaddr_in *from, int flags, const char *url, int reqnum, int pad); SQUIDCEXTERN int icpUdpSend(int, const struct sockaddr_in *, icp_common_t *, log_type, int);