--------------------- PatchSet 5294 Date: 2002/10/08 02:48:42 Author: rbcollins Branch: rbcollins_cxxtest Tag: (none) Log: extract header initalisation Members: src/ICP.h:1.1.2.1->1.1.2.2 src/icp_v2.cc:1.1.2.13->1.1.2.14 src/icp_v3.cc:1.1.2.13->1.1.2.14 Index: squid/src/ICP.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/ICP.h,v retrieving revision 1.1.2.1 retrieving revision 1.1.2.2 diff -u -r1.1.2.1 -r1.1.2.2 --- squid/src/ICP.h 8 Oct 2002 02:25:37 -0000 1.1.2.1 +++ squid/src/ICP.h 8 Oct 2002 02:48:42 -0000 1.1.2.2 @@ -1,6 +1,6 @@ /* - * $Id: ICP.h,v 1.1.2.1 2002/10/08 02:25:37 rbcollins Exp $ + * $Id: ICP.h,v 1.1.2.2 2002/10/08 02:48:42 rbcollins Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -39,6 +39,10 @@ #ifdef __cplusplus #endif +/* This struct is the wire-level header. + * DO NOT add ore move fields on pain of breakage. + * DO NOT add virtual methods. + */ struct _icp_common_t { unsigned char opcode; /* opcode */ unsigned char version; /* version number */ @@ -47,8 +51,25 @@ u_int32_t flags; u_int32_t pad; u_int32_t shostid; /* sender host id */ +#ifdef __cplusplus + _icp_common_t (char *buf, unsigned int len); +#endif }; +#ifdef __cplusplus +/* todo: mempool this */ +class ICPState { + public: + ICPState (icp_common_t &); + virtual ~ICPState(); + icp_common_t header; + request_t *request; + int fd; + struct sockaddr_in from; + char *url; +}; +#endif + request_t * icpGetRequest(char *url, int reqnum, int fd, struct sockaddr_in *from); int icpAccessAllowed(struct sockaddr_in *from, request_t * icp_request); Index: squid/src/icp_v2.cc =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/icp_v2.cc,v retrieving revision 1.1.2.13 retrieving revision 1.1.2.14 diff -u -r1.1.2.13 -r1.1.2.14 --- squid/src/icp_v2.cc 8 Oct 2002 02:25:37 -0000 1.1.2.13 +++ squid/src/icp_v2.cc 8 Oct 2002 02:48:42 -0000 1.1.2.14 @@ -1,6 +1,6 @@ /* - * $Id: icp_v2.cc,v 1.1.2.13 2002/10/08 02:25:37 rbcollins Exp $ + * $Id: icp_v2.cc,v 1.1.2.14 2002/10/08 02:48:42 rbcollins Exp $ * * DEBUG: section 12 Internet Cache Protocol * AUTHOR: Duane Wessels @@ -47,16 +47,43 @@ */ static icpUdpData *IcpQueueTail = NULL; -/* todo: mempool this */ -class ICP2State:public StoreClient { - public: - ~ICP2State(); - void created(StoreEntry * newEntry); - icp_common_t header; - request_t *request; - int fd; - struct sockaddr_in from; - char *url; +/* icp_common_t */ +_icp_common_t::_icp_common_t(char * buf, unsigned int len) +{ + if (len < sizeof (_icp_common_t)) { + /* mark as invalid */ + length = len + 1; + return; + } + xmemcpy(this, buf, sizeof(icp_common_t)); + /* + * Convert network order sensitive fields + */ + length = ntohs(length); + reqnum = ntohl(reqnum); + flags = ntohl(flags); + pad = ntohl(pad); +} + +/* ICPState */ + +ICPState::ICPState (icp_common_t &aHeader) : header(aHeader){} + +ICPState::~ICPState () +{ + safe_free (url); + if (request) + requestDestroy(request); +} + + +/* End ICPState */ + +class ICP2State : public ICPState, public StoreClient { +public: + ICP2State(icp_common_t &aHeader) : ICPState (aHeader){} + ~ICP2State(); + void created (StoreEntry *newEntry); }; static void @@ -328,17 +355,13 @@ static void icpHandleIcpV2(int fd, struct sockaddr_in from, char *buf, int len) { - icp_common_t header; + if (len <= 0) { + debug(12, 3) ("icpHandleIcpV2: ICP message is too small\n"); + return; + } + icp_common_t header (buf, len); char *url = NULL; const cache_key *key; - xmemcpy(&header, buf, sizeof(icp_common_t)); - /* - * Only these fields need to be converted - */ - header.length = ntohs(header.length); - header.reqnum = ntohl(header.reqnum); - header.flags = ntohl(header.flags); - header.pad = ntohl(header.pad); /* * Length field should match the number of bytes read */ Index: squid/src/icp_v3.cc =================================================================== RCS file: /cvsroot/squid-sf//squid/src/Attic/icp_v3.cc,v retrieving revision 1.1.2.13 retrieving revision 1.1.2.14 diff -u -r1.1.2.13 -r1.1.2.14 --- squid/src/icp_v3.cc 8 Oct 2002 02:25:37 -0000 1.1.2.13 +++ squid/src/icp_v3.cc 8 Oct 2002 02:48:42 -0000 1.1.2.14 @@ -1,6 +1,6 @@ /* - * $Id: icp_v3.cc,v 1.1.2.13 2002/10/08 02:25:37 rbcollins Exp $ + * $Id: icp_v3.cc,v 1.1.2.14 2002/10/08 02:48:42 rbcollins Exp $ * * DEBUG: section 12 Internet Cache Protocol * AUTHOR: Duane Wessels @@ -37,16 +37,11 @@ #include "Store.h" #include "ICP.h" -/* todo: mempool this */ -class ICP3State : public StoreClient { +class ICP3State : public ICPState, public StoreClient { public: + ICP3State(icp_common_t &aHeader):ICPState(aHeader){} ~ICP3State(); void created (StoreEntry *newEntry); - icp_common_t header; - request_t *request; - int fd; - struct sockaddr_in from; - char *url; }; static void @@ -63,8 +58,7 @@ return; } /* The peer is allowed to use this cache */ - ICP3State *state = new ICP3State; - state->header = header; + ICP3State *state = new ICP3State (header); state->request = icp_request; state->fd = fd; state->from = from; @@ -74,9 +68,6 @@ ICP3State::~ICP3State () { - safe_free (url); - if (request) - requestDestroy(request); } void @@ -100,17 +91,13 @@ void icpHandleIcpV3(int fd, struct sockaddr_in from, char *buf, int len) { - icp_common_t header; + if (len <= 0) { + debug(12, 3) ("icpHandleIcpV3: ICP message is too small\n"); + return; + } + icp_common_t header (buf, len); char *url = NULL; const cache_key *key; - xmemcpy(&header, buf, sizeof(icp_common_t)); - /* - * Only these fields need to be converted - */ - header.length = ntohs(header.length); - header.reqnum = ntohl(header.reqnum); - header.flags = ntohl(header.flags); - header.pad = ntohl(header.pad); /* * Length field should match the number of bytes read */