--------------------- PatchSet 5295 Date: 2002/10/08 03:15:50 Author: rbcollins Branch: rbcollins_cxxtest Tag: (none) Log: extract reply hanlding method Members: src/ICP.h:1.1.2.2->1.1.2.3 src/icp_v2.cc:1.1.2.14->1.1.2.15 src/icp_v3.cc:1.1.2.14->1.1.2.15 Index: squid/src/ICP.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/ICP.h,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -u -r1.1.2.2 -r1.1.2.3 --- squid/src/ICP.h 8 Oct 2002 02:48:42 -0000 1.1.2.2 +++ squid/src/ICP.h 8 Oct 2002 03:15:50 -0000 1.1.2.3 @@ -1,6 +1,6 @@ /* - * $Id: ICP.h,v 1.1.2.2 2002/10/08 02:48:42 rbcollins Exp $ + * $Id: ICP.h,v 1.1.2.3 2002/10/08 03:15:50 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -53,6 +53,7 @@ u_int32_t shostid; /* sender host id */ #ifdef __cplusplus _icp_common_t (char *buf, unsigned int len); + void handleReply(char *buf, struct sockaddr_in *from); #endif }; Index: squid/src/icp_v2.cc =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/icp_v2.cc,v retrieving revision 1.1.2.14 retrieving revision 1.1.2.15 diff -u -r1.1.2.14 -r1.1.2.15 --- squid/src/icp_v2.cc 8 Oct 2002 02:48:42 -0000 1.1.2.14 +++ squid/src/icp_v2.cc 8 Oct 2002 03:15:50 -0000 1.1.2.15 @@ -1,6 +1,6 @@ /* - * $Id: icp_v2.cc,v 1.1.2.14 2002/10/08 02:48:42 rbcollins Exp $ + * $Id: icp_v2.cc,v 1.1.2.15 2002/10/08 03:15:50 rbcollins Exp $ * * DEBUG: section 12 Internet Cache Protocol * AUTHOR: Duane Wessels @@ -48,9 +48,9 @@ static icpUdpData *IcpQueueTail = NULL; /* icp_common_t */ -_icp_common_t::_icp_common_t(char * buf, unsigned int len) +_icp_common_t::_icp_common_t(char *buf, unsigned int len) { - if (len < sizeof (_icp_common_t)) { + if (len < sizeof(_icp_common_t)) { /* mark as invalid */ length = len + 1; return; @@ -67,11 +67,13 @@ /* ICPState */ -ICPState::ICPState (icp_common_t &aHeader) : header(aHeader){} +ICPState:: ICPState(icp_common_t & aHeader):header(aHeader) +{ +} -ICPState::~ICPState () +ICPState::~ICPState() { - safe_free (url); + safe_free(url); if (request) requestDestroy(request); } @@ -79,11 +81,11 @@ /* End ICPState */ -class ICP2State : public ICPState, public StoreClient { -public: - ICP2State(icp_common_t &aHeader) : ICPState (aHeader){} - ~ICP2State(); - void created (StoreEntry *newEntry); +class ICP2State:public ICPState, public StoreClient { + public: + ICP2State(icp_common_t & aHeader):ICPState(aHeader) { + } ~ICP2State(); + void created(StoreEntry * newEntry); }; static void @@ -220,8 +222,8 @@ } /* ICP_ERR means no opcode selected here */ -icp_opcode -icpGetCommonOpcode () +icp_opcode +icpGetCommonOpcode() { /* if store is rebuilding, return a UDP_HIT, but not a MISS */ if (store_dirs_rebuilding && opt_reload_hit_only || @@ -259,7 +261,7 @@ icpDenyAccess(struct sockaddr_in *from, char *url, int reqnum, int fd) { debug(12, 2) ("icpDenyAccess: Access Denied for %s by %s.\n", - inet_ntoa(from->sin_addr), AclMatchedName); + inet_ntoa(from->sin_addr), AclMatchedName); if (clientdbCutoffDenied(from->sin_addr)) { /* * count this DENIED query in the clientdb, even though @@ -272,7 +274,7 @@ } int -icpAccessAllowed(struct sockaddr_in *from, request_t *icp_request) +icpAccessAllowed(struct sockaddr_in *from, request_t * icp_request) { aclCheck_t checklist; memset(&checklist, '\0', sizeof(checklist)); @@ -292,7 +294,7 @@ } request_t * -icpGetRequest (char *url, int reqnum, int fd, struct sockaddr_in *from) +icpGetRequest(char *url, int reqnum, int fd, struct sockaddr_in * from) { if (strpbrk(url, w_space)) { url = rfc1738_escape(url); @@ -303,7 +305,7 @@ if ((result = urlParse(METHOD_GET, url)) == NULL) icpCreateAndSend(ICP_ERR, 0, url, reqnum, 0, fd, from); return result; - + } static void @@ -315,11 +317,11 @@ u_int32_t flags = 0; /* We have a valid packet */ char *url = buf + sizeof(icp_common_t) + sizeof(u_int32_t); - request_t *icp_request = icpGetRequest (url, header.reqnum, fd, &from); + request_t *icp_request = icpGetRequest(url, header.reqnum, fd, &from); if (!icp_request) return; if (!icpAccessAllowed(&from, icp_request)) { - icpDenyAccess (&from, url, header.reqnum, fd); + icpDenyAccess(&from, url, header.reqnum, fd); requestDestroy(icp_request); return; } @@ -341,8 +343,8 @@ if ((rtt = netdbHostRtt(icp_request->host)) == 0) netdbPingSite(icp_request->host); } - if (icpGetCommonOpcode () != ICP_ERR) - codeToSend = icpGetCommonOpcode (); + if (icpGetCommonOpcode() != ICP_ERR) + codeToSend = icpGetCommonOpcode(); else if (Config.onoff.test_reachability && rtt == 0) codeToSend = ICP_MISS_NOFETCH; else @@ -352,6 +354,25 @@ requestDestroy(icp_request); } +void +_icp_common_t::handleReply(char *buf, struct sockaddr_in *from) +{ + if (neighbors_do_private_keys && reqnum == 0) { + debug(12, 0) ("icpHandleIcpV2: Neighbor %s returned reqnum = 0\n", + inet_ntoa(from->sin_addr)); + debug(12, 0) ("icpHandleIcpV2: Disabling use of private keys\n"); + neighbors_do_private_keys = 0; + } + char *url = buf + sizeof(icp_common_t); + debug(12, 3) ("icpHandleIcpV2: %s from %s for '%s'\n", + icp_opcode_str[opcode], + inet_ntoa(from->sin_addr), + url); + const cache_key *key = icpGetCacheKey(url, (int) reqnum); + /* call neighborsUdpAck even if ping_status != PING_WAITING */ + neighborsUdpAck(key, this, from); +} + static void icpHandleIcpV2(int fd, struct sockaddr_in from, char *buf, int len) { @@ -359,9 +380,7 @@ debug(12, 3) ("icpHandleIcpV2: ICP message is too small\n"); return; } - icp_common_t header (buf, len); - char *url = NULL; - const cache_key *key; + icp_common_t header(buf, len); /* * Length field should match the number of bytes read */ @@ -383,20 +402,7 @@ case ICP_MISS: case ICP_DENIED: case ICP_MISS_NOFETCH: - if (neighbors_do_private_keys && header.reqnum == 0) { - debug(12, 0) ("icpHandleIcpV2: Neighbor %s returned reqnum = 0\n", - inet_ntoa(from.sin_addr)); - debug(12, 0) ("icpHandleIcpV2: Disabling use of private keys\n"); - neighbors_do_private_keys = 0; - } - url = buf + sizeof(icp_common_t); - debug(12, 3) ("icpHandleIcpV2: %s from %s for '%s'\n", - icp_opcode_str[header.opcode], - inet_ntoa(from.sin_addr), - url); - key = icpGetCacheKey(url, (int) header.reqnum); - /* call neighborsUdpAck even if ping_status != PING_WAITING */ - neighborsUdpAck(key, &header, &from); + header.handleReply(buf, &from); break; case ICP_INVALID: Index: squid/src/icp_v3.cc =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/icp_v3.cc,v retrieving revision 1.1.2.14 retrieving revision 1.1.2.15 diff -u -r1.1.2.14 -r1.1.2.15 --- squid/src/icp_v3.cc 8 Oct 2002 02:48:42 -0000 1.1.2.14 +++ squid/src/icp_v3.cc 8 Oct 2002 03:15:50 -0000 1.1.2.15 @@ -1,6 +1,6 @@ /* - * $Id: icp_v3.cc,v 1.1.2.14 2002/10/08 02:48:42 rbcollins Exp $ + * $Id: icp_v3.cc,v 1.1.2.15 2002/10/08 03:15:50 rbcollins Exp $ * * DEBUG: section 12 Internet Cache Protocol * AUTHOR: Duane Wessels @@ -96,8 +96,6 @@ return; } icp_common_t header (buf, len); - char *url = NULL; - const cache_key *key; /* * Length field should match the number of bytes read */ @@ -118,20 +116,7 @@ case ICP_MISS: case ICP_DENIED: case ICP_MISS_NOFETCH: - if (neighbors_do_private_keys && header.reqnum == 0) { - debug(12, 0) ("icpHandleIcpV3: Neighbor %s returned reqnum = 0\n", - inet_ntoa(from.sin_addr)); - debug(12, 0) ("icpHandleIcpV3: Disabling use of private keys\n"); - neighbors_do_private_keys = 0; - } - url = buf + sizeof(icp_common_t); - debug(12, 3) ("icpHandleIcpV3: %s from %s for '%s'\n", - icp_opcode_str[header.opcode], - inet_ntoa(from.sin_addr), - url); - key = icpGetCacheKey(url, (int) header.reqnum); - /* call neighborsUdpAck even if ping_status != PING_WAITING */ - neighborsUdpAck(key, &header, &from); + header.handleReply(buf, &from); break; case ICP_INVALID: